材质 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 .

Access

A 材质 is accessed like any other material.

另请参阅 BaseMaterial Manual .

Allocation/Deallocation

材质 objects are created with the usual tools.

// This example creates, configures and inserts a new standard material.
材质 * const material = Material::Alloc (); if (material == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION );
const 向量 blue { 0.0, 0.0, 1.0 }; material-> SetParameter ( DescID ( MATERIAL_COLOR_COLOR ), blue, DESCFLAGS_SET::NONE ); material-> SetName ( "Blue Material" _s); doc-> InsertMaterial (material);

特性

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".

Channel States

These utility functions allow to edit the state of a "channel":

// This example reads the state of the color channel of the given material and inverts it. const Bool state = material-> GetChannelState ( CHANNEL_COLOR ); material-> SetChannelState ( CHANNEL_COLOR , !state);

Channels

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:

// This example accesses some material parameters using a BaseChannel object.

// 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 )); }

Reflection Layers

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:

注意
材质 is created and configured in some import context (e.g. SceneLoaderData ) one has to set the material parameter REFLECTION_LAYER_IMPORTED to true.
// This example creates and configures a new reflection layer.

// 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

延伸阅读

String::FloatToString
static String FloatToString(Float32 v, Int32 vvk=-1, Int32 nnk=-3)
定义: c4d_string.h:529
BaseChannel::GetShader
BaseShader * GetShader(void)
BaseShader
定义: c4d_basechannel.h:35
Xbitmap
#define Xbitmap
Bitmap.
定义: ge_prepass.h:1164
ReflectionLayer::GetName
String GetName() const
ReflectionLayer
定义: c4d_reflection.h:461
BASECHANNEL_TEXTURE
#define BASECHANNEL_TEXTURE
String. The texture for this channel.
定义: c4d_shader.h:119
DescID
定义: lib_description.h:327
REFLECTION_FLAG_TAB
#define REFLECTION_FLAG_TAB
Tab.
定义: c4d_reflection.h:25
ReflectionLayer::GetDataID
Int32 GetDataID() const
REFLECTION_LAYER_FRESNEL_MODE
#define REFLECTION_LAYER_FRESNEL_MODE
Int32 Fresnel mode: REFLECTION_FRESNEL
定义: c4d_reflection.h:381
REFLECTION_LAYER_TRANS_BRIGHTNESS
#define REFLECTION_LAYER_TRANS_BRIGHTNESS
Float Brightness.
定义: c4d_reflection.h:338
BaseChannel::GetData
BaseContainer GetData(void)
Float
maxon::Float Float
定义: ge_sys_math.h:64
REFLECTION_FRESNEL_METAL_GOLD
#define REFLECTION_FRESNEL_METAL_GOLD
Gold.
定义: c4d_reflection.h:191
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
REFLECTION_DISTRIBUTION_BECKMANN
#define REFLECTION_DISTRIBUTION_BECKMANN
Beckmann.
定义: c4d_reflection.h:50
DESCFLAGS_SET::NONE
@ NONE
None.
REFLECTION_LAYER_MAIN_DISTRIBUTION
#define REFLECTION_LAYER_MAIN_DISTRIBUTION
Int32 Distribution type: REFLECTION_DISTRIBUTION
定义: c4d_reflection.h:288
BaseChannel
定义: c4d_basechannel.h:237
ReflectionLayer::SetFlags
void SetFlags(Int32 flags)
Material::GetReflectionLayerIndex
ReflectionLayer * GetReflectionLayerIndex(Int32 index)
定义: c4d_basematerial.h:308
BaseDocument::InsertMaterial
void InsertMaterial(BaseMaterial *mat, BaseMaterial *pred=nullptr, Bool checknames=false)
REFLECTION_FRESNEL_CONDUCTOR
#define REFLECTION_FRESNEL_CONDUCTOR
Conductor.
定义: c4d_reflection.h:154
C4DAtom::SetParameter
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
maxon::Vec3< maxon::Float64, 1 >
材质
定义: c4d_basematerial.h:240
GeData::GetInt32
Int32 GetInt32(void) const
定义: c4d_gedata.h:427
Material::Alloc
static Material * Alloc()
REFLECTION_FLAG_SELECTED
#define REFLECTION_FLAG_SELECTED
Selected.
定义: c4d_reflection.h:23
REFLECTION_LAYER_FRESNEL_METAL
#define REFLECTION_LAYER_FRESNEL_METAL
Int32 Metal preset: REFLECTION_FRESNEL_METAL
定义: c4d_reflection.h:383
GeData
定义: c4d_gedata.h:82
BaseList2D::SetName
void SetName(const maxon::String &name)
定义: c4d_baselist.h:2324
Int32
maxon::Int32 Int32
定义: ge_sys_math.h:58
BaseMaterial::GetChannel
BaseChannel * GetChannel(Int32 id)
定义: c4d_basematerial.h:92
ApplicationOutput
#define ApplicationOutput(formatString,...)
定义: debugdiagnostics.h:207
REFLECTION_FLAG_ACTIVE
#define REFLECTION_FLAG_ACTIVE
Active.
定义: c4d_reflection.h:24
REFLECTION_LAYER_MAIN_BLEND_MODE
#define REFLECTION_LAYER_MAIN_BLEND_MODE
Int32 Blend mode.
定义: c4d_reflection.h:292
ReflectionLayer::SetName
void SetName(const maxon::String &name)
MATERIAL_TEXTUREMIXING_ADD
@ MATERIAL_TEXTUREMIXING_ADD
定义: mmaterial.h:61
DESCFLAGS_GET::NONE
@ NONE
None.
BaseContainer::GetString
String GetString(Int32 id, const maxon::String &preset=maxon::String()) const
定义: c4d_basecontainer.h:387
MATERIAL_TEXTUREMIXING_NORMAL
@ MATERIAL_TEXTUREMIXING_NORMAL
定义: mmaterial.h:60
Bool
maxon::Bool Bool
定义: ge_sys_math.h:53
Material::SetChannelState
void SetChannelState(Int32 channel, Bool state)
定义: c4d_basematerial.h:280
MATERIAL_COLOR_COLOR
@ MATERIAL_COLOR_COLOR
定义: mmaterial.h:56
C4DAtom::IsInstanceOf
Bool IsInstanceOf(Int32 id) const
定义: c4d_baselist.h:1373
Material::AddReflectionLayer
ReflectionLayer * AddReflectionLayer()
定义: c4d_basematerial.h:292
BaseList2D::GetName
String GetName() const
定义: c4d_baselist.h:2318
Material::GetReflectionLayerCount
Int32 GetReflectionLayerCount()
定义: c4d_basematerial.h:322
CHANNEL_COLOR
#define CHANNEL_COLOR
The color channel of a material.
定义: c4d_shader.h:94
C4DAtom::GetParameter
Bool GetParameter(const DescID &id, GeData &t_data, DESCFLAGS_GET flags)
BaseContainer
定义: c4d_basecontainer.h:46
Material::GetChannelState
Bool GetChannelState(Int32 channel)
定义: c4d_basematerial.h:273
GeData::GetFloat
Float GetFloat(void) const
定义: c4d_gedata.h:439

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1