About
Layers are used to organize a Cinema 4D scene. A layer is represented by a LayerObject, its settings are stored in a LayerData object.
GeListHead* const root = doc->GetLayerObjectRoot();
if (root == nullptr)
for (
Int32 i = 0; i < 20; ++i)
{
LayerObject* const newLayer = LayerObject::Alloc();
if (newLayer == nullptr)
LayerData layerData;
layerData.color = rgb;
layerData.solo = false;
newLayer->SetLayerData(doc, layerData);
newLayer->SetName("Layer " + String::IntToString(i));
root->InsertLast(newLayer);
}
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:69
maxon::Int32 Int32
Definition: ge_sys_math.h:51
maxon::Float Float
Definition: ge_sys_math.h:57
Vector HSVToRGB(const Vector &col)
maxon::Vec3< maxon::Float64, 1 > Vector
Definition: ge_math.h:122
LayerObject
A LayerObject represents a layer of a Cinema 4D scene. It is used to assign an element to this layer and to edit the layer.
LayerObject objects are an instance of Olayer.
Access
The LayerObject assigned to an element can be accessed and set with these ::BaseList2D functions:
- BaseList2D::GetLayerObject(): Returns the LayerObject representing the element's layer or
nullptr.
- BaseList2D::SetLayerObject(): Used to set the layer of the element.
Layers are organized in a tree. The root element of that tree is stored in the BaseDocument:
- BaseDocument::GetLayerObjectRoot(): Returns the GeListHead that is the root of the layer tree.
GeListHead* const layers = doc->GetLayerObjectRoot();
if (layers == nullptr)
LayerObject* const layer = static_cast<LayerObject*>(layers->GetFirst());
if (layer != nullptr)
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:204
- Note
- To check if a given LayerObject is currently selected in the Layer Manager, read the bit BIT_ACTIVE.
Allocation/Deallocation
LayerObject objects are created with the usual tools:
- LayerObject::Alloc(): Creates a new LayerObject object.
- LayerObject::Free(): Destroys the given LayerObject object.
GeListHead* const root = doc->GetLayerObjectRoot();
if (root == nullptr)
LayerObject* const newLayer = LayerObject::Alloc();
if (newLayer == nullptr)
newLayer->SetName("This is a new layer"_s);
root->InsertLast(newLayer);
object->SetLayerObject(newLayer);
Navigation
LayerObject objects are based on ::GeListNode and are organized in a tree. This tree can be navigated with:
- LayerObject::GetNext(): Returns the next LayerObject.
- LayerObject::GetPred(): Returns the previous LayerObject.
- LayerObject::GetUp(): Returns the parent LayerObject.
- LayerObject::GetDown(): Returns the child LayerObject.
- LayerObject::GetDownLast(): Returns the last child LayerObject.
BaseObject* const object = doc->GetActiveObject();
if (object == nullptr)
LayerObject* const layer = object->GetLayerObject(doc);
if (layer != nullptr)
{
LayerObject* parentLayer = layer;
while (parentLayer->GetUp())
{
parentLayer = parentLayer->GetUp();
}
object->SetLayerObject(parentLayer);
}
- Note
- If a layer is folded in the Layer Manager is controlled with the bit BIT_OFOLD.
LayerData
A LayerData object represents the settings of a layer.
Access
The applied layer settings of an element are accessed with these ::BaseList2D functions:
- BaseList2D::GetLayerData(): Returns the layer data of the object's layer.
- BaseList2D::SetLayerData(): Sets the layer data of the object's layer.
These functions can be used on the given element or on a LayerObject object.
const LayerData* const layerData = object->GetLayerData(doc, true);
if (layerData != nullptr)
{
}
Properties
These are the properties of a layer stored in a LayerData object. These properties define how a layer changes the behavior of an element that is assigned to that layer:
- LayerData::solo: solo mode.
- LayerData::view: visible in the editor view.
- LayerData::render: visible in render view.
- LayerData::manager: visible in the Object Manager and the Timeline.
- LayerData::locked: not selectable.
- LayerData::generators: turns generators off.
- LayerData::deformers: turns deformers off.
- LayerData::expressions: turns expressions off.
- LayerData::animation: turns animations off.
- LayerData::color: the layer color.
- LayerData::xref: elements will not be exported using Xref.
GeListHead* const root = doc->GetLayerObjectRoot();
if (root == nullptr)
LayerObject* const newLayer = LayerObject::Alloc();
if (newLayer == nullptr)
LayerData layerData;
layerData.locked = true;
layerData.solo = false;
newLayer->SetLayerData(doc, layerData);
newLayer->SetName("Locked"_s);
root->InsertLast(newLayer);
AutoAlloc<AtomArray> objects;
if (objects == nullptr)
for (
Int32 i = 0; i < objects->GetCount(); ++i)
{
BaseObject* const object = static_cast<BaseObject*>(objects->GetIndex(i));
if (object == nullptr)
object->SetLayerObject(newLayer);
}
NONE
Definition: asset_browser.h:1
- Note
- When one edits the solo bit it is also necessary to change the ::NBIT::SOLO_LAYER of the BaseDocument with GeListNode::ChangeNBit() either using ::NBITCONTROL::SET or ::NBITCONTROL:: CLEAR.
Utility
- IsObjectEnabled(): Checks if the given object should be visible in the viewport, including checking the layers.
Further Reading