how to detect which face is clicked

73 views
Skip to first unread message

viki

unread,
Jan 9, 2012, 2:33:52 AM1/9/12
to pre3d
Hi Dean,

I have built-up on your 3d cube code & add a lot more functionality to
it (like loading 6 different images on the faces, getting the image
paths from an external xml file, etc).

Now, I want to get the face in front on user click.

I have toiled a lot with the code but to no avail.
Any suggestions as to what I should be doing?

Any help is appreciated!

Thanks,

srvikram13

Dean

unread,
Jan 9, 2012, 4:37:09 PM1/9/12
to pr...@googlegroups.com
Hello,

Pre3D doesn't include any "picking" support, mostly because there are
a few different ways you can approach it, and it depends on what
you're trying to do and what your objects are like. The two easiest
strategies are "color picking". This is where you assign each face of
your cube a different color, and draw into an offscreen canvas. You
then just look at the pixel where the mouse was clicked, and you map
the color to the face. If you need to know where on a specific face,
or if you want to do it in another approach, you would generally do a
ray / face interaction test. I would personally try first doing color
picking, I think it should be pretty easy in your situation.

Best,
Dean

> --
> You received this message because you are subscribed to the Google Groups "pre3d" group.
> To post to this group, send email to pr...@googlegroups.com.
> To unsubscribe from this group, send email to pre3d+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pre3d?hl=en.
>

viki

unread,
Jan 10, 2012, 5:26:52 AM1/10/12
to pre3d
And yes, great job that pre3d!
Keep up the good work.

viki

viki

unread,
Jan 10, 2012, 5:25:27 AM1/10/12
to pre3d
Hi Dean,

Thanks for your suggestions but I cannot go for the "color picking"
approach
as I am rendering 6 different 'Images' on the faces of the cube.

If only I could get a list of objects/faces/textures (whatever we call
them) on
the canvas when the mouse is clicked.
But, I have checked the cube object, renderer, canvas.children &
canvas.getContext without any success.

I guess, that is not feasible in the current implementation of pre3d.

Thanks anyway for your time & suggestions.

viki

On Jan 10, 2:37 am, Dean <d...@gmail.com> wrote:

Dean

unread,
Jan 10, 2012, 10:42:12 AM1/10/12
to pr...@googlegroups.com
The idea would be to render the cube again, in an offscreen canvas,
with colors as the face. This is something that is only done for the
picking, the user will never see it. So you render the cube with
colors and not textures, just to be able to discover which face was
clicked on.
Reply all
Reply to author
Forward
0 new messages