meshsave.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. /* $Header: /Commando/Code/Tools/max2w3d/meshsave.h 44 10/30/00 1:12p Greg_h $ */
  19. /***********************************************************************************************
  20. *** Confidential - Westwood Studios ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Commando / G *
  24. * *
  25. * File Name : MESHSAVE.H *
  26. * *
  27. * Programmer : Greg Hjelstrom *
  28. * *
  29. * Start Date : 06/10/97 *
  30. * *
  31. * Last Update : June 10, 1997 [GH] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #if defined(_MSC_VER)
  37. #pragma once
  38. #endif
  39. #ifndef MESHSAVE_H
  40. #define MESHSAVE_H
  41. #include "rawfile.h" // have to include this before Max.h
  42. #include <Max.h>
  43. #include "bittype.h"
  44. #include "w3d_file.h"
  45. #include "chunkio.h"
  46. #include "progress.h"
  47. #include "nodelist.h"
  48. #include "util.h"
  49. #include "w3dmtl.h"
  50. #include "meshbuild.h"
  51. #include "MeshDeformSave.H"
  52. #include "w3dappdata.h"
  53. class HierarchySaveClass;
  54. class MeshConnectionsClass;
  55. class MeshSaveClass;
  56. class SkinDataClass;
  57. /*******************************************************************************************
  58. **
  59. ** VertStruct
  60. **
  61. *******************************************************************************************/
  62. struct VertStruct
  63. {
  64. Point3 Vertex;
  65. Point3 Normal;
  66. Point2 TexCoord;
  67. Color Color;
  68. uint32 MaxVertIdx; // index of the MAX vertex that this vert came from
  69. uint32 MaxFaceIdx; // index of the MAX face that this vert came from
  70. VertStruct * Next; // used by the hash table...
  71. };
  72. /*******************************************************************************************
  73. **
  74. ** FaceStruct
  75. **
  76. *******************************************************************************************/
  77. struct FaceStruct
  78. {
  79. uint32 MaxVidx[3]; // original 3ds-MAX vertex index (for smoothing computations)
  80. uint32 OurVidx[3]; // vertex, vertex normal, and texture coord indices
  81. uint32 MaterialIdx; // material index
  82. uint32 SmGroup; // smoothing group (not really needed, normals pre-calced)
  83. Point3 Normal; // Face normal
  84. float32 Dist; // Plane distance
  85. uint32 Attributes; // collision flags, sort method, etc
  86. };
  87. /*******************************************************************************************
  88. **
  89. ** MeshSaveClass - this is the big one, create meshes and skins from a MAX mesh.
  90. **
  91. *******************************************************************************************/
  92. class MeshSaveClass
  93. {
  94. public:
  95. enum {
  96. EX_UNKNOWN = 0, // exception error codes
  97. EX_CANCEL = 1
  98. };
  99. MeshSaveClass(
  100. char * mesh_name,
  101. char * container_name,
  102. INode * inode,
  103. const Mesh * input_mesh,
  104. Matrix3 & exportspace,
  105. W3DAppData2Struct & exportoptions,
  106. HierarchySaveClass * htree,
  107. TimeValue curtime,
  108. Progress_Meter_Class & meter,
  109. unsigned int * materialColors,
  110. int &numMaterialColors,
  111. int &numHouseColors,
  112. char * materialColorTexture,
  113. WorldInfoClass * world_info = NULL
  114. );
  115. ~MeshSaveClass(void);
  116. int Write_To_File(ChunkSaveClass & csave,bool export_aabtrees = false);
  117. private:
  118. INode * MaxINode;
  119. W3DAppData2Struct & ExportOptions;
  120. W3dMeshHeader3Struct Header;
  121. W3dMaterialDescClass MaterialDesc;
  122. MeshBuilderClass Builder;
  123. MeshDeformSaveClass DeformSave;
  124. TimeValue CurTime;
  125. Matrix3 ExportSpace;
  126. Matrix3 MeshToExportSpace;
  127. Matrix3 PivotSpace;
  128. HierarchySaveClass * HTree;
  129. char * UserText;
  130. bool MeshInverted; // this flag indicates that the transform is inverting this mesh
  131. W3dVertInfStruct * VertInfluences;
  132. int * MaterialRemapTable; // reindexes mtl_idx after un-used mtls are removed
  133. // Flag set if the mesh uses a PS2 material.
  134. int PS2Material;
  135. private:
  136. // Use a MeshBuilderClass to process the mesh
  137. void Build_Mesh(Mesh & mesh, Mtl *node_mtl, unsigned int *materialColors, int &numMaterialColors, int &numHouseColors);
  138. // compute properties for the mesh
  139. void compute_bounding_volumes(void);
  140. void compute_physical_constants(INode * inode,Progress_Meter_Class & meter,bool voxelize);
  141. // create the materials
  142. int scan_used_materials(Mesh & mesh, Mtl * nodemtl);
  143. void create_materials(Mtl * nodemtl,DWORD wirecolor, char *materialColorTexture);
  144. void fix_diffuse_materials(bool isHouseColor);
  145. // count number of used solid materials (no texture)
  146. int getNumSolidMaterials(Mtl * nodemtl);
  147. // creating damage stages
  148. void add_damage_stage(MeshSaveClass * damage_mesh);
  149. // methods used in building the wtm file
  150. int write_header(ChunkSaveClass & csave);
  151. int write_user_text(ChunkSaveClass & csave);
  152. int write_verts(ChunkSaveClass & csave);
  153. int write_vert_normals(ChunkSaveClass & csave);
  154. int write_vert_influences(ChunkSaveClass & csave);
  155. int write_vert_shade_indices(ChunkSaveClass & csave);
  156. int write_triangles(ChunkSaveClass & csave);
  157. int write_material_info(ChunkSaveClass & csave);
  158. int write_shaders(ChunkSaveClass & csave);
  159. int write_vertex_materials(ChunkSaveClass & csave);
  160. int write_textures(ChunkSaveClass & csave);
  161. int write_pass(ChunkSaveClass & csave,int pass);
  162. int write_vertex_material_ids(ChunkSaveClass & csave,int pass);
  163. int write_shader_ids(ChunkSaveClass & csave,int pass);
  164. int write_dcg(ChunkSaveClass & csave,int pass);
  165. int write_texture_stage(ChunkSaveClass & csave,int pass,int stage);
  166. int write_texture_ids(ChunkSaveClass & csave,int pass,int stage);
  167. int write_texture_coords(ChunkSaveClass & csave,int pass,int stage);
  168. int write_aabtree(ChunkSaveClass & csave);
  169. // transforms mesh so that it uses the desired coordinate system
  170. void prep_mesh(Mesh & mesh,Matrix3 & objoff);
  171. // inverse deform the mesh so that its ready to be used as a skin!
  172. void get_skin_modifier_objects(SkinDataClass ** skin_data_ptr,SkinWSMObjectClass ** skin_obj_ptr);
  173. int get_htree_bone_index_for_inode(INode * node);
  174. void inv_deform_mesh(void);
  175. // get rendering settings for the materials
  176. void customize_materials(void);
  177. // Write the ps2 shaders and approximate them as close as possible in the W3D shaders.
  178. int write_ps2_shaders(ChunkSaveClass & csave);
  179. // Make the PC shader emulate the PS2 shader.
  180. void setup_PC_shaders_from_PS2_shaders();
  181. friend class DamageClass;
  182. };
  183. #endif /*MESHSAVE_H*/