Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Tool Plugin Question

    SDK Help
    0
    37
    22.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 10/05/2011 at 11:26, xxxxxxxx wrote:

      You might want to use GetNearestPoint() instead and check for a radial distance from there or modify your loop to exhaust the available point set, only taking those best matching your criteria.

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 10/05/2011 at 11:37, xxxxxxxx wrote:

        LOL  oh duh.   I didn't notice that I was returning out of the loop.  Thanks for catching that.   Would GetNearestPoint() work outside of points mode?  Sorry.  I'm not home to test it. I will when I get home. 
        Thanks yet again.

        Shaw

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 10/05/2011 at 12:20, xxxxxxxx wrote:

          Thanks Robert.
          With that information I was able to change the for loop so it works with every point.

              for(int i = 0; i < pointCount; i++)  
              {  
              Vector wtail = bd->SW(Vector(mouseX, mouseY, 0));  
              Vector whead = bd->SW(Vector(mouseX, mouseY, 100000));  
              Vector otail = (!points[i]) * wtail;  
              Vector oray  = (whead - wtail) ^ (!points[i]);  
            
              cRay->Init(objPoly, TRUE);  
              cRay->Intersect(otail, !oray, 10000.0);  
            
              Vector distance = PointLineDistance(wtail, whead, points[i]);  
              const Real threshold = 20.0; // How close the mouse is to the point befor triggering the collision  
              Real dist = distance.GetLength();  
              
              if(dist <= threshold)    
                {              
                  bd->DrawHandle(points[i], DRAWHANDLE_BIG, NOCLIP_Z);  
                  GePrint("Collision with index#:" + RealToString(i)); // Prints the point index when collided           
                }        
              }
          

          Thanks for posting this example code Shawn.
          It really helps me to learn this stuff.

          -ScottA

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 10/05/2011 at 14:11, xxxxxxxx wrote:

            Hey glad you got it working Scott.  What function are you calling this code in?  And, does your sample draw the handle at the point that is being collided with?

            Thanks.  ~Shawn

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 10/05/2011 at 15:01, xxxxxxxx wrote:

              I'm not calling any function with it. Other than printing the index number of the object's point array as the mouse collides with it.
              The handle code doesn't do anything. I just forgot to delete it.

              -ScottA

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 10/05/2011 at 15:15, xxxxxxxx wrote:

                Sorry.  I wasn't clear.  I meant in what function is this code currently?  Do you have it in your Draw() function or MouseInput().  And I meant is the handle code working on your end because it wasn't working on mine but it is now.  I am thinking that this might actually be a performance monster.  I may try Roberts recommendation of using GetNearestPoint().

                Thanks

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 10/05/2011 at 15:51, xxxxxxxx wrote:

                  I was using it in draw. So when the mouse hovered over the point it would trigger the collide.
                  But since you asked. I just tried putting it under the mouse input function.
                  And while the print still works properly when the left mouse button is clicked. The handle doesn't do anything.

                  I'm very new to this stuff. So I might not be writing it properly. Or the same way as you.
                  So here's my MouseInput code in case you're curious:

                  Bool DrawTool::MouseInput(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, EditorWindow *win, const BaseContainer &msg)  
                  {  
                    if (!doc) return FALSE;  
                    
                    BaseContainer state;  
                    while (GetInputState(BFM_INPUT_MOUSE, BFM_INPUT_MOUSELEFT, state)) //While the left mouse button is pressed  
                    {  
                    if (state.GetLong(BFM_INPUT_VALUE) == 0) break; // Break out of the loop when left mouse button is NOT pressed      
                    LONG x = state.GetLong(BFM_INPUT_X);  
                    LONG y = state.GetLong(BFM_INPUT_Y);      
                    //GePrint("Left Mouse Button is pressed");  
                    
                    BaseObject* obj = doc->GetActiveObject();  
                    if(!obj) return TOOLDRAW_0;  
                    
                    PolygonObject *objPoly = (PolygonObject* )obj;  
                    if (!objPoly) return TOOLDRAW_0;  
                    LONG pointCount = objPoly->GetPointCount();  
                    Vector *points = objPoly->GetPointW();  
                          
                    AutoAlloc<GeRayCollider> cRay;  
                    GeRayColResult res;  
                    
                    // Make sure RayCollider is there  
                    if (!cRay)  
                    {  
                        GePrint("ERROR - RayCollider not Initialized");  
                        return TOOLDRAW_0;  
                    }  
                    
                    for(int i = 0; i < pointCount; i++)  
                      {  
                      Vector wtail = bd->SW(Vector(mouseX, mouseY, 0));  
                      Vector whead = bd->SW(Vector(mouseX, mouseY, 100000));  
                      Vector otail = (!points[i]) * wtail;  
                      Vector oray  = (whead - wtail) ^ (!points[i]);  
                    
                      cRay->Init(objPoly, TRUE);  
                      cRay->Intersect(otail, !oray, 10000.0);  
                    
                      Vector distance = PointLineDistance(wtail, whead, points[i]);  
                      const Real threshold = 20.0; // How close the mouse is to the point befor triggering the collision  
                      Real dist = distance.GetLength();  
                      
                      if(dist <= threshold)    
                        {              
                          bd->DrawHandle(points[i], DRAWHANDLE_BIG, NOCLIP_Z);  
                          GePrint("Collision with index#:" + RealToString(i)); // Prints the point index when collided           
                        }        
                      }  
                    }  
                  return TRUE;  
                  }
                  

                  -ScottA

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                    On 10/05/2011 at 16:29, xxxxxxxx wrote:

                    Hmm looks like GetNearestPoint only works in Points mode

                    And as is, this GeRayCollider code runs super slow when there are a lot of points.

                    Here's what I have,  I am doing it in the draw because I want it to update live..  😉  Which I could probably do more effectively in GetCursorInfo() or write my own function and call that from the Draw() but this is mostly for testing.  🙂

                      
                      
                      AutoAlloc<ViewportSelect> vps;  
                      if(!vps) return TOOLDRAW_0;  
                      
                      BaseObject* op = doc->GetActiveObject();  
                      if(!op) return TOOLDRAW_0;  
                        
                      bd->SetMatrix_Matrix(op, Matrix());  
                        
                      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;  
                      
                      LONG pointCount = objPoly->GetPointCount();  
                      Vector * points = objPoly->GetPointW();  
                      
                      AutoAlloc<GeRayCollider> cRay;  
                      
                      // Make sure RayCollider is there  
                      if (!cRay)  
                      {  
                          GePrint("ERROR - RayCollider not Initialized");  
                          return TOOLDRAW_0;  
                      }  
                      
                      for(int i = 0; i < pointCount; i++){  
                      
                          Vector wtail = bd->SW(Vector(cursorX, cursorY, 0));  
                          Vector whead = bd->SW(Vector(cursorX, cursorY, 100000));  
                          Vector otail = (!points[i]) * wtail;  
                          Vector oray  = (whead - wtail) ^ (!points[i]);  
                      
                          cRay->Init(objPoly, TRUE);  
                          cRay->Intersect(otail, !oray, 10000.0);  
                      
                          Vector distance = PointLineDistance(wtail, whead, points[i]);  
                          const Real threshold = 20.0; // How close the mouse is to the point befor triggering the collision  
                          Real dist = distance.GetLength();  
                        
                          if(dist <= threshold){              
                              bd->SetPen(Vector(1,0,0));  
                              bd->DrawHandle(points[i], DRAWHANDLE_BIG, NOCLIP_Z);          
                          }            
                      }  
                        
                      return    TOOLDRAW_AXIS|TOOLDRAW_HANDLES;  
                      
                    
                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                      On 10/05/2011 at 16:41, xxxxxxxx wrote:

                      okay I moved a few things.  I took the cray->Init out of the loop so it doesn't get reinitialized each time..  that helped a lot with performance..  still working out some kinks  but I iwll post when I am done so that you have a working and optimized sample.

                      ~Shawn

                      PS if anyone has any tips for further optimizing this code, I am all ears.  LOL

                      1 Reply Last reply Reply Quote 0
                      • H
                        Helper
                        last edited by

                        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                        On 10/05/2011 at 17:14, xxxxxxxx wrote:

                        SORRY- ACCIDENTAL DUPLICATE POST REMOVED!

                        1 Reply Last reply Reply Quote 0
                        • H
                          Helper
                          last edited by

                          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                          On 10/05/2011 at 17:15, xxxxxxxx wrote:

                          Okay here it is all cleaned up and working.  Still a small delay with objects with a ton of points but I can't see any other way to optimize.  Any suggestions are greatly appreciated.  But here's the code for anyone who wants it.  🙂

                            
                            
                              BaseObject* op = doc->GetActiveObject();  
                              if(!op) return TOOLDRAW_0;  
                            
                              bd->SetMatrix_Matrix(op, Matrix());  
                                
                              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;  
                            
                              Real radius        = data.GetReal(MY_RADIUS);  
                              Real strength    = data.GetReal(MY_STRENGTH);  
                              Real falloff    = data.GetReal(MY_FALLOFF);  
                              Vector color    = data.GetVector(MY_COLOR);  
                            
                              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 TOOLDRAW_0;  
                              }  
                            
                              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();  
                                  //const Real threshold = 20; //Tool Radius  
                                    
                                
                                  if(dist <= radius){              
                                      bd->SetPen(color);  
                                      bd->DrawHandle(points[i], DRAWHANDLE_BIG, NOCLIP_Z);          
                                  }            
                              }  
                            
                              return    TOOLDRAW_AXIS|TOOLDRAW_HANDLES;  
                            
                          
                          1 Reply Last reply Reply Quote 0
                          • H
                            Helper
                            last edited by

                            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                            On 10/05/2011 at 18:21, xxxxxxxx wrote:

                            Could you possibly post your MouseInput function Shawn?

                            I'm getting results when hovering over the objects. But I don't know how to set up the mouse function to do anything with it.

                            -ScottA

                            1 Reply Last reply Reply Quote 0
                            • H
                              Helper
                              last edited by

                              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                              On 10/05/2011 at 18:51, xxxxxxxx wrote:

                              I'm currently working on that.  I will post it when I get some results that I am happy with.  🙂

                              1 Reply Last reply Reply Quote 0
                              • H
                                Helper
                                last edited by

                                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

                                1 Reply Last reply Reply Quote 0
                                • H
                                  Helper
                                  last edited by

                                  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);          
                                        }            
                                    }
                                  
                                  1 Reply Last reply Reply Quote 0
                                  • H
                                    Helper
                                    last edited by

                                    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

                                    1 Reply Last reply Reply Quote 0
                                    • H
                                      Helper
                                      last edited by

                                      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

                                      1 Reply Last reply Reply Quote 0
                                      • H
                                        Helper
                                        last edited by

                                        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.

                                        1 Reply Last reply Reply Quote 0
                                        • H
                                          Helper
                                          last edited by

                                          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" option

                                          Adios,
                                          Cactus Dan

                                          1 Reply Last reply Reply Quote 0
                                          • H
                                            Helper
                                            last edited by

                                            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;  
                                              
                                            }  
                                              
                                            
                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post