About
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 (Cinema API)):
- InstanceObject::Alloc(): Creates a new InstanceObject.
- InstanceObject::Free(): Deletes the given InstanceObject.
Properties
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:
- InstanceObject::GetReferenceObject(): Returns the referenced BaseObject.
- InstanceObject::SetReferenceObject(): Sets the referenced BaseObject.
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.
- InstanceObject::IsMultiInstance(): Returns true if the object is in multi-instance mode.
InstanceObject* const instance = InstanceObject::Alloc();
if (instance == nullptr)
doc->InsertObject(instance,
nullptr,
nullptr);
NONE
Definition: asset_browser.h:1
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:69
#define ConstDescID(...)
Definition: lib_description.h:592
@ INSTANCEOBJECT_RENDERINSTANCE_MODE
Definition: oinstance.h:7
@ INSTANCEOBJECT_MULTIPOSITIONINPUT
Definition: oinstance.h:11
@ INSTANCEOBJECT_RENDERINSTANCE_MODE_MULTIINSTANCE
Definition: oinstance.h:10
const char * doc
Definition: pyerrors.h:226
#define iferr_return
Definition: resultbase.h:1531
For each multi-instance a matrix and a color (maxon::Color64) is stored:
- InstanceObject::GetInstanceCount(): Returns the number of multi-instances. The number of instances is the size of the matrix and color arrays.
- InstanceObject::GetInstanceMatrices(): Returns the array of instance matrices.
- InstanceObject::GetInstanceMatrix(): Returns the matrix of the given instance index.
- InstanceObject::SetInstanceMatrix(): Sets the matrix at the given instance index.
- InstanceObject::SetInstanceMatrices(): Sets the array of instance matrices.
- InstanceObject::GetMatrixDirtyID(): Returns the matrix dirty ID of the given instance index.
- InstanceObject::GetInstanceColors(): Returns the array of instance colors.
- InstanceObject::GetInstanceColor(): Returns the color of the given instance index.
- InstanceObject::SetInstanceColors(): Sets the array of instance colors.
{
const Vector colorHSV { hue, 1.0, 1.0 };
hue += hueStep;
}
Py_ssize_t i
Definition: abstract.h:645
Py_ssize_t count
Definition: abstract.h:640
Definition: basearray.h:415
ResultMem Resize(Int newCnt, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::DEFAULT)
Resizes the array to contain newCnt elements. If newCnt is smaller than GetCount() all extra elements...
Definition: basearray.h:1217
Col3< Float64, 1 > Color64
Definition: vector.h:80
maxon::Float Float
Definition: ge_sys_math.h:57
maxon::Int Int
Definition: ge_sys_math.h:55
Vector HSVToRGB(const Vector &col)
maxon::Vec3< maxon::Float64, 1 > Vector
Definition: ge_math.h:140
PyObject PyObject * step
Definition: sliceobject.h:34
The InstanceObject can also store unique IPs to identify an instance (see Generating).
- InstanceObject::GetInstanceUniqueIPs(): Returns the unique IPs.
- InstanceObject::GetInstanceUniqueIP(): Returns the unique IP for the given instance index.
- InstanceObject::SetInstanceUniqueIPs(): Sets the unique IPs.
Multi-instance information can also be accessed with a MultiInstanceData object:
- MultiInstanceData::ExtractInfo(): Loads the multi-instance data from the given InstaceObject.
- MultiInstanceData::Clear(): Clears the internal data.
- MultiInstanceData::instancedObject: The referenced BaseObject.
- MultiInstanceData::instanceMatrices: Array of instance matrices.
- MultiInstanceData::instanceColors: Array of instance colors.
- MultiInstanceData::instanceUniqueIPs: Unique IP, one for each instance.
MultiInstanceData data;
for (
const Matrix& mg : data.instanceMatrices)
{
BaseObject*
const cube = BaseObject::Alloc(
Ocube);
if (cube == nullptr)
cube->SetMg(mg);
doc->InsertObject(cube,
nullptr,
nullptr);
}
#define Ocube
Cube.
Definition: ge_prepass.h:1118
maxon::Mat3< maxon::Vector64 > Matrix
Definition: ge_math.h:159
Further Reading