THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 08/09/2009 at 16:51, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 11
Platform: Windows ;
Language(s) : C++ ;
---------
I am wondering why none of my functions do what they are supposed to. The DoCOmmand Function is supposed to subdivide the currently active object, when the command button is clocked, and the draw() is supposed to draw a square polygon if the check box named SHOW_PLANE is checked. Yet nothing is doing what I expect it to.
Here is the code for my entire .cpp file. Does anyone see any reason why my code isn't doing anything?
> `
\> #include "c4d.h"
\> #include "c4d_symbols.h"
\> #include "lib_modeling.h"
\>
\> #include "c4d_descriptiondialog.h"
\> #include "sculpttool.h"
\>
\> #define ID_SCULPTTOOL 1024455
\>
\> extern Bool AddUndo(BaseDocument* doc, AtomArray* arr, LONG type);
\>
\> class SculptTool : public DescriptionToolData
\> {
\> DescriptionCommand* data;
\> LONG buttonPress;
\>
\>
\> public:
\> SculptTool();
\>
\> virtual LONG GetToolPluginId() { return ID_SCULPTTOOL; }
\> virtual const String GetResourceSymbol() { return String("SculptTool"); }
\>
\> virtual Bool MouseInput(BaseDocument *doc, BaseContainer &data;, BaseDraw *bd, EditorWindow *win, const BaseContainer &msg;);
\> virtual LONG GetState(BaseDocument *doc);
\>
\> virtual void InitDefaultSettings(BaseDocument *doc, BaseContainer &data;);
\> virtual Bool DoCommand(ModelingCommandData &mdat;);
\> virtual Bool GetCursorInfo(BaseDocument *doc, BaseContainer &data;, BaseDraw *bd, Real x, Real y, BaseContainer &bc;);
\>
\> virtual Bool GetDEnabling(BaseDocument *doc, BaseContainer &data;, const DescID &id;,GeData &t;_data,LONG flags,const BaseContainer *itemdesc);
\> virtual LONG Draw(BaseDocument *doc, BaseContainer &data;, BaseDraw *bd, BaseDrawHelp *bh, BaseThread *bt,LONG flags);
\> Bool Message(BaseDocument* doc, BaseContainer& data, LONG type, void* t_data);
\>
\> protected:
\> Bool isdragging;
\>
\> };
\>
\> SculptTool::SculptTool()
\> {
\>
\> isdragging = FALSE;
\> }
\>
\> Bool SculptTool::GetCursorInfo(BaseDocument *doc, BaseContainer &data;, BaseDraw *bd, Real x, Real y, BaseContainer &bc;)
\> {
\> if (bc.GetId()==BFM_CURSORINFO_REMOVE) return TRUE;
\> bc.SetString(RESULT_BUBBLEHELP, GeLoadString(IDS_HLP_SCULPTTOOL));
\> return TRUE;
\> }
\>
\>
\> ///////////////////////////////////////////////////////////////////////////////////////////////////
\> void SculptTool::InitDefaultSettings(BaseDocument *doc, BaseContainer &data;)
\> {
\> //This function sets the default perameters for the Sculpt Tool Options.
\> BaseObject *op=doc->GetActiveObject();
\> PolygonObject* objPoly;
\> objPoly=(PolygonObject* )op;
\>
\> Vector color;
\> color = (1,0,0);
\> GePrint("--------------------------------------------------------");
\> GePrint(" Sculpt Tool Successfully Loaded!");
\> GePrint("--------------------------------------------------------");
\>
\> DescriptionToolData::InitDefaultSettings(doc,data);
\> SetMousePointer (MOUSE_PAINTSELECTCIRCLE);
\> data.SetReal(BRUSH_RADIUS,100);
\> data.SetReal(SCULPT_STRENGTH,100);
\> data.SetLong(SCULPT_TYPE, TYPE_SCULPT);
\> data.SetLong(BRUSH_ORIENTATION, OR_NORMAL);
\> data.SetLong(MIRROR_PLANE, X_PLANE);
\> data.SetLong(NUM_SUBDIVISIONS, 1);
\> data.SetLong(HYPERNURBS_SUBDIVISION, TRUE);
\> data.SetReal(MAX_ANGLE,pi);
\> if (objPoly)
\> {
\> data.SetLong(POLYGON_COUNT, objPoly->GetPolygonCount());
\> }
\> else
\> {
\> GePrint ("No Objects in the Scene");
\> }
\>
\> }
\> ///////////////////////////////////////////////////////////////////////////////////////////////////
\>
\> Bool SculptTool::GetDEnabling(BaseDocument *doc, BaseContainer &data;, const DescID &id;,GeData &t;_data,LONG flags,const BaseContainer *itemdesc)
\> {
\>
\> // Enable/disable our parameters
\> Bool stampBox = data.GetBool(USE_STAMP);
\> Bool enableMirror = data.GetBool(ENABLE_MIRROR);
\> BaseObject* op = doc->GetActiveObject();
\> if (!op)
\> return false;
\>
\> switch (id[0].id)
\> { case ENABLE_MIRROR:
\>
\> if (op->IsInstanceOf(Opolygon))
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case NUM_SUBDIVISIONS:
\>
\> if (op->IsInstanceOf(Opolygon))
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case HYPERNURBS_SUBDIVISION:
\>
\> if (op->IsInstanceOf(Opolygon))
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case MAX_ANGLE:
\>
\> if (op->IsInstanceOf(Opolygon))
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case POLYGON_COUNT:
\>
\> if (op->IsInstanceOf(Opolygon))
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case SCULPT_TYPE:
\>
\> if (op->IsInstanceOf(Opolygon))
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case COMMAND_SUBDIVIDE:
\>
\> if (op->IsInstanceOf(Opolygon))
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case BRUSH_RADIUS:
\>
\> if (op->IsInstanceOf(Opolygon))
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case SCULPT_STRENGTH:
\>
\> if (op->IsInstanceOf(Opolygon))
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case TOOL_VARIATION:
\>
\> if (op->IsInstanceOf(Opolygon))
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case FALLOFF_CONTROL:
\>
\> if (op->IsInstanceOf(Opolygon))
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case USE_STAMP:
\>
\> if (op->IsInstanceOf(Opolygon))
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case STAMP_IMAGE:
\>
\> if (op->IsInstanceOf(Opolygon)&&stampBox;==TRUE)
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case BRUSH_ORIENTATION:
\>
\> if (op->IsInstanceOf(Opolygon))
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case MIRROR_PLANE:
\>
\> if (op->IsInstanceOf(Opolygon)&&enableMirror;==TRUE)
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case SHOW_PLANE:
\>
\> if (op->IsInstanceOf(Opolygon)&&enableMirror;==TRUE)
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\>
\> case PLANE_COLOR:
\>
\> if (op->IsInstanceOf(Opolygon)&&enableMirror;==TRUE)
\> { return TRUE;
\> }
\> else
\> { return FALSE;
\> }
\> }
\> return TRUE;
\>
\> }
\>
\> LONG SculptTool::GetState(BaseDocument *doc)
\> {
\> return CMD_ENABLED;
\> }
\>
\>
\> Bool SculptTool::Message(BaseDocument* doc, BaseContainer& data, LONG type, void* t_data)
\> {
\>
\> switch (type)
\> {
\> case MSG_DESCRIPTION_COMMAND:
\> {
\> DescriptionCommand *dc = (DescriptionCommand* ) t_data;
\> if (dc->id[0].id==COMMAND_SUBDIVIDE)
\> {
\> GePrint("Subdivide Button Clicked");
\>
\>
\> ModelingCommandData mdat;
\> BaseContainer bc;
\> mdat.doc = doc;
\> mdat.bc = &bc;
\> mdat.mode = MODIFY_ALL;
\> DoCommand(mdat);
\> }
\> }
\> }
\> return TRUE;
\> }
\>
\> ///////////////////////////////////////////////////////////////////////////////////////////////////
\> Bool SculptTool::DoCommand(ModelingCommandData &mdat;)
\> {
\> GePrint("In DoCommand");
\> //CODE RELATED TO THE SUBDIVISION OPTIONS/////////////////////////////////
\>
\> //Define Variables
\>
\> PolygonObject *objPoly = ToPoly(mdat.doc->GetActiveObject());
\> if (!objPoly) return FALSE;
\> mdat.op = objPoly;
\>
\> //Determine Attributes
\>
\> if (mdat.bc->GetBool(HYPERNURBS_SUBDIVISION, TRUE)) //If HyperNURBS is checked
\> {
\> mdat.bc->SetBool(MDATA_SUBDIVIDE_HYPER, TRUE); //Set HyperNURBS subdivision
\> }
\> else
\> {
\> mdat.bc->SetBool(MDATA_SUBDIVIDE_HYPER, FALSE); //Disable HyperNURBS subdivision
\> }
\> mdat.bc->SetLong(MDATA_SUBDIVIDE_SUB, mdat.bc->GetLong(NUM_SUBDIVISIONS)); //Set Number of Subdivisions
\> mdat.bc->SetReal(MDATA_SUBDIVIDE_ANGLE, mdat.bc->GetReal(MAX_ANGLE)); //Set Maxiumum Angle
\>
\> //Subdivision Command
\> SendModelingCommand(MCOMMAND_SUBDIVIDE, mdat);
\> mdat.bc->SetLong(POLYGON_COUNT, objPoly->GetPolygonCount());//Shows the current polygon count
\>
\>
\> return TRUE;
\>
\> //END SUBDIVISION OPTIONS/////////////////////////////////////////////////
\> GePrint("End Of DoCommand");
\>
\> }
\>
\> ///////////////////////////////////////////////////////////////////////////////////////////////////
\>
\> LONG SculptTool::Draw(BaseDocument *doc, BaseContainer &data;, BaseDraw *bd, BaseDrawHelp *bh, BaseThread *bt,LONG flags)
\> {
\>
\>
\> PolygonObject *op = ToPoly(doc->GetActiveObject());
\> LONG lngMySymPlane =doc->GetDataInstance()->GetLong (MIRROR_PLANE);
\> LONG trans = 175;
\> Vector color = data.GetVector(PLANE_COLOR);
\>
\> //Matrix for determining scale, rotation, and position.
\> Matrix m = op->GetMg();
\> Vector rad = op->GetRad();
\>
\> m.v1 *= rad.x+100;
\> m.v2 *= rad.y+100;
\> m.v3 *= rad.z+100;
\>
\>
\> switch (lngMySymPlane)
\> {
\>
\> case Z_PLANE:
\>
\> if (doc->GetDataInstance()->GetBool(SHOW_PLANE)) // If SHOW_PLANE is checked, then draw the polygon.
\> {
\> GePrint("Z_PLANE");
\> Vector p[4];
\>
\> p[0] = Vector(-1,-1,0);
\> p[1] = Vector(-1,1,0);
\> p[2] = Vector(1,1,0);
\> p[3] = Vector(1,-1,0);
\>
\> p[0] = p[0] * m;
\> p[1] = p[1] * m;
\> p[2] = p[2] * m;
\> p[3] = p[3] * m;
\>
\> Vector f[3] = { Vector(color),Vector(color),Vector(color)};
\>
\> bd->SetLightList(BDRAW_SETLIGHTLIST_NOLIGHTS);
\> bd->SetTransparency(trans);
\> bd->Polygon3D(p,f,TRUE);
\>
\> return true;
\> }
\> else //If SHOW_PLANE is unchecked, stop drawing the polygon.
\> {
\> Vector p[4] = { Vector(0,0,0),Vector(0,0,0),Vector(0,0,0),Vector(0,0,0)};
\> Vector f[3] = { Vector(0,0,0),Vector(0,0,0),Vector(0,0,0)};
\> bd->Polygon3D(p,f,FALSE);
\> }
\>
\> return DRAW_HANDLES|DRAW_AXIS;
\> break;
\>
\> case X_PLANE:
\> if (doc->GetDataInstance()->GetBool(SHOW_PLANE)) // If SHOW_PLANE is checked, then draw the polygon.
\> {
\> GePrint("X_PLANE");
\> Vector p[4];
\>
\> p[0] = Vector(0,-1,-1);
\> p[1] = Vector(0,-1,1);
\> p[2] = Vector(0,1,1);
\> p[3] = Vector(0,1,-1);
\>
\> p[0] = p[0] * m;
\> p[1] = p[1] * m;
\> p[2] = p[2] * m;
\> p[3] = p[3] * m;
\>
\> Vector f[3] = { Vector(color),Vector(color),Vector(color)};
\>
\> bd->SetLightList(BDRAW_SETLIGHTLIST_NOLIGHTS);
\> bd->SetTransparency(trans);
\> bd->Polygon3D(p,f,TRUE);
\>
\> return true;
\> }
\> else //If SHOW_PLANE is unchecked, stop drawing the polygon.
\> {
\> Vector p[4] = { Vector(0,0,0),Vector(0,0,0),Vector(0,0,0),Vector(0,0,0)};
\> Vector f[3] = { Vector(0,0,0),Vector(0,0,0),Vector(0,0,0)};
\> bd->Polygon3D(p,f,FALSE);
\> }
\>
\> return DRAW_HANDLES|DRAW_AXIS;
\> break;
\>
\> case Y_PLANE:
\> if (doc->GetDataInstance()->GetBool(SHOW_PLANE)) // If SHOW_PLANE is checked, then draw the polygon.
\> {
\> GePrint("Y_PLANE");
\> Vector p[4];
\>
\> p[0] = Vector(-1,0,-1);
\> p[1] = Vector(-1,0,1);
\> p[2] = Vector(1,0,1);
\> p[3] = Vector(1,0,-1);
\>
\> p[0] = p[0] * m;
\> p[1] = p[1] * m;
\> p[2] = p[2] * m;
\> p[3] = p[3] * m;
\>
\> Vector f[3] = { Vector(color),Vector(color),Vector(color)};
\>
\> bd->SetLightList(BDRAW_SETLIGHTLIST_NOLIGHTS);
\> bd->SetTransparency(trans);
\> bd->Polygon3D(p,f,TRUE);
\>
\> return true;
\> }
\> else //If SHOW_PLANE is unchecked, stop drawing the polygon.
\> {
\> Vector p[4] = { Vector(0,0,0),Vector(0,0,0),Vector(0,0,0),Vector(0,0,0)};
\> Vector f[3] = { Vector(0,0,0),Vector(0,0,0),Vector(0,0,0)};
\> bd->Polygon3D(p,f,FALSE);
\> }
\>
\> return DRAW_HANDLES|DRAW_AXIS;
\> break;
\> }
\> return TRUE;
\> }
\>
\> Bool SculptTool::MouseInput(BaseDocument *doc, BaseContainer &data;, BaseDraw *bd, EditorWindow *win, const BaseContainer &msg;)
\> {
\>
\>
\>
\> if (!doc) return FALSE;
\>
\> Real mx = msg.GetReal(BFM_INPUT_X);
\> Real my = msg.GetReal(BFM_INPUT_Y);
\> Real mz = msg.GetReal(BFM_INPUT_Z);
\> LONG button;
\>
\> switch (msg.GetLong(BFM_INPUT_CHANNEL))
\> {
\> case BFM_INPUT_MOUSELEFT : button=KEY_MLEFT; break;
\> case BFM_INPUT_MOUSERIGHT: button=KEY_MRIGHT; break;
\> default: return TRUE;
\> }
\>
\>
\> Real dx, dy;
\> BaseContainer bc;
\> BaseContainer device;
\> win->MouseDragStart(button,mx,my,MOUSEDRAG_DONTHIDEMOUSE|MOUSEDRAG_NOMOVE);
\> while (win->MouseDrag(&dx;,&dy;,&device;)==MOUSEDRAG_CONTINUE)
\> {
\>
\> GePrint("Mouse's X Position is: " + RealToString(mx));
\> GePrint("Mouse's Y Position is: " + RealToString(my));
\> GePrint("Mouse's Z Position is: " + RealToString(mz));
\>
\> return TRUE;
\> }
\> }
\>
\> Bool RegisterSculptTool()
\> {
\> return RegisterToolPlugin(ID_SCULPTTOOL, GeLoadString(IDS_SCULPTTOOL), 0, GeLoadString(IDS_HLP_SCULPTTOOL), gNew SculptTool);
\> }
\>
`