Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

537 lines
22 KiB

  1. //====== Copyright (c) 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // A class representing a mesh
  4. //
  5. //=============================================================================
  6. #ifndef DMEMESH_H
  7. #define DMEMESH_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "movieobjects/dmeshape.h"
  12. #include "movieobjects/dmevertexdata.h"
  13. #include "materialsystem/materialsystemutil.h"
  14. #include "mathlib/vector.h"
  15. #include "tier1/utllinkedlist.h"
  16. #include "Color.h"
  17. //-----------------------------------------------------------------------------
  18. // Forward declarations
  19. //-----------------------------------------------------------------------------
  20. class CDmElement;
  21. class CDmeFaceSet;
  22. class CDmeVertexData;
  23. class IMaterial;
  24. class IMorph;
  25. class IMesh;
  26. class Vector;
  27. class Vector4D;
  28. class Color;
  29. class CDmeDag;
  30. class CMeshBuilder;
  31. class CDmeCombinationOperator;
  32. class CDmeSingleIndexedComponent;
  33. class CDmeDrawSettings;
  34. class CDmMeshComp;
  35. //-----------------------------------------------------------------------------
  36. // Mesh weights
  37. //-----------------------------------------------------------------------------
  38. enum MeshDeltaWeightType_t
  39. {
  40. MESH_DELTA_WEIGHT_FIRST = 0,
  41. MESH_DELTA_WEIGHT_NORMAL = 0,
  42. MESH_DELTA_WEIGHT_LAGGED,
  43. MESH_DELTA_WEIGHT_TYPE_COUNT,
  44. };
  45. //-----------------------------------------------------------------------------
  46. // Mesh representation
  47. //-----------------------------------------------------------------------------
  48. class CDmeMesh : public CDmeShape
  49. {
  50. DEFINE_ELEMENT( CDmeMesh, CDmeShape );
  51. public:
  52. // resolve internal data from changed attributes
  53. virtual void OnAttributeChanged( CDmAttribute *pAttribute );
  54. void GetBoundingSphere( Vector &c, float &r, CDmeVertexData *pPassedBase, CDmeSingleIndexedComponent *pPassedSelection ) const;
  55. virtual void GetBoundingSphere( Vector &c, float &r ) const { return GetBoundingSphere( c, r, NULL, NULL ); }
  56. void GetBoundingBox( Vector &min, Vector &max, CDmeVertexData *pPassedBase /* = NULL */, CDmeSingleIndexedComponent *pPassedSelection /* = NULL */ ) const;
  57. virtual void GetBoundingBox( Vector &min, Vector &max ) const { return GetBoundingBox( min, max, NULL, NULL ); }
  58. // accessors
  59. int FaceSetCount() const;
  60. CDmeFaceSet *GetFaceSet( int nFaceSetIndex );
  61. const CDmeFaceSet *GetFaceSet( int nFaceSetIndex ) const;
  62. void AddFaceSet( CDmeFaceSet *faceSet );
  63. void RemoveFaceSet( int nFaceSetIndex );
  64. // Base states
  65. int BaseStateCount() const;
  66. CDmeVertexData *GetBaseState( int nBaseIndex ) const;
  67. CDmeVertexData *FindBaseState( const char *pStateName ) const;
  68. CDmeVertexData *FindOrCreateBaseState( const char *pStateName );
  69. bool DeleteBaseState( const char *pStateName );
  70. // Selects a particular base state to be current state
  71. void SetCurrentBaseState( const char *pStateName );
  72. CDmeVertexData *GetCurrentBaseState();
  73. const CDmeVertexData *GetCurrentBaseState() const;
  74. bool SetBindBaseState( CDmeVertexData *pBaseState );
  75. CDmeVertexData *GetBindBaseState();
  76. const CDmeVertexData *GetBindBaseState() const;
  77. // Draws the mesh
  78. void Draw( const matrix3x4_t &shapeToWorld, CDmeDrawSettings *pDrawSettings = NULL );
  79. // Compute triangulated indices
  80. void ComputeTriangulatedIndices( const CDmeVertexData *pBaseState, const CDmeFaceSet *pFaceSet, int nFirstIndex, int *pIndices, int nOutCount ) const;
  81. // Compute a default per-vertex tangent given normal data + uv data for all vertex data referenced by this mesh
  82. void ComputeDefaultTangentData( bool bSmoothTangents = false );
  83. // Compute a default per-vertex tangent given normal data + uv data
  84. void ComputeDefaultTangentData( CDmeVertexData *pVertexData, bool bSmoothTangents = false );
  85. // Delta states
  86. int DeltaStateCount() const;
  87. CDmeVertexDeltaData *GetDeltaState( int nDeltaIndex ) const;
  88. CDmeVertexDeltaData *FindDeltaState( const char *pDeltaName, bool bSortDeltaName = true ) const;
  89. CDmeVertexDeltaData *FindOrCreateDeltaState( const char *pDeltaName, bool bSortDeltaName = true );
  90. bool DeleteDeltaState( const char *pDeltaName );
  91. bool ResetDeltaState( const char *pDeltaName );
  92. int FindDeltaStateIndex( const char *pDeltaName, bool bSortDeltaName = true ) const;
  93. void SetDeltaStateWeight( int nDeltaIndex, MeshDeltaWeightType_t type, float flMorphWeight );
  94. void SetDeltaStateWeight( int nDeltaIndex, MeshDeltaWeightType_t type, float flLeftWeight, float flRightWeight );
  95. CDmeVertexDeltaData *ModifyOrCreateDeltaStateFromBaseState( const char *pDeltaName, CDmeVertexData *pPassedBase = NULL, bool absolute = false );
  96. // Sets all of the data in the current base state to be the bind state plus the corrected delta, if delta is NULL then it's set to the bind state
  97. bool SetBaseStateToDelta( const CDmeVertexDeltaData *pDelta, CDmeVertexData *pPassedBase = NULL );
  98. // Selects the vertices from the delta that change position
  99. void SelectVerticesFromDelta( CDmeVertexDeltaData *pDelta, CDmeSingleIndexedComponent *pSelection );
  100. // Selects all the vertices in the mesh
  101. void SelectAllVertices( CDmeSingleIndexedComponent *pSelection, CDmeVertexData *pPassedBase = NULL );
  102. enum SelectHalfType_t
  103. {
  104. kLeft,
  105. kRight
  106. };
  107. // Selects all the vertices in the mesh
  108. void SelectHalfVertices( SelectHalfType_t selectHalfType, CDmeSingleIndexedComponent *pSelection, CDmeVertexData *pPassedBase = NULL );
  109. // Add the delta into the vertex data state weighted by the weight and masked by the weight map
  110. bool AddMaskedDelta(
  111. CDmeVertexDeltaData *pDelta,
  112. CDmeVertexData *pDst = NULL,
  113. float weight = 1.0f,
  114. const CDmeSingleIndexedComponent *pMask = NULL );
  115. // Add the delta into the vertex data state weighted by the weight and masked by the weight map
  116. bool AddCorrectedMaskedDelta(
  117. CDmeVertexDeltaData *pDelta,
  118. CDmeVertexData *pDst = NULL,
  119. float weight = 1.0f,
  120. const CDmeSingleIndexedComponent *pMask = NULL );
  121. // Interpolate between the current state and the specified delta by the specified percentage masked by the selection
  122. bool InterpMaskedDelta(
  123. CDmeVertexDeltaData *pDelta,
  124. CDmeVertexData *pDst = NULL,
  125. float weight = 1.0f,
  126. const CDmeSingleIndexedComponent *pMask = NULL );
  127. // Grows the selection by a specified amount
  128. void GrowSelection( int nSize, CDmeSingleIndexedComponent *pSelection, CDmMeshComp *pPassedMeshComp );
  129. // Shrinks the selection by a specified amount
  130. void ShrinkSelection( int nSize, CDmeSingleIndexedComponent *pSelection, CDmMeshComp *pPassedMeshComp );
  131. enum Falloff_t
  132. {
  133. STRAIGHT = 0,
  134. LINEAR = STRAIGHT,
  135. BELL,
  136. SMOOTH = BELL,
  137. SPIKE,
  138. DOME
  139. };
  140. enum Distance_t
  141. {
  142. DIST_ABSOLUTE = 0,
  143. DIST_RELATIVE,
  144. DIST_DEFAULT
  145. };
  146. CDmeSingleIndexedComponent *FeatherSelection( float falloffDistance, Falloff_t falloffType, Distance_t distanceType, CDmeSingleIndexedComponent *pSelection, CDmMeshComp *pPassedMeshComp );
  147. // Computes new normal deltas for all states based on position deltas
  148. void ComputeDeltaStateNormals();
  149. struct DeltaComputation_t
  150. {
  151. int m_nDeltaIndex;
  152. int m_nDimensionality;
  153. CUtlVector<int> m_DependentDeltas;
  154. };
  155. // Construct list of all n-1 -> 1 dimensional delta states that will be active when this delta state is active
  156. void ComputeDependentDeltaStateList( CUtlVector< DeltaComputation_t > &compList );
  157. // Construct list of all > n dimensional delta states that when active have the specified state as a dependent
  158. bool ComputeSuperiorDeltaStateList( const char *pDeltaName, CUtlVector< int > &superiorDeltaStates );
  159. void SetDeltaNormalDataFromActualNormals( int nDeltaIndex, const CUtlVector<int> &deltaStateList, int nNormalCount, Vector *pNormals );
  160. void ComputeAllCorrectedPositionsFromActualPositions();
  161. // Computes adds a delta to the passed data weighted by the passed weight
  162. template < class T_t > void AddDelta(
  163. const CDmeVertexDeltaData *pDelta, T_t *pFullData, int nFullData, FieldIndex_t fieldIndex, float weight = 1.0f, const CDmeSingleIndexedComponent *pMask = NULL );
  164. template < class T_t > void AddDelta(
  165. const CDmeVertexDeltaData *pDelta, T_t *pFullData, int nFullData, CDmeVertexData::StandardFields_t standardField, float weight = 1.0f, const CDmeSingleIndexedComponent *pMask = NULL );
  166. bool SetBaseStateToDeltas( CDmeVertexData *pPassedBase = NULL );
  167. template < class T_t >
  168. bool SetBaseDataToDeltas( CDmeVertexData *pBase, CDmeVertexData::StandardFields_t nStandardField, CDmrArrayConst< T_t > &srcData, CDmrArray< T_t > &dstData, bool bDoStereo, bool bDoLag );
  169. // Replace all instances of a material with a different material
  170. void ReplaceMaterial( const char *pOldMaterialName, const char *pNewMaterialName );
  171. // Reskins the mesh to new bones
  172. // The joint index remap maps an initial bone index to a new bone index
  173. void Reskin( const int *pJointTransformIndexRemap );
  174. template < class T_t > static int GenerateCompleteDataForDelta( const CDmeVertexDeltaData *pDelta, T_t *pFullData, int nFullData, CDmeVertexData::StandardFields_t standardField );
  175. // Normalizes all normals
  176. void NormalizeNormals();
  177. // Collapses redundant normals in the model
  178. // flNormalBlend is the maximum difference in the dot product between two normals to consider them
  179. // to be the same normal, a value of cos( DEG2RAD( 2.0 ) ) is the default studiomdl uses, for example
  180. void CollapseRedundantNormals( float flNormalBlend );
  181. // SWIG errors on the parsing of something in the private section of DmeMesh, it isn't exposed by SWIG anyway, so have SWIG ignore it
  182. #ifndef SWIG
  183. private:
  184. friend class CDmMeshComp;
  185. struct FaceSet_t
  186. {
  187. FaceSet_t() : m_bBuilt(false) {}
  188. IMesh *m_pMesh;
  189. bool m_bBuilt;
  190. };
  191. struct Triangle_t
  192. {
  193. int m_nIndex[3];
  194. Vector m_vecTangentS;
  195. Vector m_vecTangentT;
  196. };
  197. struct RenderVertexDelta_t
  198. {
  199. Vector m_vecDeltaPosition;
  200. Vector m_vecDeltaNormal;
  201. Vector2D m_vecDeltaUV;
  202. Vector4D m_vecDeltaColor;
  203. float m_flDeltaWrinkle;
  204. };
  205. VertexFormat_t ComputeHwMeshVertexFormat( void );
  206. IMorph *CreateHwMorph( IMaterial *pMTL );
  207. IMesh *CreateHwMesh( CDmeFaceSet *pFaceSet );
  208. // Draws the mesh when it uses too many bones
  209. void DrawDynamicMesh( CDmeFaceSet *pFaceSet, matrix3x4_t *pPoseToWorld, bool bHasActiveDeltaStates, CDmeDrawSettings *pDrawSettings = NULL );
  210. // Build a map from vertex index to a list of triangles that share the vert.
  211. void BuildTriangleMap( const CDmeVertexData *pBaseState, CDmeFaceSet* pFaceSet, CUtlVector<Triangle_t>& triangles, CUtlVector< CUtlVector<int> >* pVertToTriMap = NULL );
  212. // Computes tangent space data for triangles
  213. void ComputeTriangleTangets( const CDmeVertexData *pVertexData, CUtlVector<Triangle_t>& triangles );
  214. // Build a map from vertex index to a list of triangles that share the vert.
  215. void ComputeAverageTangent( CDmeVertexData *pVertexData, bool bSmoothTangents, CUtlVector< CUtlVector<int> >& vertToTriMap, CUtlVector<Triangle_t>& triangles );
  216. // Do we have active delta state data?
  217. bool HasActiveDeltaStates() const;
  218. // Adds deltas into a delta mesh
  219. template< class T > bool AddVertexDelta( CDmeVertexData *pBaseState, void *pVertexData, int nStride, CDmeVertexDataBase::StandardFields_t fieldId, int nIndex, bool bDoLag );
  220. template< class T > bool AddStereoVertexDelta( CDmeVertexData *pBaseState, void *pVertexData, int nStride, CDmeVertexDataBase::StandardFields_t fieldId, int nIndex, bool bDoLag );
  221. void AddTexCoordDelta( RenderVertexDelta_t *pRenderDelta, float flWeight, CDmeVertexDeltaData *pDeltaState );
  222. void AddColorDelta( RenderVertexDelta_t *pRenderDelta, float flWeight, CDmeVertexDeltaData *pDeltaState );
  223. // Builds deltas based on the current deltas, returns true if there was delta wrinkle data
  224. bool BuildDeltaMesh( int nVertices, RenderVertexDelta_t *pDelta );
  225. // Builds a map from vertex index to all triangles that use it
  226. void BuildVertToTriMap( const CDmeVertexData *pVertexData, CUtlVector<Triangle_t> &triangles, CUtlVector< CUtlVector<int> > &vertToTriMap );
  227. // Compute the dimensionality of the delta state (how many inputs affect it)
  228. int ComputeDeltaStateDimensionality( int nDeltaIndex );
  229. // Discovers the atomic controls used by the various delta states
  230. void BuildAtomicControlLists( int nCount, DeltaComputation_t *pInfo, CUtlVector< CUtlVector< int > > &deltaStateUsage );
  231. // Computes the aggregate position for all vertices after applying a set of delta states
  232. void AddDelta( CDmeVertexData *pBaseState, Vector *pDeltaPosition, int nDeltaStateIndex, CDmeVertexData::StandardFields_t fieldId );
  233. // Converts pose-space normals into deltas appropriate for correction delta states
  234. void ComputeCorrectedNormalsFromActualNormals( const CUtlVector<int> &deltaStateList, int nNormalCount, Vector *pNormals );
  235. // Copies the corrected normal data into a delta state
  236. void SetDeltaNormalData( int nDeltaIndex, int nNormalCount, Vector *pNormals );
  237. // Renders normals
  238. void RenderNormals( matrix3x4_t *pPoseToWorld, RenderVertexDelta_t *pDelta );
  239. void CacheHighlightVerts( matrix3x4_t *pPoseToWorld, RenderVertexDelta_t *pDelta, CDmeDrawSettings *pDmeDrawSettings );
  240. // Writes triangulated indices for a face set into a meshbuilder
  241. void WriteTriangluatedIndices( const CDmeVertexData *pBaseState, CDmeFaceSet *pFaceSet, CMeshBuilder &meshBuilder );
  242. // Initializes the normal material
  243. static void InitializeNormalMaterial();
  244. // Initializes the wireframe material
  245. static void InitializeWireframeMaterial();
  246. // Sort function
  247. static int DeltaStateLessFunc( const void * lhs, const void * rhs );
  248. // Computes a list of the delta states ordered by dimensionality
  249. void ComputeDeltaStateComputationList( CUtlVector< DeltaComputation_t > &compList );
  250. // Compute the number of combinations of n items taken k at a time nCk - Probably doesn't belong here but it useful for combos
  251. static void Combinations( int n, int k, CUtlVector< CUtlVector< int > > &combos, int *pTmpArray = NULL, int start = 0, int currentK = 0 );
  252. // Splits the passed delta state name on '_' and finds all of the control Delta states which make up the name
  253. bool GetControlDeltaIndices( CDmeVertexDeltaData *pDeltaState, CUtlVector< int > &controlDeltaIndices ) const;
  254. // Splits the passed delta state name on '_' and finds all of the control Delta states which make up the name
  255. bool GetControlDeltaIndices( const char *pDeltaStateName, CUtlVector< int > &controlDeltaIndices ) const;
  256. // Builds a complete list of all of the delta states expressed as the control indices
  257. bool BuildCompleteDeltaStateControlList( CUtlVector< CUtlVector< int > > &deltaStateControlList ) const;
  258. // Given a list of control indices and a complete list of control indices for each delta state, returns the delta index or -1 if it doesn't exist
  259. int FindDeltaIndexFromControlIndices( const CUtlVector< int > &controlIndices, const CUtlVector< CUtlVector< int > > &controlList ) const;
  260. // Builds a list of all of the dependent delta states that do not already exist
  261. bool BuildMissingDependentDeltaList( CDmeVertexDeltaData *pDeltaState, CUtlVector< int > &controlIndices, CUtlVector< CUtlVector< int > > &dependentStates ) const;
  262. // Cleans up the hw meshes
  263. void CleanupHWMesh();
  264. static void ComputeCorrectedPositionsFromActualPositions( const CUtlVector< int > &deltaStateList, int nPositionCount, Vector *pPositions );
  265. template < class T_t > void AddCorrectedDelta(
  266. CDmrArray< T_t > &baseDataArray,
  267. const CUtlVector< int > &baseIndices,
  268. const DeltaComputation_t &deltaComputation,
  269. const char *pFieldName,
  270. float weight = 1.0f,
  271. const CDmeSingleIndexedComponent *pMask = NULL );
  272. template < class T_t > void AddCorrectedDelta(
  273. CUtlVector< T_t > &baseData,
  274. const CUtlVector< int > &baseIndices,
  275. const DeltaComputation_t &deltaComputation,
  276. const char *pFieldName,
  277. float weight = 1.0f,
  278. const CDmeSingleIndexedComponent *pMask = NULL );
  279. template < class T_t > void AddRawDelta(
  280. CDmeVertexDeltaData *pDelta,
  281. CDmrArray< T_t > &baseDataArray,
  282. FieldIndex_t nDeltaFieldIndex,
  283. float weight = 1.0f,
  284. const CDmeSingleIndexedComponent *pMask = NULL );
  285. template < class T_t > void AddRawDelta(
  286. CDmeVertexDeltaData *pDelta,
  287. CUtlVector< T_t > &baseData,
  288. FieldIndex_t nDeltaFieldIndex,
  289. float weight = 1.0f,
  290. const CDmeSingleIndexedComponent *pMask = NULL );
  291. friend class CDmxEdit;
  292. bool RemoveBaseState( CDmeVertexData *pBase );
  293. CDmeVertexData *FindOrAddBaseState( CDmeVertexData *pBase );
  294. // CFalloff functors map [0, 1] values to [0, 1] values
  295. template < int T >
  296. class CFalloff
  297. {
  298. public:
  299. virtual inline float operator()( float x ) { return 1 - x; }
  300. };
  301. template<>
  302. class CFalloff< CDmeMesh::LINEAR >
  303. {
  304. public:
  305. virtual inline float operator()( float x ) { return 1 - x; }
  306. };
  307. template<>
  308. class CFalloff< CDmeMesh::SMOOTH >
  309. {
  310. public:
  311. virtual inline float operator()( float x ) {
  312. return ( cosf( x * M_PI ) + 1.0f ) / 2.0f;
  313. }
  314. };
  315. template<>
  316. class CFalloff< CDmeMesh::DOME >
  317. {
  318. public:
  319. virtual inline float operator()( float x ) {
  320. return ( cosf( x * M_PI / 2.0 ) );
  321. }
  322. };
  323. template<>
  324. class CFalloff< CDmeMesh::SPIKE >
  325. {
  326. public:
  327. virtual inline float operator()( float x ) {
  328. return ( 1.0f - cosf( ( 1.0f - x ) * M_PI / 2.0 ) );
  329. }
  330. };
  331. // Feather's the selection by a specified amount, creates a new CDmeSingleIndexedComponent or NULL if error
  332. template < int T >
  333. CDmeSingleIndexedComponent *FeatherSelection( float fFalloffDistance, Distance_t distanceType, CDmeSingleIndexedComponent *pSelection, CDmMeshComp *pPassedMeshComp );
  334. bool CreateDeltaFieldFromBaseField( CDmeVertexData::StandardFields_t nStandardFieldIndex, const CDmrArrayConst< float > &baseArray, const CDmrArrayConst< float > &bindArray, CDmeVertexDeltaData *pDelta );
  335. bool CreateDeltaFieldFromBaseField( CDmeVertexData::StandardFields_t nStandardFieldIndex, const CDmrArrayConst< Vector2D > &baseArray, const CDmrArrayConst< Vector2D > &bindArray, CDmeVertexDeltaData *pDelta );
  336. bool CreateDeltaFieldFromBaseField( CDmeVertexData::StandardFields_t nStandardFieldIndex, const CDmrArrayConst< Vector > &baseArray, const CDmrArrayConst< Vector > &bindArray, CDmeVertexDeltaData *pDelta );
  337. template< class T_t > bool InterpMaskedData(
  338. CDmrArray< T_t > &aData,
  339. const CUtlVector< T_t > &bData,
  340. float weight,
  341. const CDmeSingleIndexedComponent *pMask ) const;
  342. // Interpolate between the current state and the specified delta by the specified percentage masked by the selection
  343. bool InterpMaskedData(
  344. CDmeVertexData *paData,
  345. const CDmeVertexData *pbData,
  346. float weight,
  347. const CDmeSingleIndexedComponent *pMask ) const;
  348. // Find the closest vertex in the specified selection to the passed vertex in the specified base state, if the passed base state is NULL is the current base state
  349. int ClosestSelectedVertex( int vIndex, CDmeSingleIndexedComponent *pSelection, const CDmeVertexData *pPassedBase = NULL ) const;
  350. // Return the distance between the two vertices in the specified base state, if the specified base state is NULL the current state is used
  351. float DistanceBetween( int vIndex0, int vIndex1, const CDmeVertexData *pPassedBase = NULL ) const;
  352. void DrawWireframeFaceSet( CDmeFaceSet *pFaceSet, matrix3x4_t *pPoseToWorld, bool bHasActiveDeltaStates, CDmeDrawSettings *pDrawSettings );
  353. void ComputeNormalsFromPositions( CDmeVertexData *pBase, const Vector *pPosition, const CUtlVector<Triangle_t> &triangles, int nNormalCount, Vector *pNormals );
  354. CDmaElement< CDmeVertexData > m_BindBaseState;
  355. CDmaElement< CDmeVertexData > m_CurrentBaseState;
  356. CDmaElementArray< CDmeVertexData > m_BaseStates;
  357. CDmaElementArray< CDmeVertexDeltaData > m_DeltaStates;
  358. CDmaElementArray< CDmeFaceSet > m_FaceSets;
  359. // x is left value, y is right value. If the delta state isn't split, they are the same value
  360. CDmaArray<Vector2D> m_DeltaStateWeights[MESH_DELTA_WEIGHT_TYPE_COUNT];
  361. // Cached-off map of fields->
  362. CUtlVector< FaceSet_t > m_hwFaceSets;
  363. // Normal rendering materials
  364. static bool s_bNormalMaterialInitialized;
  365. static CMaterialReference s_NormalMaterial;
  366. // Wireframe rendering materials
  367. static bool s_bWireframeMaterialInitialized;
  368. static CMaterialReference s_WireframeMaterial;
  369. friend class CDmeMeshRenderInfo;
  370. #endif // #ifndef SWIG
  371. };
  372. //-----------------------------------------------------------------------------
  373. // Inline methods
  374. //-----------------------------------------------------------------------------
  375. inline int CDmeMesh::BaseStateCount() const
  376. {
  377. return m_BaseStates.Count();
  378. }
  379. inline CDmeVertexData *CDmeMesh::GetBaseState( int nBaseIndex ) const
  380. {
  381. return m_BaseStates[ nBaseIndex ];
  382. }
  383. //-----------------------------------------------------------------------------
  384. // Utility method to compute default tangent data on all meshes in the sub-dag hierarchy
  385. //-----------------------------------------------------------------------------
  386. void ComputeDefaultTangentData( CDmeDag *pDag, bool bSmoothTangents );
  387. //-----------------------------------------------------------------------------
  388. // Helper class to deal with software skinning
  389. //-----------------------------------------------------------------------------
  390. class CDmeMeshRenderInfo
  391. {
  392. public:
  393. CDmeMeshRenderInfo( CDmeVertexData *pBaseState );
  394. void ComputePosition( int nPosIndex, const matrix3x4_t *pPoseToWorld, Vector *pDeltaPosition, Vector *pPosition );
  395. void ComputePosition( int nPosIndex, const matrix3x4_t *pPoseToWorld, CDmeMesh::RenderVertexDelta_t *pDelta, Vector *pPosition );
  396. void ComputeVertex( int vi, const matrix3x4_t *pPoseToWorld, CDmeMesh::RenderVertexDelta_t *pDelta, Vector *pPosition, Vector *pNormal, Vector4D *pTangent );
  397. inline bool HasPositionData() const { return m_bHasPositionData; }
  398. inline bool HasNormalData() const { return m_bHasNormalData; }
  399. inline bool HasTangentData() const { return m_bHasTangentData; }
  400. private:
  401. const CUtlVector<int>& m_PositionIndices;
  402. const CUtlVector<Vector>& m_PositionData;
  403. const CUtlVector<int>& m_NormalIndices;
  404. const CUtlVector<Vector>& m_NormalData;
  405. const CUtlVector<int>& m_TangentIndices;
  406. const CUtlVector<Vector4D>& m_TangentData;
  407. const CDmeVertexData *m_pBaseState;
  408. int m_nJointCount;
  409. bool m_bHasPositionData;
  410. bool m_bHasNormalData;
  411. bool m_bHasTangentData;
  412. bool m_bHasSkinningData;
  413. };
  414. #endif // DMEMESH_H