Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches

About materials

C3DMaterial is the material base class that handles the 3D material properties, whereas CMaterials a list of several materials.
Each material is identified by a single MaterialID. This identifier can be used to retrieve a particular material of the scene, using C3DScene::GetMaterial method.

DEFAULT_MATERIAL_ID is the MaterialID for a default material, whereas MATERIAL_UNDEFINED is sometime used when the material is not defined or cannot be retrieved.

C3DMaterial is usually created using C3DScene::CreateNewMaterial and can be retrieved using C3DScene::GetMaterial.

C3DMaterial handles one or more CMaterialMap defined by their MapType.

There is two more precise kinds of materials derived from C3DMaterial: C3DStandardMaterial and C3DPbrMaterial, and you can retrieve the appropriate type using C3DMaterial::GetClass.

Single / double face materials

Most of the format defines a single material, which means that front and back face has the same materials.
However, the SDK supports double face materials, which means you can define a different material for front and back materials.
Some methods named FB are related to double side materials.

For example you can test if a C3DGeomObject has double side materials using C3DGeomObject::HasBackFaceMaterials. You can retrieve the FB used by the object using C3DGeomObject::GetFBMaterialsHashMap.

It is also possible to assign a different UV channel for front and back face and you can know if this is the case using C3DGeomObject::HasDifferentFrontAndBackUVChannel

Assign material to faces

newmat->SetName("new material");
newmat->SetDiffuseColor(CRGBColor(255, 0, 0));
newmat->SetDiffuseFactor(0.7f);
MaterialID matid = newmat->GetMaterialID();
int i, size = faces->GetSize();
for (int =0; i<size; i++)
(*faces)[i].SetMaterialID(matid);
@ MATERIAL_CLASS_STANDARD
The material is a C3DStandardMaterial.
Definition 3DMaterial.h:55
C3DStandardMaterial is a basic material that defines ambient, specular, bump and other coefficients.
Definition 3DMaterial.h:259
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
CRGBColor handles an r, g, b, a color that can be initialized in different way.
Definition RGBColor.h:22

Retrieve materials used by faces

CMaterialHashMap is CHashMap that helps known which material are used by a C3DFaceList::GetMaterialsHashMap or by the C3DScene::GetMaterials.

CRGBColor color;
C3DMaterial* material;
MaterialID matid;
CMaterialHashMap *hashMaterials = faces->GetMaterialsHashMap();
if (materials)
{
HashPos hashPos = materials->GetFirst();
while (hashPos != HashEnd)
{
int facecount;
hashMaterials->GetNext(hashPos, matid, facecount);
material = scene->GetMaterialByID(matid);
color = material->GetDiffuseColor();
...
}
}
C3DMaterial is the base class for materials. There is currently two kinds of materials: C3DPbrMateria...
Definition 3DMaterial.h:69
virtual CRGBColor GetDiffuseColor(unsigned int time, bool modulateByDiffuseFactor=false) const
This can be overidden as derived class might have a different computation for this.