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