Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
C3DMaterial Class Reference

C3DMaterial is the base class for materials. There is currently two kinds of materials: C3DPbrMaterial or C3DStandardMaterial. Any kind of materials can be converted to C3DStandardMaterial, because many 3D exports only handle this kind of material. Cf. #MATERIALS to know more about materials. More...

Detailed Description

C3DMaterial is the base class for materials. There is currently two kinds of materials: C3DPbrMaterial or C3DStandardMaterial. Any kind of materials can be converted to C3DStandardMaterial, because many 3D exports only handle this kind of material. Cf. #MATERIALS to know more about materials.

#include <3DMaterial.h>

Inheritance diagram for C3DMaterial:
C3DKeyframable C3DAnimatable C3DPbrMaterial C3DStandardMaterial

Public Types

enum  _faceModeEnum { FACE_DEFAULT_MODE = 0 , SINGLE_SIDE , DOUBLE_SIDE }
 
enum  _alphaModeEnum { ALPHA_BLEND = 0x01 , ALPHA_OPAQUE = 0x02 }
 
enum  AdjustMaterialFlags { ADJUST_NONE = 0 , ADJUST_DIFFUSE_IF_NO_MODULATION = 0x01 }
 
typedef enum C3DMaterial::_faceModeEnum faceModeEnum
 
typedef enum C3DMaterial::_alphaModeEnum alphaModeEnum
 
typedef enum C3DMaterial::AdjustMaterialFlags AdjustMaterialFlags
 
- Public Types inherited from C3DKeyframable
enum  TimeStamp { INVALID_TIME = -1 }
 
enum  KeyframeFlags { KEYFRAME_NONE = 0x00 , KEYFRAME_REPLACE_KEY = 0x01 , KEYFRAME_DONT_EVALUATE = 0x02 }
 
typedef enum C3DKeyframable::TimeStamp TimeStamp
 
- Public Types inherited from C3DAnimatable
enum  FindKey { KEYFRAME_PREV = 0x01 , KEYFRAME_NEXT = 0x02 , KEYFRAME_SAME = 0x04 }
 

Public Member Functions

 C3DMaterial ()
 Use CMaterials::CreateNewMaterial if the material is intended to belong to a material scene list.
 
CMaterialsGetMaterials () const
 
C3DSceneGetScene () const
 The materials to which the material is attached. NULL if material not already attached to anything.
 
MATERIAL_CLASS GetClass () const
 
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.
 
MaterialID GetMaterialID () const
 
unsigned int GetFlags ()
 
void SetFlags (unsigned int flags, bool set)
 
void SetFlag (MATERIAL_FLAGS flag, bool set)
 
bool IsOneFlagSet (unsigned int flags) const
 
bool IsFlagSet (MATERIAL_FLAGS flag) const
 
CCustomDataGetCustomData ()
 
const CCustomDataGetCustomData () const
 
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.
 
virtual void Serialize (CXArchive &ar)
 
virtual C3DMaterialoperator= (const C3DMaterial &refmat)
 
virtual bool HasSameParameters (const C3DMaterial &refmat) const
 Compare only settings.
 
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.
 
virtual C3DStandardMaterialConvertToStandardMaterial (bool replaceCurrentByStandardMaterial)
 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.
 
CXString GetName (void) const
 Get material name.
 
void SetName (const CXString &)
 Set material name.
 
void SetAlphaMode (unsigned int time, alphaModeEnum mode, float cutOffCoef=0.0f)
 Set alpha cut and cutoff coef.
 
float GetAlphaModeCutoffCoef (unsigned int time) const
 Get cutoff coef.
 
alphaModeEnum GetAlphaMode () const
 Get alpha mode.
 
void SetTransparencyFactor (unsigned int time, float value)
 
float GetTransparencyFactor (unsigned int time) const
 
virtual bool IsTransparent (unsigned int time, bool checkDiffuseAlpha=false) const
 
void SetFaceMode (faceModeEnum mode)
 Set single / double face material mode.
 
faceModeEnum GetFaceMode (void) const
 Get single / double face material mode.
 
void SetSmoothAngle (unsigned int time, float value)
 Set normal break angle.
 
float GetSmoothAngle (unsigned int time) const
 Get normal break angle.
 
bool operator== (const C3DMaterial &refmat) const
 Compare 2 materials (name and settings)
 
bool AdjustMaterial (unsigned int flags)
 flags is one or more AdjustMaterialFlags. return true if the material changed
 
bool CopyTextures (const CXString &dstfolder, bool overwriteIfExists=false)
 Copy all material maps to the given path and update pathss.
 
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)
 
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.
 
void AdjustPaths (const CXString &targetPath, bool relativePathAllowed)
 Make internal filenames used by materials relative to provided path.
 
Set a color that represent diffuse or base color
void SetDiffuseColor (unsigned int time, const CRGBColor &color)
 
virtual CRGBColor GetDiffuseColor (unsigned int time, bool modulateByDiffuseFactor=false) const
 This can be overidden as derived class might have a different computation for this.
 
void FloatGetDiffuseColor (unsigned int time, float color[4], bool modulateByDiffuseFactor=false) const
 
void SetDiffuseFactor (unsigned int time, float value)
 
float GetDiffuseFactor (unsigned int time) const
 
Set vertex color channel ID and modulation
void SetVertexColor (unsigned int time, ChannelID channel, float modulationCoef=1.0f, unsigned int channelFlags=CMaterialMap::MAPCHANNEL_UNSPECIFIED)
 
ChannelID GetVertexColor (unsigned int time, float &modulationCoef, unsigned int *channelFlags=NULL) const
 
