MeshDeformSet.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando / G 3D engine *
  23. * *
  24. * File Name : MeshDeformSet.h *
  25. * *
  26. * Programmer : Patrick Smith *
  27. * *
  28. * Start Date : 04/26/99 *
  29. * *
  30. * Last Update :
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef __MESH_DEFORM_SET_H
  36. #define __MESH_DEFORM_SET_H
  37. #include <Max.h>
  38. #include "Vector.H"
  39. #include "MeshDeformDefs.H"
  40. // Forward declarations
  41. class MeshDeformSaveSetClass;
  42. class MeshBuilderClass;
  43. ///////////////////////////////////////////////////////////////////////////
  44. //
  45. // MeshDeformSetClass
  46. //
  47. ///////////////////////////////////////////////////////////////////////////
  48. class MeshDeformSetClass
  49. {
  50. public:
  51. //////////////////////////////////////////////////////////////////////
  52. // Public data types
  53. //////////////////////////////////////////////////////////////////////
  54. //////////////////////////////////////////////////////////////////////
  55. // Public constructors/destructors
  56. //////////////////////////////////////////////////////////////////////
  57. MeshDeformSetClass (void)
  58. : m_pMesh (NULL),
  59. m_pVertexArray (NULL),
  60. m_pVertexOPStartArray (NULL),
  61. m_pVertexColors (NULL),
  62. m_VertexColorCount (0),
  63. m_State (0),
  64. m_CurrentKeyFrame (0),
  65. m_bAutoApply (true),
  66. m_VertexCount (0) { Init_Key_Frames (); }
  67. virtual ~MeshDeformSetClass (void);
  68. //////////////////////////////////////////////////////////////////////
  69. // Public methods
  70. //////////////////////////////////////////////////////////////////////
  71. //virtual LocalModData * Clone (void) { return new MeshDeformSetClass; }
  72. void Update_Mesh (TriObject &tri_obj);
  73. void Set_State (float state);
  74. // Inline accessors
  75. Mesh * Peek_Mesh (void) const { return m_pMesh; }
  76. const Point3 * Peek_Orig_Vertex_Array (void) const { return m_pVertexArray; }
  77. Point3 * Peek_Vertex_OPStart_Array (void) const { return m_pVertexOPStartArray; }
  78. VertColor * Peek_Vertex_Colors (void) const { return m_pVertexColors; }
  79. // Keyframe managment
  80. void Set_Current_Key_Frame (int index);
  81. int Get_Current_Key_Frame (void) const { return m_CurrentKeyFrame; }
  82. void Update_Key_Frame (int key_frame);
  83. void Update_Current_Data (void);
  84. void Update_Set_Members (void);
  85. void Collapse_Keyframe_Data (int keyframe);
  86. void Reset_Key_Frame_Verts (int keyframe);
  87. void Reset_Key_Frame_Colors (int keyframe);
  88. // Data managment
  89. void Set_Vertex_Position (int index, const Point3 &value);
  90. void Set_Vertex_Color (int index, int color_index, const VertColor &value);
  91. // Set managment
  92. void Select_Members (void);
  93. void Update_Members (DEFORM_CHANNELS flags);
  94. void Restore_Members (void);
  95. // Auto apply
  96. bool Does_Set_Auto_Apply (void) const { return m_bAutoApply; }
  97. void Auto_Apply (bool auto_apply = true) { m_bAutoApply = auto_apply; }
  98. // Information
  99. bool Is_Empty (void) const;
  100. int Get_Vertex_Count (int keyframe) const { return m_KeyFrames[keyframe]->verticies.Count (); }
  101. int Get_Color_Count (int keyframe) const { return m_KeyFrames[keyframe]->colors.Count (); }
  102. const VERT_INFO & Get_Vertex_Data (int keyframe, int index) const { return m_KeyFrames[keyframe]->verticies[index]; }
  103. const VERT_INFO & Get_Color_Data (int keyframe, int index) const { return m_KeyFrames[keyframe]->colors[index]; }
  104. // Persistent storage
  105. IOResult Save (ISave *save_obj);
  106. IOResult Load (ILoad *load_obj);
  107. void Save (MeshBuilderClass &builder, Mesh &mesh, MeshDeformSaveSetClass &save_set, Matrix3 *transform = NULL);
  108. protected:
  109. //////////////////////////////////////////////////////////////////////
  110. // Protected methods
  111. //////////////////////////////////////////////////////////////////////
  112. void Resize_Vertex_Array (int count, int color_count);
  113. void Copy_Vertex_Array (Mesh &mesh);
  114. // Keyframe methods
  115. void Init_Key_Frames (void);
  116. void Free_Key_Frames (void);
  117. void Determine_Interpolation_Indicies (int key_frame, bool position, int &from, int &to, float &state);
  118. // Deformation application methods
  119. void Apply_Position_Changes (UINT vert, int frame_to_check, Point3 &position, Matrix3 *transform = NULL);
  120. void Apply_Color_Changes (UINT vert, int frame_to_check, Mesh &mesh);
  121. void Apply_Color_Changes (UINT vert_index, UINT vert_color_index, int frame_to_check, VertColor &color);
  122. private:
  123. //////////////////////////////////////////////////////////////////////
  124. // Private data types
  125. //////////////////////////////////////////////////////////////////////
  126. typedef struct
  127. {
  128. DEFORM_LIST verticies;
  129. DEFORM_LIST colors;
  130. BitArray affected_verts;
  131. BitArray affected_colors;
  132. } KEY_FRAME;
  133. typedef DynamicVectorClass<KEY_FRAME *> KEY_FRAME_LIST;
  134. //////////////////////////////////////////////////////////////////////
  135. // Private member data
  136. //////////////////////////////////////////////////////////////////////
  137. Mesh * m_pMesh;
  138. Point3 * m_pVertexArray;
  139. Point3 * m_pVertexOPStartArray;
  140. VertColor * m_pVertexColors;
  141. int m_VertexCount;
  142. int m_VertexColorCount;
  143. int m_CurrentKeyFrame;
  144. float m_State;
  145. bool m_bAutoApply;
  146. // Array representing which verticies are part of the set
  147. BitArray m_SetMembers;
  148. // List of key frames
  149. KEY_FRAME_LIST m_KeyFrames;
  150. };
  151. #endif //__MESH_DEFORM_DATA_H