Overview
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
if (newDoc == nullptr)
void InsertBaseDocument(BaseDocument *doc)
void SetActiveDocument(BaseDocument *doc)
void EventAdd(EVENT eventflag=EVENT::NONE)
Definition: c4d_basedocument.h:498
void SetDocumentName(const Filename &fn)
static BaseDocument * Alloc()
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
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.
if (cube == nullptr)
doc->InsertObject(cube,
nullptr,
nullptr);
Definition: c4d_baseobject.h:225
static BaseObject * Alloc(Int32 type)
#define Ocube
Cube.
Definition: ge_prepass.h:1102
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);
void SetName(const maxon::String &name)
Definition: c4d_baselist.h:2387
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
Definition: lib_description.h:330
Py_ssize_t size
Definition: bytesobject.h:86
@ 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.
if (material == nullptr)
doc->InsertMaterial(material);
if (noiseShader == nullptr)
void InsertShader(BaseShader *shader, BaseShader *pred=nullptr)
Definition: c4d_baselist.h:2591
Definition: c4d_basechannel.h:36
static BaseShader * Alloc(Int32 type)
Definition: c4d_basematerial.h:241
static Material * Alloc()
#define Xnoise
Noise.
Definition: ge_prepass.h:1340
@ 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.
if (textureTag == nullptr)
void InsertTag(BaseTag *tp, BaseTag *pred=nullptr)
Definition: c4d_basetag.h:48
static BaseTag * Alloc(Int32 type)
#define Ttexture
Texture - TextureTag.
Definition: ge_prepass.h:1392
@ 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.
if (activeObject != nullptr)
{
while (tag != nullptr)
{
}
}
while (material != nullptr)
{
}
const char const char * name
Definition: abstract.h:195
String GetName() const
Definition: c4d_baselist.h:2381
Definition: c4d_basematerial.h:28
BaseMaterial * GetNext()
Definition: c4d_basematerial.h:60
BaseTag * GetNext()
Definition: c4d_basetag.h:79
Definition: c4d_string.h:39
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:210
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;
if (polygonObject == nullptr)
doc->InsertObject(polygonObject,
nullptr,
nullptr);
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);
}
else
{
}
Bool Message(Int32 type, void *data=nullptr)
Definition: c4d_baselist.h:1457
Vector * GetPointW()
Definition: c4d_baseobject.h:1465
Definition: c4d_baseobject.h:1631
CPolygon * GetPolygonW()
Definition: c4d_baseobject.h:1778
static PolygonObject * Alloc(Int32 pcnt, Int32 vcnt)
maxon::Vec3< maxon::Float64, 1 > Vector
Definition: ge_math.h:145
maxon::Bool Bool
Definition: ge_sys_math.h:55
maxon::Int32 Int32
Definition: ge_sys_math.h:60
#define MSG_UPDATE
Must be sent if the bounding box has to be recalculated. (Otherwise use MSG_CHANGE....
Definition: c4d_baselist.h:358
Represents a polygon that can be either a triangle or a quadrangle.
Definition: c4d_baseobject.h:44
Rendering
The function RenderDocument() can be used to render a given BaseDocument.
if (bitmap == nullptr)
const Int32 height = 720;
if (rdata == nullptr)
nullptr,
nullptr, bitmap,
flags,
nullptr);
PyCompilerFlags * flags
Definition: ast.h:14
RENDERRESULT RenderDocument(BaseDocument *doc, const BaseContainer &rdata, ProgressHook *prog, void *private_data, BaseBitmap *bmp, RENDERFLAGS renderflags, BaseThread *th, WriteProgressHook *wprog=nullptr, void *data=nullptr)
Bool ShowBitmap(const Filename &fn)
Definition: ge_autoptr.h:37
Definition: c4d_basecontainer.h:47
void SetFloat(Int32 id, Float r)
Definition: c4d_basecontainer.h:533
BaseContainer GetData()
Definition: c4d_baselist.h:2329
Definition: c4d_basedocument.h:144
Py_UCS4 * res
Definition: unicodeobject.h:1113
@ RDATA_XRES
Definition: drendersettings.h:154
@ RDATA_YRES
Definition: drendersettings.h:155
IMAGERESULT
Definition: ge_prepass.h:3914
@ OK
Image loaded/created.
RENDERFLAGS
Definition: ge_prepass.h:4681
@ NODOCUMENTCLONE
Set to avoid an automatic clone of the scene sent to RenderDocument().
RENDERRESULT
Definition: ge_prepass.h:422
@ OK
Function was successful.
unsigned long Py_ssize_t width
Definition: pycore_traceback.h:88