How to draw a primitive object in BaseDraw
-
Hi everyone!
I try to draw a primitive object like Plane, Cube, e.t.c withTooldata.Draw()
.
And in BaseDraw, i saw it have tow method to draw object:- BaseDraw.DrawPolygonObject()
- BaseDraw.DrawObject()
I've tried both methods in my code, but it's not working
def Draw(self, doc, data, bd, bh, bt, flags): bd.SetMatrix_Screen() obj = c4d.BaseObject(c4d.Ocube) bd.DrawPolygonObject(bh, obj, flags=c4d.DRAWOBJECT_NONE, parent=None, col=Vector(0.5)) bd.DrawObject(bh, obj, flags=c4d.DRAWOBJECT_NONE, drawpass=c4d.DRAWPASS_OBJECT, parent=None, col=Vector(0.5)) return c4d.TOOLDRAW_NONE
The explanation of both methods in the documentation is simple and straightforward.
And i'm not sure if I can't use these two methods in ToolData, or am I misunderstanding something? -
Hey @gheyret,
Thank you for reaching out to us. Your
obj
there has no cache. You just instantiated it, there is nothing to draw. We talked about cache building multiple times on the forum, for example here. In the geometry model section of our Python examples, I also went over caches and cache building in geometry_caches_s26.py.You should however be careful with the amount of work you do in
Draw
. Although the method is despite its name not actually a drawing method and would be more aptly named asGetDrawingInstructions
, you should still go for performance there. Building complex geometry there is not a good idea. Either build your inputs beforehand, or better, draw primitives like a cube yourself (constructed out of shaded polygons or lines).Cheers,
Ferdinand -