Colored objects with BaseDraw/DrawPolygonObject
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/06/2011 at 08:52, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R12
Platform: Windows ;
Language(s) : C++ ;---------
How can I make objects drawn with DrawPolygonObject colored?I tried the DRAWOBJECT flag DRAWOBJECT_USE_CUSTOM_COLOR as well as DRAWOBJECT_USE_OBJECT_COLOR with and without the RegisterObjectPlugin flag OBJECT_USECACHECOLOR to no avail.
DrawPolygonObject() has a parameter for the object color but it shows no effect.
And also a BaseContainer with the Settings ID_BASEOBJECT_USECOLOR_ALWAYS and ID_BASEOBJECT_COLOR don't work.
What do I miss?
Here is some sample code I tried:
///////////////////////////////////////////////////////////// // CINEMA 4D BaseDrawTest // ///////////////////////////////////////////////////////////// #include "c4d.h" #include "c4d_symbols.h" #include "obasedrawtest.h" #if API_VERSION < 12000 #define EXECUTIONRESULT LONG #define EXECUTIONFLAGS LONG #define EXECUTIONRESULT_OK EXECUTION_RESULT_OK #define DRAWRESULT Bool #define DRAWPASS LONG #define DRAWRESULT_OK TRUE #endif ///////////////////////////////////////////////////////// // Class functions ///////////////////////////////////////////////////////// class BaseDrawTest : public ObjectData { INSTANCEOF(BaseDrawTest, ObjectData) public: virtual EXECUTIONRESULT Execute(BaseObject* op, BaseDocument* doc, BaseThread* bt, LONG priority, EXECUTIONFLAGS flags); virtual DRAWRESULT Draw(BaseObject* op, DRAWPASS drawpass, BaseDraw* bd, BaseDrawHelp* bh); static NodeData *Alloc(void) { return gNew BaseDrawTest; } }; EXECUTIONRESULT BaseDrawTest::Execute(BaseObject* op, BaseDocument* doc, BaseThread* bt, LONG priority, EXECUTIONFLAGS flags) { return EXECUTIONRESULT_OK; } DRAWRESULT BaseDrawTest::Draw(BaseObject *op, DRAWPASS drawpass, BaseDraw *bd, BaseDrawHelp *bh) { if (drawpass==DRAWPASS_OBJECT) { Vector red = Vector(1.0, 0.0, 0.0); Vector green = Vector(0.0, 1.0, 0.0); Vector blue = Vector(0.0, 0.0, 1.0); { Vector vp[4]; vp[0] = Vector(-100.0, -100.0, 0.0); vp[1] = Vector(-100.0, 100.0, 0.0); vp[2] = Vector(100.0, 100.0, 0.0); vp[3] = Vector(100.0, -100.0, 0.0); Vector vf[4]; vf[0] = red; vf[1] = red; vf[2] = red; vf[3] = red; bd->SetTransparency(128); bd->DrawPoly(vp, vf, NULL, 4, NULL); } { BaseContainer bc_pplane; bc_pplane.SetLong(ID_BASEOBJECT_USECOLOR, ID_BASEOBJECT_USECOLOR_ALWAYS); bc_pplane.SetVector(ID_BASEOBJECT_COLOR, red); bc_pplane.SetReal(PRIM_POLY_WIDTH, 200.0); bc_pplane.SetReal(PRIM_POLY_HEIGHT, 200.0); bc_pplane.SetLong(PRIM_POLY_SUB, 1); bc_pplane.SetBool(PRIM_POLY_TRIANG, FALSE); PolygonObject* pplane = (PolygonObject* )GeneratePrimitive(bh->GetDocument(), Osinglepoly, bc_pplane, 1.0, FALSE, NULL); if (pplane) bd->DrawPolygonObject(bh, pplane, DRAWOBJECT_XRAY_ON, op, green); } { BaseContainer bc_cube; bc_cube.SetLong(ID_BASEOBJECT_USECOLOR, ID_BASEOBJECT_USECOLOR_ALWAYS); bc_cube.SetVector(ID_BASEOBJECT_COLOR, green); bc_cube.SetVector(PRIM_CUBE_LEN, Vector(100.0, 200.0, 100.0)); PolygonObject* cube = (PolygonObject* )GeneratePrimitive(bh->GetDocument(), Ocube, bc_cube, 1.0, FALSE, NULL); if(cube) bd->DrawPolygonObject(bh, cube, DRAWOBJECT_USE_CUSTOM_COLOR|DRAWOBJECT_XRAY_ON, op, blue); } } return DRAWRESULT_OK; } ///////////////////////////////////////////////////////// // Register function ///////////////////////////////////////////////////////// Bool RegisterBaseDrawTest(void) { // decide by name if the plugin shall be registered - just for user convenience String name = GeLoadString(IDS_BASEDRAWTEST); if (!name.Content()) return TRUE; #if API_VERSION < 12000 return RegisterObjectPlugin(ID_BASEDRAWTEST,name,OBJECT_USECACHECOLOR,BaseDrawTest::Alloc,"Obasedrawtest","icon.tif",0); #else return RegisterObjectPlugin(ID_BASEDRAWTEST,name,OBJECT_USECACHECOLOR,BaseDrawTest::Alloc,"Obasedrawtest",AutoBitmap("icon.tif"),0); #endif }
My goal is a transparent but colored object drawn into the view.
The first approach with DrawPoly works and create a red and transparent plane but I couldn't manage it with DrawPolygonObject. Of course they become transparent with the xray setting but I couldn't make them colored!
By the way, I know that some of the color definitions above are inconsistent. This was with intent to see if one of the methods work and if yes to know which one.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/06/2011 at 14:26, xxxxxxxx wrote:
Note that this actually sets the color properties of the drawn object, not the color of the draw. Shouldn't matter. I've used it to great effect in InterPoser Pro for my Tool support.
ObjectColorProperties ocp; ocp.usecolor = ID_BASEOBJECT_USECOLOR_ALWAYS; ocp.xray = FALSE; ocp.color = Vector(0.0,1.0,0.0); //green obj->SetColorProperties(&ocp);
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/06/2011 at 15:47, xxxxxxxx wrote:
Hi Robert,
thank you for the tip,
but unfortunately I have no idea how to use ObjectColorProperties in conjunction with BaseDraw.Maybe you can show it to me on the basis of my code example above?
Kind regrads,
Tom -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/06/2011 at 17:11, xxxxxxxx wrote:
Just add that code for each object using DrawPolygonObject() (before calling DrawPolygonObject()). ObjectColorProperties and SetColorProperties() are independent of BaseDraw:
{ BaseContainer bc_pplane; bc_pplane.SetLong(ID_BASEOBJECT_USECOLOR, ID_BASEOBJECT_USECOLOR_ALWAYS); bc_pplane.SetVector(ID_BASEOBJECT_COLOR, red); bc_pplane.SetReal(PRIM_POLY_WIDTH, 200.0); bc_pplane.SetReal(PRIM_POLY_HEIGHT, 200.0); bc_pplane.SetLong(PRIM_POLY_SUB, 1); bc_pplane.SetBool(PRIM_POLY_TRIANG, FALSE); PolygonObject* pplane = (PolygonObject* )GeneratePrimitive(bh->GetDocument(), Osinglepoly, bc_pplane, 1.0, FALSE, NULL); ObjectColorProperties ocp; ocp.usecolor = ID_BASEOBJECT_USECOLOR_ALWAYS; ocp.xray = TRUE; ocp.color = Vector(0.0,1.0,0.0); //green pplane->SetColorProperties(&ocp); if (pplane) bd->DrawPolygonObject(bh, pplane, DRAWOBJECT_XRAY_ON, op, green); } { BaseContainer bc_cube; bc_cube.SetLong(ID_BASEOBJECT_USECOLOR, ID_BASEOBJECT_USECOLOR_ALWAYS); bc_cube.SetVector(ID_BASEOBJECT_COLOR, green); bc_cube.SetVector(PRIM_CUBE_LEN, Vector(100.0, 200.0, 100.0)); PolygonObject* cube = (PolygonObject* )GeneratePrimitive(bh->GetDocument(), Ocube, bc_cube, 1.0, FALSE, NULL); ObjectColorProperties ocp; ocp.usecolor = ID_BASEOBJECT_USECOLOR_ALWAYS; ocp.xray = TRUE; ocp.color = Vector(0.0,0.0,1.0); //blue cube->SetColorProperties(&ocp); if(cube) bd->DrawPolygonObject(bh, cube, DRAWOBJECT_USE_CUSTOM_COLOR|DRAWOBJECT_XRAY_ON, op, blue); }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/06/2011 at 02:23, xxxxxxxx wrote:
Ah okay, simple and straightforward.
Thanks a lot, that was easier than I thought!