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.

186 lines
4.4 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "movieobjects/dmefaceset.h"
  7. #include "movieobjects/dmematerial.h"
  8. #include "tier0/dbg.h"
  9. #include "UtlBuffer.h"
  10. #include "datamodel/dmelementfactoryhelper.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. //-----------------------------------------------------------------------------
  14. // Expose this class to the scene database
  15. //-----------------------------------------------------------------------------
  16. IMPLEMENT_ELEMENT_FACTORY( DmeFaceSet, CDmeFaceSet );
  17. //-----------------------------------------------------------------------------
  18. // Constructor, destructor
  19. //-----------------------------------------------------------------------------
  20. void CDmeFaceSet::OnConstruction()
  21. {
  22. m_indices.Init( this, "faces" );
  23. m_material.Init( this, "material" );
  24. }
  25. void CDmeFaceSet::OnDestruction()
  26. {
  27. }
  28. //-----------------------------------------------------------------------------
  29. // accessors
  30. //-----------------------------------------------------------------------------
  31. CDmeMaterial *CDmeFaceSet::GetMaterial()
  32. {
  33. return m_material.GetElement();
  34. }
  35. void CDmeFaceSet::SetMaterial( CDmeMaterial *pMaterial )
  36. {
  37. m_material = pMaterial;
  38. }
  39. int CDmeFaceSet::AddIndices( int nCount )
  40. {
  41. int nCurrentCount = m_indices.Count();
  42. m_indices.EnsureCount( nCount + nCurrentCount );
  43. return nCurrentCount;
  44. }
  45. void CDmeFaceSet::SetIndices( int nFirstIndex, int nCount, int *pIndices )
  46. {
  47. m_indices.SetMultiple( nFirstIndex, nCount, pIndices );
  48. }
  49. //-----------------------------------------------------------------------------
  50. //
  51. //-----------------------------------------------------------------------------
  52. void CDmeFaceSet::SetIndex( int i, int nValue )
  53. {
  54. m_indices.Set( i, nValue );
  55. }
  56. //-----------------------------------------------------------------------------
  57. // Returns the number of triangulated indices
  58. //-----------------------------------------------------------------------------
  59. int CDmeFaceSet::GetNextPolygonVertexCount( int nFirstIndex ) const
  60. {
  61. int nCurrIndex = nFirstIndex;
  62. int nTotalCount = m_indices.Count();
  63. while( nCurrIndex < nTotalCount )
  64. {
  65. if ( m_indices[nCurrIndex] == -1 )
  66. break;
  67. ++nCurrIndex;
  68. }
  69. return nCurrIndex - nFirstIndex;
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Returns the number of triangulated indices total
  73. //-----------------------------------------------------------------------------
  74. int CDmeFaceSet::GetTriangulatedIndexCount() const
  75. {
  76. int nIndexCount = 0;
  77. int nVertexCount = 0;
  78. int nTotalCount = m_indices.Count();
  79. for ( int nCurrIndex = 0; nCurrIndex < nTotalCount; ++nCurrIndex )
  80. {
  81. if ( m_indices[nCurrIndex] == -1 )
  82. {
  83. if ( nVertexCount >= 3 )
  84. {
  85. nIndexCount += ( nVertexCount - 2 ) * 3;
  86. }
  87. nVertexCount = 0;
  88. continue;
  89. }
  90. ++nVertexCount;
  91. }
  92. if ( nVertexCount >= 3 )
  93. {
  94. nIndexCount += ( nVertexCount - 2 ) * 3;
  95. }
  96. return nIndexCount;
  97. }
  98. //-----------------------------------------------------------------------------
  99. // Returns the number of indices total
  100. //-----------------------------------------------------------------------------
  101. int CDmeFaceSet::GetIndexCount() const
  102. {
  103. int nIndexCount = 0;
  104. int nVertexCount = 0;
  105. int nTotalCount = m_indices.Count();
  106. for ( int nCurrIndex = 0; nCurrIndex < nTotalCount; ++nCurrIndex )
  107. {
  108. if ( m_indices[nCurrIndex] == -1 )
  109. {
  110. nIndexCount += nVertexCount;
  111. nVertexCount = 0;
  112. continue;
  113. }
  114. ++nVertexCount;
  115. }
  116. nIndexCount += nVertexCount;
  117. return nIndexCount;
  118. }
  119. //-----------------------------------------------------------------------------
  120. //
  121. //-----------------------------------------------------------------------------
  122. void CDmeFaceSet::RemoveMultiple( int elem, int num )
  123. {
  124. m_indices.RemoveMultiple( elem, num );
  125. }
  126. //-----------------------------------------------------------------------------
  127. // Returns the number of faces in the face set
  128. //-----------------------------------------------------------------------------
  129. int CDmeFaceSet::GetFaceCount() const
  130. {
  131. int nFaceCount = 0;
  132. int nVertexCount = 0;
  133. const int nIndexCount = NumIndices();
  134. for ( int i = 0; i < nIndexCount; ++i )
  135. {
  136. if ( GetIndex( i ) < 0 )
  137. {
  138. if ( nVertexCount > 0 )
  139. {
  140. ++nFaceCount;
  141. }
  142. nVertexCount = 0;
  143. continue;
  144. }
  145. ++nVertexCount;
  146. }
  147. if ( nVertexCount > 0 )
  148. {
  149. ++nFaceCount;
  150. }
  151. return nFaceCount;
  152. }