InstanceObject Manual

内容表

关于

InstanceObject represents an instance object in Cinema 4D . Such an instance object references another scene object. Additionally, it can store multiple matrices for multi-instances.

InstanceObject objects are an instance of Oinstance .

Creation

InstanceObject objects are created with the usual tools ( Entity Creation and Destruction Manual (Classic) ):

特性

The parameters of an InstanceObject are edited as usual using C4DAtom::GetParameter() and C4DAtom::SetParameter() . The parameter IDs are defined in Oinstance.h .

The referenced object can be accessed with the INSTANCEOBJECT_LINK parameter or with these functions:

Multi-Instances

An InstanceObject can store multiple instance positions. So it can represent not only one but many instances. To turn on the multi-instance mode set the parameter INSTANCEOBJECT_RENDERINSTANCE_MODE to INSTANCEOBJECT_RENDERINSTANCE_MODE_MULTIINSTANCE .

// This example creates an intance object that uses the given reference object and matrix object.

// create instance object InstanceObject * const instance = InstanceObject::Alloc (); if (instance == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION );

// insert object into the scene doc-> InsertObject (instance, nullptr , nullptr );

// use the given reference object instance-> SetReferenceObject (reference) iferr_return ;

// use position data provided by the given matrix object

if (!instance-> SetParameter ( INSTANCEOBJECT_MULTIPOSITIONINPUT , matrix, DESCFLAGS_SET::NONE )) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION ); if (!instance-> SetParameter ( INSTANCEOBJECT_RENDERINSTANCE_MODE , INSTANCEOBJECT_RENDERINSTANCE_MODE_MULTIINSTANCE , DESCFLAGS_SET::NONE )) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );

For each multi-instance a matrix and a color ( maxon::Color64 ) is stored:

// This example defines positions and colors and stores them in the given instance object as multi-instance data.

// prepare matrices and colors maxon::BaseArray<Matrix> matrices; maxon::BaseArray<maxon::Color64> colors;

const Int count = 100; matrices. Resize (count) iferr_return ; colors. Resize (count) iferr_return ;

// generate positions and colors Float position = 0.0; const Float step = 300.0; Float hue = 0.0; const Float hueStep = 1.0 / count; for ( Int i = 0; i < count; ++i) { // matrices matrices[i] = MatrixMove ( 向量 (position, 0.0, 0.0)); position += step; // colors const 向量 colorHSV { hue, 1.0, 1.0 }; const 向量 colorRGB = HSVToRGB (colorHSV); colors[i] = maxon::Color64 (colorRGB); hue += hueStep; }

// store data in the instance object instance-> SetInstanceMatrices (matrices) iferr_return ; instance-> SetInstanceColors (colors) iferr_return ;

The InstanceObject can also store unique IPs to identify an instance (see Generating ).

Multi-instance information can also be accessed with a MultiInstanceData object:

// This example reads the multi-instance data from the given instance object using MultiInstanceData.

// read data MultiInstanceData data; data. ExtractInfo (instanceObject) iferr_return ;

// for each position, create a cube object for ( const 矩阵 & mg : data. instanceMatrices ) { BaseObject * const cube = BaseObject::Alloc ( Ocube ); if (cube == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION ); cube-> SetMg (mg); doc-> InsertObject (cube, nullptr , nullptr ); }

延伸阅读

InstanceObject::SetReferenceObject
maxon::Result< void > SetReferenceObject(BaseObject *refObj)
BaseDocument::InsertObject
void InsertObject(BaseObject *op, BaseObject *parent, BaseObject *pred, Bool checknames=false)
Int
maxon::Int Int
定义: ge_sys_math.h:62
maxon::Color64
Col3< Float64, 1 > Color64
定义: vector.h:78
BaseObject
定义: c4d_baseobject.h:224
maxon::Mat3< maxon::Vector64 >
Float
maxon::Float Float
定义: ge_sys_math.h:64
InstanceObject::SetInstanceColors
maxon::Result< void > SetInstanceColors(const maxon::BaseArray< maxon::Color64 > &colors)
BaseObject::SetMg
void SetMg(const Matrix &m)
定义: c4d_baseobject.h:488
INSTANCEOBJECT_RENDERINSTANCE_MODE_MULTIINSTANCE
@ INSTANCEOBJECT_RENDERINSTANCE_MODE_MULTIINSTANCE
定义: oinstance.h:10
maxon::BaseArray::Resize
ResultMem Resize(Int newCnt, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::DEFAULT)
定义: basearray.h:1077
INSTANCEOBJECT_RENDERINSTANCE_MODE
@ INSTANCEOBJECT_RENDERINSTANCE_MODE
定义: oinstance.h:7
iferr_return
#define iferr_return
定义: resultbase.h:1434
Ocube
#define Ocube
Cube.
定义: ge_prepass.h:1040
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
HSVToRGB
Vector HSVToRGB(const Vector &col)
maxon::BaseArray
定义: basearray.h:366
DESCFLAGS_SET::NONE
@ NONE
None.
InstanceObject
定义: lib_instanceobject.h:37
MultiInstanceData::ExtractInfo
maxon::Result< void > ExtractInfo(InstanceObject *obj)
定义: lib_instanceobject.h:241
InstanceObject::Alloc
static InstanceObject * Alloc()
C4DAtom::SetParameter
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
maxon::Vec3< maxon::Float64, 1 >
MultiInstanceData::instanceMatrices
maxon::BaseArray< Matrix > instanceMatrices
Global matrices, one for each instance.
定义: lib_instanceobject.h:276
MatrixMove
Matrix MatrixMove(const Vector &t)
向量
maxon::Vec3< maxon::Float64, 1 > Vector
定义: ge_math.h:145
BaseObject::Alloc
static BaseObject * Alloc(Int32 type)
MultiInstanceData
定义: lib_instanceobject.h:222
INSTANCEOBJECT_MULTIPOSITIONINPUT
@ INSTANCEOBJECT_MULTIPOSITIONINPUT
定义: oinstance.h:11
InstanceObject::SetInstanceMatrices
maxon::Result< void > SetInstanceMatrices(const maxon::BaseArray< Matrix > &matrices)

Copyright  © 2014-2025 乐数软件    

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