BaseView / BaseDraw Manual


A BaseView object represents a viewport window. Such a BaseView can be obtained from the active BaseDocument to get information on the viewport window. The class BaseDraw is based on BaseView. It can be used to draw something in a viewport window via a "Draw" function.

It is only allowed to draw into the viewport inside a "Draw" function. See Draw Manual.


The BaseDraw windows used to display the active BaseDocument can be accessed with:

See BaseDocument Editor Windows.

Such a BaseDraw can be used to access the scene camera.

// This example accesses the active BaseDraw to get its camera.
// Then it moves the active object into the view of that camera.
BaseDraw* const baseDraw = doc->GetActiveBaseDraw();
if (baseDraw == nullptr)
return maxon::OK;
BaseObject* const cameraObject = baseDraw->GetEditorCamera();
// move active object into the camera view
const Matrix cameraMatrix = cameraObject->GetMg();
Matrix targetPosition = activeObject->GetMg(); = + (900.0 * cameraMatrix.sqmat.v3);


The viewport windows are redrawn if something in the active document changed:

  • EventAdd(): Informs Cinema 4D that something in the active document changed. DrawViews() will be called.
  • DrawViews(): Manually triggers the scene execution and a viewport redraw. Typically only used directly in ToolData based tools.

See also Core Messages Manual and Cinema 4D Threads Manual.


The parameters of a given BaseDraw are accessed as usual with C4DAtom::GetParameter() and C4DAtom::SetParameter(). The parameter IDs are defined in dbasedraw.h

// This example enables the display of polygon normals.
// scale normal size
const Float newScale = oldScale * 2.0;
// This example changes the projection type and display mode.
const DescID projectionID = DescLevel(BASEDRAW_DATA_PROJECTION);
const Int32 projectionType = BASEDRAW_PROJECTION_FRONT;
baseDraw->SetParameter(projectionID, projectionType, DESCFLAGS_SET::NONE);
baseDraw->SetParameter(displayID, displayType, DESCFLAGS_SET::NONE);

A BaseDraw defines also certain display filters that decide what element types are displayed in the viewport windows.

To edit the filter settings use the parameters defined in dbasedraw.h
// This example checks if the given BaseObject is visible in the active editor view.
BaseDraw* const bd = doc->GetActiveBaseDraw();
if (!bd)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
const DISPLAYFILTER filter = bd->GetDisplayFilter();
const Bool displayFilter = CheckDisplayFilter(object, filter);
// check editor visibility
const Bool editorVisibiliy = CheckEditorVisibility(object);
// check if the object is visible in the viewport
if (displayFilter && editorVisibiliy)
ApplicationOutput("The object is visible in the Editor"_s);
ApplicationOutput("The object is not visible in the Editor"_s);
// This example switches the filter setting
// of the SDS filter.
const DISPLAYFILTER filter = baseDraw->GetDisplayFilter();
// switch filter for SDS


A viewport window with planar projection can be rotated:

// This example restores the rotation of all editor windows.
const Int32 count = doc->GetBaseDrawCount();
for (Int32 i = 0; i < count; ++i)
BaseDraw* const baseDraw = doc->GetBaseDraw(i);
if (baseDraw == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);


A viewport window with a perspective projection displays the scene from the point of view of a camera. This camera is defined using an object. This can be a scene camera, a scene object or the editor camera.

See also CameraObject Manual.

