About
BaseMaterial is the base class for all materials in Cinema 4D. Materials are typically assigned to a BaseObject using a TextureTag. They can be configured like any other BaseList2D based entity. Materials often own BaseShader elements. The most often used material is the standard material (Material class).
BaseMaterial objects are an instance of Mbase
.
Access
Materials are stored in a BaseDocument. They can be accessed with:
- BaseDocument::GetFirstMaterial(): Returns the first BaseMaterial in the list.
- BaseDocument::SearchMaterial(): Searches for a BaseMaterial with the given name.
- BaseDocument::GetActiveMaterial(): Returns the currently selected BaseMaterial.
- BaseDocument::GetActiveMaterials(): Returns the current multi-selection of BaseMaterial objects.
- BaseDocument::SetActiveMaterial(): Adds or removes the given BaseMaterial to the selection or starts a new selection.
See BaseDocument Materials
A TextureTag stores a reference to a material. This referenced material is accessed with:
- TextureTag::GetMaterial(): Returns the referenced material.
TextureTag*
const ttag =
static_cast<TextureTag*
>(
object->GetTag(
Ttexture));
if (ttag == nullptr)
BaseMaterial* const material = ttag->GetMaterial();
if (material != nullptr)
{
}
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:69
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:204
#define Ttexture
Texture - TextureTag.
Definition: ge_prepass.h:1420
See TextureTag Manual.
Allocation/Deallocation
BaseMaterial objects are created with the usual tools.
- BaseMaterial::Alloc(): Creates a new BaseMaterial.
- BaseMaterial::Free(): Deletes the given BaseMaterial.
A newly created material is typically added to a BaseDocument that takes ownership:
- BaseDocument::InsertMaterial(): Inserts a BaseMaterial into the list.
A material is assigned to a BaseObject using a TextureTag. The referenced material is set with:
- TextureTag::SetMaterial(): Sets the referenced material.
AutoAlloc<BaseMaterial> cheen {
Mcheen };
AutoAlloc<TextureTag> textureTag;
const Bool noCheen = cheen ==
nullptr;
const Bool noTextureTag = textureTag ==
nullptr;
if (noCheen || noTextureTag)
textureTag->SetMaterial(cheen);
doc->InsertMaterial(cheen.Release(),
nullptr);
object->InsertTag(textureTag.Release());
#define Mcheen
Cheen.
Definition: ge_prepass.h:1014
maxon::Bool Bool
Definition: ge_sys_math.h:46
const char * doc
Definition: pyerrors.h:226
Navigation
The BaseMaterial elements of a BaseDocument are stored in a list:
- BaseMaterial::GetNext(): Returns the previous BaseMaterial in the list.
- BaseMaterial::GetPred(): Returns the next BaseMaterial in the list.
BaseMaterial* material =
doc->GetFirstMaterial();
while (material != nullptr)
{
material = material->GetNext();
}
Read-Only Properties
The following functions allow to access various properties of a BaseMaterial.
- BaseMaterial::GetChannel(): Returns a BaseChannel object. This is only useful if the material in question is a standard Material.
- BaseMaterial::GetPreview(): Returns the material preview image.
- BaseMaterial::GetAverageColor(): Returns the average color. For standard materials this is mostly based on the color parameter. For other materials it is based on the viewport preview image.
- BaseMaterial::GetRenderInfo(): Returns information about what the material requires from the raytracer and what it will return.
- BaseMaterial::HasEditorTransparency(): Returns true if the material supports viewport transparency.
BaseBitmap* const preview = material->GetPreview(0);
Bool ShowBitmap(const Filename &fn)
Update
In certain situations it is needed to manually trigger an update of the material previews. This may be for example needed in a custom material plugin.
- BaseMaterial::Update(): Recalculates the material's thumbnail and viewport preview.
Sample Material
Materials define the surface properties of objects. They are sampled in the rendering pipeline e.g. in a VideoPost, another material or a shader.
Internal material resources are initiated and freed with these functions:
- BaseMaterial::InitTextures(): Initializes the material textures, loading any files required.
- BaseMaterial::UnlockTextures(): Unlocks all textures used by the material.
If needed the material calculation is initiated with:
- BaseMaterial::InitCalculation(): Must be called before any calculations if VOLUMEINFO::INITCALCULATION is set.
The material can now be sampled and used with:
- BaseMaterial::Displace(): Calls the displacement routine of a material.
- BaseMaterial::ChangeNormal(): Calls the bump routine of a material.
- BaseMaterial::CalcSurface(): Computes the surface properties of the material.
- BaseMaterial::CalcTransparency(): Computes the transparency properties of the material.
- BaseMaterial::CalcAlpha(): Computes the alpha properties of the material.
- BaseMaterial::CalcVolumetric(): Computes the color of a volumetric ray in the material.
These examples sample a BaseMaterial in a VideoPostData plugin:
VolumeData* const volumeData = vps->vd;
InitRenderStruct irs(vps->doc);
irs.vd = volumeData;
Py_UCS4 * res
Definition: unicodeobject.h:1113
OK
User has selected a font.
Definition: customgui_fontchooser.h:0
SURFACE
Called during rendering for surface calculation.
Definition: ge_prepass.h:0
INITCALCULATION
Needs MaterialData::InitCalculation() call.
Definition: ge_prepass.h:13
OUTOFMEMORY
Not enough memory.
Definition: ge_prepass.h:1
INITRENDERRESULT
Definition: ge_prepass.h:412
volumeData->ray = &ray;
volumeData->n = si.n;
volumeData->p = si.p;
volumeData->tex = texData;
volumeData->calc_illum = 0;
volumeData->uvw = uvw;
material->CalcSurface(volumeData);
const Vector surfaceColor = volumeData->col;
maxon::Vec3< maxon::Float64, 1 > Vector
Definition: ge_math.h:140
material->UnlockTextures();
Compare Entity
Two BaseMaterial elements can be compared with:
- BaseMaterial::Compare(): Returns true if the materials are identical.
BaseMaterial* firstMaterial =
doc->GetFirstMaterial();
if (firstMaterial == nullptr)
if (selectedMaterial->Compare(firstMaterial))
ApplicationOutput(
"The selected material has the same settings as the first material");
return OK
Definition: apibase.h:2740
- Note
- The comparison is mostly based on the material's BaseContainer. Other internal data may not be compared.
Bits
If an element is copied it must mark the materials it uses so that these materials are copied along with the actual element.
- BIT_MATMARK: This bit defines the material as a "marked" material.
{
BaseDocument*
const doc =
node->GetDocument();
return false;
GeData geData;
BaseMaterial*
const mat =
static_cast<BaseMaterial*
>(geData.GetLink(
doc,
Mbase));
if (data)
{
MarkMaterials* const markMaterial = static_cast<MarkMaterials*>(data);
if (markMaterial->omat == mat)
{
}
}
else
{
if (mat)
}
break;
}
NONE
Definition: asset_browser.h:1
CHANGE_SMALL
Change to the local data of the node as its data container. Does not apply for changes on substructur...
Definition: ge_prepass.h:4
#define BIT_MATMARK
Marked material.
Definition: ge_prepass.h:894
#define MSG_MULTI_MARKMATERIALS
Definition: c4d_baselist.h:564
#define MSG_CHANGE
Definition: c4d_baselist.h:375
#define Mbase
Base material.
Definition: ge_prepass.h:1006
#define ConstDescID(...)
Definition: lib_description.h:592
Further Reading