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

    Just can't get GetPixelInfoPoint to work :-(

    SDK Help
    0
    41
    33.1k
    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

      On 18/06/2014 at 07:46, xxxxxxxx wrote:

      Howdy,

      Try this sample code:

      #include "c4d.h"
      #include "c4d_symbols.h"
      #include "lib_collider.h"
        
      class TestTool : public ToolData
      {
      private:
      	Real mx, my;
      	Bool mDrag;
      	
      public:
      	virtual TOOLDRAW Draw(BaseDocument* doc, BaseContainer& data, BaseDraw* bd, BaseDrawHelp* bh, BaseThread* bt, TOOLDRAWFLAGS flags);
      	virtual Bool MouseInput(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, EditorWindow *win, const BaseContainer &msg);
      };
        
      TOOLDRAW TestTool::Draw(BaseDocument* doc, BaseContainer& data, BaseDraw* bd, BaseDrawHelp* bh, BaseThread* bt, TOOLDRAWFLAGS flags)
      {
      	BaseObject	*op = doc->GetActiveObject(); if(!op) return TOOLDRAW_0;
      	if(!(op->IsInstanceOf(Opoint) && ToPoint(op)->GetPointR())) return TOOLDRAW_0;
      	
      	Real rad = 10.0;
      	if(mDrag)
      	{
      		bd->SetPen(Vector(0,0,0));
      		bd->DrawCircle2D(LONG(mx),LONG(my),rad);
      	}
        
      	return TOOLDRAW_HANDLES|TOOLDRAW_AXIS|TOOLDRAW_HIGHLIGHTS;
      }
        
      Bool TestTool::MouseInput(BaseDocument *doc, BaseContainer &data, BaseDraw *bd,EditorWindow *win, const BaseContainer &msg)
      {
      	BaseObject	*op = doc->GetActiveObject(); if(!op) return false;
      	if(!(op->IsInstanceOf(Opoint) && ToPoint(op)->GetPointR())) return false;
      		
      	mx = msg.GetReal(BFM_INPUT_X);
      	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;
      	}
      	
      	Real rad = 10.0;
      	Bool vOnly = true;
      	
      	AutoAlloc<ViewportSelect> vps; if(!vps) return false;
      	
      	LONG left, top, right, bottom, width, height;
      	bd->GetFrame(&left, &top, &right, &bottom);
      	width = right - left + 1;
      	height = bottom - top + 1;
      	
      	vps->Init(width,height,bd,op,Mpoints,vOnly,VIEWPORTSELECTFLAGS_USE_HN|VIEWPORTSELECTFLAGS_USE_DEFORMERS);
      	vps->SetBrushRadius(rad);
        
      	Real dx, dy;
      	mDrag = false;
      	BaseContainer bc, device;
      	win->MouseDragStart(button,mx,my,MOUSEDRAGFLAGS_DONTHIDEMOUSE|MOUSEDRAGFLAGS_NOMOVE);
      	while (win->MouseDrag(&dx,&dy,&device)==MOUSEDRAGRESULT_CONTINUE)
      	{
      		mx+=dx;
      		my+=dy;
      		mDrag = true;
      		LONG x = mx, y = my;
      		
      		ViewportPixel *vp = vps->GetNearestPoint(op,x,y,rad);
      		if(vp)
      		{
      			GePrint(LongToString(vp->i));
      		}
      		DrawViews(DRAWFLAGS_INDRAG|DRAWFLAGS_NO_REDUCTION|DRAWFLAGS_ONLY_ACTIVE_VIEW|DRAWFLAGS_NO_THREAD|DRAWFLAGS_NO_ANIMATION);
      	}
      	mDrag = false;
      	EventAdd(EVENT_FORCEREDRAW);
        
      	return TRUE;
      }
        
      #define ID_TOOLDATA_TEST		1000007
        
      Bool RegisterTestTool(void)
      {
      	return RegisterToolPlugin(ID_TOOLDATA_TEST,"Test Tool",0,AutoBitmap("Test.tif"),"Test Tool",gNew TestTool);
      }
      

      Adios,
      Cactus Dan

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

        On 18/06/2014 at 08:37, xxxxxxxx wrote:

        I replaced all my code with your code and added the following:

        (...)
        ViewportPixel *vp = vps1->GetNearestPoint(op,x,y,rad);
        if(vp)
        {
             GePrint(LongToString(vp->i));
        }
        else
        {
             GePrint("vp is NULL");
        }
        (...)

        And all I got, as I dragged the cursor was "vp is NULL" in the Console 😞

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

          On 18/06/2014 at 09:11, xxxxxxxx wrote:

          Howdy,

          OK, I added the line:

          else GePrint("vp is NULL");
          

          ... and it only prints that when the mouse is not over a point of the object and within the radius.

          Adios,
          Cactus Dan

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

            On 18/06/2014 at 09:24, xxxxxxxx wrote:

            If the code works in Python. Then It's not a code problem.

            The simplest way to check it is to put this in the sculpting.cpp file's while loop: GePrint(pPixel->op->GetName());
            If this returns NULL and not the name of the object. Then there's got to be something wrong with your SDK installation.

            -ScottA

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

              On 18/06/2014 at 09:33, xxxxxxxx wrote:

              So, why the hell is it not working for me?!?
              Would you guys be willing to check out my code?
              It is not much longer than the one posted above by Scott 😉

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

                On 18/06/2014 at 09:38, xxxxxxxx wrote:

                Howdy,

                Hehe, at this point that may be your only option. If you want to keep your code confidential, feel free to pm or email it to one of us.

                Adios,
                Cactus Dan

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

                  On 18/06/2014 at 09:38, xxxxxxxx wrote:

                  Scott, I did what you said and the sculpt tool works fine and prints out the name of the object.

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

                    On 18/06/2014 at 09:44, xxxxxxxx wrote:

                    Well, I will send it through pm just because I don't want to show my lame code to everyone 😉
                    Thank you very much in advance.

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

                      On 18/06/2014 at 09:50, xxxxxxxx wrote:

                      I just sent you a PM with my code, Dan.
                      I will only send it to Scott if he says it is OK to do so.
                      Thank you very much in advance to both of you.

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

                        On 18/06/2014 at 10:29, xxxxxxxx wrote:

                        If Dan's willing to help you out. There's no need to send it to me Rui.
                        He can probably help you better than I can.
                        Plus, he's a Mac user. So you can send files to each other. And I can't do that.

                        -ScottA

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

                          On 18/06/2014 at 10:33, xxxxxxxx wrote:

                          Thank you very much for the help, anyway, Scott 🙂
                          I guess I will be needing more help in the near future, now that I jumped on the C++ boat.
                          I can compile for Mac and Windows and that is great. But I'm still a newbie.

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

                            On 18/06/2014 at 10:53, xxxxxxxx wrote:

                            Howdy,

                            Well, I added your "CheckRadius" function to the test code that I posted, and it always prints "pPixel is NULL" the same as you're getting. So that function looks like it is the culprit.

                            But if I change the code in that function to:

                            LONG x = mouseX;
                            LONG y = mouseY;
                            ViewportPixel *pPixel = vps->GetNearestPoint(current_obj,x,y,radius);
                            if(pPixel) GePrint(LongToString(pPixel->i));
                            else GePrint("pPixel is NULL");
                            

                            ... then it works.

                            What is the purpose of the code in CheckRadius()? I mean why the nested for() loops?

                            Edit:
                            I can see using the nested for() loops in the sculpting tool example in the sdk project, because that tool would need to affect the surrounding points along with the point under the mouse, therefore the use of:

                            pPixel = pPixel->next;
                            

                            ... but for a painting tool, it just seems like the GetNearestPoint() function would be the easier.

                            Adios,
                            Cactus Dan

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

                              On 18/06/2014 at 12:41, xxxxxxxx wrote:

                              Well, it is a painting tool that should paint ALL points inside the radius.
                              But since the ViewportPixel structure is a linked list, maybe the GetNearestPoint returns a linked list of all points that are withing the radius.
                              I will give it a try 🙂
                              Thank you, Dan.

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

                                On 18/06/2014 at 12:54, xxxxxxxx wrote:

                                Damn!!
                                Now my CheckRadius function is just:

                                  
                                void cPolyPaintTool::CheckRadius(BaseDocument* doc, BaseContainer &data;, Real mouseX, Real mouseY, Real radius)   
                                {   
                                LONG x = _mouseX;   
                                LONG y = _mouseY;   
                                LONG rad = radius;   
                                        
                                ViewportPixel* pPixel = vps->GetNearestPoint(current_obj, x, y,rad,FALSE,NULL,0);   
                                                  
                                if (pPixel) GePrint(LongToString(pPixel->i));   
                                else   
                                     GePrint("pPixel is NULL");   
                                }   
                                

                                And I still only get "pPixel is NULL". It never printed an index.

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

                                  On 18/06/2014 at 13:56, xxxxxxxx wrote:

                                  Howdy,

                                  Maybe it is working?

                                  Here's a test I did. I added a breakpoint within the while loop in your original CheckRadius() function code, and ran it in the Debugger. The debugger did break at that point, which means that at least one pass through the loop did return a valid pointer to the ViewportPixel. It's just that there were so many other passes that return NULL, that I missed it in the console.

                                  Here's a screen capture video showing it:
                                  http://www.cactus3d.com/BreakPoint.mov

                                  You can see in the video that 1 pass did print "1" to the console which is the point's index I clicked on in the viewport.

                                  Adios,
                                  Cactus Dan

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

                                    On 18/06/2014 at 14:05, xxxxxxxx wrote:

                                    So, why doesn't it return lots of indexes when I search for the points inside the nested loops?
                                    Because I'm "painting" on top of a very dense mesh.

                                    p.s. I don't know how to run a plugin in the Debugger 😞

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

                                      On 18/06/2014 at 14:11, xxxxxxxx wrote:

                                      Howdy,

                                      Well, remember that the console has a line limit, so when it goes over that limit, it starts truncating lines from the beginning.

                                      Have you tried commenting out the line to print when it's NULL, and see if anything is printed to the console?

                                      Adios,
                                      Cactus Dan

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

                                        On 18/06/2014 at 14:15, xxxxxxxx wrote:

                                        Yes, I did. And nothing gets printed 😞

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

                                          On 18/06/2014 at 15:17, xxxxxxxx wrote:

                                          Howdy,

                                          When it prints nothing are simply clicking on a point or are you dragging the mouse over the point?

                                          Adios,
                                          Cactus Dan

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

                                            On 18/06/2014 at 15:23, xxxxxxxx wrote:

                                            It prints nothing, no matter if I click or drag the mouse over the point(s).

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post