About
Many Cinema API plugin classes can implement a "Draw" function that allows to draw something in the editor viewport. These "Draw" functions differ from class to class.
Draw
A "Draw" function can be found in the following Cinema API base classes:
- ObjectData::Draw(): Is called for each object plugin instance.
- TagData::Draw(): Is called for each tag plugin instance.
- ToolData::Draw(): Is called for the tool plugin.
- SceneHookData::Draw(): Is called for the SceneHook plugin.
- MaterialData::Draw(): Is called for every object/tag pair that uses the material plugin instance.
- ShaderData::Draw(): Is called for each shader plugin instance.
- SnapData::Draw(): Is called for the snap mode plugin.
- Note
- To avoid drawing order problems the drawing operations of multiple objects or tags can be replaced by the use of the "Draw" function in a SceneHookData plugin.
Usage
A "Draw" function is typically called multiple times during the drawing process for different draw passes and for each open viewport window. The given BaseDraw object represents a viewport window and is used to draw in that window.
This is an example implementation of ObjectData::Draw():
{
if (drawpass != DRAWPASS_OBJECT)
return SUPER::Draw(
op, drawpass, bd, bh);
const Matrix& mg = bh->GetMg();
bd->SetMatrix_Matrix(
op, mg);
bd->SetPen(
Vector(1.0, 0.0, 0.0));
bd->SetPen(
Vector(00, 1.0, 0.0));
bd->SetPen(
Vector(0.0, 0.0, 1.0));
return SUPER::Draw(
op, drawpass, bd, bh);
}
#define DRAW_PARAMETER_LINEWIDTH
::Float Line width in pixels. (OpenGL only.)
Definition: c4d_basedraw.h:1519
DRAWPASS
Definition: ge_prepass.h:3542
DRAWRESULT
Definition: ge_prepass.h:4391
#define NOCLIP_D
Clip against the view border.
Definition: c4d_basedraw.h:1139
maxon::Mat3< maxon::Vector64 > Matrix
Definition: ge_math.h:159
maxon::Vec3< maxon::Float64, 1 > Vector
Definition: ge_math.h:140
PyObject * op
Definition: object.h:520
Typical tasks in a "Draw" function are:
- Check the current draw pass to avoid unnecessary operations.
- Check if the assigned layer of the object, tag or material disables viewport drawing.
- Set the reference coordinate system for the following drawing operations.
- Set the drawing parameters for the following drawing operations.
- Perform drawing operations.
- Reset the drawing parameters.
How to use a BaseDraw object is described in BaseView / BaseDraw Manual.
Examples
For objects that can be assigned to layers it might be necessary to check if the assigned layer forbids viewport drawing. See Layer Manual.
BaseDocument*
doc = bh->GetDocument();
const LayerData* ld =
op->GetLayerData(
doc);
if (ld && (!ld->view))
SKIP
Definition: asset_browser.h:0
const char * doc
Definition: pyerrors.h:226
If the drawing operations should only be applied to the currently selected viewport window it is needed to check if the given BaseDraw represents the selected viewport.
BaseDraw*
const activeBD =
doc->GetActiveBaseDraw();
const Bool isActiveBD = bd && (bd == activeBD);
if (!isActiveBD)
maxon::Bool Bool
Definition: ge_sys_math.h:46
It is also possible to enable or disable several viewport filters that define what should be visible in the viewport.
NONE
Definition: asset_browser.h:1
Further Reading