w3dmtl.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 : Max2W3d *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/max2w3d/w3dmtl.h $*
  25. * *
  26. * $Author:: Andre_a $*
  27. * *
  28. * $Modtime:: 12/07/00 2:47p $*
  29. * *
  30. * $Revision:: 15 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef W3DMTL_H
  39. #define W3DMTL_H
  40. #include "always.h"
  41. #include "w3d_file.h"
  42. #include "vector.h"
  43. class GameMtl;
  44. class Mtl;
  45. class ChunkSaveClass;
  46. /*
  47. ** W3dMapClass.
  48. ** This class simply ties together the map info and the map filename
  49. */
  50. class W3dMapClass
  51. {
  52. public:
  53. W3dMapClass(void) : Filename(NULL), AnimInfo(NULL) {};
  54. W3dMapClass(const W3dMapClass & that);
  55. ~W3dMapClass(void);
  56. W3dMapClass & operator = (const W3dMapClass & that);
  57. void Reset(void);
  58. void Set_Filename(const char * name);
  59. void Set_Anim_Info(const W3dTextureInfoStruct * info);
  60. void Set_Anim_Info(int framecount,float framerate);
  61. char * Filename;
  62. W3dTextureInfoStruct * AnimInfo;
  63. };
  64. /*
  65. ** W3dMaterialClass.
  66. ** This class ties together w3d structures for up to 'MAX_PASSES' material passes.
  67. ** It is typically plugged into the next class (W3dMaterialDescClass) so that
  68. ** duplicate members can detected and shared.
  69. */
  70. class W3dMaterialClass
  71. {
  72. public:
  73. W3dMaterialClass(void);
  74. ~W3dMaterialClass(void);
  75. enum { MAX_PASSES = 4, MAX_STAGES = 2 };
  76. void Reset(void);
  77. /*
  78. ** Construction from Max materials
  79. */
  80. void Init(Mtl * mtl);
  81. void Init(GameMtl * gamemtl);
  82. /*
  83. ** Manual Construction
  84. */
  85. void Set_Surface_Type(unsigned int type);
  86. void Set_Sort_Level(int level);
  87. void Set_Pass_Count(int count);
  88. void Set_Vertex_Material(const W3dVertexMaterialStruct & vmat,int pass = 0);
  89. void Set_Mapper_Args(const char *args_buffer, int pass = 0, int stage = 0);
  90. void Set_Shader(const W3dShaderStruct & shader,int pass = 0);
  91. void Set_Texture(const W3dMapClass & map,int pass = 0,int stage = 0);
  92. void Set_Map_Channel(int pass,int stage,int channel);
  93. /*
  94. ** Inspection
  95. */
  96. unsigned int Get_Surface_Type(void) const;
  97. int Get_Sort_Level(void) const;
  98. int Get_Pass_Count(void) const;
  99. W3dVertexMaterialStruct * Get_Vertex_Material(int pass = 0) const;
  100. const char * Get_Mapper_Args(int pass /*= 0*/, int stage /*= 0*/) const;
  101. W3dShaderStruct Get_Shader(int pass = 0) const;
  102. W3dMapClass * Get_Texture(int pass = 0,int stage = 0) const;
  103. int Get_Map_Channel(int pass = 0,int stage = 0) const;
  104. bool Is_Multi_Pass_Transparent(void) const;
  105. protected:
  106. void Free(void);
  107. unsigned int SurfaceType;
  108. int SortLevel;
  109. int PassCount;
  110. W3dShaderStruct Shaders[MAX_PASSES];
  111. W3dVertexMaterialStruct * Materials[MAX_PASSES];
  112. char * MapperArgs[MAX_PASSES][MAX_STAGES];
  113. W3dMapClass * Textures[MAX_PASSES][MAX_STAGES];
  114. int MapChannel[MAX_PASSES][MAX_STAGES];
  115. };
  116. /*
  117. ** W3dMaterialDescClass
  118. ** This class's purpose is to process the set of w3dmaterials used by a mesh into a set
  119. ** of surrender passes with shaders, vertexmaterials, textures. Part of its job is
  120. ** to detect duplicated shaders and vertex materials and remove them.
  121. */
  122. class W3dMaterialDescClass
  123. {
  124. public:
  125. typedef enum ErrorType
  126. {
  127. OK = 0, // material description was built successfully
  128. INCONSISTENT_PASSES, // material doesn't have same number of passes
  129. MULTIPASS_TRANSPARENT, // material is transparent and multi-pass (NO-NO!)
  130. INCONSISTENT_SORT_LEVEL, // material doesn't have the same sort level!
  131. };
  132. W3dMaterialDescClass(void);
  133. ~W3dMaterialDescClass(void);
  134. void Reset(void);
  135. /*
  136. ** Interface for adding a material description. The material will be assigned
  137. ** an index based on the order at which they are added. Add your materials in
  138. ** order, then use their indices to find the remapped vertex materials, textures,
  139. ** and shaders...
  140. */
  141. ErrorType Add_Material(const W3dMaterialClass & mat,const char * name = NULL);
  142. /*
  143. ** Global Information. These methods give access to all of the unique vertex materials,
  144. ** shaders, and textures being used.
  145. */
  146. int Material_Count(void);
  147. int Pass_Count(void);
  148. int Vertex_Material_Count(void);
  149. int Shader_Count(void);
  150. int Texture_Count(void);
  151. int Get_Sort_Level(void);
  152. W3dVertexMaterialStruct * Get_Vertex_Material(int vmat_index);
  153. const char * Get_Mapper_Args(int vmat_index, int stage);
  154. W3dShaderStruct * Get_Shader(int shader_index);
  155. W3dMapClass * Get_Texture(int texture_index);
  156. /*
  157. ** Per-Pass Information. These methods convert a material index and pass index pair into
  158. ** an index to the desired vertex material, texture or shader.
  159. */
  160. int Get_Vertex_Material_Index(int mat_index,int pass);
  161. int Get_Shader_Index(int mat_index,int pass);
  162. int Get_Texture_Index(int mat_index,int pass,int stage);
  163. W3dVertexMaterialStruct * Get_Vertex_Material(int mat_index,int pass);
  164. const char * Get_Mapper_Args(int mat_index,int pass,int stage);
  165. W3dShaderStruct * Get_Shader(int mat_index,int pass);
  166. W3dMapClass * Get_Texture(int mat_index,int pass,int stage);
  167. int Get_Map_Channel(int mat_index,int pass,int stage);
  168. bool Stage_Needs_Texture_Coordinates(int pass,int stage);
  169. bool Pass_Uses_Vertex_Alpha(int pass);
  170. bool Pass_Uses_Alpha(int pass);
  171. /*
  172. ** Vertex Material Names. It will be useful to have named vertex materials. I'll keep
  173. ** the name of the first material which contained each vertex material as its name. Use
  174. ** these functions to get the name associated with a vertex material
  175. */
  176. const char * Get_Vertex_Material_Name(int mat_index,int pass);
  177. const char * Get_Vertex_Material_Name(int vmat_index);
  178. private:
  179. int Add_Vertex_Material(W3dVertexMaterialStruct * vmat,const char *mapper_args0,const char *mapper_args1,int pass,const char * name);
  180. int Add_Shader(const W3dShaderStruct & shader,int pass);
  181. int Add_Texture(W3dMapClass * map,int pass,int stage);
  182. unsigned long Compute_Crc(const W3dVertexMaterialStruct & vmat,const char *mapper_args0,const char *mapper_args1);
  183. unsigned long Compute_Crc(const W3dShaderStruct & shader);
  184. unsigned long Compute_Crc(const W3dMapClass & map);
  185. unsigned long Add_String_To_Crc(const char *str, unsigned long crc);
  186. /*
  187. ** MaterialRemapClass
  188. ** When the user supplies a W3dMaterial to this material description class,
  189. ** its sub-parts are installed and an instance of this class is created to
  190. ** re-index to each one.
  191. */
  192. class MaterialRemapClass
  193. {
  194. public:
  195. MaterialRemapClass(void);
  196. bool operator != (const MaterialRemapClass & that);
  197. bool operator == (const MaterialRemapClass & that);
  198. int PassCount;
  199. int VertexMaterialIdx[W3dMaterialClass::MAX_PASSES];
  200. int ShaderIdx[W3dMaterialClass::MAX_PASSES];
  201. int TextureIdx[W3dMaterialClass::MAX_PASSES][W3dMaterialClass::MAX_STAGES];
  202. int MapChannel[W3dMaterialClass::MAX_PASSES][W3dMaterialClass::MAX_STAGES];
  203. };
  204. /*
  205. ** VertMatClass
  206. ** This class encapsulates a vertex material structure and makes it extendable for
  207. ** any purposes needed by the plugin code. For example, the pass index is stored
  208. ** so that we can prevent "welding" of vertex materials in different passes (since
  209. ** this may not be desireable...)
  210. */
  211. class VertMatClass
  212. {
  213. public:
  214. VertMatClass(void);
  215. ~VertMatClass(void);
  216. VertMatClass & VertMatClass::operator = (const VertMatClass & that);
  217. bool operator != (const VertMatClass & that);
  218. bool operator == (const VertMatClass & that);
  219. void Set_Name(const char * name);
  220. void Set_Mapper_Args(const char * args, int stage);
  221. W3dVertexMaterialStruct Material;
  222. char * MapperArgs[W3dMaterialClass::MAX_STAGES]; // note: these strings are new'ed, not malloc'ed (unlike Name)
  223. int PassIndex; // using this to prevent joining of vertmats in different passes.
  224. int Crc; // crc, used for quick rejection when checking for matches.
  225. char * Name; // material name associated with the first occurence of this vmat.
  226. };
  227. /*
  228. ** ShadeClass
  229. ** Again, simply here to make the shader extendable for any purposes needed by this
  230. ** pre-processing code...
  231. */
  232. class ShadeClass
  233. {
  234. public:
  235. ShadeClass & operator = (const ShadeClass & that) { Shader = that.Shader; Crc = that.Crc; return *this;}
  236. bool operator != (const ShadeClass & that) { return !(*this == that); }
  237. bool operator == (const ShadeClass & that) { assert(0); return false; }
  238. W3dShaderStruct Shader;
  239. int Crc;
  240. };
  241. /*
  242. ** TexClass
  243. ** Simply here to allow extra info to be stored with each texture, as needed by this
  244. ** pre-processing code...
  245. */
  246. class TexClass
  247. {
  248. public:
  249. TexClass & operator = (const TexClass & that) { Map = that.Map; Crc = that.Crc; return *this; }
  250. bool operator != (const TexClass & that) { return !(*this == that); }
  251. bool operator == (const TexClass & that) { assert(0); return false; }
  252. W3dMapClass Map;
  253. int Crc;
  254. };
  255. int PassCount;
  256. int SortLevel;
  257. DynamicVectorClass < MaterialRemapClass > MaterialRemaps;
  258. DynamicVectorClass < ShadeClass > Shaders;
  259. DynamicVectorClass < VertMatClass > VertexMaterials;
  260. DynamicVectorClass < TexClass > Textures;
  261. };
  262. #endif