tsMesh.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _TSMESH_H_
  23. #define _TSMESH_H_
  24. #ifndef _STREAM_H_
  25. #include "core/stream/stream.h"
  26. #endif
  27. #ifndef _MMATH_H_
  28. #include "math/mMath.h"
  29. #endif
  30. #ifndef _TVECTOR_H_
  31. #include "core/util/tVector.h"
  32. #endif
  33. #ifndef _ABSTRACTPOLYLIST_H_
  34. #include "collision/abstractPolyList.h"
  35. #endif
  36. #ifndef _GFXDEVICE_H_
  37. #include "gfx/gfxDevice.h"
  38. #endif
  39. #ifndef _GFXPRIMITIVEBUFFER_H_
  40. #include "gfx/gfxPrimitiveBuffer.h"
  41. #endif
  42. #ifndef _TSPARSEARRAY_H_
  43. #include "core/tSparseArray.h"
  44. #endif
  45. #include "core/util/safeDelete.h"
  46. #if defined(TORQUE_OS_XENON)
  47. //# define USE_MEM_VERTEX_BUFFERS
  48. #endif
  49. #if defined(USE_MEM_VERTEX_BUFFERS)
  50. # include "gfx/D3D9/360/gfx360MemVertexBuffer.h"
  51. #endif
  52. namespace Opcode { class Model; class MeshInterface; }
  53. namespace IceMaths { class IndexedTriangle; class Point; }
  54. class Convex;
  55. class SceneRenderState;
  56. class SceneObject;
  57. struct MeshRenderInst;
  58. class TSRenderState;
  59. class RenderPassManager;
  60. class TSMaterialList;
  61. class TSShapeInstance;
  62. struct RayInfo;
  63. class ConvexFeature;
  64. class ShapeBase;
  65. struct TSDrawPrimitive
  66. {
  67. enum
  68. {
  69. Triangles = 0 << 30, ///< bits 30 and 31 index element type
  70. Strip = 1 << 30, ///< bits 30 and 31 index element type
  71. Fan = 2 << 30, ///< bits 30 and 31 index element type
  72. Indexed = BIT(29), ///< use glDrawElements if indexed, glDrawArrays o.w.
  73. NoMaterial = BIT(28), ///< set if no material (i.e., texture missing)
  74. MaterialMask = ~(Strip|Fan|Triangles|Indexed|NoMaterial),
  75. TypeMask = Strip|Fan|Triangles
  76. };
  77. S32 start;
  78. S32 numElements;
  79. S32 matIndex; ///< holds material index & element type (see above enum)
  80. };
  81. #if defined(USE_MEM_VERTEX_BUFFERS)
  82. struct __NullVertexStruct {};
  83. typedef GFX360MemVertexBufferHandle<__NullVertexStruct> TSVertexBufferHandle;
  84. #else
  85. typedef GFXVertexBufferDataHandle TSVertexBufferHandle;
  86. #endif
  87. class TSMesh;
  88. class TSShapeAlloc;
  89. /// @name Vertex format serialization
  90. /// {
  91. struct TSBasicVertexFormat
  92. {
  93. S16 texCoordOffset;
  94. S16 boneOffset;
  95. S16 colorOffset;
  96. S16 numBones;
  97. S16 vertexSize;
  98. TSBasicVertexFormat();
  99. TSBasicVertexFormat(TSMesh *mesh);
  100. void getFormat(GFXVertexFormat &fmt);
  101. void calculateSize();
  102. void writeAlloc(TSShapeAlloc* alloc);
  103. void readAlloc(TSShapeAlloc* alloc);
  104. void addMeshRequirements(TSMesh *mesh);
  105. };
  106. /// }
  107. ///
  108. class TSMesh
  109. {
  110. friend class TSShape;
  111. public:
  112. /// Helper class for a freeable vector
  113. template<class T>
  114. class FreeableVector : public Vector<T>
  115. {
  116. public:
  117. bool free_memory() { return Vector<T>::resize(0); }
  118. FreeableVector<T>& operator=(const Vector<T>& p) { Vector<T>::operator=(p); return *this; }
  119. FreeableVector<T>& operator=(const FreeableVector<T>& p) { Vector<T>::operator=(p); return *this; }
  120. };
  121. /// @name Aligned Vertex Data
  122. /// {
  123. #pragma pack(1)
  124. struct __TSMeshVertexBase
  125. {
  126. Point3F _vert;
  127. F32 _tangentW;
  128. Point3F _normal;
  129. Point3F _tangent;
  130. Point2F _tvert;
  131. const Point3F &vert() const { return _vert; }
  132. void vert(const Point3F &v) { _vert = v; }
  133. const Point3F &normal() const { return _normal; }
  134. void normal(const Point3F &n) { _normal = n; }
  135. Point4F tangent() const { return Point4F(_tangent.x, _tangent.y, _tangent.z, _tangentW); }
  136. void tangent(const Point4F &t) { _tangent = t.asPoint3F(); _tangentW = t.w; }
  137. const Point2F &tvert() const { return _tvert; }
  138. void tvert(const Point2F &tv) { _tvert = tv; }
  139. };
  140. struct __TSMeshVertex_3xUVColor
  141. {
  142. Point2F _tvert2;
  143. GFXVertexColor _color;
  144. const Point2F &tvert2() const { return _tvert2; }
  145. void tvert2(const Point2F& c) { _tvert2 = c; }
  146. const GFXVertexColor &color() const { return _color; }
  147. void color(const GFXVertexColor &c) { _color = c; }
  148. };
  149. struct __TSMeshIndex_List {
  150. U8 x;
  151. U8 y;
  152. U8 z;
  153. U8 w;
  154. };
  155. struct __TSMeshVertex_BoneData
  156. {
  157. __TSMeshIndex_List _indexes;
  158. Point4F _weights;
  159. const __TSMeshIndex_List &index() const { return _indexes; }
  160. void index(const __TSMeshIndex_List& c) { _indexes = c; }
  161. const Point4F &weight() const { return _weights; }
  162. void weight(const Point4F &w) { _weights = w; }
  163. };
  164. #pragma pack()
  165. struct TSMeshVertexArray
  166. {
  167. protected:
  168. U8 *base;
  169. dsize_t vertSz;
  170. U32 numElements;
  171. U32 colorOffset;
  172. U32 boneOffset;
  173. bool vertexDataReady;
  174. bool ownsData;
  175. public:
  176. TSMeshVertexArray() : base(NULL), numElements(0), colorOffset(0), boneOffset(0), vertexDataReady(false), ownsData(false) {}
  177. virtual ~TSMeshVertexArray() { set(NULL, 0, 0, 0, 0); }
  178. virtual void set(void *b, dsize_t s, U32 n, S32 inColorOffset, S32 inBoneOffset, bool nowOwnsData = true)
  179. {
  180. if (base && ownsData)
  181. dFree_aligned(base);
  182. base = reinterpret_cast<U8 *>(b);
  183. vertSz = s;
  184. numElements = n;
  185. colorOffset = inColorOffset >= 0 ? inColorOffset : 0;
  186. boneOffset = inBoneOffset >= 0 ? inBoneOffset : 0;
  187. ownsData = nowOwnsData;
  188. }
  189. /// Gets pointer to __TSMeshVertexBase for vertex idx
  190. __TSMeshVertexBase &getBase(int idx) const
  191. {
  192. AssertFatal(idx < numElements, "Out of bounds access!"); return *reinterpret_cast<__TSMeshVertexBase *>(base + (idx * vertSz));
  193. }
  194. /// Gets pointer to __TSMeshVertex_3xUVColor for vertex idx
  195. __TSMeshVertex_3xUVColor &getColor(int idx) const
  196. {
  197. AssertFatal(idx < numElements, "Out of bounds access!"); return *reinterpret_cast<__TSMeshVertex_3xUVColor *>(base + (idx * vertSz) + colorOffset);
  198. }
  199. /// Gets pointer to __TSMeshVertex_BoneData for vertex idx, additionally offsetted by subBoneList
  200. __TSMeshVertex_BoneData &getBone(int idx, int subBoneList) const
  201. {
  202. AssertFatal(idx < numElements, "Out of bounds access!"); return *reinterpret_cast<__TSMeshVertex_BoneData *>(base + (idx * vertSz) + boneOffset + (sizeof(__TSMeshVertex_BoneData) * subBoneList));
  203. }
  204. /// Returns base address of vertex data
  205. __TSMeshVertexBase *address() const
  206. {
  207. return reinterpret_cast<__TSMeshVertexBase *>(base);
  208. }
  209. U32 size() const { return numElements; }
  210. dsize_t mem_size() const { return numElements * vertSz; }
  211. dsize_t vertSize() const { return vertSz; }
  212. bool isReady() const { return vertexDataReady; }
  213. void setReady(bool r) { vertexDataReady = r; }
  214. U8* getPtr() { return base; }
  215. inline U32 getColorOffset() const { return colorOffset; }
  216. inline U32 getBoneOffset() const { return boneOffset; }
  217. };
  218. protected:
  219. U32 meshType;
  220. Box3F mBounds;
  221. Point3F mCenter;
  222. F32 mRadius;
  223. F32 mVisibility;
  224. const GFXVertexFormat *mVertexFormat;
  225. TSMesh *parentMeshObject; ///< Current parent object instance
  226. U32 mPrimBufferOffset;
  227. GFXVertexBufferDataHandle mVB;
  228. GFXPrimitiveBufferHandle mPB;
  229. public:
  230. S32 parentMesh; ///< index into shapes mesh list
  231. S32 numFrames;
  232. S32 numMatFrames;
  233. S32 vertsPerFrame;
  234. U32 mVertOffset;
  235. U32 mVertSize;
  236. protected:
  237. void _convertToVertexData(TSMeshVertexArray &outArray, const Vector<Point3F> &_verts, const Vector<Point3F> &_norms);
  238. public:
  239. enum
  240. {
  241. /// types...
  242. StandardMeshType = 0,
  243. SkinMeshType = 1,
  244. DecalMeshType = 2,
  245. SortedMeshType = 3,
  246. NullMeshType = 4,
  247. TypeMask = StandardMeshType|SkinMeshType|DecalMeshType|SortedMeshType|NullMeshType,
  248. /// flags (stored with meshType)...
  249. Billboard = BIT(31), HasDetailTexture = BIT(30),
  250. BillboardZAxis = BIT(29), UseEncodedNormals = BIT(28),
  251. HasColor = BIT(27), HasTVert2 = BIT(26),
  252. FlagMask = Billboard|BillboardZAxis|HasDetailTexture|UseEncodedNormals|HasColor|HasTVert2
  253. };
  254. U32 getMeshType() const { return meshType & TypeMask; }
  255. U32 getHasColor() const { return colors.size() > 0 || meshType & HasColor; }
  256. U32 getHasTVert2() const { return tverts2.size() > 0 || meshType & HasTVert2; }
  257. void setFlags(U32 flag) { meshType |= flag; }
  258. void clearFlags(U32 flag) { meshType &= ~flag; }
  259. U32 getFlags( U32 flag = 0xFFFFFFFF ) const { return meshType & flag; }
  260. const Point3F* getNormals( S32 firstVert );
  261. TSMeshVertexArray mVertexData;
  262. U32 mNumVerts; ///< Number of verts allocated in main vertex buffer
  263. virtual void convertToVertexData();
  264. virtual void copySourceVertexDataFrom(const TSMesh* srcMesh);
  265. /// @}
  266. /// @name Vertex data
  267. /// @{
  268. FreeableVector<Point3F> verts;
  269. FreeableVector<Point3F> norms;
  270. FreeableVector<Point2F> tverts;
  271. FreeableVector<Point4F> tangents;
  272. // Optional second texture uvs.
  273. FreeableVector<Point2F> tverts2;
  274. // Optional vertex colors data.
  275. FreeableVector<ColorI> colors;
  276. /// @}
  277. Vector<TSDrawPrimitive> primitives;
  278. Vector<U8> encodedNorms;
  279. Vector<U32> indices;
  280. /// billboard data
  281. Point3F billboardAxis;
  282. /// @name Convex Hull Data
  283. /// Convex hulls are convex (no angles >= 180º) meshes used for collision
  284. /// @{
  285. Vector<Point3F> planeNormals;
  286. Vector<F32> planeConstants;
  287. Vector<U32> planeMaterials;
  288. S32 planesPerFrame;
  289. U32 mergeBufferStart;
  290. /// @}
  291. /// @name Render Methods
  292. /// @{
  293. /// This is used by sgShadowProjector to render the
  294. /// mesh directly, skipping the render manager.
  295. virtual void render( TSVertexBufferHandle &vb );
  296. void innerRender( TSVertexBufferHandle &vb, GFXPrimitiveBufferHandle &pb );
  297. virtual void render( TSMaterialList *,
  298. const TSRenderState &data,
  299. bool isSkinDirty,
  300. const Vector<MatrixF> &transforms,
  301. TSVertexBufferHandle &vertexBuffer,
  302. const char *meshName);
  303. void innerRender( TSMaterialList *, const TSRenderState &data, TSVertexBufferHandle &vb, GFXPrimitiveBufferHandle &pb, const char *meshName );
  304. /// @}
  305. /// @name Material Methods
  306. /// @{
  307. void setFade( F32 fade ) { mVisibility = fade; }
  308. void clearFade() { setFade( 1.0f ); }
  309. /// @}
  310. /// @name Collision Methods
  311. /// @{
  312. virtual bool buildPolyList( S32 frame, AbstractPolyList * polyList, U32 & surfaceKey, TSMaterialList* materials );
  313. virtual bool getFeatures( S32 frame, const MatrixF&, const VectorF&, ConvexFeature*, U32 &surfaceKey );
  314. virtual void support( S32 frame, const Point3F &v, F32 *currMaxDP, Point3F *currSupport );
  315. virtual bool castRay( S32 frame, const Point3F & start, const Point3F & end, RayInfo * rayInfo, TSMaterialList* materials );
  316. virtual bool castRayRendered( S32 frame, const Point3F & start, const Point3F & end, RayInfo * rayInfo, TSMaterialList* materials );
  317. virtual bool buildConvexHull(); ///< returns false if not convex (still builds planes)
  318. bool addToHull( U32 idx0, U32 idx1, U32 idx2 );
  319. /// @}
  320. /// @name Bounding Methods
  321. /// calculate and get bounding information
  322. /// @{
  323. void computeBounds();
  324. virtual void computeBounds( const MatrixF &transform, Box3F &bounds, S32 frame = 0, Point3F *center = NULL, F32 *radius = NULL );
  325. void computeBounds( const Point3F *, S32 numVerts, S32 stride, const MatrixF &transform, Box3F &bounds, Point3F *center, F32 *radius );
  326. const Box3F& getBounds() const { return mBounds; }
  327. const Point3F& getCenter() const { return mCenter; }
  328. F32 getRadius() const { return mRadius; }
  329. virtual S32 getNumPolys() const;
  330. static U8 encodeNormal( const Point3F &normal );
  331. static const Point3F& decodeNormal( U8 ncode ) { return smU8ToNormalTable[ncode]; }
  332. /// @}
  333. virtual U32 getMaxBonesPerVert() { return 0; }
  334. /// persist methods...
  335. virtual void assemble( bool skip );
  336. static TSMesh* assembleMesh( U32 meshType, bool skip );
  337. virtual void disassemble();
  338. void createTangents(const Vector<Point3F> &_verts, const Vector<Point3F> &_norms);
  339. void findTangent( U32 index1,
  340. U32 index2,
  341. U32 index3,
  342. Point3F *tan0,
  343. Point3F *tan1,
  344. const Vector<Point3F> &_verts);
  345. /// on load...optionally convert primitives to other form
  346. static bool smUseTriangles;
  347. static bool smUseOneStrip;
  348. static S32 smMinStripSize;
  349. static bool smUseEncodedNormals;
  350. /// Enables mesh instancing on non-skin meshes that
  351. /// have less that this count of verts.
  352. static S32 smMaxInstancingVerts;
  353. /// Default node transform for standard meshes which have blend indices
  354. static MatrixF smDummyNodeTransform;
  355. /// convert primitives on load...
  356. void convertToTris(const TSDrawPrimitive *primitivesIn, const S32 *indicesIn,
  357. S32 numPrimIn, S32 & numPrimOut, S32 & numIndicesOut,
  358. TSDrawPrimitive *primitivesOut, S32 *indicesOut) const;
  359. void convertToSingleStrip(const TSDrawPrimitive *primitivesIn, const S32 *indicesIn,
  360. S32 numPrimIn, S32 &numPrimOut, S32 &numIndicesOut,
  361. TSDrawPrimitive *primitivesOut, S32 *indicesOut) const;
  362. void leaveAsMultipleStrips(const TSDrawPrimitive *primitivesIn, const S32 *indicesIn,
  363. S32 numPrimIn, S32 &numPrimOut, S32 &numIndicesOut,
  364. TSDrawPrimitive *primitivesOut, S32 *indicesOut) const;
  365. /// Moves vertices from the vertex buffer back into the split vert lists, unless verts already exist
  366. virtual void makeEditable();
  367. /// Clears split vertex lists
  368. virtual void clearEditable();
  369. void updateMeshFlags();
  370. /// methods used during assembly to share vertexand other info
  371. /// between meshes (and for skipping detail levels on load)
  372. S32* getSharedData32( S32 parentMesh, S32 size, S32 **source, bool skip );
  373. S8* getSharedData8( S32 parentMesh, S32 size, S8 **source, bool skip );
  374. /// @name Assembly Variables
  375. /// variables used during assembly (for skipping mesh detail levels
  376. /// on load and for sharing verts between meshes)
  377. /// @{
  378. static Vector<Point3F*> smVertsList;
  379. static Vector<Point3F*> smNormsList;
  380. static Vector<U8*> smEncodedNormsList;
  381. static Vector<Point2F*> smTVertsList;
  382. // Optional second texture uvs.
  383. static Vector<Point2F*> smTVerts2List;
  384. // Optional vertex colors.
  385. static Vector<ColorI*> smColorsList;
  386. static Vector<bool> smDataCopied;
  387. static const Point3F smU8ToNormalTable[];
  388. /// @}
  389. TSMesh();
  390. virtual ~TSMesh();
  391. Opcode::Model *mOptTree;
  392. Opcode::MeshInterface* mOpMeshInterface;
  393. IceMaths::IndexedTriangle* mOpTris;
  394. IceMaths::Point* mOpPoints;
  395. void prepOpcodeCollision();
  396. bool buildConvexOpcode( const MatrixF &mat, const Box3F &bounds, Convex *c, Convex *list );
  397. bool buildPolyListOpcode( const S32 od, AbstractPolyList *polyList, const Box3F &nodeBox, TSMaterialList *materials );
  398. bool castRayOpcode( const Point3F &start, const Point3F &end, RayInfo *rayInfo, TSMaterialList *materials );
  399. void dumpPrimitives(U32 startVertex, U32 startIndex, GFXPrimitive *piArray, U16* ibIndices);
  400. virtual U32 getNumVerts();
  401. static const F32 VISIBILITY_EPSILON;
  402. };
  403. class TSSkinMesh : public TSMesh
  404. {
  405. public:
  406. struct BatchData
  407. {
  408. enum Constants
  409. {
  410. maxBonePerVert = 16, // Assumes a maximum of 4 blocks of bone indices for HW skinning
  411. };
  412. /// @name Batch by vertex
  413. /// These are used for batches where each element is a vertex, built by
  414. /// iterating over 0..maxBonePerVert bone transforms
  415. /// @{
  416. struct TransformOp
  417. {
  418. S32 transformIndex;
  419. F32 weight;
  420. TransformOp() : transformIndex( -1 ), weight( -1.0f ) {}
  421. TransformOp( const S32 tIdx, const F32 w ) : transformIndex( tIdx ), weight( w ) {};
  422. };
  423. struct BatchedVertex
  424. {
  425. S32 vertexIndex;
  426. S32 transformCount;
  427. TransformOp transform[maxBonePerVert];
  428. BatchedVertex() : vertexIndex( -1 ), transformCount( -1 ) {}
  429. };
  430. Vector<BatchedVertex> vertexBatchOperations;
  431. /// @}
  432. // # = num bones
  433. Vector<S32> nodeIndex;
  434. Vector<MatrixF> initialTransforms;
  435. // # = numverts
  436. Vector<Point3F> initialVerts;
  437. Vector<Point3F> initialNorms;
  438. bool initialized;
  439. BatchData() : initialized(false) { ; }
  440. };
  441. /// This method will build the batch operations and prepare the BatchData
  442. /// for use.
  443. void createSkinBatchData();
  444. /// Inserts transform indices and weights into vertex data
  445. void setupVertexTransforms();
  446. /// Returns maximum bones used per vertex
  447. virtual U32 getMaxBonesPerVert();
  448. virtual void convertToVertexData();
  449. virtual void copySourceVertexDataFrom(const TSMesh* srcMesh);
  450. void printVerts();
  451. void addWeightsFromVertexBuffer();
  452. void makeEditable();
  453. void clearEditable();
  454. public:
  455. typedef TSMesh Parent;
  456. /// @name Vertex tuples
  457. /// {
  458. FreeableVector<F32> weight; ///< blend weight
  459. FreeableVector<S32> boneIndex; ///< Maps from mesh node to bone in shape
  460. FreeableVector<S32> vertexIndex; ///< index of affected vertex
  461. /// }
  462. /// Maximum number of bones referenced by this skin mesh
  463. S32 maxBones;
  464. /// Structure containing data needed to batch skinning
  465. BatchData batchData;
  466. /// set verts and normals...
  467. void updateSkinBuffer( const Vector<MatrixF> &transforms, U8 *buffer );
  468. /// update bone transforms for this mesh
  469. void updateSkinBones( const Vector<MatrixF> &transforms, Vector<MatrixF>& destTransforms );
  470. // render methods..
  471. void render( TSVertexBufferHandle &instanceVB );
  472. void render( TSMaterialList *,
  473. const TSRenderState &data,
  474. bool isSkinDirty,
  475. const Vector<MatrixF> &transforms,
  476. TSVertexBufferHandle &vertexBuffer,
  477. const char *meshName );
  478. // collision methods...
  479. bool buildPolyList( S32 frame, AbstractPolyList *polyList, U32 &surfaceKey, TSMaterialList *materials );
  480. bool castRay( S32 frame, const Point3F &start, const Point3F &end, RayInfo *rayInfo, TSMaterialList *materials );
  481. bool buildConvexHull(); // does nothing, skins don't use this
  482. void computeBounds( const MatrixF &transform, Box3F &bounds, S32 frame, Point3F *center, F32 *radius );
  483. /// persist methods...
  484. void assemble( bool skip );
  485. void disassemble();
  486. /// Helper method to add a blend tuple for a vertex
  487. inline void addWeightForVert(U32 vi, U32 bi, F32 w)
  488. {
  489. weight.push_back(w);
  490. boneIndex.push_back(bi);
  491. vertexIndex.push_back(vi);
  492. }
  493. /// variables used during assembly (for skipping mesh detail levels
  494. /// on load and for sharing verts between meshes)
  495. static Vector<MatrixF*> smInitTransformList;
  496. static Vector<S32*> smVertexIndexList;
  497. static Vector<S32*> smBoneIndexList;
  498. static Vector<F32*> smWeightList;
  499. static Vector<S32*> smNodeIndexList;
  500. static bool smDebugSkinVerts;
  501. TSSkinMesh();
  502. };
  503. #endif // _TSMESH_H_