00001 /*======================================================================= 00002 * Copyright 1991-1996, Silicon Graphics, Inc. 00003 * ALL RIGHTS RESERVED 00004 * 00005 * UNPUBLISHED -- Rights reserved under the copyright laws of the United 00006 * States. Use of a copyright notice is precautionary only and does not 00007 * imply publication or disclosure. 00008 * 00009 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: 00010 * Use, duplication or disclosure by the Government is subject to restrictions 00011 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights 00012 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or 00013 * in similar or successor clauses in the FAR, or the DOD or NASA FAR 00014 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., 00015 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. 00016 * 00017 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY 00018 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, 00019 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY 00020 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON 00021 * GRAPHICS, INC. 00022 **=======================================================================*/ 00023 /*======================================================================= 00024 ** Author : Paul S. Strauss (MMM yyyy) 00025 **=======================================================================*/ 00026 /*======================================================================= 00027 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00028 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00029 *** *** 00030 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00031 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00032 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00033 *** *** 00034 *** RESTRICTED RIGHTS LEGEND *** 00035 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00036 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00037 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00038 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00039 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00040 *** *** 00041 *** COPYRIGHT (C) 1996-2017 BY FEI S.A.S, *** 00042 *** BORDEAUX, FRANCE *** 00043 *** ALL RIGHTS RESERVED *** 00044 **=======================================================================*/ 00045 /*======================================================================= 00046 ** Modified by : VSG (MMM YYYY) 00047 **=======================================================================*/ 00048 00049 00050 #ifndef _SO_NORMAL_BUNDLE 00051 #define _SO_NORMAL_BUNDLE 00052 00053 #include <Inventor/bundles/SoBundle.h> 00054 #include <Inventor/elements/SoNormalElement.h> 00055 #include <Inventor/elements/SoNormalBindingElement.h> 00056 #include <Inventor/misc/SoNormalGenerator.h> 00057 00058 class SoNormalCache; 00059 00061 // 00062 // Class: SoNormalBundle 00063 // 00064 // Bundle that allows shapes to deal with normals and normal bindings 00065 // more easily. This class provides a fairly simple interface to 00066 // normal handling, including normal generation. 00067 // 00068 // This class can be used during either rendering or primitive 00069 // generation. For primitive generation, the get() method can be used 00070 // to access normals. For GL rendering, the send() method can be used 00071 // to send normals to GL. 00072 // 00074 00075 { 00076 00077 public: 00078 00079 // Constructor - takes the action the bundle is used for and a 00080 // flag to indicate whether the bundle is being used for 00081 // rendering. If this is TRUE, the bundle can be used to send 00082 // normals to GL. 00083 SoNormalBundle( SoAction *action, SbBool forRendering ); 00084 00085 // Destructor 00086 virtual ~SoNormalBundle(); 00087 00088 // Returns TRUE if normals need to be generated. 00089 SbBool shouldGenerate(int numNeeded); 00090 00091 // Initializes generation in the case where shouldGenerate() is 00092 // not called. (shouldGenerate() does this automatically). 00093 void initGenerator(int initialNum = 100); 00094 00096 // 00097 // If shouldGenerate() returns TRUE, these methods can be used by 00098 // shapes to specify the geometry to generate normals for. They 00099 // are front-ends to methods on the SoNormalGenerator class: 00100 // 00101 00102 // Send a polygon's worth of vertices. Begin a polygon, send as 00103 // many vertices as you want, and then end the polygon. 00104 void beginPolygon() 00105 { generator->beginPolygon(); } 00106 void polygonVertex(const SbVec3f &point) 00107 { generator->polygonVertex(point); } 00108 void endPolygon() 00109 { generator->endPolygon(); } 00110 00111 // Send a triangle 00112 void triangle(const SbVec3f &p1, 00113 const SbVec3f &p2, 00114 const SbVec3f &p3) 00115 { generator->triangle(p1, p2, p3); } 00116 00117 // See SoNormalGenerator for details. 00118 void setupIndexedVertexArray(const SbVec3f* pointArray) 00119 { generator->setupIndexedVertexArray(pointArray); } 00120 void polygonVertex(const int32_t index) 00121 { generator->polygonVertex(index); } 00122 void triangle(const int32_t index1,const int32_t index2,const int32_t index3) 00123 { generator->triangle(index1,index2,index3); } 00124 void setupIndexedConnectivity(const int32_t* connectivityArray) 00125 { generator->setupIndexedConnectivity(connectivityArray); } 00126 void setupApproxShapeSize(const int32_t numVert,const int32_t numFace) 00127 { generator->setupApproxShapeSize(numVert,numFace); } 00128 00129 // Calculates the normals once all vertices have been sent. The 00130 // normals are stored by the bundle so the caller does not have to 00131 // deal with them directly. The startIndex argument specifies the 00132 // index at which the generated normals will begin-- it can be 00133 // used by shapes that allow the coordinates and normals to be 00134 // offset (non-indexed shapes). If addToState is TRUE, the 00135 // state will be pushed, the normals will be added to the 00136 // state; otherwise, you can just use 00137 // getGeneratedNormals/getNumGeneratedNormals to get the generated 00138 // normals. 00139 // 00140 // The normal bundle DOES NOT FREE the generated normals! It is 00141 // expected that normals will be added to a normal cache, and the 00142 // normal cache will free the normals. 00143 // 00144 void generate(int startIndex = 0, 00145 SbBool addToState=TRUE); 00146 00147 // Returns the generated normals. 00148 const SbVec3f * getGeneratedNormals() const 00149 { return generator->getNormals(); } 00150 int getNumGeneratedNormals() const 00151 { return generator->getNumNormals(); } 00152 SoNormalBindingElement::Binding getNormalBinding() const 00153 { 00154 if (m_isIndexedNormal) 00155 return SoNormalBindingElement::PER_VERTEX_INDEXED; 00156 else 00157 return SoNormalBindingElement::PER_VERTEX; 00158 } 00159 00160 00161 // This allows shapes that generate their own normals (for 00162 // efficiency) to store the resulting normals in the state. The 00163 // bundle takes care of pushing/popping the state. 00164 // Note: This method only adds the normals to the state, it does 00165 // NOT store a pointer to them (so you cannot call the 00166 // getGenerated() routines) 00167 void set( 00168 int32_t numNormals, 00169 const SbVec3f *normals, 00170 const SoNormalBindingElement::Binding binding /*= SoNormalBindingElement::PER_VERTEX */, 00171 const int startIndex = 0 00172 ); 00173 00174 // to set the SoNormalBundle from a SoNormalCache 00175 void set(SoNormalCache* nc); 00176 00177 // Returns indexed normal. This can be used for primitive 00178 // generation or during rendering 00179 const SbVec3f& get(int index) const 00180 { return normElt->getNum() != 0 ? normElt->get(index - m_startIndex) : s_zVers; } 00181 00182 // Sends indexed normal to the GL, for use only during GL rendering 00183 virtual void send(int index) const; 00184 00185 // return the number of normal crack 00186 // -1 if the info is not available. 00187 int numNormalCrack() const 00188 { return generator->numNormalCrack(); } 00189 00190 int getStartIndex() const 00191 { return m_startIndex; } 00192 00193 private: 00194 00195 SoNormalGenerator *generator; // Normal generator 00196 00197 private: 00198 // Normal elements: 00199 const SoNormalElement *normElt; 00200 const SoNormalElement *GLNormElt; 00201 00202 SbBool isRendering; // Bundle being used for rendering 00203 SbBool pushedState; // We pushed state to set normals 00204 SoNode *currentNode; // Node that created the bundle 00205 bool m_isIndexedNormal; 00206 static const SbVec3f s_zVers; 00207 int m_startIndex; // this the offset used in indexing the normals WITHOUT allocating useless memory 00208 bool m_normSetOrGen; 00209 00210 }; 00211 00212 #endif /* _SO_NORMAL_BUNDLE */ 00213 00214