Marquee selection in P3D( and P2D) using offscreen PGraphicsbuffer

I’m currently using an offscreen buffer in a 3D view and also a 2D view to help select objects in a UI when the mouse is clicked.
The method is basically similar to what @Quark has built for shapes3D i.e. assigning a unique colour to every object and then testing mouseX/Y in the PGraphics buffer to see if the mouse is over an assigned colour rather than background and get the instance of the object associated with that colour.
I’ve also used the same approach in a 2D view because it was a very easy solution for when the 2D view had been zoomed out or panned about.

What I’m now trying to figure out, is an effecient method to use a marquee selection / drag rectangle that references this PGraphics offscreen buffer for both 3D and 2D views so that multiple objects can easily be selected in one go.
My attempts to loop thru XY positions and testing pixel colour in the buffer have ended up dragging the application to near standstill.
The buffer is quite large approx. 1780*900. In the 2Dview all objects are of a known similar size, so in theory I shouln’t need to test every pixel…I think, but that doesn’t help with the 3D view.
Would it perhaps be quicker / better to save the buffer as a PImage, loadPixels and iterate thru that rather than the PGraphics ‘buffer’, would it make any difference ?

Has anyone here got a marquee selection working in a P3D context before ?

1 Like

what kind of shapes do you have? Only circles and rects? Or very irregular ones?

When you have only circles and rects you could perform basic checks (collision checks) instead of checking the color of all pixels in the marquee.

Even when you have very irregular ones, it would be possible to store 3 points inside the shape and compare them with the marquee.

Don’t save the buffer as a IImage it shouldn’t be neccessary

  1. Draw the buffer image betwen the startDraw and endDraw as usual
  2. After (1) use loadPixels and loop through those pixels inside the marque not he entire buffer,
  3. For any non-background colour get the object reference and store it in a Set. Note you don’t have to worry about duplicates with a Set

Once done you have set of unique object references for objects within the marquee


Thank you @quark, that is beautiful and works perfectly :star_struck:

After I answered this question I realised Shapes3D didn’t have a marquee selection method, I simply had not thought of it.

That has been corrected and the next release of Shapes3D includes a marquee selection method. :grinning: