Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
meshgeometry.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/meshgeometry.h $*
26 * *
27 * Original Author:: Greg Hjelstrom *
28 * *
29 * $Author:: Jani_p $*
30 * *
31 * $Modtime:: 11/24/01 7:28p $*
32 * *
33 * $Revision:: 11 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39#ifndef MESHGEOMETRY_H
40#define MESHGEOMETRY_H
41
42#include "always.h"
43#include "refcount.h"
44#include "bittype.h"
45#include "simplevec.h"
46#include "sharebuf.h"
47#include "w3derr.h"
48#include "vector3.h"
49#include "vector3i.h"
50#include "vector4.h"
51#include "wwdebug.h"
52#include "multilist.h"
53#include "coltest.h"
54#include "inttest.h"
55
56
57class AABoxClass;
58class OBBoxClass;
59class SphereClass;
60class ChunkLoadClass;
61class AABTreeClass;
62class HTreeClass;
63class RenderInfoClass;
64
65// Define which kind of index vector to use (16- or 32 bit)
67//typedef Vector3i TriIndex;
68
69/*
70** The following two defines control two space-saving optimizations. In Renegade I've found
71** that the plane equations are about 8% of the geometry space and vertex normals are about 10%
72** so I'm trying to see if we can get by without them. The plane equations are mainly used
73** by collision detection functions and those are culled pretty well. Anyway, collision is
74** already so expensive that adding a cross product to it doesn't seem to matter.
75**
76** NOTE: currently with optimizations enabled, memory gets trashed if you use OPTIMIZE_VNORM_RAM
77** I suspect this is due to the way Dynamesh uses (abuses) MeshGeometryClass and haven't had
78** time to track it down yet.
79*/
80#define OPTIMIZE_PLANEEQ_RAM 1
81#define OPTIMIZE_VNORM_RAM 0
82
87
89{
90 //W3DMPO_GLUE(MeshGeometryClass)
91
92public:
93
96 virtual ~MeshGeometryClass(void);
97
99
101 {
102 DIRTY_BOUNDS = 0x00000001,
103 DIRTY_PLANES = 0x00000002,
104 DIRTY_VNORMALS = 0x00000004,
105
106 SORT = 0x00000010,
109 DISABLE_PLANE_EQ = 0x00000080,
110 TWO_SIDED = 0x00000100,
111
112 ALIGNED = 0x00000200,
113 SKIN = 0x00000400,
114 ORIENTED = 0x00000800,
115 CAST_SHADOW = 0x00001000,
116
117 PRELIT_MASK = 0x0000E000,
118 PRELIT_VERTEX = 0x00002000,
121
122 ALLOW_NPATCHES = 0x00010000,
123 };
124
125 void Reset_Geometry(int polycount,int vertcount);
126
127 const char * Get_Name(void) const;
128 void Set_Name(const char * newname);
129
130 const char * Get_User_Text(void);
131 void Set_User_Text(char * usertext);
132
133 void Set_Flag(FlagsType flag,bool onoff) { if (onoff) { Flags |= flag; } else { Flags &= ~flag; } }
134 int Get_Flag(FlagsType flag) { return Flags & flag; }
135
136 void Set_Sort_Level(int level) { SortLevel = level; }
137 int Get_Sort_Level(void) const { return SortLevel; }
138
139 int Get_Polygon_Count(void) const { return PolyCount; }
140 int Get_Vertex_Count(void) const { return VertexCount; }
141
142 const TriIndex* Get_Polygon_Array(void) { return get_polys(); }
143 Vector3 * Get_Vertex_Array(void) { WWASSERT(Vertex); return Vertex->Get_Array(); }
144 const Vector3 * Get_Vertex_Normal_Array(void);
145 const Vector4 * Get_Plane_Array(bool create = true);
146 void Compute_Plane(int pidx,PlaneClass * set_plane) const;
147 const uint32 * Get_Vertex_Shade_Index_Array(bool create = true) { return get_shade_indices(create); }
148 const uint16 * Get_Vertex_Bone_Links(void) { return get_bone_links(); }
150 uint8 Get_Poly_Surface_Type(int poly_index) const;
151
152 void Get_Bounding_Box(AABoxClass * set_box);
153 void Get_Bounding_Sphere(SphereClass * set_sphere);
154
155 // exposed culling support
156 bool Has_Cull_Tree(void) { return CullTree != NULL; }
157
158 void Generate_Rigid_APT(const Vector3 & view_dir, SimpleDynVecClass<uint32> & apt);
159 void Generate_Rigid_APT(const OBBoxClass & local_box, SimpleDynVecClass<uint32> & apt);
160 void Generate_Rigid_APT(const OBBoxClass & local_box, const Vector3 & view_dir, SimpleDynVecClass<uint32> & apt);
161
162 void Generate_Skin_APT(const OBBoxClass & world_box, SimpleDynVecClass<uint32> & apt, const Vector3 *world_vertex_locs);
163
164 // containment
165 bool Contains(const Vector3 &point);
166
167 // ray casting and intersection (takes a transform for the mesh). Note that unlike the MeshClass
168 // functions with similar names, these work in object space.
169 bool Cast_Ray(RayCollisionTestClass & raytest);
170 bool Cast_AABox(AABoxCollisionTestClass & boxtest);
171 bool Cast_OBBox(OBBoxCollisionTestClass & boxtest);
173
174 // This function analyses the transform passed into it to call various optimized functions if
175 // the transform is identity or a simple rotation about the z-axis. Otherwise it transforms
176 // boxtest into object space, performs an oob cast and transforms the result back.
177 bool Cast_World_Space_AABox(AABoxCollisionTestClass & boxtest, const Matrix3D &transform);
178
179 // W3D File Format support. Note that derived classes have to override these functions completely
180 // so that they can handle their extra chunks. Using these functions you could load mesh data out
181 // of a W3D file while ignoring all materials, textures, etc.
182 virtual WW3DErrorType Load_W3D(ChunkLoadClass & cload);
183
184 void Scale(const Vector3 &sc);
185
186protected:
187
188 // internal accessor functions that are not exposed to the user (non-const...)
189 TriIndex * get_polys(void);
191 uint32 * get_shade_indices(bool create = true);
192 Vector4 * get_planes(bool create = true);
193 uint16 * get_bone_links(bool create = true);
194
195 // Utility functions (used by collision/intersection functions)
196 int cast_semi_infinite_axis_aligned_ray(const Vector3 & start_point, int axis_dir, unsigned char & flags);
197
198 bool cast_aabox_identity(AABoxCollisionTestClass & boxtest,const Vector3 & trans);
199 bool cast_aabox_z90(AABoxCollisionTestClass & boxtest,const Vector3 & trans);
200 bool cast_aabox_z180(AABoxCollisionTestClass & boxtest,const Vector3 & trans);
201 bool cast_aabox_z270(AABoxCollisionTestClass & boxtest,const Vector3 & trans);
202
207
208 // functions to recompute dirty normals and bounding volumes.
209 virtual void Compute_Plane_Equations(Vector4 * array);
210 virtual void Compute_Vertex_Normals(Vector3 * array);
211 virtual void Compute_Bounds(Vector3 * verts);
212 void Generate_Culling_Tree(void);
213
214 // W3D chunk reading
223
224 // functions to compute the deformed vertices of skins.
225 // Destination pointers MUST point to arrays large enough to hold all vertices
226 void get_deformed_vertices(Vector3 *dst_vert, Vector3 *dst_norm, const HTreeClass * htree);
227 void get_deformed_vertices(Vector3 *dst_vert, const HTreeClass * htree);
228 void get_deformed_screenspace_vertices(Vector4 *dst_vert,const RenderInfoClass & rinfo,const Matrix3D & mesh_tm,const HTreeClass * htree);
229
230 // General info
233 int Flags;
236
237 // Geometry
240
248
254
255};
256
257/*
258** Inline functions for MeshGeometryClass
259*/
261{
262 WWASSERT(Poly);
263 return Poly->Get_Array();
264}
265
266
268{
269 if (create && !VertexShadeIdx) {
270 VertexShadeIdx = NEW_REF(ShareBufferClass<uint32>,(VertexCount, "MeshGeometryClass::VertexShadeIdx"));
271 }
272 if (VertexShadeIdx) {
273 return VertexShadeIdx->Get_Array();
274 }
275 return NULL;
276}
277
279{
280 if (create && !VertexBoneLink) {
281 VertexBoneLink = NEW_REF(ShareBufferClass<uint16>,(VertexCount, "MeshGeometryClass::VertexBoneLink"));
282 }
283 if (VertexBoneLink) {
284 return VertexBoneLink->Get_Array();
285 }
286 return NULL;
287}
288
290{
292 WWASSERT(poly_index >= 0 && poly_index < PolyCount);
293 uint8 *type = PolySurfaceType->Get_Array();
294 return type[poly_index];
295}
296
297#endif //MESHGEOMETRY_H
298
#define NULL
Definition BaseType.h:92
#define WWASSERT
unsigned short uint16
Definition bittype.h:45
unsigned long uint32
Definition bittype.h:46
unsigned char uint8
Definition bittype.h:44
WW3DErrorType read_vertex_shade_indices(ChunkLoadClass &cload)
uint32 * get_shade_indices(bool create=true)
void Get_Bounding_Sphere(SphereClass *set_sphere)
ShareBufferClass< uint8 > * PolySurfaceType
void Reset_Geometry(int polycount, int vertcount)
ShareBufferClass< uint16 > * VertexBoneLink
WW3DErrorType read_vertex_influences(ChunkLoadClass &cload)
virtual void Compute_Plane_Equations(Vector4 *array)
ShareBufferClass< char > * UserText
int Get_Sort_Level(void) const
void Generate_Skin_APT(const OBBoxClass &world_box, SimpleDynVecClass< uint32 > &apt, const Vector3 *world_vertex_locs)
bool cast_aabox_brute_force(AABoxCollisionTestClass &boxtest)
bool Intersect_OBBox(OBBoxIntersectionTestClass &boxtest)
ShareBufferClass< Vector3 > * Vertex
ShareBufferClass< uint32 > * VertexShadeIdx
void get_deformed_screenspace_vertices(Vector4 *dst_vert, const RenderInfoClass &rinfo, const Matrix3D &mesh_tm, const HTreeClass *htree)
bool cast_ray_brute_force(RayCollisionTestClass &raytest)
virtual void Compute_Bounds(Vector3 *verts)
WW3DErrorType read_vertex_normals(ChunkLoadClass &cload)
virtual WW3DErrorType Load_W3D(ChunkLoadClass &cload)
ShareBufferClass< Vector4 > * PlaneEq
const Vector3 * Get_Vertex_Normal_Array(void)
bool cast_obbox_brute_force(OBBoxCollisionTestClass &boxtest)
bool Cast_World_Space_AABox(AABoxCollisionTestClass &boxtest, const Matrix3D &transform)
bool Contains(const Vector3 &point)
int Get_Vertex_Count(void) const
bool Cast_AABox(AABoxCollisionTestClass &boxtest)
virtual ~MeshGeometryClass(void)
const char * Get_Name(void) const
void Compute_Plane(int pidx, PlaneClass *set_plane) const
TriIndex * get_polys(void)
const TriIndex * Get_Polygon_Array(void)
ShareBufferClass< Vector3 > * VertexNorm
AABTreeClass * CullTree
MeshGeometryClass & operator=(const MeshGeometryClass &that)
bool Cast_OBBox(OBBoxCollisionTestClass &boxtest)
WW3DErrorType read_user_text(ChunkLoadClass &cload)
WW3DErrorType read_vertices(ChunkLoadClass &cload)
bool Cast_Ray(RayCollisionTestClass &raytest)
uint16 * get_bone_links(bool create=true)
virtual void Compute_Vertex_Normals(Vector3 *array)
Vector4 * get_planes(bool create=true)
uint8 * Get_Poly_Surface_Type_Array(void)
bool Has_Cull_Tree(void)
void Set_Sort_Level(int level)
ShareBufferClass< TriIndex > * Poly
void Scale(const Vector3 &sc)
Vector3 * Get_Vertex_Array(void)
WW3DErrorType read_chunks(ChunkLoadClass &cload)
bool intersect_obbox_brute_force(OBBoxIntersectionTestClass &localtest)
const uint16 * Get_Vertex_Bone_Links(void)
int cast_semi_infinite_axis_aligned_ray(const Vector3 &start_point, int axis_dir, unsigned char &flags)
void Generate_Rigid_APT(const Vector3 &view_dir, SimpleDynVecClass< uint32 > &apt)
void Generate_Culling_Tree(void)
void Set_Flag(FlagsType flag, bool onoff)
bool cast_aabox_z270(AABoxCollisionTestClass &boxtest, const Vector3 &trans)
ShareBufferClass< char > * MeshName
bool cast_aabox_z90(AABoxCollisionTestClass &boxtest, const Vector3 &trans)
WW3DErrorType read_aabtree(ChunkLoadClass &cload)
void Set_Name(const char *newname)
void Set_User_Text(char *usertext)
int Get_Polygon_Count(void) const
bool cast_aabox_z180(AABoxCollisionTestClass &boxtest, const Vector3 &trans)
const char * Get_User_Text(void)
void get_deformed_vertices(Vector3 *dst_vert, Vector3 *dst_norm, const HTreeClass *htree)
uint8 Get_Poly_Surface_Type(int poly_index) const
void Get_Bounding_Box(AABoxClass *set_box)
Vector3 BoundSphereCenter
WW3DErrorType read_triangles(ChunkLoadClass &cload)
int Get_Flag(FlagsType flag)
const uint32 * Get_Vertex_Shade_Index_Array(bool create=true)
Vector3 * get_vert_normals(void)
const Vector4 * Get_Plane_Array(bool create=true)
bool cast_aabox_identity(AABoxCollisionTestClass &boxtest, const Vector3 &trans)
RefCountClass(void)
Definition refcount.h:108
Vector3i16 TriIndex
#define NEW_REF(C, P)
Definition refcount.h:62
unsigned char flag
Definition vchannel.cpp:273
WW3DErrorType
Definition w3derr.h:51