mesh.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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/ww3d2/mesh.h 17 3/14/02 2:37p Greg_h $ */
  19. /***********************************************************************************************
  20. *** Confidential - Westwood Studios ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Commando / G 3D engine *
  24. * *
  25. * File Name : MESH.H *
  26. * *
  27. * Programmer : Greg Hjelstrom *
  28. * *
  29. * Start Date : 06/11/97 *
  30. * *
  31. * Last Update : June 11, 1997 [GH] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #if defined(_MSC_VER)
  37. #pragma once
  38. #endif
  39. #ifndef MESH_H
  40. #define MESH_H
  41. #include "always.h"
  42. #include "rendobj.h"
  43. #include "bittype.h"
  44. #include "w3derr.h"
  45. #include "dx8polygonrenderer.h"
  46. class MeshBuilderClass;
  47. class HModelClass;
  48. class AuxMeshDataClass;
  49. class MeshLoadInfoClass;
  50. class W3DMeshClass;
  51. class MaterialInfoClass;
  52. class ChunkLoadClass;
  53. class ChunkSaveClass;
  54. class RenderInfoClass;
  55. class MeshModelClass;
  56. class DecalMeshClass;
  57. class LightEnvironmentClass;
  58. class MaterialPassClass;
  59. class IndexBufferClass;
  60. struct W3dMeshHeaderStruct;
  61. struct W3dTexCoordStruct;
  62. class TextureClass;
  63. class VertexMaterialClass;
  64. struct VertexFormatXYZNDUV2;
  65. class DX8FVFCategoryContainer;
  66. /**
  67. ** MeshClass -- Render3DObject for rendering meshes.
  68. */
  69. class MeshClass : public RenderObjClass
  70. {
  71. public:
  72. MeshClass(void);
  73. MeshClass(const MeshClass & src);
  74. private:
  75. MeshClass & operator = (const MeshClass &);
  76. public:
  77. virtual ~MeshClass(void);
  78. /////////////////////////////////////////////////////////////////////////////
  79. // Render Object Interface
  80. /////////////////////////////////////////////////////////////////////////////
  81. virtual RenderObjClass * Clone(void) const;
  82. virtual int Class_ID(void) const { return CLASSID_MESH; }
  83. virtual const char * Get_Name(void) const;
  84. virtual void Set_Name(const char * name);
  85. virtual int Get_Num_Polys(void) const;
  86. virtual void Render(RenderInfoClass & rinfo);
  87. void Render_Material_Pass(MaterialPassClass * pass,IndexBufferClass * ib);
  88. virtual void Special_Render(SpecialRenderInfoClass & rinfo);
  89. /////////////////////////////////////////////////////////////////////////////
  90. // Render Object Interface - Collision Detection
  91. /////////////////////////////////////////////////////////////////////////////
  92. virtual bool Cast_Ray(RayCollisionTestClass & raytest);
  93. virtual bool Cast_AABox(AABoxCollisionTestClass & boxtest);
  94. virtual bool Cast_OBBox(OBBoxCollisionTestClass & boxtest);
  95. virtual bool Intersect_AABox(AABoxIntersectionTestClass & boxtest);
  96. virtual bool Intersect_OBBox(OBBoxIntersectionTestClass & boxtest);
  97. /////////////////////////////////////////////////////////////////////////////
  98. // Render Object Interface - Bounding Volumes
  99. /////////////////////////////////////////////////////////////////////////////
  100. virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const;
  101. virtual void Get_Obj_Space_Bounding_Box(AABoxClass & box) const;
  102. /////////////////////////////////////////////////////////////////////////////
  103. // Render Object Interface - Attributes, Options, Properties, etc
  104. /////////////////////////////////////////////////////////////////////////////
  105. virtual void Scale(float scale);
  106. virtual void Scale(float scalex, float scaley, float scalez);
  107. virtual MaterialInfoClass * Get_Material_Info(void);
  108. virtual int Get_Sort_Level(void) const;
  109. virtual void Set_Sort_Level(int level);
  110. /////////////////////////////////////////////////////////////////////////////
  111. // Render Object Interface - Decals
  112. /////////////////////////////////////////////////////////////////////////////
  113. virtual void Create_Decal(DecalGeneratorClass * generator);
  114. virtual void Delete_Decal(uint32 decal_id);
  115. /////////////////////////////////////////////////////////////////////////////
  116. // MeshClass Interface
  117. /////////////////////////////////////////////////////////////////////////////
  118. WW3DErrorType Init(const MeshBuilderClass & builder,MaterialInfoClass * matinfo,const char * name,const char * hmodelname);
  119. WW3DErrorType Load_W3D(ChunkLoadClass & cload);
  120. void Generate_Culling_Tree(void);
  121. MeshModelClass * Get_Model(void);
  122. MeshModelClass * Peek_Model(void);
  123. uint32 Get_W3D_Flags(void);
  124. const char * Get_User_Text(void) const;
  125. bool Contains(const Vector3 &point);
  126. void Compose_Deformed_Vertex_Buffer(
  127. VertexFormatXYZNDUV2* verts,
  128. const Vector2* uv0,
  129. const Vector2* uv1,
  130. const unsigned* diffuse);
  131. void Get_Deformed_Vertices(Vector3 *dst_vert, Vector3 *dst_norm);
  132. void Get_Deformed_Vertices(Vector3 *dst_vert);
  133. void Set_Lighting_Environment(LightEnvironmentClass * light_env) { LightEnvironment = light_env; }
  134. LightEnvironmentClass * Get_Lighting_Environment(void) { return LightEnvironment; }
  135. void Set_Next_Visible_Skin(MeshClass * next_visible) { NextVisibleSkin = next_visible; }
  136. MeshClass * Peek_Next_Visible_Skin(void) { return NextVisibleSkin; }
  137. void Set_Base_Vertex_Offset(int base) { BaseVertexOffset = base; }
  138. int Get_Base_Vertex_Offset(void) { return BaseVertexOffset; }
  139. // Do old .w3d mesh files get fog turned on or off?
  140. static bool Legacy_Meshes_Fogged;
  141. void Replace_Texture(TextureClass* texture,TextureClass* new_texture);
  142. void Replace_VertexMaterial(VertexMaterialClass* vmat,VertexMaterialClass* new_vmat);
  143. void Make_Unique();
  144. unsigned Get_Debug_Id() const { return MeshDebugId; }
  145. void Set_Debugger_Disable(bool b) { IsDisabledByDebugger=b; }
  146. bool Is_Disabled_By_Debugger() const { return IsDisabledByDebugger; }
  147. /*
  148. ** User Lighting feature, meshes can have a user lighting array.
  149. */
  150. void Install_User_Lighting_Array(Vector4 * lighting);
  151. unsigned int * Get_User_Lighting_Array(bool alloc = false);
  152. virtual void Save_User_Lighting (ChunkSaveClass & csave);
  153. virtual void Load_User_Lighting (ChunkLoadClass & cload);
  154. protected:
  155. void Free(void);
  156. virtual void Add_Dependencies_To_List (DynamicVectorClass<StringClass> &file_list, bool textures_only = false);
  157. virtual void Update_Cached_Bounding_Volumes(void) const;
  158. DX8FVFCategoryContainer* Peek_FVF_Category_Container(void);
  159. void install_materials(MeshLoadInfoClass * loadinfo);
  160. void clone_materials(const MeshClass & srcmesh);
  161. void setup_materials_for_user_lighting(void);
  162. void setup_material_for_user_lighting(VertexMaterialClass * mtl);
  163. MeshModelClass * Model;
  164. DecalMeshClass * DecalMesh;
  165. LightEnvironmentClass * LightEnvironment; // cached pointer to the light environment for this mesh
  166. int BaseVertexOffset; // offset to our first vertex in whatever vb this mesh is in.
  167. MeshClass * NextVisibleSkin; // linked list of visible skins
  168. unsigned MeshDebugId;
  169. bool IsDisabledByDebugger;
  170. unsigned int * UserLighting; // optional array of user lighting values
  171. // DX8 Mesh rendering system data
  172. DX8PolygonRendererList PolygonRendererList;
  173. friend class MeshBuilderClass;
  174. friend class DX8MeshRendererClass;
  175. friend class DX8PolygonRendererClass;
  176. };
  177. inline MeshModelClass * MeshClass::Peek_Model(void)
  178. {
  179. return Model;
  180. }
  181. // This utility function recurses throughout the subobjects of a renderobject,
  182. // and for each MeshClass it finds it sets the given MeshModel flag on its
  183. // model. This is useful for stuff like making a RenderObjects' polys sort.
  184. //void Set_MeshModel_Flag(RenderObjClass *robj, MeshModelClass::FlagsType flag, int onoff);
  185. void Set_MeshModel_Flag(RenderObjClass *robj, int flag, int onoff);
  186. #endif /*MESH_H*/