材质 Manual
A 材质 object represents a Cinema 4D standard material. It is based on BaseMaterial . A standard material offers multiple parameters organized in "channels".
材质
objects are an instance of
Mmaterial
.
A 材质 is accessed like any other material.
另请参阅 BaseMaterial Manual .
材质 objects are created with the usual tools.
The parameters of a
材质
can be edited as usual with
C4DAtom::SetParameter()
and
C4DAtom::GetParameter()
. The parameter IDs are defined in
mmaterial.h
. For convenience the parameters of a group are often combined to a "channel".
These utility functions allow to edit the state of a "channel":
Certain parameters and functionality of a parameter group are combined in a BaseChannel object:
The returned BaseChannel object can be used to handle the referenced shaders:
Between the call of InitTexture() and FreeTexture() the shader of the channel can be sampled:
Further operations are:
These functions are useful to get general settings of the channel and the settings of a used bitmap shader:
// get the BaseChannel BaseChannel * const channel = material-> GetChannel ( CHANNEL_COLOR ); if (channel == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );
// check the shader BaseShader * const shader = channel-> GetShader (); if (shader != nullptr ) ApplicationOutput ( "Used Shader: " + shader-> GetName ());
// if the shader is a "Bitmap" shader, access some data if (shader != nullptr && shader-> IsInstanceOf ( Xbitmap )) { const BaseContainer bc = channel-> GetData (); ApplicationOutput ( "Image File: " + bc. GetString ( BASECHANNEL_TEXTURE )); }
A standard material can manage multiple reflection layers. Such reflection layers can be created and edited. The used parameter IDs are defined in
c4d_reflection.h
,见
REFLECTION_LAYER
.
The settings of a ReflectionLayer object are:
// create a new layer ReflectionLayer * const layer = material-> AddReflectionLayer (); if (layer == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION ); const Int32 layerID = layer-> GetDataID ();
// configure layer layer-> SetName ( "Gold Layer" _s); layer-> SetFlags ( REFLECTION_FLAG_SELECTED | REFLECTION_FLAG_TAB | REFLECTION_FLAG_ACTIVE ); const Int32 distributionID = layerID + REFLECTION_LAYER_MAIN_DISTRIBUTION ; material-> SetParameter (distributionID, REFLECTION_DISTRIBUTION_BECKMANN , DESCFLAGS_SET::NONE ); const Int32 fresnelModeID = layerID + REFLECTION_LAYER_FRESNEL_MODE ; material-> SetParameter (fresnelModeID, REFLECTION_FRESNEL_CONDUCTOR , DESCFLAGS_SET::NONE ); const Int32 fresnelMetalID = layerID + REFLECTION_LAYER_FRESNEL_METAL ; material-> SetParameter (fresnelMetalID, REFLECTION_FRESNEL_METAL_GOLD , DESCFLAGS_SET::NONE );
and
// This example loops through all layers of the given material. const Int32 layerCount = material-> GetReflectionLayerCount (); for ( Int32 i = 0; i < layerCount; ++i) { ReflectionLayer * const layer = material-> GetReflectionLayerIndex (i); if (layer == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );// print name ApplicationOutput ( "Layer: " + layer-> GetName ()); const Int32 layerID = layer-> GetDataID (); GeData data;
// access and print value const DescID valueID(layerID + REFLECTION_LAYER_TRANS_BRIGHTNESS ); material-> GetParameter (valueID, data, DESCFLAGS_GET::NONE ); const Float value = data. GetFloat (); ApplicationOutput ( "Value: " + String::FloatToString (value));
// print mode const DescID blendModeID(layerID + REFLECTION_LAYER_MAIN_BLEND_MODE ); material-> GetParameter (blendModeID, data, DESCFLAGS_GET::NONE );
// check if blend mode is "Normal" if (data. GetInt32 () == MATERIAL_TEXTUREMIXING_NORMAL ) ApplicationOutput ( "Mode: Normal" );
// check if blend mode is "Add" if (data. GetInt32 () == MATERIAL_TEXTUREMIXING_ADD ) ApplicationOutput ( "Mode: Add" ); }
另请参阅 Blog post: Cinema 4D R16 Reflectance channel's API