mesh.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. ** Command & Conquer Generals(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 15 8/20/01 9:31a Jani_p $ */
  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 "LightEnvironment.h" //added for 'Generals'
  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 MaterialPassClass;
  58. class IndexBufferClass;
  59. struct W3dMeshHeaderStruct;
  60. struct W3dTexCoordStruct;
  61. class TextureClass;
  62. class VertexMaterialClass;
  63. struct VertexFormatXYZNDUV2;
  64. /**
  65. ** MeshClass -- Render3DObject for rendering meshes.
  66. */
  67. class MeshClass : public W3DMPO, public RenderObjClass
  68. {
  69. W3DMPO_GLUE(MeshClass)
  70. public:
  71. MeshClass(void);
  72. MeshClass(const MeshClass & src);
  73. MeshClass & operator = (const MeshClass &);
  74. virtual ~MeshClass(void);
  75. /////////////////////////////////////////////////////////////////////////////
  76. // Render Object Interface
  77. /////////////////////////////////////////////////////////////////////////////
  78. virtual RenderObjClass * Clone(void) const;
  79. virtual int Class_ID(void) const { return CLASSID_MESH; }
  80. virtual const char * Get_Name(void) const;
  81. virtual void Set_Name(const char * name);
  82. virtual int Get_Num_Polys(void) const;
  83. virtual void Render(RenderInfoClass & rinfo);
  84. void Render_Material_Pass(MaterialPassClass * pass,IndexBufferClass * ib);
  85. virtual void Special_Render(SpecialRenderInfoClass & rinfo);
  86. /////////////////////////////////////////////////////////////////////////////
  87. // Render Object Interface - Collision Detection
  88. /////////////////////////////////////////////////////////////////////////////
  89. virtual bool Cast_Ray(RayCollisionTestClass & raytest);
  90. virtual bool Cast_AABox(AABoxCollisionTestClass & boxtest);
  91. virtual bool Cast_OBBox(OBBoxCollisionTestClass & boxtest);
  92. virtual bool Intersect_AABox(AABoxIntersectionTestClass & boxtest);
  93. virtual bool Intersect_OBBox(OBBoxIntersectionTestClass & boxtest);
  94. /////////////////////////////////////////////////////////////////////////////
  95. // Render Object Interface - Bounding Volumes
  96. /////////////////////////////////////////////////////////////////////////////
  97. virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const;
  98. virtual void Get_Obj_Space_Bounding_Box(AABoxClass & box) const;
  99. /////////////////////////////////////////////////////////////////////////////
  100. // Render Object Interface - Attributes, Options, Properties, etc
  101. /////////////////////////////////////////////////////////////////////////////
  102. virtual void Scale(float scale);
  103. virtual void Scale(float scalex, float scaley, float scalez);
  104. virtual MaterialInfoClass * Get_Material_Info(void);
  105. virtual int Get_Sort_Level(void) const;
  106. virtual void Set_Sort_Level(int level);
  107. /////////////////////////////////////////////////////////////////////////////
  108. // Render Object Interface - Decals
  109. /////////////////////////////////////////////////////////////////////////////
  110. virtual void Create_Decal(DecalGeneratorClass * generator);
  111. virtual void Delete_Decal(uint32 decal_id);
  112. /////////////////////////////////////////////////////////////////////////////
  113. // MeshClass Interface
  114. /////////////////////////////////////////////////////////////////////////////
  115. WW3DErrorType Init(const MeshBuilderClass & builder,MaterialInfoClass * matinfo,const char * name,const char * hmodelname);
  116. WW3DErrorType Load_W3D(ChunkLoadClass & cload);
  117. void Generate_Culling_Tree(void);
  118. MeshModelClass * Get_Model(void);
  119. MeshModelClass * Peek_Model(void);
  120. uint32 Get_W3D_Flags(void);
  121. const char * Get_User_Text(void) const;
  122. int Get_Draw_Call_Count(void) const;
  123. bool Contains(const Vector3 &point);
  124. void Compose_Deformed_Vertex_Buffer(
  125. VertexFormatXYZNDUV2* verts,
  126. const Vector2* uv0,
  127. const Vector2* uv1,
  128. const unsigned* diffuse);
  129. void Get_Deformed_Vertices(Vector3 *dst_vert, Vector3 *dst_norm);
  130. void Get_Deformed_Vertices(Vector3 *dst_vert);
  131. void Set_Lighting_Environment(LightEnvironmentClass * light_env) { if (light_env) {m_localLightEnv=*light_env;LightEnvironment = &m_localLightEnv;} else {LightEnvironment = NULL;} }
  132. LightEnvironmentClass * Get_Lighting_Environment(void) { return LightEnvironment; }
  133. inline float Get_Alpha_Override(void) { return m_alphaOverride;}
  134. void Set_Next_Visible_Skin(MeshClass * next_visible) { NextVisibleSkin = next_visible; }
  135. MeshClass * Peek_Next_Visible_Skin(void) { return NextVisibleSkin; }
  136. void Set_Base_Vertex_Offset(int base) { BaseVertexOffset = base; }
  137. int Get_Base_Vertex_Offset(void) { return BaseVertexOffset; }
  138. // Do old .w3d mesh files get fog turned on or off?
  139. static bool Legacy_Meshes_Fogged;
  140. void Replace_Texture(TextureClass* texture,TextureClass* new_texture);
  141. void Replace_VertexMaterial(VertexMaterialClass* vmat,VertexMaterialClass* new_vmat);
  142. void Make_Unique();
  143. protected:
  144. virtual void Add_Dependencies_To_List (DynamicVectorClass<StringClass> &file_list, bool textures_only = false);
  145. virtual void Update_Cached_Bounding_Volumes(void) const;
  146. void Free(void);
  147. void install_materials(MeshLoadInfoClass * loadinfo);
  148. void clone_materials(const MeshClass & srcmesh);
  149. MeshModelClass * Model;
  150. DecalMeshClass * DecalMesh;
  151. LightEnvironmentClass * LightEnvironment; // cached pointer to the light environment for this mesh
  152. LightEnvironmentClass m_localLightEnv; //added for 'Generals'
  153. float m_alphaOverride; //added for 'Generals' to allow variable alpha on meshes.
  154. float m_materialPassEmissiveOverride; //added for 'Generals' to allow variable emissive on additional passes.
  155. float m_materialPassAlphaOverride; //added for 'Generals' to allow variable alpha on additional render passes.
  156. int BaseVertexOffset; // offset to our first vertex in whatever vb this mesh is in.
  157. MeshClass * NextVisibleSkin; // linked list of visible skins
  158. friend class MeshBuilderClass;
  159. };
  160. inline MeshModelClass * MeshClass::Peek_Model(void)
  161. {
  162. return Model;
  163. }
  164. // This utility function recurses throughout the subobjects of a renderobject,
  165. // and for each MeshClass it finds it sets the given MeshModel flag on its
  166. // model. This is useful for stuff like making a RenderObjects' polys sort.
  167. //void Set_MeshModel_Flag(RenderObjClass *robj, MeshModelClass::FlagsType flag, int onoff);
  168. void Set_MeshModel_Flag(RenderObjClass *robj, int flag, int onoff);
  169. #endif /*MESH_H*/