Draw Manual

内容表

关于

Many classic 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 classic base classes:

注意
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 插件。

用法

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() :

DRAWRESULT Draw( BaseObject * op, DRAWPASS drawpass, BaseDraw * bd, BaseDrawHelp * bh) { // only draw in the DRAWPASS_OBJECT if (drawpass != DRAWPASS_OBJECT) return SUPER::Draw(op, drawpass, bd, bh);

// set the matrix / space for the following drawing operations // in this case, use the object's matrix const 矩阵 & mg = bh-> GetMg (); bd-> SetMatrix_Matrix (op, mg);

// set line width const GeData oldValue = bd-> GetDrawParam ( DRAW_PARAMETER_LINEWIDTH ); bd-> SetDrawParam ( DRAW_PARAMETER_LINEWIDTH , GeData { 3.0 });

// draw lines bd-> SetPen ( 向量 (1.0, 0.0, 0.0)); bd-> DrawLine ( 向量 (-100, 0, 0), 向量 (100, 0, 0), NOCLIP_D );

bd-> SetPen ( 向量 (00, 1.0, 0.0)); bd-> DrawLine ( 向量 (0, 100, 0), 向量 (0, -100, 0), NOCLIP_D );
bd-> SetPen ( 向量 (0.0, 0.0, 1.0)); bd-> DrawLine ( 向量 (0, 0, 100), 向量 (0, 0, -100), NOCLIP_D );

// reset parameters bd-> SetDrawParam ( DRAW_PARAMETER_LINEWIDTH , oldValue); return SUPER::Draw(op, drawpass, bd, bh); }

Typical tasks in a "Draw" function are:

How to use a BaseDraw object is described in BaseView / BaseDraw Manual .

范例

For objects that can be assigned to layers it might be necessary to check if the assigned layer forbids viewport drawing. See Layer Manual .

// check if the assigned layer disables drawing BaseDocument * doc = bh-> GetDocument (); const LayerData * ld = op-> GetLayerData (doc);

// check if not visible in the editor if (ld && (!ld-> view )) return DRAWRESULT::SKIP ;

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.

// This example checks if the current BaseDraw is the active BaseDraw. BaseDraw * const activeBD = doc-> GetActiveBaseDraw (); const Bool isActiveBD = bd && (bd == activeBD); if (!isActiveBD) return DRAWRESULT::SKIP ;

It is also possible to enable or disable several viewport filters that define what should be visible in the viewport.

// This example checks if "Null" objects should be drawn in the viewport. // If not, the drawing is skipped.

// check display filter for "Null" objects if (!(bd->GetDisplayFilter() & DISPLAYFILTER::NONE )) return DRAWRESULT::SKIP ;

延伸阅读

DISPLAYFILTER::NONE
@ NONE
None.
BaseDraw::GetDrawParam
GeData GetDrawParam(Int32 id) const
定义: c4d_basedraw.h:1505
BaseDrawHelp
定义: c4d_basedraw.h:39
BaseObject
定义: c4d_baseobject.h:224
maxon::Mat3< maxon::Vector64 >
BaseDraw::SetDrawParam
void SetDrawParam(Int32 id, const GeData &data)
定义: c4d_basedraw.h:1497
BaseDocument::GetActiveBaseDraw
BaseDraw * GetActiveBaseDraw(void)
NOCLIP_D
#define NOCLIP_D
Clip against the view border.
定义: c4d_basedraw.h:1130
DRAWRESULT::SKIP
@ SKIP
There was nothing to draw in this pass.
BaseDraw
定义: c4d_basedraw.h:747
BaseDraw::SetPen
void SetPen(const Vector &col, Int32 flags=0)
定义: c4d_basedraw.h:981
LayerData::view
Bool view
Visible in editor view.
定义: c4d_basedocument.h:346
DRAWPASS
DRAWPASS
定义: ge_prepass.h:3258
LayerData
定义: c4d_basedocument.h:311
BaseDrawHelp::GetDocument
BaseDocument * GetDocument(void)
定义: c4d_basedraw.h:73
DRAWRESULT
DRAWRESULT
定义: ge_prepass.h:4097
BaseDraw::DrawLine
void DrawLine(const Vector &p1, const Vector &p2, Int32 flags)
定义: c4d_basedraw.h:1209
GeData
定义: c4d_gedata.h:82
DRAW_PARAMETER_LINEWIDTH
#define DRAW_PARAMETER_LINEWIDTH
Float Line width in pixels. (OpenGL only.)
定义: c4d_basedraw.h:1510
BaseDrawHelp::GetMg
const Matrix & GetMg(void)
定义: c4d_basedraw.h:85
BaseDraw::SetMatrix_Matrix
void SetMatrix_Matrix(BaseObject *op, const Matrix &mg)
定义: c4d_basedraw.h:1101
向量
maxon::Vec3< maxon::Float64, 1 > Vector
定义: ge_math.h:145
Bool
maxon::Bool Bool
定义: ge_sys_math.h:53
BaseDocument
定义: c4d_basedocument.h:490
BaseList2D::GetLayerData
const LayerData * GetLayerData(BaseDocument *doc, Bool rawdata=false)

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1