About
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.
- Warning
- It is only allowed to draw into the viewport inside a "Draw" function. See Draw Manual.
Access
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.
if (baseDraw == nullptr)
Matrix targetPosition = activeObject->GetMg();
targetPosition.
off = cameraMatrix.
off + (900.0 * cameraMatrix.
sqmat.v3);
activeObject->SetMg(targetPosition);
Definition: c4d_basedraw.h:755
BaseObject * GetEditorCamera()
Definition: c4d_basedraw.h:864
Definition: c4d_baseobject.h:248
Matrix GetMg() const
Definition: c4d_baseobject.h:510
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
const char * doc
Definition: pyerrors.h:226
V off
The translation vector.
Definition: matrix.h:263
SqrMat3< V > sqmat
The 3×3 matrix for rotation, scale and shear.
Definition: matrix.h:266
Update
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.
Properties
The parameters of a given BaseDraw are accessed as usual with C4DAtom::GetParameter() and C4DAtom::SetParameter(). The parameter IDs are defined in dbasedraw.h
const Float newScale = oldScale * 2.0;
GeData GetParameterData(Int32 id)
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
Float GetFloat() const
Definition: c4d_gedata.h:468
@ BASEDRAW_DATA_SELECTED_NORMALS
Definition: dbasedraw.h:44
@ BASEDRAW_DATA_SHOWNORMALS
Definition: dbasedraw.h:30
@ BASEDRAW_DATA_NORMALS_SCALE
Definition: dbasedraw.h:69
maxon::Float Float
Definition: ge_sys_math.h:62
#define ConstDescID(...)
Definition: lib_description.h:594
Represents a level within a DescID.
Definition: lib_description.h:298
Definition: lib_description.h:355
@ BASEDRAW_PROJECTION_FRONT
Definition: dbasedraw.h:250
@ BASEDRAW_DATA_SDISPLAYACTIVE
Definition: dbasedraw.h:26
@ BASEDRAW_SDISPLAY_HIDDENLINE
Definition: dbasedraw.h:234
@ BASEDRAW_DATA_PROJECTION
Definition: dbasedraw.h:40
maxon::Int32 Int32
Definition: ge_sys_math.h:56
A BaseDraw defines also certain display filters that decide what element types are displayed in the viewport windows.
- Note
- To edit the filter settings use the parameters defined in
dbasedraw.h
if (bd == nullptr)
if (displayFilter && editorVisibiliy)
{
}
else
{
}
Bool CheckDisplayFilter(BaseObject *op, DISPLAYFILTER filter)
Bool CheckEditorVisibility(BaseObject *op)
DISPLAYFILTER GetDisplayFilter() const
Definition: c4d_basedraw.h:1598
maxon::Bool Bool
Definition: ge_sys_math.h:51
DISPLAYFILTER
Definition: ge_prepass.h:4551
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:204
else
@ BASEDRAW_DISPLAYFILTER_HYPERNURBS
Definition: dbasedraw.h:192
@ HYPERNURBS
Subdivision Surface.
Rotation
A viewport window with planar projection can be rotated:
{
if (baseDraw == nullptr)
}
Py_ssize_t i
Definition: abstract.h:645
Py_ssize_t count
Definition: abstract.h:640
void InitUndo(BaseDocument *doc)
Definition: c4d_basedraw.h:1488
void SetPlanarRotation(Float r)
Definition: c4d_basedraw.h:336
Camera
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.
if (bd == nullptr)
{
if (cam != nullptr)
}
else
{
if (camera == nullptr)
doc->InsertObject(camera,
nullptr,
nullptr);
}
void SetSceneCamera(BaseObject *op, Bool animate=false)
Definition: c4d_basedraw.h:832
const BaseObject * GetSceneCamera(const BaseDocument *doc)
Definition: c4d_basedraw.h:818
Bool HasCameraLink()
Definition: c4d_basedraw.h:811
String GetName() const
Definition: c4d_baselist.h:2544
static BaseObject * Alloc(Int32 type)
#define Ocamera
Camera - CameraObject.
Definition: ge_prepass.h:1046
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.
if (envObject)
{
}
if (skyObject)
{
if (tag)
{
if (material)
}
}
BaseObject * GetSkyObject() const
Definition: c4d_basedraw.h:846
BaseObject * GetEnvironmentObject() const
Definition: c4d_basedraw.h:839
Definition: c4d_baselist.h:2377
BaseTag * GetTag(Int32 type, Int32 nr=0)
Definition: c4d_baseobject.h:749
Definition: c4d_basetag.h:52
Definition: c4d_baselist.h:1521
Bool GetParameter(const DescID &id, GeData &t_data, DESCFLAGS_GET flags) const
Definition: c4d_gedata.h:83
const Vector & GetVector() const
Definition: c4d_gedata.h:486
const C4DAtomGoal * GetLinkAtom(const BaseDocument *doc, Int32 instanceof=0) const
static String VectorToString(const Vector32 &v, Int32 nnk=-1)
Definition: c4d_string.h:573
#define atom
Definition: graminit.h:72
#define Ttexture
Texture - TextureTag.
Definition: ge_prepass.h:1412
@ ENVIRONMENT_AMBIENT
Definition: oenvironment.h:6
@ TEXTURETAG_MATERIAL
Definition: ttexture.h:29
GPU Renderer
The GPU renderer of Cinema 4D can render inside a given BaseDraw window.
- BaseDraw::IsMarkedAsGPURenderer(): Returns true if the BaseDraw is used as a GPU renderer view.
- BaseDraw::IsGPURenderer(): Returns true if the BaseDraw is running the GPU renderer.
Drawing
Inside a "Draw" function one can use the following functions to draw into the viewport windows. See Draw Manual.
- Warning
- It is not allowed to draw in any other context.
While drawing one should check if the drawing thread has been aborted:
{
{
err.DiagOutput();
err.DbgStop();
return false;
};
if (
node ==
nullptr ||
doc ==
nullptr || bd ==
nullptr || bh ==
nullptr)
return true;
PyCompilerFlags * flags
Definition: ast.h:14
Definition: c4d_basedocument.h:497
Definition: c4d_basedraw.h:40
Bool TestBreak()
Definition: c4d_basedraw.h:1731
Definition: c4d_basedocument.h:52
Definition: c4d_thread.h:29
SCENEHOOKDRAW
Definition: ge_prepass.h:3317
#define iferr_scope_handler
Definition: resultbase.h:1407
#define iferr_throw(ERR)
Definition: resultbase.h:1589
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().
Parameters
Several parameters configure the drawing operations that follow.
The parameters are:
- Note
- At the end of the drawing operation these parameters have to be restored.
void DrawLine(const Vector &p1, const Vector &p2, Int32 flags)
Definition: c4d_basedraw.h:1219
void SetDrawParam(Int32 id, const GeData &data)
Definition: c4d_basedraw.h:1507
GeData GetDrawParam(Int32 id) const
Definition: c4d_basedraw.h:1515
void SetPen(const Vector &col, Int32 flags=0)
Definition: c4d_basedraw.h:991
#define DRAW_PARAMETER_LINEWIDTH
Float Line width in pixels. (OpenGL only.)
Definition: c4d_basedraw.h:1520
#define NOCLIP_D
Clip against the view border.
Definition: c4d_basedraw.h:1140
Settings
The draw settings configure the drawing operations that follow.
- Note
- The color used with BaseDraw::SetPen() may be obtained with GetViewColor(). See also Colors.
{
}
void SetPointSize(Float pointsize)
Definition: c4d_basedraw.h:997
void SetMatrix_Matrix(BaseObject *op, const Matrix &mg)
Definition: c4d_basedraw.h:1111
void DrawHandle(const Vector &vp, DRAWHANDLE type, Int32 flags)
Definition: c4d_basedraw.h:1192
Definition: c4d_tools.h:835
MAXON_ATTRIBUTE_FORCE_INLINE Float Get01()
Definition: c4d_tools.h:865
Py_ssize_t size
Definition: bytesobject.h:86
void Py_ssize_t * pos
Definition: dictobject.h:50
maxon::Mat3< maxon::Vector64 > Matrix
Definition: ge_math.h:163
const char const char grammar * g
Definition: parsetok.h:52
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:
See also DRAW_PARAMETER_ALPHA_THRESHOLD above.
Matrix
A drawing operation may be performed in screen, camera or world space. Before any drawing operation the operation space must be defined.
const Vector screenPos { 100, 100.0, 0.0 };
const Vector worldPos { 100.0, 100.0, 100.0 };
void SetMatrix_Camera()
Definition: c4d_basedraw.h:1099
void SetMatrix_Screen()
Definition: c4d_basedraw.h:1077
@ BIG
Handle used by object generators and deformers.
2D Drawing Operations
These functions perform drawing operations in 2D space:
- Note
- To calculate screen space coordinates see Transformation.
const Vector center { 100, 100, 0 };
const Vector tangentPoint { 150, 100, 0 };
void DrawPoint2D(const Vector &p)
Definition: c4d_basedraw.h:1154
void DrawCircle2D(Int32 mx, Int32 my, Float rad)
Definition: c4d_basedraw.h:1179
void DrawLine2D(const Vector &p1, const Vector &p2)
Definition: c4d_basedraw.h:1162
maxon::Vec3< maxon::Float64, 1 > Vector
Definition: ge_math.h:141
Text can easily be drawn with:
- Note
- These functions are typically used with a scene hook.
{
entryA.
_txt =
"This is the first entry";
entryB.
_txt =
"This is the second entry";
}
void SetTransparency(Int32 trans)
Definition: c4d_basedraw.h:972
DRAWPASS GetDrawPass() const
Definition: c4d_basedraw.h:1623
void DrawMultipleHUDText(const maxon::BaseArray< HUDTextEntry > &texts)
Definition: c4d_basedraw.h:1774
Class structure to hold HUD Text for BaseDraw::DrawMultipleHudText.
Definition: c4d_basedraw.h:247
Vector _position
The screen space position for the text.
Definition: c4d_basedraw.h:252
String _txt
The text to draw to the HUD.
Definition: c4d_basedraw.h:251
Definition: basearray.h:415
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append(ARG &&x)
Appends a new element at the end of the array and constructs it using the forwarded value.
Definition: basearray.h:628
DRAWPASS
Definition: ge_prepass.h:3514
@ HIGHLIGHT_PASS_INV
Inverted highlight pass.
#define iferr_return
Definition: resultbase.h:1524
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:
if (clipMap)
{
clipMap->Init(100, 50, 32);
clipMap->BeginDraw();
clipMap->SetColor(255, 0, 0, 64);
clipMap->FillRect(0, 0, 100, 50);
clipMap->SetColor(0, 0, 0, 255);
clipMap->TextAt(0, 11, "Hello World");
clipMap->EndDraw();
const BaseBitmap*
const bitmap = clipMap->GetBitmap();
if (bitmap)
{
bd->
DrawTexture(bitmap, positions.GetFirst(), colors.GetFirst(), normals.GetFirst(), uvcoords.GetFirst(), 4, alpha, texture);
}
}
Definition: ge_autoptr.h:37
Definition: c4d_basebitmap.h:441
void DrawTexture(const BaseBitmap *bmp, const Vector *padr4, const Vector *cadr, const Vector *vnadr, const Vector *uvadr, Int32 pntcnt, DRAW_ALPHA alphamode, DRAW_TEXTUREFLAGS flags)
Definition: c4d_basedraw.h:1257
DRAW_ALPHA
Definition: ge_prepass.h:2975
@ FROM_IMAGE
Generates the alpha channel from the RGB image information.
DRAW_TEXTUREFLAGS
Definition: ge_prepass.h:2988
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():
const Vector color { 1.0, 0.0, 0.0 };
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]);
const Matrix & GetMg()
Definition: c4d_basedraw.h:85
void SetLightList(Int32 mode)
Definition: c4d_basedraw.h:1011
Float SimpleShade(const Vector &p, const Vector &n)
Definition: c4d_basedraw.h:1725
void DrawPolygon(const Vector *p, const Vector *f, Bool quad)
Definition: c4d_basedraw.h:1302
#define BDRAW_SETLIGHTLIST_NOLIGHTS
No lights.
Definition: c4d_basedraw.h:1015
PyObject * op
Definition: object.h:520
Objects
Complete polygon objects can be drawn with:
const Bool docSet =
doc !=
nullptr;
if (docSet && isObjectPass)
{
const Bool activeObjectSet = activeObject !=
nullptr;
const Bool activeObjectIsNotOp = activeObject !=
op;
if (activeObjectSet && activeObjectIsNotOp)
{
{
}
}
}
DRAWRESULT DrawObject(BaseDrawHelp *bh, BaseObject *op, DRAWOBJECT flags, DRAWPASS drawpass, BaseObject *parent=nullptr, const Vector &col=Vector(.5))
Definition: c4d_basedraw.h:1349
Bool IsInstanceOf(Int32 id) const
Definition: c4d_baselist.h:1562
const BaseDocument * GetDocument() const
Definition: c4d_baselist.h:2140
#define Opolygon
Polygon - PolygonObject.
Definition: ge_prepass.h:1042
Line Strip
The line strip functions allow to easily draw line paths:
{
}
void LineStripBegin()
Definition: c4d_basedraw.h:1381
void LineStripEnd()
Finishes line strips started with LineStripBegin().
Definition: c4d_basedraw.h:1386
void LineStrip(const Vector &vp, const Vector &vc, Int32 flags)
Definition: c4d_basedraw.h:1395
PyObject * x
Definition: bytesobject.h:38
#define NOCLIP_Z
Z clipping.
Definition: c4d_basedraw.h:1141
XOR Lines
XOR lines are used with selection tools in the viewport. Typically one should use the LassoSelection class instead.
- Warning
- These functions have been marked as deprecated.
See also EditorWindow::DrawXORLine().
{
}
else
{
}
Bool DrawViews(DRAWFLAGS flags, BaseDraw *bd=nullptr)
Bool InitDrawXORPolyLine()
Definition: c4d_basedraw.h:1408
void DrawXORPolyLine(const Float32 *p, Int32 cnt)
Definition: c4d_basedraw.h:1445
void FreeDrawXORPolyLine()
Definition: c4d_basedraw.h:1415
void BeginDrawXORPolyLine()
Definition: c4d_basedraw.h:1452
void EndDrawXORPolyLine(Bool blit)
Definition: c4d_basedraw.h:1460
DRAWFLAGS
Definition: ge_prepass.h:2818
@ NO_ANIMATION
Ignore all animation.
@ ONLY_ACTIVE_VIEW
Only redraw the active view.
@ NO_THREAD
Synchronous call.
Colors
Colors can be obtained and converted with:
circleSettings.
sqmat.v1 *= 200.0;
circleSettings.
sqmat.v2 *= 200.0;
circleSettings.
sqmat.v3 *= 200.0;
Vector GetObjectColor(const BaseDrawHelp *bh, const BaseObject *op, Bool lines=false, Bool usedInBaseDraw=true, Int instanceIndex=0) const
Definition: c4d_basedraw.h:958
void DrawCircle(const Matrix &m)
Definition: c4d_basedraw.h:1263
Frame
The dimensions of a viewport window are accessed with:
PrintFrameSize(cl, ct, cr, cb);
PrintFrameSize(cl, ct, cr, cb);
void GetSafeFrame(Int32 *cl, Int32 *ct, Int32 *cr, Int32 *cb)
void GetFrame(Int32 *cl, Int32 *ct, Int32 *cr, Int32 *cb)
Stereo
These functions get and change the stereo settings for the given viewport window:
Projection
A viewport window can display the scene using orthogonal or perspective projection:
Transformation
The following functions allow to transform a given point between world, screen and camera space:
if (object)
{
const Vector worldSpacePos =
object->GetMg().off;
const Vector screenSpacePos = bd->
WS(worldSpacePos);
}
Vector WS(const Vector &p) const
Definition: c4d_basedraw.h:410
{
}
const char * m
Definition: abstract.h:692
Vector SW(const Vector &p) const
Definition: c4d_basedraw.h:418
static Bool PickObject(BaseDraw *bd, BaseDocument *doc, Int32 x, Int32 y, Int32 rad, VIEWPORT_PICK_FLAGS flags, LassoSelection *ls, C4DObjectList *list, maxon::SquareMatrix4d *m=nullptr, Int32 *sampleLocation=nullptr)
Py_UCS4 * res
Definition: unicodeobject.h:1113
PyWideStringList * list
Definition: initconfig.h:447
Definition: matrix4d.h:13
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:
if (err == 0)
{
object->SetMg(mg);
}
Bool GeSyncMessage(Int32 messageid, Int32 destid=0, UInt p1=0, UInt p2=0)
Vector ProjectPointOnPlane(const Vector &p, const Vector &v, Float mouse_x, Float mouse_y, Int32 *err=nullptr)
#define EVMSG_ASYNCEDITORMOVE
The user moved something in the editor window. Managers should update things like position fields.
Definition: ge_prepass.h:2779
Testing and Clipping
The following tests can be performed:
const Matrix mg = polyObject->GetMg();
const Vector bbox = polyObject->GetMp();
const Vector rad = polyObject->GetRad();
{
const Vector*
const points = polyObject->GetPointR();
const Int32 pointCount = polyObject->GetPointCount();
{
const Vector point = mg * points[
i];
const Vector screenSpacePos = bd->
WS(point);
{
}
}
}
Vector CheckColor(const Vector &col)
Definition: c4d_basedraw.h:965
Bool TestPoint(Float x, Float y) const
Definition: c4d_basedraw.h:349
Bool TestClipping3D(const Vector &mp, const Vector &rad, const Matrix &mg, Bool *clip2d, Bool *clipz) const
Int32 SAFEINT32(Float32 x)
Definition: apibasemath.h:275
A given line define by two points can be clipped:
A view can use near- and far-clipping:
Undo
A BaseDraw has its own undo buffer that stores changes:
{
if (baseDraw == nullptr)
}
Miscellaneous
Further functions are:
maxon::DataDictionary stats;
for (const auto& data : stats)
{
}
PyObject * value
Definition: abstract.h:715
PyObject * key
Definition: abstract.h:289
Bool GetDrawStatistics(maxon::DataDictionary &statistics) const
Definition: c4d_basedraw.h:1631
Definition: datatypebase.h:1229
Definition: datatypebase.h:770
PyObject ** type
Definition: pycore_pyerrors.h:34
BaseDrawHelp
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
.
if (bhelp == nullptr)
bhelp->
SetMg(originalMatrix);
Definition: c4d_basecontainer.h:48
void SetInt32(Int32 id, Int32 l)
Definition: c4d_basecontainer.h:587
static void Free(BaseDrawHelp *&p)
void SetDisplay(BaseContainer *bc)
Definition: c4d_basedraw.h:109
void SetMg(const Matrix &mg)
Definition: c4d_basedraw.h:97
BaseDocument * GetDocument()
Definition: c4d_basedraw.h:73
BaseContainer GetDisplay()
Definition: c4d_basedraw.h:103
static BaseDrawHelp * Alloc(BaseDraw *bd, BaseDocument *doc)
DRAWOBJECT
Definition: ge_prepass.h:4660
@ USE_CUSTOM_COLOR
Use a custom color.
@ XRAY_OFF
Disables X-Ray mode.
@ NO_EOGL
No Extended OpenGL.
@ FAILURE
There was an error while drawing.
@ DISPLAYTAG_SDISPLAYMODE
Definition: tdisplay.h:6
Further Reading