PDA

View Full Version : Web buttons & webGL objects



chlowden
04-11-2012, 05:13 AM
Hello
I am a total webgl neophyte who is wondering what is possible.

I have a 3D cube that I have been able to encode in webgl using the converter below.
http://doc.instantreality.org/tools/x3d ... converter/ (http://doc.instantreality.org/tools/x3d_encoding_converter/)

What I am wondering is if it is possible to define that certain parts of the 3D scene are buttons. For instance, could a certain part of each side of the cube to a button or have some sort of interactivity beyond animation or camera manipulation.

Any thoughts, examples or solutions are very welcome?
Many thanks

gardin
04-20-2012, 12:06 PM
There is no features built into WebGL for stuff like that.

What you need to do, and this can be pretty complicated, is to implement some code of your own to find out what the user clicked at.

The complicated way would be to do some raytracing and collision detection, but that would require a lot of code.

The easier version is, when the user clicks somewhere you render your cube (or whole scene) to a buffer, like framebuffer_object, thus not showing it to the user, but instead rendering it to a renderbuffer or texture. And when you do this, you render each surface of the cube with a special color. One side red, other yellow, next blue, green etc.

When this is done, you extract the pixel from the renderbuffer/texture to the CPU around where the user clicked. If it is red, the user clicked on the first surface etc.