bool RemoveVertexColor ()
 
Retrieve the UVW or vertex color channelID

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 For example the final channel for UV depend of 1) object global uv channel 2) for each face, material map of the face 3) wether the front or back of the face is to be displayed 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) 5) wether the map use MAPCHANNEL_FIRST_CHANNEL_FOUND

ChannelID GetUVWChannelID (const CGeomInfo *info, MapType maptype, bool front=true) const
 
int GetRequiredUVWChannelID (const CGeomInfo *info, CHashTable< ChannelID > &channels, MapType maptype=MAPTYPE_UNDEFINED, bool clearMap=true) const
 
ChannelID GetVCChannelID (const CGeomInfo *info, unsigned int time, float &value) const
 
int GetRequiredVCChannelID (const CGeomInfo *info, CHashTable< ChannelID > &channels, MapType maptype=MAPTYPE_UNDEFINED, bool clearMap=true) const
 
Managing texture material map associated to the material
CMaterialMapAddMaterialMap (MapType type)
 
CMaterialMapAddMaterialMap (const CXString &filename, ChannelID id, MapType type, MapProjection projection, unsigned int channelFlags=CMaterialMap::MAPCHANNEL_NONE)
 
HashPos GetFirstMap ()
 
CMaterialMapGetNextMap (HashPos &pos, MapType &type)
 
bool RemoveMaterialMap (MapType type)
 
CMaterialMapGetMaterialMap (MapType type)
 
const CMaterialMapGetMaterialMap (MapType type) const
 
- Public Member Functions inherited from C3DKeyframable
int AddKey (int time, C3DKeyframe *newkey)
 Return -1 if fails or keyframe number.
 
int AddKey (int time, const C3DKeyframe &newkey)
 Return keyframe number.
 
int DeleteKey (int time, longuint classid=KEYFRAME_NULLID)
 If time = INVALID_TIME, then all key of classid are deleted or all keys are deleted if classid = KEYFRAME_NULLID.
 
void DeleteAllKeys ()
 
C3DKeyframeCreateKey (int time, longuint classid, unsigned int flags=KEYFRAME_NONE)
 Create key of the given classid. flags is one or more KeyframeFlags.
 
C3DKeyframeGetKeyByIndex (unsigned int index, int *time=NULL, longuint classid=KEYFRAME_NULLID)
 This invalidate the cache, and can lead to slower computation.
 
const C3DKeyframeGetConstKeyByIndex (unsigned int index, int *time=NULL, longuint classid=KEYFRAME_NULLID) const
 
int GetKeyNbr (longuint classid=KEYFRAME_NULLID) const
 
bool Evaluate (int time, C3DKeyframe &findkey) const
 This method evaluate the key at the given time. Same but slower that the following method that return a pointer.
 
const C3DKeyframeEvaluate (int time, longuint classid) const
 This method evaluate the key at the given time. This is the fastest method. The key content cannot be changed.
 
int CopyKeys (const C3DKeyframable *srckeys, longuint classid=KEYFRAME_NULLID, CTimeRange range=CTimeRange(0, CTimeRange::MAX_TIME))
 Copy key of the given classid in the given time range.
 
bool operator== (const C3DKeyframable &refkeys) const
 
bool operator= (const C3DKeyframable &key)
 
virtual void OnKeyframesChanged (longuint classID) const
 
virtual CTimeRange GetTimeRange (longuint classid=KEYFRAME_NULLID) const
 
virtual const C3DKeyframeGetConstKey (int time, unsigned int findKeyFlag, longuint classid=KEYFRAME_NULLID, int *findKeyTime=NULL) const
 Retrieve a keyframe at / before or after the specified time depending on findKeyFlag.
 
- Public Member Functions inherited from C3DAnimatable
int GetKeyTime (int time, unsigned int pos, longuint classid=KEYFRAME_NULLID)
 

Static Public Member Functions

static C3DMaterialCreate (MATERIAL_CLASS materialClass)
 Create a C3DMaterial. Equivalent to xNew(C3DMaterial)
 

Member Enumeration Documentation

◆ _alphaModeEnum

Enumerator
ALPHA_BLEND 

Default mode, the cutoff value define the alpha cutoff threshold (0 by default).

ALPHA_OPAQUE 

Alpha is disabled, the map is entirely visible.

◆ AdjustMaterialFlags

Flags used in AdjustMaterial to modify materials in order to tweak them depending on the export capabilities

Enumerator
ADJUST_DIFFUSE_IF_NO_MODULATION 

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.

Member Function Documentation

◆ ConvertToStandardMaterial()

virtual C3DStandardMaterial * C3DMaterial::ConvertToStandardMaterial ( bool  replaceCurrentByStandardMaterial)
inlinevirtual

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.

Reimplemented in C3DStandardMaterial, and C3DPbrMaterial.

◆ GetScene()

C3DScene * C3DMaterial::GetScene ( ) const

The materials to which the material is attached. NULL if material not already attached to anything.

The scene to which the materials belonh. NULL if material not already attached to anything

◆ HasSameParameters()

virtual bool C3DMaterial::HasSameParameters ( const C3DMaterial refmat) const
virtual

Compare only settings.

Reimplemented in C3DPbrMaterial.

◆ IsTransparent()

virtual bool C3DMaterial::IsTransparent ( unsigned int  time,
bool  checkDiffuseAlpha = false 
) const
virtual

Check if material has some transparency. The material is considered to be opaque, unless something allows us to know that it is transparent. 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

◆ Serialize()

virtual void C3DMaterial::Serialize ( CXArchive ar)
virtual

Reimplemented from C3DKeyframable.


The documentation for this class was generated from the following file: