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
.
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:
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 .
// 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:
// prepare matrices and colors maxon::BaseArray<Matrix> matrices; maxon::BaseArray<maxon::Color64> colors;
// 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:
// 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 ); }