We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › 3D Picking
Pages: 1 2 
3D Picking (Read 4498 times)
3D Picking
Feb 18th, 2010, 3:08am
 
I know subpixel was thinking about this last week, so hopefully he'll be happy to see it working...

I wrote a block of code that simplifies the process of clicking on a specific object in a 3D view. What's even cooler is that it's easy to add into existing sketches - you just need to capitalize a few function names, throw in my code, and a few calls to ID()... and you can click on any 3D object and it'll know which one you clicked on.

It's my hope that others can use this in their own works.
Besides, how cool are 3D buttons

Check it out HERE.
Re: 3D Picking
Reply #1 - Feb 18th, 2010, 5:00am
 
Nice!

Do you have any plans about releasing a picking library? That would be awesome!
Re: 3D Picking
Reply #2 - Feb 18th, 2010, 5:24am
 
This is cool!

I'm working on something similar using glu.gluPickMatrix(), the process is similar but integrated with OpenGL.
Re: 3D Picking
Reply #3 - Feb 18th, 2010, 8:03am
 
The Shapes3D library has 3D shape picking but that can't be used with existing sketches.

To provide 3D picking code that can be plugged into existing sketches is a real challenge and it's good to see someone do it.

Nice one
Smiley

Re: 3D Picking
Reply #4 - Feb 18th, 2010, 5:52pm
 
Quote:
Do you have any plans about releasing a picking library?


I knew someone would ask that...  Roll Eyes

I wasn't planning on it, but I guess I could give it a go.  Cool
Re: 3D Picking
Reply #5 - Feb 18th, 2010, 9:30pm
 
I saw it on OpenProcessing and like it a lot :o)

-spxl
Re: 3D Picking
Reply #6 - Feb 18th, 2010, 9:49pm
 
Great work  Wink
Re: 3D Picking
Reply #7 - Feb 19th, 2010, 8:40am
 
@Quark

very interesting.

I tried to build it in a program of mine, but didn't work.

Are we sure that it is working with peasycam?

Thank you!

Chrisir


Re: 3D Picking
Reply #8 - Feb 20th, 2010, 4:33am
 
Yes it does.

I have modified the shape picking example from the library to show it working with PeasyCam.
Smiley

Code:
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;

import shapes3d.utils.*;
import shapes3d.*;

import processing.opengl.*;

Box[] box = new Box[10];
float a;
PeasyCam pcam;
boolean mouseClicked = false;

void setup(){
 size(200,200,OPENGL);
 pcam = new PeasyCam(this,0,0,0,100);

 cursor(CROSS);
 float size;
 for (int i = 0; i < box.length; i++) {
   size = 5 + (int)random(15);
   box[i] = new Box(this,size,size,size);
   box[i].moveTo(random(-18,18), random(-18,18), random(-18,18));
   box[i].fill(randomColor());
 }
}

void draw(){
 background(255);
 pushMatrix();
 ambientLight(200,200,200);
 directionalLight(128, 128, 128, -1, 0, -1);

 for (int i = 0; i < box.length; i++) {
   box[i].draw();
 }
   if(mouseClicked){
   Shape3D picked = Shape3D.pickShape(this,mouseX, mouseY);
   if(picked != null)
     picked.fill(randomColor());
   mouseClicked = false;
 }

 popMatrix();
 a += 0.002;
}

void mouseClicked(){
 mouseClicked = true;
}

int randomColor(){
 return color(random(60,200), random(60,200), random(60,200));
}
Re: 3D Picking
Reply #9 - Feb 20th, 2010, 8:29am
 
Can you explain a bit what technique do you use to determine the id of the object under the cursor?
Re: 3D Picking
Reply #10 - Feb 20th, 2010, 9:10am
 
TfGuy44, cool - I'll play around with it.  Is this faster than a color buffer pick? What is it doing?

Chrisir, I also did a picking example with peasycam.  Do a search for Peasy Picking.

gll, I'd be interested in testing that out, particularly if it offers some performance gains over a strait color buffer pick.  I can run through 20,000 vertexes in my pick routine.  I wonder if this could be pushed to the video card with OpenCL or OpenGL.  I already have a vertex vbo... be nice to do the picking on the card.
Re: 3D Picking
Reply #11 - Feb 20th, 2010, 10:21am
 
The implementation we did is currently in Scala. You could have look at the code: http://anar.ch/websvn/filedetails.php?repname=Scala+%28ANAR%2B%29&path=%2FCamera.scala (look at 3D picking in the middle).

http://www.lighthouse3d.com/opengl/picking/index.php3?openglway might be a good reference.

With OpenGL, you still need to render twice, but you don't do all steps of a normal OpenGL cycle. I think there's not all the final rasterizations. In this sense, it should improve computations time. You could get a list of objects above the cursor instead of only the front object. I think that you could manage to optimize even more if you don't reload the geometry in the card (with VBO).
Re: 3D Picking
Reply #12 - Feb 20th, 2010, 12:21pm
 

@quark:

solved it.

I now use something like:

 box[iBox].moveTo(MyPVector.x, MyPVector.y, MyPVector.z);
 box[iBox].fill(color(222,0,0));  
 box[iBox].draw();

 iBox++;

How can I give the boxes names? Or an 3D-Index?

Thank you so much! ...again...

Because when I pick it:

   Shape3D picked = Shape3D.pickShape(this,mouseX, mouseY);
   if(picked != null) {
     picked.fill(color (254,0,0));

I need its index.

Thank you!

Chrisir

Re: 3D Picking
Reply #13 - Feb 20th, 2010, 1:14pm
 
I have been thinking all day about how to put that stuff in a library that wouldn't require to change anything to the code and... here it is:

Example
http://www.openprocessing.org/visuals/?visualID=7744

Library
http://n.clavaud.free.fr/processing/picking-library/

You just need to call pickingHelper.start(yourObjectID); before you draw the objects. You can temporary disable picking by calling pickingHelper.stop(), if you don't want some objects to be drawn.

@jeffg: this is regular color picking, though, so... no big surprise.
@marcin ignac: more info here in the hacks section. otherwise, if you read french, then have a look at this tutorial I wrote some time ago.
Re: 3D Picking
Reply #14 - Feb 20th, 2010, 1:59pm
 

Am I missing something?

Where can I get nknk?

Wink

Pages: 1 2