NvModel.h
Go to the documentation of this file.00001 // TAGRELEASE: PUBLIC 00002 00003 #ifndef NV_MODEL_H 00004 #define NV_MODEL_H 00005 00006 #include <NvFoundation.h> 00007 00008 00009 #include <vector> 00010 #include "NV/NvMath.h" 00011 00014 00016 struct NvModelPrimType { 00017 NvModelPrimType() {} 00018 enum Enum { 00019 NONE = 0x0, 00020 POINTS = 0x1, 00021 EDGES = 0x2, 00022 TRIANGLES = 0x4, 00023 TRIANGLES_WITH_ADJACENCY = 0x8, 00024 ALL = 0xf 00025 }; 00026 }; 00027 00032 class NvModel { 00033 private: 00034 NvModel(); 00035 00036 public: 00037 00040 static NvModel* Create(); 00041 00042 virtual ~NvModel(); 00043 00049 bool loadModelFromFileDataObj( char* fileData); 00050 00062 void compileModel( NvModelPrimType::Enum prim = NvModelPrimType::TRIANGLES); 00063 00069 void computeBoundingBox( nv::vec3f &minVal, nv::vec3f &maxVal); 00070 00075 void rescale( float radius); 00076 00082 void rescaleToOrigin( float radius); 00083 00092 void rescaleWithCenter( nv::vec3f center, nv::vec3f r, float radius); 00093 00097 void addToAllPositions( nv::vec3f center); 00098 00099 00107 void computeTangents(); 00108 00114 void computeNormals(); 00115 00118 void removeDegeneratePrims(); 00119 00123 bool hasNormals() const; 00124 bool hasTexCoords() const; 00125 bool hasTangents() const; 00126 bool hasColors() const; 00128 00132 int32_t getPositionSize() const; 00133 int32_t getNormalSize() const; 00134 int32_t getTexCoordSize() const; 00135 int32_t getTangentSize() const; 00136 int32_t getColorSize() const; 00138 00143 void clearNormals(); 00144 void clearTexCoords(); 00145 void clearTangents(); 00146 void clearColors(); 00148 00155 const float* getPositions() const; 00156 const float* getNormals() const; 00157 const float* getTexCoords() const; 00158 const float* getTangents() const; 00159 const float* getColors() const; 00161 00168 const uint32_t* getPositionIndices() const; 00169 const uint32_t* getNormalIndices() const; 00170 const uint32_t* getTexCoordIndices() const; 00171 const uint32_t* getTangentIndices() const; 00172 const uint32_t* getColorIndices() const; 00174 00180 int32_t getPositionCount() const; 00181 int32_t getNormalCount() const; 00182 int32_t getTexCoordCount() const; 00183 int32_t getTangentCount() const; 00184 int32_t getColorCount() const; 00186 00189 int32_t getIndexCount() const; 00190 00194 const float* getCompiledVertices() const; 00195 00200 const uint32_t* getCompiledIndices( NvModelPrimType::Enum prim = NvModelPrimType::TRIANGLES) const; 00201 00205 int32_t getCompiledPositionOffset() const; 00206 int32_t getCompiledNormalOffset() const; 00207 int32_t getCompiledTexCoordOffset() const; 00208 int32_t getCompiledTangentOffset() const; 00209 int32_t getCompiledColorOffset() const; 00211 00214 int32_t getCompiledVertexSize() const; 00215 00218 int32_t getCompiledVertexCount() const; 00219 00223 int32_t getCompiledIndexCount( NvModelPrimType::Enum prim = NvModelPrimType::TRIANGLES) const; 00224 00225 int32_t getOpenEdgeCount() const; 00226 00227 protected: 00229 static const int32_t NumPrimTypes = 4; 00230 00231 //Would all this be better done as a channel abstraction to handle more arbitrary data? 00232 00233 //data structures for model data, not optimized for rendering 00234 std::vector<float> _positions; 00235 std::vector<float> _normals; 00236 std::vector<float> _texCoords; 00237 std::vector<float> _sTangents; 00238 std::vector<float> _colors; 00239 int32_t _posSize; 00240 int32_t _tcSize; 00241 int32_t _cSize; 00242 00243 std::vector<uint32_t> _pIndex; 00244 std::vector<uint32_t> _nIndex; 00245 std::vector<uint32_t> _tIndex; 00246 std::vector<uint32_t> _tanIndex; 00247 std::vector<uint32_t> _cIndex; 00248 00249 //data structures optimized for rendering, compiled model 00250 std::vector<uint32_t> _indices[NumPrimTypes]; 00251 std::vector<float> _vertices; 00252 int32_t _pOffset; 00253 int32_t _nOffset; 00254 int32_t _tcOffset; 00255 int32_t _sTanOffset; 00256 int32_t _cOffset; 00257 int32_t _vtxSize; 00258 00259 int32_t _openEdges; 00260 00261 static bool loadObjFromFileData( char *fileData, NvModel &m); 00262 }; 00263 00264 #endif