Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
3DMaterial.h
Go to the documentation of this file.
1//! @file 3DMaterial.h
2//! @brief The files handles materials definition
3//!
4//////////////////////////////////////////////////////////////////////
5
6#if !defined(AFX_3DMaterial_H__CA6BC29F_FAC2_11D1_A0DE_000000000000__INCLUDED_)
7#define AFX_3DMaterial_H__CA6BC29F_FAC2_11D1_A0DE_000000000000__INCLUDED_
8
9#ifdef _MSC_VER
10#pragma once
11#endif // _MSC_VER
12
13#include "3DAnimatable.h"
14#include "RGBColor.h"
15
16#include "DependentChannels.h"
17#include "MaterialMap.h"
18
19BEGIN_MOOTOOLS_NAMESPACE
20
21#define MATERIAL_GUID_CLASS MAKE_CUSTOM_ID('M', 'A', 'T', 'R')
22
23//! @enum MATERIAL_COPY_FLAGS
24//! These flags give a way to control material copy
26{
27 MATERIAL_COPY_DEFAULT = 0x00,
28 MATERIAL_COPY_KEEP_ID = 0x01, // Keep the material id when copying. If id already exist, then it is not replaced.
29 MATERIAL_COPY_REMOVE_ALL = 0x02, // Remove all existings materials before copying
30 MATERIAL_COPY_USE_HASH = 0x04, // Copy only materials find in the provided hash
32
33//! @enum MATERIAL_FLAGS
34//! Flags defining different material properties
35typedef enum MATERIAL_FLAGS XEnumType(unsigned int)
36{
37 MATERIAL_NONE = 0x00,
38 MATERIAL_FLAGS_MASK = 0x000FFFFF,
39 MATERIAL_IS_HIDDEN = 0x01,
40 MATERIAL_DISABLE_DIFFUSE_MODULATION = 0x02, //!< This means that the diffuse color has no effect on texturing (does not modulate texture)
41 MATERIAL_USE_FRONT_CHANNEL_WHEN_BACK_MISSING = 0x1000, //!< For the material maps, use the front UV on the back side (the flag is not active if front & back materials are defined or if back channel exists). The flag requires the object context and is taken into account in GetChannelID(CGeomInfo *info... for example
42 MATERIAL_INVALIDATION_MASK = 0xFFF00000,
43 MATERIAL_NAME_CHANGED = 0x00100000,
44 MATERIAL_MAPS_CHANGED = 0x00200000,
45 MATERIAL_COLORS_CHANGED = 0x00400000,
46 MATERIAL_OTHERS_CHANGED = 0x00800000,
47 MATERIAL_MAPS_DOWNLOADED = 0x01000000, // A material map has been downloaded. If the file was missing, this give a chance to the CMaterialMap to load again the bitmap
49
50//! @enum MATERIAL_CLASS
51//! C3DMaterial is the base material. C3DMaterial::GetClass allows to cast to the appropriate derived class
52typedef enum MATERIAL_CLASS XEnumType(unsigned char)
53{
54 MATERIAL_CLASS_UNDEFINED = 0,
55 MATERIAL_CLASS_STANDARD = 1, //!< The material is a C3DStandardMaterial
56 MATERIAL_CLASS_PBR, //!< The material is a C3DPbrMaterial
58
59class CMaterials;
61
62template <> class CHashMethods<MapType> : public CHashMethods<unsigned int> {};
63
64//! @class C3DMaterial
65//! @brief C3DMaterial is the base class for materials. There is currently two kinds of materials: C3DPbrMaterial or C3DStandardMaterial.
66//! Any kind of materials can be converted to C3DStandardMaterial, because many 3D exports only handle this kind of material.
67//! Cf. #MATERIALS to know more about materials.
68class DLL_3DFUNCTION C3DMaterial : public CXObject, public C3DKeyframable
69{
70 friend CMaterials;
71
72public:
73 typedef enum _faceModeEnum XEnumType(unsigned int)
74 {
75 FACE_DEFAULT_MODE = 0,
76 SINGLE_SIDE,
77 DOUBLE_SIDE,
78 } faceModeEnum;
79
80 typedef enum _alphaModeEnum XEnumType(unsigned int)
81 {
82 ALPHA_BLEND = 0x01, //!< Default mode, the cutoff value define the alpha cutoff threshold (0 by default).
83 ALPHA_OPAQUE = 0x02, //!< Alpha is disabled, the map is entirely visible
84 } alphaModeEnum;
85
86protected:
87 //! @enum DataID
88 //! @brief This enum is used in the serialization process to load/save specific material properties
89 typedef enum DataID
90 {
91 MATERIAL_ALPHA_MODE = MAKE_CUSTOM_ID('A', 'P', 'M', 'D'), // UInt
92 MATERIAL_FACE_CULLMODE = MAKE_CUSTOM_ID('F', 'C', 'C', 'M'), // UInt
93 MAT_VC_CHANNEL_ID = MAKE_CUSTOM_ID('V', 'C', 'I', 'D'),
94 MAT_VC_CHANNEL_FLAGS = MAKE_CUSTOM_ID('V', 'C', 'F', 'G'),
95 } DataID;
96
97 //! @enum KeyframableID
98 //! @brief This enum define the animatable material information
99 typedef enum KeyframableID XEnumType(longuint)
100 {
101 KEYFRAME_MAT_SMOOTH_COEF = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_FLOAT, MAKE_CUSTOM_ID('M', 'T', 'S', 'M')), //!< CFloatKey
102 KEYFRAME_MAT_DIFFUSE_COLOR = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_COLOR, MAKE_CUSTOM_ID('M', 'T', 'D', 'R')), //!< CColorKey
103 KEYFRAME_MAT_DIFFUSE_COEF = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_FLOAT, MAKE_CUSTOM_ID('M', 'T', 'D', 'F')), //!< CFloatKey
104 KEYFRAME_MAT_VC_COEF = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_FLOAT, MAKE_CUSTOM_ID('M', 'T', 'V', 'C')), //!< CFloatKey
105 KEYFRAME_MAT_ALPHA_CUTOFF_COEF = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_FLOAT, MAKE_CUSTOM_ID('M', 'T', 'C', 'O')), //!< CFloatKey, Alpha cutoff coef
106 KEYFRAME_MAT_TRANSPARENCY_COEF = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_FLOAT, MAKE_CUSTOM_ID('M', 'T', 'T', 'Y')), //!< CFloatKey
107 } KeyframableID;
108
109protected:
110 MATERIAL_CLASS materialClass;
111 unsigned int materialFlags;
112 CXString name;
113 CCustomData data; // Not serialized at the moment
114
115 // The materials list to which material belong, needed for fast material access, initialized when using C3DMaterials::CreateNewMaterial
116 // NULL when material is constructed on the heap.
117 CMaterials *materials;
119
120 MaterialID materialID;
121 faceModeEnum faceMode;
122 ChannelID vertexColorID;
123 unsigned int vertexColorFlags;
124
125 void DeleteMaps();
126
127 virtual unsigned int GetHashValue() const; // Return a value that will help for retrieving quickly a material by its property or name using CMaterials::Find
128 void HashInsert();
129 void HashRemove();
130
131public:
132 DECLARE_SERIAL_XOBJECT(C3DMaterial); // Cf. implement note
133
134 C3DMaterial(); //!< Use CMaterials::CreateNewMaterial if the material is intended to belong to a material scene list.
135 virtual ~C3DMaterial();
136
137 static C3DMaterial* Create(MATERIAL_CLASS materialClass); //!< Create a C3DMaterial. Equivalent to xNew(C3DMaterial)
138
139 CMaterials* GetMaterials() const { return materials; }; //!< The materials to which the material is attached. NULL if material not already attached to anything
140 C3DScene* GetScene() const; //!< The scene to which the materials belonh. NULL if material not already attached to anything
141
142 inline MATERIAL_CLASS GetClass() const {
143 return materialClass;
144 }
145
146 MaterialID SetMaterialID(MaterialID refID = MATERIAL_UNDEFINED); //!< Create a new material with the given MaterialID. If material is not attached to a material list, then provided id is always used. If the material is already attached to a material list, provided id might be modified if it is already used by the materials list. Note: if you intend to change a materialID which is already in the material list, you should remove it from the list before.
147 MaterialID GetMaterialID() const;
148
149 unsigned int GetFlags() { return materialFlags; }
150 void SetFlags(unsigned int flags, bool set);
151 void SetFlag(MATERIAL_FLAGS flag, bool set);
152 bool IsOneFlagSet(unsigned int flags) const;
153 bool IsFlagSet(MATERIAL_FLAGS flag) const;
154
155 CCustomData& GetCustomData();
156 const CCustomData& GetCustomData() const;
157
158 void Inherit(const C3DMaterial* refmat); //!< Inherit basic information from refmat (mainly C3DMaterial information such name, materialID, flags, KeyframableID, DataID,...). The material should not be attached to any material list (materialid
159
160 // Virtuals
161 virtual void Serialize(CXArchive& ar);
162 virtual C3DMaterial& operator=(const C3DMaterial& refmat);
163 virtual bool HasSameParameters(const C3DMaterial& refmat) const; //!< Compare only settings
164 virtual void ChangeChannelID(CHashMap<CChannelInfo, const CChannelInfo&, CChannelInfo>& channelMap); //!< Remap the materialmap channel ID to the new channelID provided by the map. Used mainly internally when concatenating different mesh for example
165 virtual C3DStandardMaterial* ConvertToStandardMaterial(bool replaceCurrentByStandardMaterial) { XASSERT(0); return NULL; } //!< Must be overidden Return a standard material from the given material. If deleteCurrentAndReplaceByNewOne = false, the returned materials must be attached to CMaterials list, or deleted when no more need. If deleteCurrentAndReplaceByNewOne = true, the current material is destroyed (if not already a standard material) and the new standard is added to materials list to which the material is attached.
166
167 CXString GetName(void) const; //!< Get material name
168 void SetName(const CXString&); //!< Set material name
169
170 void SetAlphaMode(unsigned int time, alphaModeEnum mode, float cutOffCoef = 0.0f); //!< Set alpha cut and cutoff coef
171 float GetAlphaModeCutoffCoef(unsigned int time) const; //!< Get cutoff coef
172 alphaModeEnum GetAlphaMode() const; //!< Get alpha mode
173
174 void SetTransparencyFactor(unsigned int time, float value);
175 float GetTransparencyFactor(unsigned int time) const;
176
177 //! Check if material has some transparency. The material is considered to be opaque, unless something allows us to know that it is transparent.
178 //! If checkDiffuseAlpha = true and ALPHA_OPAQUE not set, the diffuse map is loaded and it's alpha channel checked. If checkDiffuseAlpha = false, the map is assumed to be opaque
179 virtual bool IsTransparent(unsigned int time, bool checkDiffuseAlpha = false) const;
180
181 void SetFaceMode(faceModeEnum mode); //!< Set single / double face material mode
182 faceModeEnum GetFaceMode(void) const; //!< Get single / double face material mode
183
184 void SetSmoothAngle(unsigned int time, float value); //!< Set normal break angle
185 float GetSmoothAngle(unsigned int time) const; //!< Get normal break angle
186
187 //! @name Set a color that represent diffuse or base color
188 //! @{
189 void SetDiffuseColor(unsigned int time, const CRGBColor& color);
190 virtual CRGBColor GetDiffuseColor(unsigned int time, bool modulateByDiffuseFactor = false) const; //!< This can be overidden as derived class might have a different computation for this
191 void FloatGetDiffuseColor(unsigned int time, float color[4], bool modulateByDiffuseFactor = false) const;
192
193 void SetDiffuseFactor(unsigned int time, float value);
194 float GetDiffuseFactor(unsigned int time) const;
195
196 //! @}
197
198 //! @name Set vertex color channel ID and modulation
199 //! @{
200 void SetVertexColor(unsigned int time, ChannelID channel, float modulationCoef = 1.0f, unsigned int channelFlags = CMaterialMap::MAPCHANNEL_UNSPECIFIED);
201 ChannelID GetVertexColor(unsigned int time, float& modulationCoef, unsigned int *channelFlags = NULL) const; // Return the material vertex color information if any, If channelFlags not NULL it is filled with the MapChannelFlags
202 bool RemoveVertexColor(); // Return true if some information exists
203
204 //! @}
205
206 bool operator==(const C3DMaterial& refmat) const; //!< Compare 2 materials (name and settings)
207
208 //! @enum AdjustMaterialFlags
209 //! Flags used in AdjustMaterial to modify materials in order to tweak them depending on the export capabilities
211 {
212 ADJUST_NONE = 0,
213 ADJUST_DIFFUSE_IF_NO_MODULATION = 0x01, //!< MATERIAL_DISABLE_DIFFUSE_MODULATION not supported by all I/O. If set, this replace the diffuse by a grey color with the luminance of original diffuse color
214 } AdjustMaterialFlags;
215
216 bool AdjustMaterial(unsigned int flags); //!< flags is one or more AdjustMaterialFlags. return true if the material changed
217
218 //! @name Retrieve the UVW or vertex color channelID
219 //! These methods are helper to retrieve the final channelID to use for a given geom object. It checks if there is a global channel, and specific flag that might modify the channel ID used by the material for a specific object
220 //! For example the final channel for UV depend of
221 //! 1) object global uv channel
222 //! 2) for each face, material map of the face
223 //! 3) wether the front or back of the face is to be displayed
224 //! 4) wether MATERIAL_USE_FRONT_CHANNEL_WHEN_BACK_MISSING is set or not for material (the flag have effect only if the object has only front face specified. It allows to have the same front & back UV)
225 //! 5) wether the map use MAPCHANNEL_FIRST_CHANNEL_FOUND
226 //! @{
227 ChannelID GetUVWChannelID(const CGeomInfo *info, MapType maptype, bool front = true) const; // Return vertex color to use depending on the provided CGeomInfo. It can be the object GetGlobalVCChannel if defined, or the material vertex color channel otherwise
228 int GetRequiredUVWChannelID(const CGeomInfo *info, CHashTable<ChannelID>& channels, MapType maptype = MAPTYPE_UNDEFINED, bool clearMap = true) const; // Return the channel ID list required for a given object and a given material
229
230 ChannelID GetVCChannelID(const CGeomInfo* info, unsigned int time, float& value) const; // Return vertex color to use depending on the provided CGeomInfo. It can be the object GetGlobalVCChannel if defined, or the material vertex color channel otherwise
231 int GetRequiredVCChannelID(const CGeomInfo* info, CHashTable<ChannelID>& channels, MapType maptype = MAPTYPE_UNDEFINED, bool clearMap = true) const; // Return the channel ID list required for a given object and a given material
232
233 //! @}
234
235 //! @name Managing texture material map associated to the material
236 //! @{
237 CMaterialMap* AddMaterialMap(MapType type);
238 CMaterialMap *AddMaterialMap(const CXString& filename, ChannelID id, MapType type, MapProjection projection, unsigned int channelFlags = CMaterialMap::MAPCHANNEL_NONE);
239 HashPos GetFirstMap();
240 CMaterialMap * GetNextMap(HashPos& pos, MapType & type);
241
242 bool RemoveMaterialMap(MapType type);
243 CMaterialMap *GetMaterialMap(MapType type);
244 const CMaterialMap *GetMaterialMap(MapType type) const;
245
246 //! @}
247
248 bool CopyTextures(const CXString& dstfolder, bool overwriteIfExists = false); //!< Copy all material maps to the given path and update pathss
249
250 bool IsGenerateUVWNeeded(MapType type = MAPTYPE_UNDEFINED) const; //!< Return true if one of the map has a projection mode that require UVW to be generated, for all the map type (type == MAPTYPE_UNDEFINED) or for the specific MapType (type = MAPTYPE_DIFFUSE for example)
251 unsigned int CreateMissingUVWBackChannels(const CGeomInfo* info, MapType type = MAPTYPE_UNDEFINED, CHANNEL_PROPERTIES channelTagFlag = CHANNEL_NONE) const; //!< Copy front UVW channels to back channels if back are missing. If type = MAPTYPE_UNDEFINED, then all maps are checked, otherwise only the provided map.
252
253 void AdjustPaths(const CXString& targetPath, bool relativePathAllowed); //!< Make internal filenames used by materials relative to provided path
254};
255
256//! @class C3DStandardMaterial
257//! @brief C3DStandardMaterial is a basic material that defines ambient, specular, bump and other coefficients
258class DLL_3DFUNCTION C3DStandardMaterial : public C3DMaterial
259{
260protected:
261 typedef enum DataID XEnumType(longuint)
262 {
263 } DataID;
264
265 //! @enum KeyframableID
266 //! @brief This enum define the animatable C3DStandardMaterial information
267 typedef enum KeyframableID XEnumType(longuint)
268 {
269 KEYFRAME_MAT_AMBIENT_COLOR = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_COLOR, MAKE_CUSTOM_ID('M', 'T', 'A', 'R')), //!< CColorKey
270 KEYFRAME_MAT_AMBIENT_COEF = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_FLOAT, MAKE_CUSTOM_ID('M', 'T', 'A', 'F')), //!< CFloatKey
271 KEYFRAME_MAT_SPECULAR_COLOR = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_COLOR, MAKE_CUSTOM_ID('M', 'T', 'S', 'R')), //!< CColorKey
272 KEYFRAME_MAT_SPECULAR_COEF = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_FLOAT, MAKE_CUSTOM_ID('M', 'T', 'S', 'F')), //!< CFloatKey
273 KEYFRAME_MAT_BUMP_COEF = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_FLOAT, MAKE_CUSTOM_ID('M', 'T', 'B', 'M')), //!< CFloatKey
274 KEYFRAME_MAT_REFLECTION_COEF = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_FLOAT, MAKE_CUSTOM_ID('M', 'T', 'R', 'F')), //!< CFloatKey
275 KEYFRAME_MAT_REFRACTION_COEF = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_FLOAT, MAKE_CUSTOM_ID('M', 'T', 'R', 'R')), //!< CFloatKey
276 } KeyframableID;
277
278 void ReadPreviousVersion(CXArchive& ar, unsigned int version);
279
280public:
281 DECLARE_SERIAL_XOBJECT(C3DStandardMaterial);
282
284
285 void SetAmbientColor(unsigned int time, const CRGBColor& color);
286 CRGBColor GetAmbientColor(unsigned int time, bool modulateByAmbient = false) const;
287 void FloatGetAmbientColor(unsigned int time, float color[4]);
288
289 CMaterialMap* GetAmbientMaps(); //!< @deprecated use GetMaterialMap(MAPTYPE_AMBIANT)
290 CMaterialMap* GetDiffuseMaps(); //!< @deprecated use GetMaterialMap(MAPTYPE_DIFFUSE)
291 CMaterialMap* GetNormalMaps(); //!< @deprecated use GetMaterialMap(MAPTYPE_NORMALMAP)
292
293 void SetSpecularColor(unsigned int time, const CRGBColor& color);
294 CRGBColor GetSpecularColor(unsigned int time) const;
295 void FloatGetSpecularColor(unsigned int time, float color[4]) const;
296 CMaterialMap* GetSpecularMaps();
297
298 void SetBumpFactor(unsigned int time, float value);
299 float GetBumpFactor(unsigned int time) const;
300 CMaterialMap* GetBumpMaps();
301
302 void SetAmbientFactor(unsigned int time, float value);
303 float GetAmbientFactor(unsigned int time) const;
304
305 void SetSpecularFactor(unsigned int time, float value);
306 float GetSpecularFactor(unsigned int time) const;
307
308 CMaterialMap* GetTransparencyMaps();
309
310 void SetReflectionFactor(unsigned int time, float value); //!< Reflection coef between 0.0 and 1.0f (default 0.0)
311 float GetReflectionFactor(unsigned int time) const;
312
313 void SetRefractionFactor(unsigned int time, float value); //!< IOR refraction indice >= 1.0 (default 1.0)
314 float GetRefractionFactor(unsigned int time) const;
315
317 return this; // This is already a standard material
318 }
319
320 void Serialize(CXArchive& ar);
321
322};
323
324//! @class C3DPbrMaterial
325//! @brief C3DPbrMaterial defines a PBR material which is used by different file formats such GLTF or FBX.
326class DLL_3DFUNCTION C3DPbrMaterial : public C3DMaterial
327{
328public:
329 typedef enum PbrInputFormat
330 {
331 UNDEFINED_INPUT_FORMAT = -1,
332 FROM_3DSMAX = 0,
333 FROM_MAYA,
334 } PbrInputFormat;
335
336 //! @enum DataID
337 //! @brief This enum is used in the serialization process to load/save specific C3DPbrMaterial properties
338 typedef enum DataID
339 {
340 PBR_INPUT_FORMAT = MAKE_CUSTOM_ID('P', 'B', 'F', 'M'), // PBR input format source: 0 - 3ds Max, 1- Maya,
341 OCCLUSION_STRENGTH = MAKE_CUSTOM_ID('S', 'T', 'R', 'N'),
342 EMISSIVE_COLOR = MAKE_CUSTOM_ID('E', 'M', 'C', 'R'),
343 } DataID;
344
345protected:
346 typedef enum KeyframableID XEnumType(longuint)
347 {
348 KEYFRAME_MAT_EMISSIVE_COLOR = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_COLOR, MAKE_CUSTOM_ID('M', 'T', 'E', 'C')),
349 KEYFRAME_MAT_EMISSIVE_COEF = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_FLOAT, MAKE_CUSTOM_ID('M', 'T', 'E', 'F')),
350 KEYFRAME_MAT_OCCLUSION_COEF = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_FLOAT, MAKE_CUSTOM_ID('M', 'T', 'O', 'C')),
351 KEYFRAME_MAT_METALLIC_COEF = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_FLOAT, MAKE_CUSTOM_ID('M', 'T', 'M', 'E')),
352 KEYFRAME_MAT_ROUGHNESS_COEF = KEYFRAMEID(C3DKeyframe::KEYFRAME_TYPE_FLOAT, MAKE_CUSTOM_ID('M', 'T', 'R', 'O')),
353
354 } KeyframableID;
355
356public:
357 DECLARE_SERIAL_XOBJECT(C3DPbrMaterial);
358
360
361 virtual C3DStandardMaterial* ConvertToStandardMaterial(bool replaceCurrentByStandardMaterial); //!< Return a standard material from the given material. If deleteCurrentAndReplaceByNewOne = false, the returned materials must be attached to CMaterials list, or deleted when no more need. If deleteCurrentAndReplaceByNewOne = true, the current material is destroyed (if not already a standard material) and the new standard is added to materials list to which the material is attached.
362 virtual void Serialize(CXArchive& ar);
363 virtual C3DMaterial& operator=(const C3DMaterial& refmat);
364 virtual bool HasSameParameters(const C3DMaterial& refmat) const; //!< Compare only the settings (not the name)
365
366 void SetMetallicFactor(unsigned int time, float value);
367 float GetMetallicFactor(unsigned int time) const;
368 void SetRoughnessFactor(unsigned int time, float value);
369 float GetRoughnessFactor(unsigned int time) const;
370
371 void SetEmissiveColor(unsigned int time, const CRGBColor& color);
372 void SetEmissiveFactor(unsigned int time, float value);
373
374 CRGBColor GetEmissiveColor(unsigned int time) const;
375 float GetEmissiveFactor(unsigned int time) const;
376
377 void SetOcclusionStrengthFactor(unsigned int time, float value);
378 float GetOcclusionStrengthFactor(unsigned int time) const;
379};
380
381class CMaterialNameMap;
382//! @class CMaterials
383//! @brief CMaterials stores scene materials. CMaterials::CreateNewMaterial allows to create a material and insert it in the list.
384//! @note
385//! The data is internally stored in a hash table
386class DLL_3DFUNCTION CMaterials : public CXObject
387{
388 friend void C3DMaterial::HashRemove();
389 friend void C3DMaterial::HashInsert();
390
391public:
392 DECLARE_SERIAL_XOBJECT(CMaterials);
393
394 CMaterials();
395 virtual ~CMaterials();
396
397 void SetScene(C3DScene *scene);
398 C3DScene* GetScene() const { return scene; }; //!< The scene that own the materials
399 CGuidMgr* GetGuidMgr() const { return guidMgr; }; //!< If scene is defined then guidMgr is the scene guidMgr. The material list handles scene materials. Otherwise it can be a private material list, related to something else (renderer...)
400
401 virtual void Serialize( CXArchive& ar );
402
403 HashPos GetFirst() const { return hashMaterials.GetFirst(); } //!< if matclass = MATERIAL_CLASS_UNDEFINED, return all type of materials, otherwise return materials of the given class
404 void GetNext(HashPos& pos, MaterialID& id, C3DMaterial*& mat) const { hashMaterials.GetNext(pos, id, mat); }; //!< if defined matclass should be the same than the one use in GetFirstMaterial
405 unsigned int GetMaterials(C3DMaterialArray& mats, bool resetArray = true, MATERIAL_CLASS matclass = MATERIAL_CLASS_UNDEFINED) const;
406 unsigned int GetMaterials(C3DMaterialArray& mats, MapType maptype, bool checkIfBitmapExist, bool resetArray = true) const;
407 unsigned int GetCount(MATERIAL_CLASS matclass = MATERIAL_CLASS_UNDEFINED) const;
408
409 C3DMaterial* CreateNewMaterial(MATERIAL_CLASS materialClass); //!< Create and add a new material of the specified material class
410 C3DMaterial *CreateNewMaterial(MaterialID& refid, MATERIAL_CLASS materialClass); //!< Create and add a new material of the specified material class with the provided refid. If refid is alreaday used, a new material id is assigned which is returned in refid
411 MaterialID AddNewMaterial(C3DMaterial* mat); //!< Add the new material which has not been assigned to any materials. Return its MaterialId definitive which will be the same as the one defined if possible.
412 C3DMaterial *SetDefaultMaterial(C3DStandardMaterial *defaultMat = NULL); //!< Return the default material. defaultMat is optional and can define specific color properties.
413 bool RemoveMaterial(MaterialID refID, bool deleteIt = true);
414 bool ReplaceMaterial(C3DMaterial *newMat, bool deletePrevious = true); //!< Replace an existing material with newMat->GetMaterialID() by the newMat provided material. If this MaterialID does not exist, then newMat is simply added to the materials. When deletePrevious = false, the old material is removed from the materials list and it is not deleted. NewMat is supposed to not be attached to any existing materials list
415 void CopyMaterials(const CMaterials& refmaterials, unsigned int flags = MATERIAL_COPY_KEEP_ID|MATERIAL_COPY_REMOVE_ALL, const C3DScene *dstScene = NULL, const CMaterialHashMap *hash = NULL);
416
417 C3DMaterial *Find(const C3DMaterial& material, bool sameName) const; //!< Find a material that have similar properties and optionally the same name
418 C3DMaterial *FindByID(MaterialID refID, bool createIfMissing = false) const; //!< Find the material that have the given MaterialID. Return NULL if none is found. (no material is created, even with DEFAULT_MATERIAL)
419 C3DMaterial *FindByName(const CXString& name) const; //!< Find the first material with the given name (beware: there can be several different materials with the same name).
420
421 unsigned int IsGenerateUVWNeeded(MaterialID matid = MATERIAL_UNDEFINED, MapType type = MAPTYPE_UNDEFINED) const; //!< If matid == MATERIAL_UNDEFINED, it returns the number of materials that have a projection that requires UVW generation. If matid != MATERIAL_UNDEFINED it returns 1 if the specified material requires UVW generationrequired
422 unsigned int CreateMissingUVWBackChannels(const CGeomInfo* info, MaterialID matid = MATERIAL_UNDEFINED, MapType type = MAPTYPE_UNDEFINED, CHANNEL_PROPERTIES channelTagFlag = CHANNEL_NONE) const;
423
424 unsigned int FilterByText(const CXString& filter, bool matchCase, C3DMaterialIDArray& matids, bool resetHash); //!< Advanced search: find all materials that match the given text. Return the number of element in matids
425
426 void AdjustPaths(const CXString& targetPath, bool relativePathAllowed); //!< Make internal filenames used by materials relative to provided path
427
428 void RemoveAll();
429
430protected:
434
435 mutable CXCriticalSection threadLock;
436
437 C3DScene *scene;
438 CGuidMgr *guidMgr;
439 CMaterialIDMap hashMaterials; // The materials themselfs
440 CMaterialPropertiesMap hashByProperties; // Use to retrieve quickly a material giving its properties
441 CMaterialNameMap hashByNames; // Use to retrieve quickly a material giving its name
442
443 void HashInsert(C3DMaterial *material);
444 void HashRemove(C3DMaterial *const material);
445 void HashFree();
446
447#ifdef _DEBUG
448 void CheckHash() const;
449#endif
450};
451
452END_MOOTOOLS_NAMESPACE
453
454#ifdef MOOTOOLS_MFC_PRODUCT_BUILD
455#ifdef MOOTOOLS_NO_BITMAP
456#pragma message("Build Warning: MOOTOOLS_NO_BITMAP defined in a product build. CMaterialMap might differ between dll resulting in impredicable behavior\n")
457#endif
458#endif
459
460#endif // !defined(AFX_3DMaterial_H__CA6BC29F_FAC2_11D1_A0DE_000000000000__INCLUDED_)
C3DKeyframable class for handling keyframes.
MATERIAL_CLASS
Definition 3DMaterial.h:53
@ MATERIAL_CLASS_PBR
The material is a C3DPbrMaterial.
Definition 3DMaterial.h:56
@ MATERIAL_CLASS_STANDARD
The material is a C3DStandardMaterial.
Definition 3DMaterial.h:55
MATERIAL_COPY_FLAGS
Definition 3DMaterial.h:26
MATERIAL_FLAGS
Definition 3DMaterial.h:36
@ MATERIAL_USE_FRONT_CHANNEL_WHEN_BACK_MISSING
For the material maps, use the front UV on the back side (the flag is not active if front & back mate...
Definition 3DMaterial.h:41
@ MATERIAL_DISABLE_DIFFUSE_MODULATION
This means that the diffuse color has no effect on texturing (does not modulate texture)
Definition 3DMaterial.h:40
CDependentChannels class definition which handles a CChannel array.
MapProjection
Projection type of the texture map.
Definition MaterialMap.h:53
MapType
This enum allows to know the kind of texture map.
Definition MaterialMap.h:26
CRGBColor is a class that handles RGBA colors.
This is the base class for any object that can be animated using C3DKeyframe.
Definition 3DAnimatable.h:51
@ KEYFRAME_TYPE_FLOAT
C3DFloatKey keyframe.
Definition 3DKeyframe.h:70
@ KEYFRAME_TYPE_COLOR
C3DColorKey keyframe.
Definition 3DKeyframe.h:74
C3DMaterial is the base class for materials. There is currently two kinds of materials: C3DPbrMateria...
Definition 3DMaterial.h:69
AdjustMaterialFlags
Definition 3DMaterial.h:211
void AdjustPaths(const CXString &targetPath, bool relativePathAllowed)
Make internal filenames used by materials relative to provided path.
CXString GetName(void) const
Get material name.
float GetAlphaModeCutoffCoef(unsigned int time) const
Get cutoff coef.
void SetSmoothAngle(unsigned int time, float value)
Set normal break angle.
virtual bool IsTransparent(unsigned int time, bool checkDiffuseAlpha=false) const
C3DMaterial()
Use CMaterials::CreateNewMaterial if the material is intended to belong to a material scene list.
bool IsGenerateUVWNeeded(MapType type=MAPTYPE_UNDEFINED) const
Return true if one of the map has a projection mode that require UVW to be generated,...
virtual bool HasSameParameters(const C3DMaterial &refmat) const
Compare only settings.
void SetName(const CXString &)
Set material name.
unsigned int CreateMissingUVWBackChannels(const CGeomInfo *info, MapType type=MAPTYPE_UNDEFINED, CHANNEL_PROPERTIES channelTagFlag=CHANNEL_NONE) const
Copy front UVW channels to back channels if back are missing. If type = MAPTYPE_UNDEFINED,...
virtual void ChangeChannelID(CHashMap< CChannelInfo, const CChannelInfo &, CChannelInfo > &channelMap)
Remap the materialmap channel ID to the new channelID provided by the map. Used mainly internally whe...
virtual CRGBColor GetDiffuseColor(unsigned int time, bool modulateByDiffuseFactor=false) const
This can be overidden as derived class might have a different computation for this.
bool AdjustMaterial(unsigned int flags)
flags is one or more AdjustMaterialFlags. return true if the material changed
static C3DMaterial * Create(MATERIAL_CLASS materialClass)
Create a C3DMaterial. Equivalent to xNew(C3DMaterial)
void SetFaceMode(faceModeEnum mode)
Set single / double face material mode.
void Inherit(const C3DMaterial *refmat)
Inherit basic information from refmat (mainly C3DMaterial information such name, materialID,...
MaterialID SetMaterialID(MaterialID refID=MATERIAL_UNDEFINED)
Create a new material with the given MaterialID. If material is not attached to a material list,...
faceModeEnum GetFaceMode(void) const
Get single / double face material mode.
void SetAlphaMode(unsigned int time, alphaModeEnum mode, float cutOffCoef=0.0f)
Set alpha cut and cutoff coef.
virtual C3DStandardMaterial * ConvertToStandardMaterial(bool replaceCurrentByStandardMaterial)
Must be overidden Return a standard material from the given material. If deleteCurrentAndReplaceByNew...
Definition 3DMaterial.h:165
_alphaModeEnum
Definition 3DMaterial.h:81
bool CopyTextures(const CXString &dstfolder, bool overwriteIfExists=false)
Copy all material maps to the given path and update pathss.
bool operator==(const C3DMaterial &refmat) const
Compare 2 materials (name and settings)
alphaModeEnum GetAlphaMode() const
Get alpha mode.
C3DScene * GetScene() const
The materials to which the material is attached. NULL if material not already attached to anything.
float GetSmoothAngle(unsigned int time) const
Get normal break angle.
C3DPbrMaterial defines a PBR material which is used by different file formats such GLTF or FBX.
Definition 3DMaterial.h:327
virtual C3DStandardMaterial * ConvertToStandardMaterial(bool replaceCurrentByStandardMaterial)
Return a standard material from the given material. If deleteCurrentAndReplaceByNewOne = false,...
virtual bool HasSameParameters(const C3DMaterial &refmat) const
Compare only the settings (not the name)
DataID
This enum is used in the serialization process to load/save specific C3DPbrMaterial properties.
Definition 3DMaterial.h:339
The class allows to get access to the scene graph, node hierarchy, material.
Definition 3DScene.h:306
C3DStandardMaterial is a basic material that defines ambient, specular, bump and other coefficients.
Definition 3DMaterial.h:259
void SetReflectionFactor(unsigned int time, float value)
Reflection coef between 0.0 and 1.0f (default 0.0)
void SetRefractionFactor(unsigned int time, float value)
IOR refraction indice >= 1.0 (default 1.0)
CMaterialMap * GetDiffuseMaps()
CMaterialMap * GetAmbientMaps()
virtual C3DStandardMaterial * ConvertToStandardMaterial(bool replaceCurrentByStandardMaterial)
Must be overidden Return a standard material from the given material. If deleteCurrentAndReplaceByNew...
Definition 3DMaterial.h:316
CMaterialMap * GetNormalMaps()
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
CCustomData is a handly class for storing any kind of data.
Definition CustomData.h:106
CGeomInfo is an helper class oftenly required by different methods.
Definition GeomInfo.h:71
Definition GuidMgr.h:22
Definition Hash.h:146
CMaterialMap handles material texture map.
Definition MaterialMap.h:95
@ MAPCHANNEL_UNSPECIFIED
This means that existing flags are kept and not replaced by the new one.
Definition MaterialMap.h:108
CMaterials stores scene materials. CMaterials::CreateNewMaterial allows to create a material and inse...
Definition 3DMaterial.h:387
C3DMaterial * CreateNewMaterial(MaterialID &refid, MATERIAL_CLASS materialClass)
Create and add a new material of the specified material class with the provided refid....
unsigned int GetMaterials(C3DMaterialArray &mats, bool resetArray=true, MATERIAL_CLASS matclass=MATERIAL_CLASS_UNDEFINED) const
if defined matclass should be the same than the one use in GetFirstMaterial
C3DMaterial * CreateNewMaterial(MATERIAL_CLASS materialClass)
Create and add a new material of the specified material class.
CGuidMgr * GetGuidMgr() const
The scene that own the materials.
Definition 3DMaterial.h:399
void AdjustPaths(const CXString &targetPath, bool relativePathAllowed)
Make internal filenames used by materials relative to provided path.
bool ReplaceMaterial(C3DMaterial *newMat, bool deletePrevious=true)
Replace an existing material with newMat->GetMaterialID() by the newMat provided material....
C3DMaterial * Find(const C3DMaterial &material, bool sameName) const
Find a material that have similar properties and optionally the same name.
MaterialID AddNewMaterial(C3DMaterial *mat)
Add the new material which has not been assigned to any materials. Return its MaterialId definitive w...
unsigned int IsGenerateUVWNeeded(MaterialID matid=MATERIAL_UNDEFINED, MapType type=MAPTYPE_UNDEFINED) const
If matid == MATERIAL_UNDEFINED, it returns the number of materials that have a projection that requir...
HashPos GetFirst() const
if matclass = MATERIAL_CLASS_UNDEFINED, return all type of materials, otherwise return materials of t...
Definition 3DMaterial.h:403
C3DMaterial * FindByID(MaterialID refID, bool createIfMissing=false) const
Find the material that have the given MaterialID. Return NULL if none is found. (no material is creat...
virtual void Serialize(CXArchive &ar)
If scene is defined then guidMgr is the scene guidMgr. The material list handles scene materials....
unsigned int FilterByText(const CXString &filter, bool matchCase, C3DMaterialIDArray &matids, bool resetHash)
Advanced search: find all materials that match the given text. Return the number of element in matids...
C3DMaterial * FindByName(const CXString &name) const
Find the first material with the given name (beware: there can be several different materials with th...
C3DMaterial * SetDefaultMaterial(C3DStandardMaterial *defaultMat=NULL)
Return the default material. defaultMat is optional and can define specific color properties.
CRGBColor handles an r, g, b, a color that can be initialized in different way.
Definition RGBColor.h:22
Definition XArchive.h:17
Definition XThreadSync.h:20