Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
meshmdl.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/***********************************************************************************************
20 *** 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 ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WW3D *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/meshmdl.h $*
26 * *
27 * Author:: Greg Hjelstrom *
28 * *
29 * $Modtime:: 11/24/01 6:17p $*
30 * *
31 * $Revision:: 40 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37
38#if defined(_MSC_VER)
39#pragma once
40#endif
41
42#ifndef MESHMDL_H
43#define MESHMDL_H
44
45#include "vector2.h"
46#include "vector3.h"
47#include "vector4.h"
48#include "vector3i.h"
49#include "sharebuf.h"
50#include "shader.h"
51#include "wwdebug.h"
52#include "vertmaterial.h"
53#include "bittype.h"
54#include "colmath.h"
55#include "simplevec.h"
56#include "wwstring.h"
57#include "rinfo.h"
58#include "meshgeometry.h"
59#include "meshmatdesc.h"
60#include "dx8list.h"
61
62class TextureClass;
63class RenderInfoClass;
65class MatBufferClass;
66class TexBufferClass;
67class AABoxClass;
68class OBBoxClass;
69class FrustumClass;
70class SphereClass;
71class AABTreeClass;
75class ChunkLoadClass;
76class ChunkSaveClass;
77class MeshClass;
78class HTreeClass;
81
83class DX8PolygonRendererAttachClass;
85class GapFillerClass;
86
88
120
121
126class GapFillerClass : public W3DMPO
127{
129
130 TriIndex* PolygonArray;
131 unsigned PolygonCount;
132 unsigned ArraySize;
136 MeshModelClass* mmc;
137
138 GapFillerClass& operator = (const GapFillerClass & that) {}
139public:
141 GapFillerClass(const GapFillerClass& that);
143
144 WWINLINE const TriIndex* Get_Polygon_Array() const { return PolygonArray; }
145 WWINLINE unsigned Get_Polygon_Count() const { return PolygonCount; }
146 WWINLINE TextureClass** Get_Texture_Array(int pass, int stage) const { return TextureArray[pass][stage]; }
147 WWINLINE VertexMaterialClass** Get_Material_Array(int pass) const { return MaterialArray[pass]; }
148 WWINLINE ShaderClass* Get_Shader_Array(int pass) const { return ShaderArray[pass]; }
149
150 void Add_Polygon(unsigned polygon_index,unsigned vidx1,unsigned vidx2, unsigned vidx3);
151 void Shrink_Buffers();
152};
153
155{
157
158public:
159
160 MeshModelClass(void);
161 MeshModelClass(const MeshModelClass & that);
162 ~MeshModelClass(void);
163
165 void Reset(int polycount,int vertcount,int passcount);
167 void Shadow_Render(SpecialRenderInfoClass & rinfo,const Matrix3D & tm,const HTreeClass * htree);
168
170 // Material interface, All of these functions call through to the current
171 // material decription.
173 void Set_Pass_Count(int passes) { CurMatDesc->Set_Pass_Count(passes); }
174 int Get_Pass_Count(void) const { return CurMatDesc->Get_Pass_Count(); }
175
176 const Vector2 * Get_UV_Array(int pass = 0, int stage = 0) { return CurMatDesc->Get_UV_Array(pass,stage); }
177 int Get_UV_Array_Count(void) { return CurMatDesc->Get_UV_Array_Count(); }
178 const Vector2 * Get_UV_Array_By_Index(int index) { return CurMatDesc->Get_UV_Array_By_Index(index, false); }
179
180 unsigned * Get_DCG_Array(int pass) { return CurMatDesc->Get_DCG_Array(pass); }
181 unsigned * Get_DIG_Array(int pass) { return CurMatDesc->Get_DIG_Array(pass); }
182 VertexMaterialClass::ColorSourceType Get_DCG_Source(int pass) { return CurMatDesc->Get_DCG_Source(pass); }
183 VertexMaterialClass::ColorSourceType Get_DIG_Source(int pass) { return CurMatDesc->Get_DIG_Source(pass); }
184
185 unsigned * Get_Color_Array(int array_index,bool create = true) { return CurMatDesc->Get_Color_Array(array_index,create); }
186
187 void Set_Single_Material(VertexMaterialClass * vmat,int pass=0) { CurMatDesc->Set_Single_Material(vmat,pass); }
188 void Set_Single_Texture(TextureClass * tex,int pass=0,int stage=0) { CurMatDesc->Set_Single_Texture(tex,pass,stage); }
189 void Set_Single_Shader(ShaderClass shader,int pass=0) { CurMatDesc->Set_Single_Shader(shader,pass); }
190
191 // the "Get" functions add a reference before returning the pointer (if appropriate)
192 VertexMaterialClass * Get_Single_Material(int pass=0) const { return CurMatDesc->Get_Single_Material(pass); }
193 TextureClass * Get_Single_Texture(int pass=0,int stage=0) const { return CurMatDesc->Get_Single_Texture(pass,stage); }
194 ShaderClass Get_Single_Shader(int pass=0) const { return CurMatDesc->Get_Single_Shader(pass); }
195
196 // the "Peek" functions just return the pointer and it's the caller's responsibility to
197 // maintain a reference to an object with a reference to the data
198 VertexMaterialClass * Peek_Single_Material(int pass=0) const { return CurMatDesc->Peek_Single_Material(pass); }
199 TextureClass * Peek_Single_Texture(int pass=0,int stage=0) const { return CurMatDesc->Peek_Single_Texture(pass,stage); }
200
201 void Set_Material(int vidx,VertexMaterialClass * vmat,int pass=0) { CurMatDesc->Set_Material(vidx,vmat,pass); }
202 void Set_Shader(int pidx,ShaderClass shader,int pass=0) { CurMatDesc->Set_Shader(pidx,shader,pass); }
203 void Set_Texture(int pidx,TextureClass * tex,int pass=0,int stage=0) { CurMatDesc->Set_Texture(pidx,tex,pass,stage); }
204
205 // Queries for determining whether this model has per-polygon arrays of Materials, Shaders, or Textures
206 bool Has_Material_Array(int pass) const { return CurMatDesc->Has_Material_Array(pass); }
207 bool Has_Shader_Array(int pass) const { return CurMatDesc->Has_Shader_Array(pass); }
208 bool Has_Texture_Array(int pass,int stage) const { return CurMatDesc->Has_Texture_Array(pass,stage); }
209
210 // "Get" functions for Materials, Textures, and Shaders when there are more than one (per-polygon/per-vertex)
211 VertexMaterialClass * Get_Material(int vidx,int pass=0) const { return CurMatDesc->Get_Material(vidx,pass); }
212 TextureClass * Get_Texture(int pidx,int pass=0,int stage=0) const { return CurMatDesc->Get_Texture(pidx,pass,stage); }
213 ShaderClass Get_Shader(int pidx,int pass=0) const { return CurMatDesc->Get_Shader(pidx,pass); }
214
215 // "Peek" functions for Materials and Textures when there are more than one (per-polygon/per-vertex)
216 VertexMaterialClass * Peek_Material(int vidx,int pass=0) const { return CurMatDesc->Peek_Material(vidx,pass); }
217 TextureClass * Peek_Texture(int pidx,int pass=0,int stage=0) const { return CurMatDesc->Peek_Texture(pidx,pass,stage); }
218
219 void Replace_Texture(TextureClass* texture,TextureClass* new_texture);
221
223 // Modification interface. Call these functions to cause the model to ensure
224 // that the specified array is unique to this instance. (I.e. if the specified
225 // data is being shared, break the link!)
228 void Make_UV_Array_Unique(int pass=0,int stage=0);
229 void Make_Color_Array_Unique(int array_index=0);
230
231 // Load the w3d file format
233
235 // Decal interface
237 void Create_Decal(DecalGeneratorClass * generator, MeshClass * parent);
238 void Delete_Decal(uint32 decal_id);
239
241 // Alternate Material Description Interface
242 // Some models will allow you to alternate between multiple material descriptions
246
247 // Process texture reductions
248// void Process_Texture_Reduction(void);
249
250 // FVF category container will be NULL if the mesh hasn't been registered to the rendering system
252
253 // Determine whether any rendering feature used by this mesh requires vertex normals
254 bool Needs_Vertex_Normals(void);
255
257 const GapFillerClass* Get_Gap_Filler() const { return GapFiller; }
258
259 bool Has_Polygon_Renderers(void) { return !PolygonRendererList.Is_Empty(); }
260
261protected:
262
263 // MeshClass will set this for skins so that they can get the bone transforms
264 void Set_HTree(const HTreeClass * htree);
265
266public: // Jani: I need to have an access to these for now...
267
268 TexBufferClass * Get_Texture_Array(int pass,int stage,bool create = true)
269 {
270 return CurMatDesc->Get_Texture_Array(pass,stage,create);
271 }
272 MatBufferClass * Get_Material_Array(int pass,bool create = true)
273 {
274 return CurMatDesc->Get_Material_Array(pass,create);
275 }
276 ShaderClass * Get_Shader_Array(int pass,bool create = true)
277 {
278 return CurMatDesc->Get_Shader_Array(pass,create);
279 }
280
281protected:
282
284
285 // loading
308
309 // post-processing
310 void post_process(void);
311 void post_process_fog(void);
312
313 unsigned int get_sort_flags(int pass) const;
314 unsigned int get_sort_flags(void) const;
316 void modify_for_overbright(void);
317
318 // mat info support
320 void clone_materials(const MeshModelClass & srcmesh);
322
323 // Material Descriptions
324 // DefMatDesc - the default material description, allocated in constructor, always present.
325 // AlternateMatDes - an optional alternate material description, allocated at load time if needed
326 // CurMatDesc - pointer to the currently active material description.
330
331 // Collection of the unique materials in the mesh
333
334 // DX8 Mesh rendering system data
336
337 // Jani: Adding this here temporarily... must fine better place
339 bool HasBeenInUse; // For debugging purposes!
340
341 friend class MeshClass;
342 friend class MeshDeformSetClass;
343 friend class MeshDeformClass;
348};
349
350
351
352
353
354
355
356#endif
357
#define W3DMPO_GLUE(ARGCLASS)
Definition always.h:120
#define WWINLINE
Definition always.h:172
unsigned long uint32
Definition bittype.h:46
WWINLINE TextureClass ** Get_Texture_Array(int pass, int stage) const
Definition meshmdl.h:146
WWINLINE VertexMaterialClass ** Get_Material_Array(int pass) const
Definition meshmdl.h:147
void Add_Polygon(unsigned polygon_index, unsigned vidx1, unsigned vidx2, unsigned vidx3)
Definition meshmdl.cpp:568
WWINLINE const TriIndex * Get_Polygon_Array() const
Definition meshmdl.h:144
GapFillerClass(MeshModelClass *mmc)
Definition meshmdl.cpp:451
void Shrink_Buffers()
Definition meshmdl.cpp:606
WWINLINE ShaderClass * Get_Shader_Array(int pass) const
Definition meshmdl.h:148
WWINLINE unsigned Get_Polygon_Count() const
Definition meshmdl.h:145
friend class MeshClass
Definition meshmdl.h:341
void Set_Texture(int pidx, TextureClass *tex, int pass=0, int stage=0)
Definition meshmdl.h:203
WW3DErrorType read_materials(ChunkLoadClass &cload, MeshLoadContextClass *context)
MeshModelClass & operator=(const MeshModelClass &that)
Definition meshmdl.cpp:124
WW3DErrorType read_shader_ids(ChunkLoadClass &cload, MeshLoadContextClass *context)
MeshMatDescClass * DefMatDesc
Definition meshmdl.h:327
GapFillerClass * GapFiller
Definition meshmdl.h:338
friend class MeshDeformSetClass
Definition meshmdl.h:342
WW3DErrorType read_per_tri_materials(ChunkLoadClass &cload, MeshLoadContextClass *context)
TextureClass * Peek_Texture(int pidx, int pass=0, int stage=0) const
Definition meshmdl.h:217
bool Has_Shader_Array(int pass) const
Definition meshmdl.h:207
WW3DErrorType read_per_face_texcoord_ids(ChunkLoadClass &cload, MeshLoadContextClass *context)
void Make_UV_Array_Unique(int pass=0, int stage=0)
Definition meshmdl.cpp:310
unsigned * Get_DCG_Array(int pass)
Definition meshmdl.h:180
unsigned * Get_Color_Array(int array_index, bool create=true)
Definition meshmdl.h:185
void compute_static_sort_levels(void)
void post_process(void)
WW3DErrorType read_texture_stage(ChunkLoadClass &cload, MeshLoadContextClass *context)
void Set_Single_Texture(TextureClass *tex, int pass=0, int stage=0)
Definition meshmdl.h:188
void Set_Material(int vidx, VertexMaterialClass *vmat, int pass=0)
Definition meshmdl.h:201
void Make_Color_Array_Unique(int array_index=0)
Definition meshmdl.cpp:315
bool Needs_Vertex_Normals(void)
Definition meshmdl.cpp:361
MatBufferClass * Get_Material_Array(int pass, bool create=true)
Definition meshmdl.h:272
WW3DErrorType read_prelit_material(ChunkLoadClass &cload, MeshLoadContextClass *context)
MaterialInfoClass * MatInfo
Definition meshmdl.h:332
void install_materials(MeshLoadContextClass *loadinfo)
void Init_For_NPatch_Rendering()
Definition meshmdl.cpp:653
WW3DErrorType read_scg(ChunkLoadClass &cload, MeshLoadContextClass *context)
void Reset(int polycount, int vertcount, int passcount)
Definition meshmdl.cpp:157
const Vector2 * Get_UV_Array_By_Index(int index)
Definition meshmdl.h:178
void Delete_Decal(uint32 decal_id)
void Create_Decal(DecalGeneratorClass *generator, MeshClass *parent)
void Enable_Alternate_Material_Description(bool onoff)
Definition meshmdl.cpp:320
VertexMaterialClass * Peek_Material(int vidx, int pass=0) const
Definition meshmdl.h:216
void install_alternate_material_desc(MeshLoadContextClass *context)
bool Has_Material_Array(int pass) const
Definition meshmdl.h:206
void Register_For_Rendering()
Definition meshmdl.cpp:181
bool Has_Polygon_Renderers(void)
Definition meshmdl.h:259
int Get_Pass_Count(void) const
Definition meshmdl.h:174
VertexMaterialClass::ColorSourceType Get_DIG_Source(int pass)
Definition meshmdl.h:183
WW3DErrorType read_vertex_colors(ChunkLoadClass &cload, MeshLoadContextClass *context)
WW3DErrorType read_vertex_material_ids(ChunkLoadClass &cload, MeshLoadContextClass *context)
WW3DErrorType read_vertex_materials(ChunkLoadClass &cload, MeshLoadContextClass *context)
WW3DErrorType read_v2_materials(ChunkLoadClass &cload, MeshLoadContextClass *context)
ShaderClass * Get_Shader_Array(int pass, bool create=true)
Definition meshmdl.h:276
~MeshModelClass(void)
Definition meshmdl.cpp:107
friend class DX8SkinFVFCategoryContainer
Definition meshmdl.h:345
TextureClass * Get_Texture(int pidx, int pass=0, int stage=0) const
Definition meshmdl.h:212
VertexMaterialClass * Get_Single_Material(int pass=0) const
Definition meshmdl.h:192
void Set_Pass_Count(int passes)
Definition meshmdl.h:173
bool Has_Texture_Array(int pass, int stage) const
Definition meshmdl.h:208
DX8PolygonRendererList PolygonRendererList
Definition meshmdl.h:335
bool Is_Alternate_Material_Description_Enabled(void)
Definition meshmdl.cpp:351
DX8FVFCategoryContainer * Peek_FVF_Category_Container()
Definition meshmdl.cpp:262
WW3DErrorType read_material_info(ChunkLoadClass &cload, MeshLoadContextClass *context)
WW3DErrorType read_material_pass(ChunkLoadClass &cload, MeshLoadContextClass *context)
WW3DErrorType read_textures(ChunkLoadClass &cload, MeshLoadContextClass *context)
WW3DErrorType read_texture_ids(ChunkLoadClass &cload, MeshLoadContextClass *context)
friend class MeshDeformClass
Definition meshmdl.h:343
MeshMatDescClass * AlternateMatDesc
Definition meshmdl.h:328
MeshModelClass(void)
Definition meshmdl.cpp:71
unsigned int get_sort_flags(void) const
WW3DErrorType read_texcoords(ChunkLoadClass &cload, MeshLoadContextClass *context)
friend class DX8MeshRendererClass
Definition meshmdl.h:346
TextureClass * Get_Single_Texture(int pass=0, int stage=0) const
Definition meshmdl.h:193
void Set_Single_Shader(ShaderClass shader, int pass=0)
Definition meshmdl.h:189
WW3DErrorType read_shaders(ChunkLoadClass &cload, MeshLoadContextClass *context)
void Set_Shader(int pidx, ShaderClass shader, int pass=0)
Definition meshmdl.h:202
WW3DErrorType Load_W3D(ChunkLoadClass &cload)
WW3DErrorType read_dig(ChunkLoadClass &cload, MeshLoadContextClass *context)
void post_process_fog(void)
VertexMaterialClass * Get_Material(int vidx, int pass=0) const
Definition meshmdl.h:211
int Get_UV_Array_Count(void)
Definition meshmdl.h:177
void Shadow_Render(SpecialRenderInfoClass &rinfo, const Matrix3D &tm, const HTreeClass *htree)
Definition meshmdl.cpp:274
void Set_HTree(const HTreeClass *htree)
void Set_Single_Material(VertexMaterialClass *vmat, int pass=0)
Definition meshmdl.h:187
friend class MeshLoadContextClass
Definition meshmdl.h:344
MeshMatDescClass * CurMatDesc
Definition meshmdl.h:329
friend class DX8PolygonRendererClass
Definition meshmdl.h:347
TexBufferClass * Get_Texture_Array(int pass, int stage, bool create=true)
Definition meshmdl.h:268
const Vector2 * Get_UV_Array(int pass=0, int stage=0)
Definition meshmdl.h:176
void modify_for_overbright(void)
void Replace_Texture(TextureClass *texture, TextureClass *new_texture)
Definition meshmdl.cpp:207
VertexMaterialClass * Peek_Single_Material(int pass=0) const
Definition meshmdl.h:198
unsigned * Get_DIG_Array(int pass)
Definition meshmdl.h:181
WW3DErrorType read_stage_texcoords(ChunkLoadClass &cload, MeshLoadContextClass *context)
void Replace_VertexMaterial(VertexMaterialClass *vmat, VertexMaterialClass *new_vmat)
Definition meshmdl.cpp:235
WW3DErrorType read_v3_materials(ChunkLoadClass &cload, MeshLoadContextClass *context)
void Make_Geometry_Unique()
Definition meshmdl.cpp:291
WW3DErrorType read_chunks(ChunkLoadClass &cload, MeshLoadContextClass *context)
WW3DErrorType read_dcg(ChunkLoadClass &cload, MeshLoadContextClass *context)
const GapFillerClass * Get_Gap_Filler() const
Definition meshmdl.h:257
ShaderClass Get_Shader(int pidx, int pass=0) const
Definition meshmdl.h:213
ShaderClass Get_Single_Shader(int pass=0) const
Definition meshmdl.h:194
bool HasBeenInUse
Definition meshmdl.h:339
void clone_materials(const MeshModelClass &srcmesh)
VertexMaterialClass::ColorSourceType Get_DCG_Source(int pass)
Definition meshmdl.h:182
TextureClass * Peek_Single_Texture(int pass=0, int stage=0) const
Definition meshmdl.h:199
MultiListClass< DX8PolygonRendererClass > DX8PolygonRendererList
Definition dx8list.h:65
Vector3i16 TriIndex
WW3DErrorType
Definition w3derr.h:51