Overview
- A 3D scene is represented by a BaseDocument.
- The "active" BaseDocument is currently displayed in the Cinema 4D viewport. Other BaseDocument instances can be allocated at any time.
- Cinema 4D must be informed on any change to the "active" BaseDocument by calling EventAdd().
- 3D objects are based on BaseObject and can be inserted into a BaseDocument.
- Tags add additional functionality or data to a BaseObjects. Tags are based on BaseTag.
- Polygon data is represented as PolygonObject objects.
- Materials are based on BaseMaterial. The standard material is represented as Material.
- A given BaseDocumnet can be rendered using the RenderDocument() function.
Working with Documents
A 3D scene is represented as a BaseDocument. A BaseDocument can store objects, materials, takes etc. Cinema 4D can handle multiple documents at once. The document display in the viewport is the active document that can be accessed with GetActiveDocument(). This active document must only be modified in the context of user interaction from the main thread. It must not be edited from within the execution pipeline or from a thread that is not the main thread.
After the active document has been edited, one must call EventAdd() to inform Cinema 4D that something has changed.
See also
BaseDocument* const newDoc = BaseDocument::Alloc();
if (newDoc == nullptr)
newDoc->SetDocumentName("new_document.c4d");
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:69
void InsertBaseDocument(BaseDocument *doc)
void SetActiveDocument(BaseDocument *doc)
void EventAdd(EVENT eventflag=EVENT::NONE)
Creating new Objects
BaseObject is the base class of all scene objects. Such scene objects can be polygon objects or splines but also generators, deformers, camera objects or lights.
To create a new object one must know the object type's ID. E.g. the ID for a "Cube" is Ocube. A newly created object can simply be inserted into a BaseDocument that will take ownership.
See also Scene Elements Overview.
BaseObject*
const cube = BaseObject::Alloc(
Ocube);
if (cube == nullptr)
doc->InsertObject(cube,
nullptr,
nullptr);
#define Ocube
Cube.
Definition: ge_prepass.h:1118
const char * doc
Definition: pyerrors.h:226
Setting Parameters
The BaseObject class is based on C4DAtom. This means that parameters of objects can be accessed using C4DAtom::SetParameter() and C4DAtom::GetParameter().
For each element type, there is typically a header file that includes the parameter IDs. E.g. for the Ocube object type there is the ocube.h header file.
Different objects are based on fundamental base classes. Ocube is based on Obase so it inherits the base class' parameters which are defined in the corresponding header file (e.g. obase.h).
See C4DAtom Manual.
cube->SetName("This is a new Cube."_s);
NONE
Definition: asset_browser.h:1
Py_ssize_t size
Definition: bytesobject.h:86
#define ConstDescID(...)
Definition: lib_description.h:592
maxon::Vec3< maxon::Float64, 1 > Vector
Definition: ge_math.h:140
@ PRIM_CUBE_LEN
Definition: ocube.h:6
Creating new Materials
Materials and shaders can be created like objects. Materials must be inserted into the host BaseDocument. A new shader instance must be inserted into a host object. This is typically the material using the shader. BaseMaterial is the base class of all materials. Material is the class representing the standard Cinema 4D material.
See Materials and Shaders Overview.
Material* const material = Material::Alloc();
if (material == nullptr)
doc->InsertMaterial(material);
BaseShader*
const noiseShader = BaseShader::Alloc(
Xnoise);
if (noiseShader == nullptr)
material->InsertShader(noiseShader);
#define Xnoise
Noise.
Definition: ge_prepass.h:1367
@ MATERIAL_COLOR_SHADER
Definition: mmaterial.h:294
Working with Tags
Tags are used to add arbitrary data or additional functionality to given BaseObject. Tags that store information are e.g. NormalTag or UVWTag. A TextureTag is used to assign a material to a BaseObject.
See BaseTag and VariableTag Manual and TextureTag Manual.
BaseTag*
const textureTag = BaseTag::Alloc(
Ttexture);
if (textureTag == nullptr)
cube->InsertTag(textureTag);
#define Ttexture
Texture - TextureTag.
Definition: ge_prepass.h:1420
@ TEXTURETAG_MATERIAL
Definition: ttexture.h:29
@ TEXTURETAG_PROJECTION
Definition: ttexture.h:10
@ TEXTURETAG_PROJECTION_UVW
Definition: ttexture.h:17
Finding Elements in the Document
There are many different ways to access the objects, materials or tags that are stored in a BaseDocument. The user can select objects, materials and tags. The BaseDocument class gives access to these "active" elements. Additionally it is also possible to search for objects by name.
The objects of a scene are organized in a tree. For iterating such a tree see Navigation in Lists and Trees.
See BaseDocument Manual.
BaseObject*
const activeObject =
doc->GetActiveObject();
if (activeObject != nullptr)
{
const String
name = activeObject->GetName();
BaseTag* tag = activeObject->GetFirstTag();
while (tag != nullptr)
{
const String tagName = tag->GetName();
tag = tag->GetNext();
}
}
BaseMaterial* material =
doc->GetFirstMaterial();
while (material != nullptr)
{
const String materialName = material->GetName();
material = material->GetNext();
}
const char const char * name
Definition: abstract.h:195
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:204
Creating Polygon Objects
A PolygonObject stores point and polygon data. Such a PolygonObject is created and inserted into the BaseDocument like any other object.
const Int32 pointCnt = 4;
PolygonObject* const polygonObject = PolygonObject::Alloc(pointCnt, polyCnt);
if (polygonObject == nullptr)
doc->InsertObject(polygonObject,
nullptr,
nullptr);
Vector*
const points = polygonObject->GetPointW();
CPolygon* const polygons = polygonObject->GetPolygonW();
const Bool pointsReady = points !=
nullptr;
const Bool polygonsReady = polygons !=
nullptr;
if (pointsReady && polygonsReady)
{
points[1] =
Vector(0, 0, 100);
points[2] =
Vector(100, 0, 100);
points[3] =
Vector(100, 0, 0);
polygons[0] = CPolygon(0, 1, 2, 3);
}
else
{
}
#define MSG_UPDATE
Must be sent if the bounding box has to be recalculated. (Otherwise use MSG_CHANGE....
Definition: c4d_baselist.h:372
maxon::Bool Bool
Definition: ge_sys_math.h:46
maxon::Int32 Int32
Definition: ge_sys_math.h:51
Rendering
The function RenderDocument() can be used to render a given BaseDocument.
AutoAlloc<BaseBitmap> bitmap;
if (bitmap == nullptr)
const Int32 height = 720;
RenderData*
const rdata =
doc->GetActiveRenderData();
if (rdata == nullptr)
BaseContainer renderSettings = rdata->GetDataInstanceRef();
nullptr,
nullptr, bitmap,
flags,
nullptr);
PyCompilerFlags * flags
Definition: ast.h:14
Py_UCS4 * res
Definition: unicodeobject.h:1113
OK
User has selected a font.
Definition: customgui_fontchooser.h:0
@ RDATA_XRES
Definition: drendersettings.h:152
@ RDATA_YRES
Definition: drendersettings.h:153
NODOCUMENTCLONE
Set to avoid an automatic clone of the scene sent to RenderDocument().
Definition: ge_prepass.h:2
IMAGERESULT
Definition: ge_prepass.h:3947
RENDERFLAGS
Definition: ge_prepass.h:4718
RENDERRESULT
Definition: ge_prepass.h:426
Bool ShowBitmap(const Filename &fn)
RENDERRESULT RenderDocument(BaseDocument *doc, const BaseContainer &rdata, ProgressHook *prog, void *private_data, BaseBitmap *bmp, RENDERFLAGS renderflags, BaseThread *th, WriteProgressHook *wprog=nullptr, void *data=nullptr)
unsigned long Py_ssize_t width
Definition: pycore_traceback.h:88