Selecting items from a scene using Proscene library with a back buffer.
In my program I am calling size(mWidth, mHeight, JAVA2D) to set 2d rendering so the text that is drawn for a GUI will display properly. I am then using a back buffer and creating and instance of a Scene to be drawn into it with the rest of my objects. This allows me to have precise camera controls without running into issues with the graphics being laggy. The issue I am running into is selecting objects. None of my custom objects were made with interactive frames initially, and when I added them to my program they were not detected when I clicked or moused over the object. It also caused a large amount of memory usage when implementing the InteractiveFrames. What in anyone's opinion would be the easiest way to implement proscene's grabbing methods in this situation? I have 100+ objects being drawn and in the example below I show a similar situation but there are only 100 objects being drawn. Thanks in advance guys and gals!
for this example to work you need both the proscene and controlP5 libraries.
this snippet is designed to make it easy for people to copy and paste the code then make quick and easy edits. The original code is thousands of lines and 30 ish classes. For these reasons the variables here are left as public as to save the time need to ensure correct encapsulation. This is not the case in the real project.
- import remixlab.proscene.*;
- import controlP5.*;
- ControlP5 controlP5;
- Scene scene;
- PGraphics backBuffer;
- ArrayList<SceneObject> objects;
- class SceneObject {
- public float mWidth;
- public float mHeight;
- public float mDepth;
- public PVector mPosition;
- SceneObject(float w, float h, float d)
- {
- mWidth = w;
- mHeight = h;
- mDepth = d;
- float low = -100;
- float high = 100;
- mPosition = new PVector(random(low, high), random(low, high), random(low, high));
- }
- void display()
- {
- backBuffer.translate(mPosition.x, mPosition.y, mPosition.z);
- backBuffer.colorMode(HSB);
- backBuffer.fill(#000000);
- backBuffer.stroke(#FFFFFF);
- backBuffer.box(mWidth, mHeight, mDepth);
- }
- }
- void setup()
- {
- size(500, 500, JAVA2D);
- backBuffer = createGraphics(width, height, P3D);
- scene = new Scene(this, (PGraphics3D)backBuffer);
- controlP5 = new ControlP5(this);
- controlP5.setAutoDraw(false);
- objects = new ArrayList<SceneObject>();
- for (int i = 0; i < 100; i++)
- {
- SceneObject obj = new SceneObject(15f, 15f, 15f);
- objects.add(obj);
- }
- }
- void draw()
- {
- // Draw the 3D.
- backBuffer.beginDraw();
- scene.beginDraw();
- backBuffer.background(255);
- Iterator it = objects.iterator();
- while (it.hasNext())
- {
- SceneObject obj = (SceneObject)it.next();
- backBuffer.pushMatrix();
- obj.display();
- backBuffer.popMatrix();
- }
- scene.endDraw();
- backBuffer.endDraw();
- // Refresh the screen with the new
- // image from the back buffer.
- refresh();
- // Draw the 2D.
- drawGUI();
- }
- void drawGUI()
- {
- controlP5.draw();
- }
- void refresh()
- {
- image(backBuffer, 0, 0);
- }