ViewportSelect



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

    On 02/08/2011 at 11:00, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R12 
    Platform:   Windows  ; Mac  ;  
    Language(s) :     C++  ;

    ---------
    Is it okay to use ViewportSelect in Draw() in a tooldata plugin?

    I am trying to implement the following code but vps->Init() keeps returning FALSE.

      
      BaseObject* op = doc->GetActiveObject();  
      if(!op) return TOOLDRAW_0;  
      
      //CONVERT TO POLYGON OBJECT  
      PolygonObject *objPoly = ToPoly(op);  
      if(!objPoly) return TOOLDRAW_0;  
      
      //HELPER VARIABLES  
      //=============================================//  
        
      //Viewport Dimensions  
      LONG left, top, right, bottom, width, height;  
      bd->GetFrame(&left, &top, &right, &bottom);  
      width                    = right - left + 1;  
      height                    = bottom - top + 1;      
      
      LONG editorMode            = doc->GetMode();  
      Vector * points            = objPoly->GetPointW();  
      EditorWindow *win        = bd->GetEditorWindow();  
      
      Real radius                = 50;  
      Vector color            = Vector(1,1,1);  
        
      LONG x = cursorX;  
      LONG y = cursorY;  
      
      GePrint("X: " + LongToString(x) + " Y: " + LongToString(y));  
        
      //Viewport Select Variables  
      AutoAlloc<ViewportSelect> vps;  
      GePrint("1");  
      
    #ifdef C4D_R12  
      if (!vps || !vps->Init(width, height, bd, objPoly, editorMode, TRUE, VIEWPORTSELECTFLAGS_0))  
      {  
          GePrint("NO INIT");  
          return TOOLDRAW_0;  
      }  
    #else  
      if (!vps || !vps->Init(width, height, bd, objPoly, editorMode, TRUE, 0)) return TOOLDRAW_0;  
    #endif     
      
      vps->SetBrushRadius(radius);  
      bd->SetPen(color);  
      
      bd->SetMatrix_Matrix(objPoly, Matrix());  
      vps->ShowHotspot(win, x, y);  
      
      ViewportPixel *vpPoint    = vps->GetNearestPoint(objPoly, x, y, radius, FALSE, NULL, NULL);  
      
      //DeSelect based on pixel radius  
      LONG xmin = x - radius;  
      LONG xmax = x + radius;  
      LONG ymin = y - radius;  
      LONG ymax = y + radius;  
      
      LONG            iy;  
      ViewportPixel*    vp            = NULL;  
      Vector            origin        = Vector(x, y, 0);  
      Vector            current;  
      Vector            dist;  
      Real            dis;  
      
      for(LONG ix = xmin; ix < xmax; ++ix)  
      {  
          for(iy = ymin; iy  < ymax; ++iy)  
          {  
              current        = Vector(ix, iy, 0);  
              dist        = origin - current;  
              dis            = Len(dist);  
      
              if (dis < radius)  
              {  
                      vp = vps->GetPixelInfoPoint(ix, iy);  
                      bd->DrawHandle(points[vp->i], DRAWHANDLE_BIG, NOCLIP_Z);  
                      GePrint("DRAW HANDLE");  
              }  
          }  
      }  
      
      return    TOOLDRAW_AXIS|TOOLDRAW_HANDLES;  
    

    Thanks,  Shawn



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

    On 11/08/2011 at 06:08, xxxxxxxx wrote:

    I think it's a bad idea to do this in Draw(). You can always store the data obtained by ViewPortSelect in member variables of your tool class and trigger a viewport redraw with DrawViews. Draw will be called then.

    cheers,
    Matthias


Log in to reply