decalmsh.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. /***********************************************************************************************
  19. *** 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 ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/decalmsh.h $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Jani_p $*
  29. * *
  30. * $Modtime:: 11/24/01 6:18p $*
  31. * *
  32. * $Revision:: 7 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #if defined(_MSC_VER)
  38. #pragma once
  39. #endif
  40. #ifndef DECALMSH_H
  41. #define DECALMSH_H
  42. #include "always.h"
  43. #include "bittype.h"
  44. #include "simplevec.h"
  45. #include "vector.h"
  46. #include "vector2.h"
  47. #include "vector3.h"
  48. #include "vector3i.h"
  49. #include "vector4.h"
  50. #include "shader.h"
  51. #include "vertmaterial.h"
  52. #include "meshgeometry.h"
  53. class MeshClass;
  54. class RenderInfoClass;
  55. class DecalGeneratorClass;
  56. class DecalSystemClass;
  57. class OBBoxClass;
  58. class TextureClass;
  59. /**
  60. ** DecalMeshClass
  61. ** This is a "subordinate" class to MeshModel which simply adds "decal" polygons to the mesh.
  62. ** These polygons will always be exact copies of polygons already in the parent mesh.
  63. **
  64. ** Design Goals:
  65. ** - Each decal can have its own material settings
  66. ** - Dynamically growing array of decals
  67. ** - Each decal is assigned a unique "logical-decal-id" by the decal manager
  68. ** - A decal mesh may be instructed to remove a specified "logical-decal"
  69. **
  70. ** DecalMeshClass is an abstract base class from which we derive concrete classes.
  71. */
  72. class DecalMeshClass : public RefCountClass
  73. {
  74. public:
  75. DecalMeshClass(MeshClass * parent,DecalSystemClass * system);
  76. virtual ~DecalMeshClass(void);
  77. // world_vertex_locs and world_vertex_norms are dynamically updated worldspace vertex data
  78. // which are used by some decal types which cannot use static object geometry (such as decals
  79. // for skins, procedurally generated meshes, etc.)
  80. virtual void Render(void) = 0;
  81. virtual bool Create_Decal( DecalGeneratorClass * generator,
  82. const OBBoxClass & localbox,
  83. SimpleDynVecClass<uint32> & apt,
  84. const DynamicVectorClass<Vector3> * world_vertex_locs = 0) = 0;
  85. virtual bool Delete_Decal(uint32 id) = 0;
  86. virtual int Decal_Count(void) = 0;
  87. virtual uint32 Get_Decal_ID(int decal_index) = 0;
  88. MeshClass * Peek_Parent(void);
  89. DecalSystemClass * Peek_System(void);
  90. DecalMeshClass * Peek_Next_Visible(void) { return NextVisible; }
  91. void Set_Next_Visible(DecalMeshClass * mesh) { NextVisible = mesh; }
  92. protected:
  93. /*
  94. ** Members
  95. */
  96. MeshClass * Parent;
  97. DecalSystemClass * DecalSystem;
  98. DecalMeshClass * NextVisible;
  99. };
  100. /*
  101. ** RigidDecalMeshClass: a concrete class derived from DecalMeshClass which is
  102. ** used for decals on rigid (non-skin) meshes.
  103. */
  104. class RigidDecalMeshClass : public DecalMeshClass
  105. {
  106. public:
  107. RigidDecalMeshClass(MeshClass * parent,DecalSystemClass * system);
  108. virtual ~RigidDecalMeshClass(void);
  109. // Rigid decal meshes have static geometry so they do not use world_vertex_locs/norms
  110. virtual void Render(void);
  111. virtual bool Create_Decal( DecalGeneratorClass * generator,
  112. const OBBoxClass & localbox,
  113. SimpleDynVecClass<uint32> & apt,
  114. const DynamicVectorClass<Vector3> * world_vertex_locs = 0);
  115. virtual bool Delete_Decal(uint32 id);
  116. int Decal_Count(void);
  117. uint32 Get_Decal_ID(int decal_index);
  118. protected:
  119. int Process_Material_Run(int start_index);
  120. /*
  121. ** Connectivity
  122. */
  123. SimpleDynVecClass<TriIndex> Polys;
  124. /*
  125. ** Geometry
  126. */
  127. SimpleDynVecClass<Vector3> Verts;
  128. SimpleDynVecClass<Vector3> VertNorms;
  129. /*
  130. ** Materials
  131. */
  132. SimpleDynVecClass<ShaderClass> Shaders;
  133. SimpleDynVecClass<TextureClass *> Textures;
  134. SimpleDynVecClass<VertexMaterialClass *> VertexMaterials;
  135. SimpleDynVecClass<Vector2> TexCoords;
  136. /*
  137. ** Decal Organization
  138. */
  139. struct DecalStruct
  140. {
  141. uint32 DecalID;
  142. uint16 VertexStartIndex;
  143. uint16 VertexCount;
  144. uint16 FaceStartIndex;
  145. uint16 FaceCount;
  146. };
  147. SimpleDynVecClass<DecalStruct> Decals;
  148. };
  149. /*
  150. ** SkinDecalMeshClass: a concrete class derived from DecalMeshClass which is
  151. ** used for decals on skin meshes.
  152. */
  153. class SkinDecalMeshClass : public DecalMeshClass
  154. {
  155. public:
  156. SkinDecalMeshClass(MeshClass * parent,DecalSystemClass * system);
  157. virtual ~SkinDecalMeshClass(void);
  158. // Skin decals use world_vertex_locs/norms since they cannot use static geometry
  159. virtual void Render(void);
  160. virtual bool Create_Decal( DecalGeneratorClass * generator,
  161. const OBBoxClass & localbox,
  162. SimpleDynVecClass<uint32> & apt,
  163. const DynamicVectorClass<Vector3> * world_vertex_locs);
  164. virtual bool Delete_Decal(uint32 id);
  165. int Decal_Count(void);
  166. uint32 Get_Decal_ID(int decal_index);
  167. protected:
  168. int Process_Material_Run(int start_index);
  169. /*
  170. ** Connectivity
  171. */
  172. SimpleDynVecClass<TriIndex> Polys;
  173. /*
  174. ** Indirected vertex indices (for copying dynamically updated mesh geometry)
  175. */
  176. SimpleDynVecClass<uint32> ParentVertexIndices;
  177. /*
  178. ** Materials
  179. */
  180. SimpleDynVecClass<ShaderClass> Shaders;
  181. SimpleDynVecClass<TextureClass *> Textures;
  182. SimpleDynVecClass<VertexMaterialClass *> VertexMaterials;
  183. SimpleDynVecClass<Vector2> TexCoords;
  184. /*
  185. ** Decal Organization
  186. */
  187. struct DecalStruct
  188. {
  189. uint32 DecalID;
  190. uint16 VertexStartIndex;
  191. uint16 VertexCount;
  192. uint16 FaceStartIndex;
  193. uint16 FaceCount;
  194. };
  195. SimpleDynVecClass<DecalStruct> Decals;
  196. };
  197. /*
  198. ** DecalMeshClass inline functions
  199. */
  200. inline MeshClass * DecalMeshClass::Peek_Parent(void)
  201. {
  202. return Parent;
  203. }
  204. inline DecalSystemClass * DecalMeshClass::Peek_System(void)
  205. {
  206. return DecalSystem;
  207. }
  208. /*
  209. ** RigidDecalMeshClass inline functions
  210. */
  211. inline int RigidDecalMeshClass::Decal_Count(void)
  212. {
  213. return Decals.Count();
  214. }
  215. inline uint32 RigidDecalMeshClass::Get_Decal_ID(int decal_index)
  216. {
  217. return Decals[decal_index].DecalID;
  218. }
  219. /*
  220. ** SkinDecalMeshClass inline functions
  221. */
  222. inline int SkinDecalMeshClass::Decal_Count(void)
  223. {
  224. return Decals.Count();
  225. }
  226. inline uint32 SkinDecalMeshClass::Get_Decal_ID(int decal_index)
  227. {
  228. return Decals[decal_index].DecalID;
  229. }
  230. #endif //DECALMSH_H