// This example accesses or sets the scene camera.
// get the BaseDraw
BaseDraw* const bd = doc->GetActiveBaseDraw();
if (bd == nullptr)
return maxon::OK;
// check if a scene camera is used
if (bd->HasCameraLink())
// get scene camera and print the name
BaseObject* const cam = bd->GetSceneCamera(doc);
if (cam)
ApplicationOutput("Camera Object: " + cam->GetName());
// create a new camera object
if (camera == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
doc->InsertObject(camera, nullptr, nullptr);
// use this camera as the scene camera

Scene Elements

The viewport also displays a background and some global light settings. Both the background and the global seetings are defines using scene elements.

// This example accesses the sky object and
// environment object from the given BaseDraw.
BaseObject* const envObject = baseDraw->GetEnvironmentObject();
if (envObject)
GeData data;
const Vector color = data.GetVector();
ApplicationOutput("Environment Color: " + String::VectorToString(color));
// check the used sky object
BaseObject* const skyObject = baseDraw->GetSkyObject();
if (skyObject)
BaseTag* const tag = skyObject->GetTag(Ttexture);
if (tag)
GeData data;
C4DAtom* const atom = data.GetLinkAtom(doc);
BaseList2D* const material = static_cast<BaseList2D*>(atom);
if (material)
ApplicationOutput("Material on Sky: " + material->GetName());

GPU Renderer

The GPU renderer of Cinema 4D can render inside a given BaseDraw window.

// This example checks if the given BaseDraw is marked as
// a GPU render view and is currently using the GPU renderer.
if (baseDraw->IsMarkedAsGPURenderer())
if (baseDraw->IsGPURenderer())
ApplicationOutput("BaseDraw is rendering using the GPU renderer.");


Inside a "Draw" function one can use the following functions to draw into the viewport windows. See Draw Manual.

It is not allowed to draw in any other context.

While drawing one should check if the drawing thread has been aborted:

// This example tests if the current drawing operation should be aborted.
return false;
// check if all pointers are valid
if (!node || !doc || !bd || !bh)
// check if the drawing operation should be aborted
if (bd->TestBreak())
return true;

Drawing Pass

The viewport is drawn in several passes. One should check if the drawing operation is needed in the current pass. This is especially important for ObjectData::Draw().


Several parameters configure the drawing operations that follow.

The parameters are:

At the end of the drawing operation these parameters have to be restored.
// This example changes the line width, draws a line and resets the old value.
// store and set line width
const GeData oldLineWidth = bd->GetDrawParam(DRAW_PARAMETER_LINEWIDTH);
// draw lines
bd->SetPen(Vector(1.0, 0.0, 0.0));
bd->DrawLine(Vector(0, 0, 0), Vector(100, 100, 0), NOCLIP_D);
// reset parameter


The draw settings configure the drawing operations that follow.

The color used with BaseDraw::SetPen() may be obtained with GetViewColor(). See also Colors.
// This example draws some points with random color and size.
bd->SetMatrix_Matrix(nullptr, Matrix(), 6);
Random rnd;
for (Int32 i = 0; i < 100; ++i)
// set random color
const Float r = rnd.Get01();
const Float g = rnd.Get01();
const Float b = rnd.Get01();
const Vector color = Vector(r, g, b);
// set random size
const Float size = rnd.Get01() * 10.0;
// draw point with custom size
const Vector pos = Vector(i * 10.0, 0.0, 0.0);

The light list defines what lights should influence the shading on 3D drawing operations. Typically used to disable lights.

Transparency settings for polygon drawing are defined with:



A drawing operation may be performed in screen, camera or world space. Before any drawing operation the operation space must be defined.

// This example draws some points in various spaces.
// draw something in screen space
const Vector screenPos = Vector(100, 100.0, 0.0);
bd->DrawHandle(screenPos, DRAWHANDLE::BIG, 0);
// draw something in camera space
const Vector camPos = Vector(0.0); // center of non-perspective camera
bd->DrawHandle(camPos, DRAWHANDLE::BIG, 0);
// draw something in world space
const Vector worldPos = Vector(100.0, 100.0, 100.0);
bd->SetMatrix_Matrix(nullptr, Matrix());
bd->DrawHandle(worldPos, DRAWHANDLE::BIG, 0);

2D Drawing Operations

These functions perform drawing operations in 2D space:

To calculate screen space coordinates see Transformation.
// This example draws a 2D line, circle and point.
const Vector center = Vector(100, 100, 0);
const Vector tangentPoint = Vector(150, 100, 0);
// draw line and circle
bd->DrawLine2D(center, tangentPoint);
bd->DrawCircle2D((Int32)center.x, (Int32)center.y, tangentPoint.x - center.x);
// draw point

Text can easily be drawn with:

These functions are typically used with a scene hook.
// This example draws two text boxes in the viewport in a scene hook.
const DRAWPASS pass = bd->GetDrawPass();
// check if the current pass is the object pass with inverted highlight flag
HUDTextEntry entryA;
entryA._txt = "This is the first entry";
entryA._position = Vector(200, 220, 0);
hudEntries.Append(entryA) iferr_return;
HUDTextEntry entryB;
entryB._txt = "This is the second entry";
entryB._position = Vector(200, 260, 0);
hudEntries.Append(entryB) iferr_return;

General Drawing Operations

Depending on the current transformation matrix these operations can draw in 2D or 3D space.

The z-buffer is configured with:

These clipping flags used with 3D drawing operations:

  • NOCLIP_D: Clip against the viewport window.
  • NOCLIP_Z: Clip against near and far plane.

The drawing operations are:

// This example fills a GeClipMap.
// The internal BaseBitmap is used to draw the content to the screen.
if (clipMap)
clipMap->Init(100, 50, 32);
// fill background
clipMap->SetColor(255, 0, 0, 64);
clipMap->FillRect(0, 0, 100, 50);
// draw text
clipMap->SetColor(0, 0, 0, 255);
clipMap->TextAt(0, 11, "Hello World");
const BaseBitmap* const bitmap = clipMap->GetBitmap();
if (bitmap)
// draw texture in screen space
bd->DrawTexture(bitmap, positions.GetFirst(), colors.GetFirst(), normals.GetFirst(), uvcoords.GetFirst(), 4, alpha, texture);

Each BaseDraw::DrawPolygon() puts the polygon into an internal array. The drawing of this array can be triggered with:

A simple shading value is often used with BaseDraw::DrawPoly() and BaseDraw::DrawPolygon():

// This example shades four vertices and uses the
// calculated colors with BaseDraw::DrawPolygon().
// base color
const Vector color(1.0, 0.0, 0.0);
// calculate shades
colors[0] = color * bd->SimpleShade(vertice[0], normals[0]);
colors[1] = color * bd->SimpleShade(vertice[1], normals[1]);
colors[2] = color * bd->SimpleShade(vertice[2], normals[2]);
colors[3] = color * bd->SimpleShade(vertice[3], normals[3]);
// draw in object space
const Matrix& mg = bh->GetMg();
bd->SetMatrix_Matrix(op, mg);
// no additional shading
// set transparency
// draw polygon
bd->DrawPolygon(vertice, colors, true);


Complete polygon objects can be drawn with:

// This example re-draws the currently active polygon object in a ObjectData::Draw() function.
BaseDocument* const doc = bd->GetDocument();
// check if the current pass is the object pass
if (doc && drawpass == DRAWPASS::OBJECT)
// get the active object
BaseObject* const activeObject = doc->GetActiveObject();
// check if the active object is not the host object itself
// and if it is a polygon object
if (activeObject && activeObject != op && activeObject->IsInstanceOf(Opolygon))
// draw the object
bd->SetMatrix_Matrix(nullptr, Matrix());
bd->DrawObject(bh, activeObject, DRAWOBJECT::NONE, drawpass, nullptr);

Line Strip

The line strip functions allow to easily draw line paths:

// This example draws a random path composed of several lines.
Random randomGen;
// start position
Vector pos(0);
// init
const GeData oldLineWidth = bd->GetDrawParam(DRAW_PARAMETER_LINEWIDTH);
bd->SetMatrix_Matrix(nullptr, Matrix());
// draw random lines
for (Int32 i = 0; i < 100; ++i)
// get random color
const Float r = randomGen.Get01();
const Float g = randomGen.Get01();
const Float b = randomGen.Get01();
const Vector color = Vector(r, g, b);
bd->LineStrip(pos, color, NOCLIP_Z);
// apply random offset
const Float x = randomGen.Get01() * 100;
const Float y = randomGen.Get01() * 100;
const Float z = randomGen.Get01() * 100;
pos += Vector(x, y, z);
// reset parameter

XOR Lines

XOR lines are used with selection tools in the viewport. Typically one should use the LassoSelection class instead.

See also EditorWindow::DrawXORLine().

// This example draws a XOR line in ToolData::MouseInput().
// check if the view can be initialized
bd->DrawXORPolyLine(point, 2);
const DRAWFLAGS flags =
DrawViews(flags, bd);
win->DrawXORLine((Int32)point[0], (Int32)point[1], (Int32)point[2], (Int32)point[3]);


Colors can be obtained and converted with:

// This example gets the object color for the object itself in ObjectData::Draw().
// This color is then used to draw a circle.
const Vector color = bd->GetObjectColor(bh, op);
bd->SetMatrix_Matrix(nullptr, Matrix());
Matrix circleSettings = bh->GetMg();
circleSettings.sqmat.v1 *= 200.0;
circleSettings.sqmat.v2 *= 200.0;
circleSettings.sqmat.v3 *= 200.0;


The dimensions of a viewport window are accessed with:

// This example prints the frame size of the given BaseDraw.
// PrintFrameSize() is a custom utility function.
Int32 cl, ct, cr, cb;
// frame size
baseDraw->GetFrame(&cl, &ct, &cr, &cb);
PrintFrameSize(cl, ct, cr, cb);
// safe frame
baseDraw->GetSafeFrame(&cl, &ct, &cr, &cb);
PrintFrameSize(cl, ct, cr, cb);


These functions get and change the stereo settings for the given viewport window:


A viewport window can display the scene using orthogonal or perspective projection:


The following functions allow to transform a given point between world, screen and camera space:

// This example draws a circle around the position of the active object.
const BaseObject* const object = doc->GetActiveObject();
if (object)
const Vector worldSpacePos = object->GetMg().off;
const Vector screenSpacePos = bd->WS(worldSpacePos);
bd->DrawCircle2D((Int32)screenSpacePos.x, (Int32)screenSpacePos.y, 100);
// This example picks an object in the viewport within a ToolData:MouseInput() function.
// The distance of the picked object is obtained from the C4DObjectList and used
// with BaseView::SW() to get the world space position.
const Int32 xpos = (Int32)x;
const Int32 ypos = (Int32)y;
const Bool res = ViewportSelect::PickObject(bd, doc, xpos, ypos, 1,
VIEWPORT_PICK_FLAGS::NONE, nullptr, list, &m);
if (res && (list->GetCount() > 0))
const Float distance = list->GetZ(0);
const Vector worldSpacePos = bd->SW(Vector(x, y, distance));
ApplicationOutput("World Space Hit Point: " + String::VectorToString(worldSpacePos));

Also sizes can be transformed:

  • BaseView::PW_S(): Returns the size in world units for a single pixel at the given Z-depth.
  • BaseView::WP_S(): Returns the size in pixels for a single world unit at the given Z-depth.
  • BaseView::PW_W(): Returns the size in world units for a single pixel at the given screen space position.
  • BaseView::WP_W(): Returns the size in screen space pixels for a single world unit at world position.

These 3D projection functions are typically used to handle mouse input in tools:

// This example moves an object on the base plane in a ToolData::MouseInput() function.
Int32 err = 0;
const Vector pos = bd->ProjectPointOnPlane(Vector(0), Vector(0, 1, 0), positionX, positionY, &err);
if (err == 0)
// place object
Matrix mg = object->GetMg(); = pos;
// update managers and viewport

Testing and Clipping

The following tests can be performed:

// This example draws a 2D circle for each point of the given polygon object.
// The object is only handled if its bounding box is visible in the viewport.
// A circle is only drawn if the point is inside the viewport window.
// get polygon object properties
const Matrix mg = polyObject->GetMg();
const Vector bbox = polyObject->GetMp();
const Vector rad = polyObject->GetRad();
// test if the poly object is visible at all
if (bd->TestClipping3D(bbox, rad, mg, nullptr, nullptr))
// set pen color
Vector color(0.6, 0.6, 0.6);
color = bd->CheckColor(color);
// points
const Vector* const points = polyObject->GetPointR();
const Int32 pointCount = polyObject->GetPointCount();
// get each point
for (Int32 i = 0; i < pointCount; ++i)
const Vector point = mg * points[i];
const Vector screenSpacePos = bd->WS(point);
// check each point
if (bd->TestPoint(screenSpacePos.x, screenSpacePos.y))
// draw circle for each point
bd->DrawCircle2D(SAFEINT32(screenSpacePos.x), SAFEINT32(screenSpacePos.y), 10.0f);

A given line define by two points can be clipped:

A view can use near- and far-clipping:


A BaseDraw has its own undo buffer that stores changes:

// This example restores the rotation of all editor windows.
const Int32 count = doc->GetBaseDrawCount();
for (Int32 i = 0; i < count; ++i)
BaseDraw* const baseDraw = doc->GetBaseDraw(i);
if (baseDraw == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);


Further functions are:

// This example accesses the OpenGl statistics of the given BaseDraw
// and prints them to the console window.
// get draw statistics
if (!baseDraw->GetDrawStatistics(stats))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
String text("Statistics: \n");


BaseDrawHelp is a utility class that contains useful information. It is mostly used in the context of ObjectData::Draw(). An instance is typically handed over as an argument but can also be created on demand:

The BaseDrawHelp object provides access to these properties:

Information on the BaseObject that is supposed to be drawn:

A BaseObject may be drawn with a specific display mode as defined in Tdisplay.h.

// This example draws a given polygon object using a BaseDrawHelp in ObjectData::Draw().
// allocate BaseDrawHelp
if (!bhelp)
// get the current display options
BaseContainer displayOptions = bh->GetDisplay();
// set mode to "Wire"
// set display options
// get Matrix from original BaseDrawHelp object
const Matrix originalMatrix = bh->GetMg();
// draw an object
bd->DrawObject(bhelp, object, flags, DRAWPASS::OBJECT, nullptr, Vector(1.0, 0, 0));
// free BaseDrawHelp

Further Reading