meshsave.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. ** Command & Conquer Renegade(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 45 1/28/02 3:47p 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 "w3dappdata.h"
  52. class HierarchySaveClass;
  53. class MeshConnectionsClass;
  54. class MeshSaveClass;
  55. class SkinDataClass;
  56. /*******************************************************************************************
  57. **
  58. ** VertStruct
  59. **
  60. *******************************************************************************************/
  61. struct VertStruct
  62. {
  63. Point3 Vertex;
  64. Point3 Normal;
  65. Point2 TexCoord;
  66. Color Color;
  67. uint32 MaxVertIdx; // index of the MAX vertex that this vert came from
  68. uint32 MaxFaceIdx; // index of the MAX face that this vert came from
  69. VertStruct * Next; // used by the hash table...
  70. };
  71. /*******************************************************************************************
  72. **
  73. ** FaceStruct
  74. **
  75. *******************************************************************************************/
  76. struct FaceStruct
  77. {
  78. uint32 MaxVidx[3]; // original 3ds-MAX vertex index (for smoothing computations)
  79. uint32 OurVidx[3]; // vertex, vertex normal, and texture coord indices
  80. uint32 MaterialIdx; // material index
  81. uint32 SmGroup; // smoothing group (not really needed, normals pre-calced)
  82. Point3 Normal; // Face normal
  83. float32 Dist; // Plane distance
  84. uint32 Attributes; // collision flags, sort method, etc
  85. };
  86. /*******************************************************************************************
  87. **
  88. ** MeshSaveClass - this is the big one, create meshes and skins from a MAX mesh.
  89. **
  90. *******************************************************************************************/
  91. class MeshSaveClass
  92. {
  93. public:
  94. enum {
  95. EX_UNKNOWN = 0, // exception error codes
  96. EX_CANCEL = 1
  97. };
  98. MeshSaveClass(
  99. char * mesh_name,
  100. char * container_name,
  101. INode * inode,
  102. const Mesh * input_mesh,
  103. Matrix3 & exportspace,
  104. W3DAppData2Struct & exportoptions,
  105. HierarchySaveClass * htree,
  106. TimeValue curtime,
  107. Progress_Meter_Class & meter,
  108. WorldInfoClass * world_info = NULL
  109. );
  110. ~MeshSaveClass(void);
  111. int Write_To_File(ChunkSaveClass & csave,bool export_aabtrees = false);
  112. private:
  113. INode * MaxINode;
  114. W3DAppData2Struct & ExportOptions;
  115. W3dMeshHeader3Struct Header;
  116. W3dMaterialDescClass MaterialDesc;
  117. MeshBuilderClass Builder;
  118. TimeValue CurTime;
  119. Matrix3 ExportSpace;
  120. Matrix3 MeshToExportSpace;
  121. Matrix3 PivotSpace;
  122. HierarchySaveClass * HTree;
  123. char * UserText;
  124. bool MeshInverted; // this flag indicates that the transform is inverting this mesh
  125. W3dVertInfStruct * VertInfluences;
  126. int * MaterialRemapTable; // reindexes mtl_idx after un-used mtls are removed
  127. // Flag set if the mesh uses a PS2 material.
  128. int PS2Material;
  129. private:
  130. // Use a MeshBuilderClass to process the mesh
  131. void Build_Mesh(Mesh & mesh, Mtl *node_mtl);
  132. // compute properties for the mesh
  133. void compute_bounding_volumes(void);
  134. void compute_physical_constants(INode * inode,Progress_Meter_Class & meter,bool voxelize);
  135. // create the materials
  136. int scan_used_materials(Mesh & mesh, Mtl * nodemtl);
  137. void create_materials(Mtl * nodemtl,DWORD wirecolor);
  138. // creating damage stages
  139. void add_damage_stage(MeshSaveClass * damage_mesh);
  140. // methods used in building the wtm file
  141. int write_header(ChunkSaveClass & csave);
  142. int write_user_text(ChunkSaveClass & csave);
  143. int write_verts(ChunkSaveClass & csave);
  144. int write_vert_normals(ChunkSaveClass & csave);
  145. int write_vert_influences(ChunkSaveClass & csave);
  146. int write_vert_shade_indices(ChunkSaveClass & csave);
  147. int write_triangles(ChunkSaveClass & csave);
  148. int write_material_info(ChunkSaveClass & csave);
  149. int write_shaders(ChunkSaveClass & csave);
  150. int write_vertex_materials(ChunkSaveClass & csave);
  151. int write_textures(ChunkSaveClass & csave);
  152. int write_pass(ChunkSaveClass & csave,int pass);
  153. int write_vertex_material_ids(ChunkSaveClass & csave,int pass);
  154. int write_shader_ids(ChunkSaveClass & csave,int pass);
  155. int write_dcg(ChunkSaveClass & csave,int pass);
  156. int write_texture_stage(ChunkSaveClass & csave,int pass,int stage);
  157. int write_texture_ids(ChunkSaveClass & csave,int pass,int stage);
  158. int write_texture_coords(ChunkSaveClass & csave,int pass,int stage);
  159. int write_aabtree(ChunkSaveClass & csave);
  160. // transforms mesh so that it uses the desired coordinate system
  161. void prep_mesh(Mesh & mesh,Matrix3 & objoff);
  162. // inverse deform the mesh so that its ready to be used as a skin!
  163. void get_skin_modifier_objects(SkinDataClass ** skin_data_ptr,SkinWSMObjectClass ** skin_obj_ptr);
  164. int get_htree_bone_index_for_inode(INode * node);
  165. void inv_deform_mesh(void);
  166. // get rendering settings for the materials
  167. void customize_materials(void);
  168. // Write the ps2 shaders and approximate them as close as possible in the W3D shaders.
  169. int write_ps2_shaders(ChunkSaveClass & csave);
  170. // Make the PC shader emulate the PS2 shader.
  171. void setup_PC_shaders_from_PS2_shaders();
  172. friend class DamageClass;
  173. };
  174. #endif /*MESHSAVE_H*/