BaseMaterial Manual
BaseMaterial is the base class for all materials in Cinema 4D . Materials are typically assigned to a BaseObject 使用 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 ( 材质 class).
BaseMaterial
objects are an instance of
Mbase
.
Materials are stored in a BaseDocument . They can be accessed with:
A TextureTag stores a reference to a material. This referenced material is accessed with:
BaseMaterial objects are created with the usual tools.
A newly created material is typically added to a BaseDocument that takes ownership:
A material is assigned to a BaseObject 使用 TextureTag . The referenced material is set with:
// make new material AutoAlloc<BaseMaterial> cheen { Mcheen };
// make TextureTag AutoAlloc<TextureTag> textureTag;
// check if the "Cheen" material and the // "Texture" tag could be allocated const Bool noCheen = cheen == nullptr ; const Bool noTextureTag = textureTag == nullptr ; if (noCheen || noTextureTag) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION );
// assign material textureTag-> SetMaterial (cheen);
// insert material and tag doc-> InsertMaterial (cheen.Release(), nullptr ); object ->InsertTag(textureTag. 发行 ());
The BaseMaterial elements of a BaseDocument are stored in a list:
The following functions allow to access various properties of a BaseMaterial .
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.
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:
If needed the material calculation is initiated with:
The material can now be sampled and used with:
These examples sample a BaseMaterial in a VideoPostData plugin:
// This example prepares the material for usage within the rendering pipeline. VolumeData * const volumeData = vps-> vd ;// init material InitRenderStruct irs(vps-> doc ); irs.vd = volumeData;
// if VOLUMEINFO_INITCALCULATION is set, call InitCalculation() if (material-> GetRenderInfo () & VOLUMEINFO::INITCALCULATION ) material-> InitCalculation (volumeData, INITCALCULATION::SURFACE );
// init const INITRENDERRESULT res = material-> InitTextures (irs); if (res != INITRENDERRESULT::OK ) return RENDERRESULT::OUTOFMEMORY ;
// prepare VolumeData volumeData-> ray = &ray; volumeData-> n = si.n; volumeData-> p = si.p; volumeData-> tex = texData; volumeData-> calc_illum = 0; volumeData-> uvw = uvw;
// sample the material surface color material-> CalcSurface (volumeData);
// get result color const 向量 surfaceColor = volumeData-> col ;
// This example unlocks a material after it has been // used in the rendering pipeline.
// free material material-> UnlockTextures ();
Two BaseMaterial elements can be compared with:
// compare the selected material with the first material if (selectedMaterial->Compare(firstMaterial)) ApplicationOutput ( "The selected material has the same settings as the first material" );
If an element is copied it must mark the materials it uses so that these materials are copied along with the actual element.
// get referenced material GeData geData; node-> GetParameter (EXAMPLE_MATERIAL_LINK, geData, DESCFLAGS_GET::NONE ); BaseMaterial * const mat = static_cast< BaseMaterial * > (geData. GetLink (doc, Mbase )); if (data) // called when the element is pasted into the scene, update material links { MarkMaterials * const markMaterial = static_cast< MarkMaterials * > (data);
// check original material if (markMaterial-> omat == mat) { doc-> AddUndo ( UNDOTYPE::CHANGE_SMALL , node); // set new material node-> SetParameter (EXAMPLE_MATERIAL_LINK, markMaterial-> nmat , DESCFLAGS_SET::NONE ); node-> 消息 ( MSG_CHANGE ); } } else // called when the element is copied, mark needed materials { if (mat) mat-> SetBit ( BIT_MATMARK ); } break ; }