meshdam.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/meshdam.cpp $*
  25. * *
  26. * Author:: Greg_h *
  27. * *
  28. * $Modtime:: 1/08/01 10:04a $*
  29. * *
  30. * $Revision:: 1 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if 0
  36. #include "meshdam.h"
  37. #include "w3d_file.h"
  38. #include "w3derr.h"
  39. #include "chunkio.h"
  40. //#include <sr.hpp>
  41. /***********************************************************************************************
  42. * DamageClass::DamageClass -- constructor *
  43. * *
  44. * INPUT: *
  45. * *
  46. * OUTPUT: *
  47. * *
  48. * WARNINGS: *
  49. * *
  50. * HISTORY: *
  51. * 10/28/1997 GH : Created. *
  52. *=============================================================================================*/
  53. DamageClass::DamageClass(void):
  54. DamageIndex(0),
  55. NumMaterials(0),
  56. NumVerts(0),
  57. NumColors(0),
  58. Verts(NULL),
  59. Colors(NULL)
  60. {
  61. }
  62. /***********************************************************************************************
  63. * DamageClass::~DamageClass -- destructor *
  64. * *
  65. * INPUT: *
  66. * *
  67. * OUTPUT: *
  68. * *
  69. * WARNINGS: *
  70. * *
  71. * HISTORY: *
  72. * 10/28/1997 GH : Created. *
  73. *=============================================================================================*/
  74. DamageClass::~DamageClass(void)
  75. {
  76. if (Verts != NULL) {
  77. delete [] Verts;
  78. Verts = NULL;
  79. }
  80. if (Colors != NULL) {
  81. delete[] Colors;
  82. Colors = NULL;
  83. }
  84. }
  85. /***********************************************************************************************
  86. * DamageClass::Load -- load damage data from a W3D file *
  87. * *
  88. * INPUT: *
  89. * *
  90. * OUTPUT: *
  91. * *
  92. * WARNINGS: *
  93. * *
  94. * HISTORY: *
  95. * 10/28/1997 GH : Created. *
  96. *=============================================================================================*/
  97. WW3DErrorType DamageClass::Load(ChunkLoadClass & cload,MeshModelClass * basemesh)
  98. {
  99. #if 0
  100. /*
  101. ** Open the first chunk, it should be the damage header
  102. */
  103. cload.Open_Chunk();
  104. if (cload.Cur_Chunk_ID() != W3D_CHUNK_DAMAGE_HEADER) {
  105. return WW3D_ERROR_LOAD_FAILED;
  106. }
  107. W3dMeshDamageStruct header;
  108. if (cload.Read(&header,sizeof(W3dMeshDamageStruct)) != sizeof(W3dMeshDamageStruct)) {
  109. return WW3D_ERROR_LOAD_FAILED;
  110. }
  111. cload.Close_Chunk();
  112. /*
  113. ** allocate the arrays based on the info in the header
  114. */
  115. NumVerts = header.NumDamageVerts;
  116. if (NumVerts > 0) {
  117. Verts = W3DNEWARRAY DamageVertexStruct[NumVerts];
  118. }
  119. NumColors = header.NumDamageColors;
  120. if (NumColors > 0) {
  121. Colors = W3DNEWARRAY DamageColorStruct[NumColors];
  122. }
  123. // TODO: allocate materials
  124. /*
  125. ** Now read in the rest of the chunks
  126. */
  127. while (1) {
  128. /*
  129. ** Read in the chunk header
  130. ** If there are no more chunks within the chunk, we are done.
  131. */
  132. if (!cload.Open_Chunk()) {
  133. return WW3D_ERROR_OK;
  134. }
  135. /*
  136. ** Process the chunk
  137. */
  138. int error = WW3D_ERROR_OK;
  139. switch (cload.Cur_Chunk_ID()) {
  140. // case W3D_CHUNK_DAMAGE_MATERIALS:
  141. // //TODO: read new set of materials
  142. // break;
  143. case W3D_CHUNK_DAMAGE_VERTICES:
  144. error = read_vertices(cload,basemesh);
  145. break;
  146. case W3D_CHUNK_DAMAGE_COLORS:
  147. error = read_colors(cload,basemesh);
  148. break;
  149. default:
  150. break;
  151. }
  152. cload.Close_Chunk();
  153. if (error != WW3D_ERROR_OK) {
  154. return error;
  155. }
  156. }
  157. #endif
  158. return WW3D_ERROR_OK;
  159. }
  160. /***********************************************************************************************
  161. * DamageClass::read_vertices -- read damage vertices from a W3D file *
  162. * *
  163. * INPUT: *
  164. * *
  165. * OUTPUT: *
  166. * *
  167. * WARNINGS: *
  168. * *
  169. * HISTORY: *
  170. * 11/04/1997 GH : Created. *
  171. *=============================================================================================*/
  172. WW3DErrorType DamageClass::read_vertices(ChunkLoadClass & cload,MeshModelClass * basemesh)
  173. {
  174. #if 0
  175. W3dMeshDamageVertexStruct dv;
  176. for (int i=0; i<NumVerts; i++) {
  177. if (cload.Read(&dv,sizeof(W3dMeshDamageVertexStruct)) != sizeof(W3dMeshDamageVertexStruct)) {
  178. return WW3D_ERROR_LOAD_FAILED;
  179. }
  180. srVector3 * vert_array = basemesh->getVertexLoc();
  181. srVector3 sr_v;
  182. sr_v = vert_array[dv.VertexIndex];
  183. Verts[i].VertexIdx = dv.VertexIndex;
  184. Verts[i].Vertex0.Set(sr_v[0],sr_v[1],sr_v[2]);
  185. Verts[i].Vertex1.Set(dv.NewVertex.X,dv.NewVertex.Y,dv.NewVertex.Z);
  186. }
  187. #endif
  188. return WW3D_ERROR_OK;
  189. }
  190. /***********************************************************************************************
  191. * DamageClass::read_colors -- read damage colors from a w3d file *
  192. * *
  193. * INPUT: *
  194. * *
  195. * OUTPUT: *
  196. * *
  197. * WARNINGS: *
  198. * *
  199. * HISTORY: *
  200. * 11/04/1997 GH : Created. *
  201. *=============================================================================================*/
  202. WW3DErrorType DamageClass::read_colors(ChunkLoadClass & cload,MeshModelClass * basemesh)
  203. {
  204. #if 0
  205. W3dMeshDamageColorStruct dc;
  206. for (int i=0; i<NumColors; i++) {
  207. if (cload.Read(&dc,sizeof(W3dMeshDamageColorStruct)) != sizeof(W3dMeshDamageColorStruct)) {
  208. return WW3D_ERROR_LOAD_FAILED;
  209. }
  210. Colors[i].VertexIdx = dc.VertexIndex;
  211. // TODO: check for existing vertex colors, store original here
  212. Colors[i].Color0.R = 255;
  213. Colors[i].Color0.G = 255;
  214. Colors[i].Color0.B = 255;
  215. Colors[i].Color1.R = dc.NewColor.R;
  216. Colors[i].Color1.G = dc.NewColor.G;
  217. Colors[i].Color1.B = dc.NewColor.B;
  218. }
  219. #endif
  220. return WW3D_ERROR_OK;
  221. }
  222. #endif //0