Shapes3D.pickShape and G4P P3D view combine?

Can the pickshape function of Shapes3D be used with a 3D gview in G4P ?

I can’t seem to make it work, I think possibly something is going wrong with a matrix transform somewhere between the gview and the pickbuffer … or maybe it only works when shape is drawn to sketch main draw() loop?
Has anyone else got this working ?

Not using peasyCam by the way, have my own fairly simple camera setup.

1 Like

The current version of Shapes3D will not work properly with the new GView and GViewPeasyCam controls. I am currently working on Shapes3D V3 and that works with G4P no problem. You will have to wait until it is released.

1 Like

Also Shapes3D has been totally rewritten for V3 and there are huge changes to the API. I have also been updating the website and everything on there is for the new version V3) of Shapes3D.

Thanks for info Peter, can you explain the underlying reason why it does not work please.

GView uses an offscreen buffer for its graphic, which is then displayed on the full display window graphic.

Shapes3D V2 expects to draw all shapes on the full display window graphic so can’t use GView controls.

Shaes3D V3 can draw shapes to any graphic buffer so can use GView etc.

Thanks Peter,
Understood…I think.
The reason I tried to make this work with shapes3D is that I was using my own picker, (which I think is derived from code you posted a couple of years ago on the old forum) this picker wouldn’t work with a second view, so I thought I’d test with Shapes3D.

As the ‘proxy’ objects for the picker are drawn to an offscreen buffer (pick buffer), does the problem come down to converting the mouseX/Y position from the second view/ gView to the offscreen pick buffer, along with passing over the camera projection from gView to the pickbuffer ?

This was the original question and as I have said it is not possible with Shapes3D V2 but will be possible with V3 when I release it.

I don’t think that it is my code as I have no recollection of posting anything. There is a third party picking library developed for Processing (see libraries page), I have never used this library but you might try it out.

  1. The pick buffer must be the same size as the second view / gView
  2. the [x,y] coordinates used for picking must be relative to the second view / gView so if you are using the mouseX and mouseY then you would need to translate these based on where the gView is.
  3. the model transformation matrix used on the pick buffer must be the same as when drawing the original shape.

I am not sure what you mean by proxy objects but in Shapes3D each object has two draw methods depending on whether it is being drawn to the screen or drawn to the pick buffer. Whenever a shape is drawn to the main display / gView it stores the current matrix which is applied to the pickbuffer. This is much better than having duplicate shape objects for the pickbuffer.

1 Like

Apologies, not enough coffee before I posted this morning ! and thank you again for your replies and patience.
I can’t find the original old post …only this that kinda refers to it.
Anyway not important now, as I now understand how the draw methods with Shapes3D are working.

This i’m pretty sure, is the part I was missing :

If you what to see how its done in Shapes3D V3 then you should look at the source file on Sourceforge.

Every shape inherits from this class and there are three key methods you should look at, first the method to render the shape and the second draw its to the pickbuffer. These methods start at line 1020

In the draw method there are two key lines

on_canvas = pg;
which remembers the canvas the shape is being rendered on we need this because we need to make sure we use the correct pickbuffer, and

on_canvas_matrix = pg.getMatrix().get();
which remembers the current transformation matrix just before the shape is rendered.

Now if you look in the next method, public void drawPickBuffer(PGraphics pg) you see the line

this is where where we apply the matrix for rendering to the pickbuffer.

Finally in the same class we have a static method to perform the picking, see line 98.

This line is interesting because it shows that every rendering canvas has its own pick buffer which is why we need to remember it in the draw(...) method.
PGraphics colorBuffer = mapCanvas2ColorBuffer.get(canvas);

The next few lines creates the pickbuffer if it hasn’t already been made or create a new one if the rendering canvas has changed size. Once this is done we draw all appropiate shapes to the pickbuffer

Hope this helps :smile:


That is great, thanks for the clear explanation.
I look forward to the release of V3 :clap: