Tool Plugin Question
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/05/2011 at 02:59, xxxxxxxx wrote:
Well here is my MouseInput function. It is still not doing what I want it to. My goal is to be able to change Y position of the point when the user drags the mouse over the point. Not sure why this isn't doing anything right now.
BaseObject* op = doc->GetActiveObject(); if(!op) return FALSE; ModelingCommandData mcd; mcd.op = op; mcd.mode = MODELINGCOMMANDMODE_ALL; mcd.doc = doc; SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, mcd); BaseObject *res = static_cast<BaseObject*>(mcd.result->GetIndex(0)); PolygonObject *objPoly = (PolygonObject * )res; if (!objPoly) return FALSE; bd->SetMatrix_Matrix(objPoly, Matrix()); Real radius = data.GetReal(MY_RADIUS); Real strength = data.GetReal(MY_STRENGTH); Real falloff = data.GetReal(MY_FALLOFF); LONG pointCount = objPoly->GetPointCount(); Vector * points = objPoly->GetPointW(); AutoAlloc<GeRayCollider> cRay; cRay->Init(objPoly, TRUE); Vector wtail = bd->SW(Vector(cursorX, cursorY, 0)); Vector whead = bd->SW(Vector(cursorX, cursorY, 100000)); // Make sure RayCollider is there if (!cRay) { GePrint("ERROR - RayCollider not Initialized"); return FALSE; } Real mx = msg.GetReal(BFM_INPUT_X); Real my = msg.GetReal(BFM_INPUT_Y); 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; } BaseContainer device; Real dx, dy; doc->AddUndo(UNDOTYPE_CHANGE, op); win->MouseDragStart(KEY_MLEFT, mx, my, MOUSEDRAGFLAGS_DONTHIDEMOUSE); while (win->MouseDrag(&dx, &dy, &device) == MOUSEDRAGRESULT_CONTINUE) { if (dx == 0.0 && dy == 0.0) continue; for(int i = 0; i < pointCount; i++){ Vector otail = (!points[i]) * wtail; Vector oray = (whead - wtail) ^ (!points[i]); Vector distance = PointLineDistance(wtail, whead, points[i]); Real dist = distance.GetLength(); if(dist <= radius){ points[i].y += 100; objPoly->Message(MSG_UPDATE); } } } if (win->MouseDragEnd()== MOUSEDRAGRESULT_ESCAPE) { doc->DoUndo(TRUE); } EventAdd(); return TRUE;
What I expect to happen with this code is that when the user drags over the points, those points increase in height by 100. But as it is, it does absolutely nothing to the points. So I am stumped right now.
~Shawn
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/05/2011 at 09:41, xxxxxxxx wrote:
Not much to make the code faster except for some smart preprocessing step to eliminate points but probably would not improve performance much (you gain some in the final loop but lose some in the preprocessing). A small improvement would be to use pointers instead of array indices. Also notice that you can gain more performance by referencing the point in the array once.
Vector* lpoints = points+pointCount; Vector pt; for(; points != lpoints; ++points){ pt = *points; Vector otail = (!pt) * wtail; Vector oray = (whead - wtail) ^ (!pt); Vector distance = PointLineDistance(wtail, whead, pt); Real dist = distance.GetLength(); //const Real threshold = 20; //Tool Radius if(dist <= radius){ bd->SetPen(color); bd->DrawHandle(pt, DRAWHANDLE_BIG, NOCLIP_Z); } }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/05/2011 at 09:51, xxxxxxxx wrote:
Thanks Robert, I'll give that a try and see if it speeds things up. Still can't figure out why I can't move any points... LOL doesn't seem to make sense, because theo bject is a polygon and I am looping through all points and attempting to move the point that is within the radius of the tool.. hmmm...
Thanks again.
~Shawn -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/05/2011 at 10:13, xxxxxxxx wrote:
Howdy,
Well, if I may suggest, you could find the desired point in ToolData::GetCursorInfo() and store the point index in a member LONG variable, so that when you click the mouse, and the tool enters the ToolData::MouseInput() function, the desired point has already been determined.
It may be that your ToolData::MouseInput() function isn't doing anything because in the while loop you're constantly cycling through the points, checking the distance from the mouse. Once you enter the while loop, the point you want to move should already be determined.
You can call the ToolData::Draw() function from the ToolData::GetCursorInfo() function by calling DrawViews(). The ToolData::Draw() function could then be as simple as getting the index from the value stored in the member LONG variable, and drawing the handle on that point.
You could also store a -1 in that member LONG variable for when the mouse is not on any points, and then check the value of the index in both the ToolData::MouseInput() and ToolData::Draw() functions, and if the value is less than 0, return without doing anything.
Adios,
Cactus Dan -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/05/2011 at 10:27, xxxxxxxx wrote:
You most definitely may! LOL thanks a lot Dan I will try that out when I get home today.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/05/2011 at 12:11, xxxxxxxx wrote:
Howdy,
You're welcome.
A couple of other things you may want to consider in a tool that will manipulate points are:
1. support for deformed points
2. support for an "Only Modify Visible Elements" optionAdios,
Cactus Dan -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/05/2011 at 19:22, xxxxxxxx wrote:
Well.. I did the things you mentioned Dan, and that sped up performance immensely. Thanks for that.. I am still trying to wrap my head around getting the points to move.. Here's some of my functions.
First, two global variables are declared:
GeAutoDynamicArray<LONG>pointIndex; LONG rPointCount;
pointIndex is an array of the point indices that are within the radius from the mouse which is determined by the user.
rPointCount is the number of points that fall within that radius.
Here's the GetCursorInfo() : Here I determine the location of the mouse, figure out the points that are within the radius that is determined by the user, and store the indices of those points in the array.
//GET CURSOR INFO //=============================================// Bool MyClass::GetCursorInfo(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, Real x, Real y, BaseContainer &bc){ cursorX = x; cursorY = y; rPointCount = 0; if (x > -1.0) SpecialEventAdd(EVMSG_UPDATEHIGHLIGHT); BaseObject* op = doc->GetActiveObject(); if(!op) return FALSE; ModelingCommandData mcd; mcd.op = op; mcd.mode = MODELINGCOMMANDMODE_ALL; mcd.doc = doc; SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, mcd); BaseObject *res = static_cast<BaseObject*>(mcd.result->GetIndex(0)); PolygonObject *objPoly = (PolygonObject * )res; if (!objPoly) return FALSE; bd->SetMatrix_Matrix(objPoly, Matrix()); Real radius = data.GetReal(MY_RADIUS); Real strength = data.GetReal(MY_STRENGTH); Real falloff = data.GetReal(MY_FALLOFF); LONG pointCount = objPoly->GetPointCount(); Vector * points = objPoly->GetPointW(); AutoAlloc<GeRayCollider> cRay; cRay->Init(objPoly, TRUE); Vector wtail = bd->SW(Vector(x, y, 0)); Vector whead = bd->SW(Vector(x, y, 100000)); // Make sure RayCollider is there if (!cRay) { GePrint("ERROR - RayCollider not Initialized"); return FALSE; } for(int i = 0; i < pointCount; i++){ Vector otail = (!points[i]) * wtail; Vector oray = (whead - wtail) ^ (!points[i]); Vector distance = PointLineDistance(wtail, whead, points[i]); Real dist = distance.GetLength(); if(dist <= radius){ pointIndex[rPointCount] = i; rPointCount++; } } return TRUE; }
Here's the Draw() function: Here I iterate through only the points that within the radius and draw a handle on each point to essentially highlight the points.
//DRAW //=============================================// TOOLDRAW MyClass::Draw(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, BaseDrawHelp *bh, BaseThread *bt,TOOLDRAWFLAGS flags){ BaseObject* op = doc->GetActiveObject(); if(!op) return TOOLDRAW_0; ModelingCommandData mcd; mcd.op = op; mcd.mode = MODELINGCOMMANDMODE_ALL; mcd.doc = doc; SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, mcd); BaseObject *res = static_cast<BaseObject*>(mcd.result->GetIndex(0)); PolygonObject *objPoly = (PolygonObject * )res; if (!objPoly) return TOOLDRAW_0; bd->SetMatrix_Matrix(objPoly, Matrix()); Vector color = data.GetVector(MY_COLOR); LONG pointCount = objPoly->GetPointCount(); Vector * points = objPoly->GetPointW(); for (int i = 0; i < rPointCount; i++){ LONG tmp = pointIndex[i]; bd->SetPen(color); bd->DrawHandle(points[tmp], DRAWHANDLE_BIG, NOCLIP_Z); } return TOOLDRAW_AXIS|TOOLDRAW_HANDLES; }
Heres the MouseInput() function: Here I convert the active object to a polygon object and then move the highlighted points. Now I tried to do what Dan said and have the selected points already determined before I enter the while loop but I am not sure how to accomplish this, because in order to move the correct points I still need to iterate through them.. At least I think I do. So instead, I iterate through only the highlighted points in this MouseInput function.. but, as before, the points do not move at all.. I am sure that I am not doing something right. Dan, am I doing it the way you envisioned? If not, what would you change?
//MOUSE INPUT //=============================================// Bool MyClass::MouseInput(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, EditorWindow *win, const BaseContainer &msg){ BaseObject* op = doc->GetActiveObject(); if(!op) return FALSE; ModelingCommandData mcd; mcd.op = op; mcd.mode = MODELINGCOMMANDMODE_ALL; mcd.doc = doc; SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, mcd); BaseObject *res = static_cast<BaseObject*>(mcd.result->GetIndex(0)); PolygonObject *objPoly = (PolygonObject * )res; if (!objPoly) return FALSE; Vector * points = objPoly->GetPointW(); Real mx = msg.GetReal(BFM_INPUT_X); Real my = msg.GetReal(BFM_INPUT_Y); 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; } BaseContainer device; Real dx, dy; doc->AddUndo(UNDOTYPE_CHANGE, op); win->MouseDragStart(KEY_MLEFT, mx, my, MOUSEDRAGFLAGS_DONTHIDEMOUSE); while (win->MouseDrag(&dx, &dy, &device) == MOUSEDRAGRESULT_CONTINUE) { for (int i = 0; i < rPointCount; i++){ LONG tmp = pointIndex[i]; points[tmp].y += 100; } } if (win->MouseDragEnd()== MOUSEDRAGRESULT_ESCAPE) { doc->DoUndo(TRUE); } EventAdd(); return TRUE; }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/05/2011 at 19:52, xxxxxxxx wrote:
Howdy,
In your MouseInput() function, this line:
Vector * points = objPoly->GetPointW();
is getting the points array of the resulting object from MCOMMAND_CURRENTSTATETOOBJECT, so those are probably not the points you actually want to move.
Adios,
Cactus Dan -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/05/2011 at 06:33, xxxxxxxx wrote:
Okay so essentially, I need to get the original object, which is not an editable polygon object, and convert it to an editable polygon object, and then somehow get it back to the non editable object. How does one achieve this? It's easy to do from the object itself, I just send it all back out via GetVirtualObjects() but how do I Get it back to a non editable object from the tool?
or will I need to somehow check for the tool being used on that object within the object itself, which as i mentioned before but that was a while ago (haha) this is meant to change points on an object plugin that I have created, so I have full access to the object's inner workings too.
~Shawn -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/05/2011 at 07:30, xxxxxxxx wrote:
Howdy,
OK, since your plugin object is using GetVirtualObjects(), then I'm assuming it is a generator. If so then it should have a polygonal cache object. I'm not sure if you can safely access the polygonal cache object from a tool, but if you can, then
BaseObject *cachOp = op->GetCache();
...would return a pointer to the polygonal cache object and from there you could get the points array of the polygonal cache object.
Take a thorough look in the sdk documentation under BaseObject::GetDeformCache() to find a complete description of the polygonal caches.
If it's not thread safe (and it probably isn't) to access and change the points of the polygonal cache from a tool, then your object must be getting the points from somewhere to build the polygonal object in GetVirtualObjects(). So, what you could do, is have a pointer to a Vector array
Vector *points;
...as a public class member variable in your plugin object, and store your points there first. You could use that array to build your object in GetVirtualObjects(), and you could give your tool direct access to that array by adding a public function to the plugin object class:
Vector* GetObjectPointsArray(void) { return *points }
... and place your class definition in the plugin's main header file so that both the plugin object and the tool will include the class definition.
The tool can then access that array by getting the plugin object's node data like this:MyObjectClass *myOp = static_cast<MyObjectClass*>(op->GetNodeData()); if(!myOp) return TRUE; // exit if "myOp" is NULL Vector *points = myOp->GetObjectPointsArray(); if(!points) return TRUE; // exit if "points" is NULL
That will give your tool direct access to the points array in your plugin object. Of course, you'll have to add Read(), Write() and CopyTo() functions to your plugin object class to make sure the points array stays valid.
I'm not sure if this method is thread safe either, though.
Adios,
Cactus Dan -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/05/2011 at 07:39, xxxxxxxx wrote:
Awesome Dan! Thanks a lot.. this gives me some things to tinker with when I get home. Thanks again for all your help everyone!
~Shawn -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/05/2011 at 07:43, xxxxxxxx wrote:
Howdy,
Also take a look in the sdk documentation under "Important threading information" to see what is thread safe and what is not.
Adios,
Cactus Dan