The UBG 3D2D system helps convert data back and forth between 2D and 3D spaces. Features include translating a 3D point into 2D viewport space, translating a 2D point in viewport space into a 3D ray, and numerous shape and mesh interception scripts to allow click on 3D objects.
There are 2 essential structures that you need to consider when using this system:
The translator handles translating point data between spaces. In order to go from one space to another you need to create a translator with ubg_3d2d_create_translator and define your camera / view bounds. Once you have this you can use ubg_3d2d_translation_* and ubg_3d2d_position_* functions by passing in your translator structure. When you perform a translation from 2D to 3D space the function will return a ray structure. This is a position/direction pair which can be used with the mesh tracker to detect collisions in 3D space.
You can either check for collisions against primitives directly or use a meshtracker to detect a collision with a 3D mesh. All collision functions start with ubg_3d2d_ray_to_*. A mesh tracker takes an unfrozen vbuffer and model matrix and then reconstructs the data in a way more kind to collision checking. It also provides the ability to retrieve more specific data about collisions such as multiple intersection points and info about the specific triangles hit. You will need one meshtracker for each mesh which you can create by calling ubg_3d2d_create_meshtracker. Once created you can check for collisions between a ray and either it's OOB or the actual mesh itself triangle-by-triangle. Note that even precise checks will still do an OOB check to significantly speed up miss-checks.
An example initialization of the translator and meshtracker might look something like this:
If you were to check if there was a precise collision against this mesh then your code would look like this:
The code above would convert the mouse coordinates into a 3D ray and then use that ray for a collision against the mesh. The function would return whether or not there was a collision and the specific collision data could then be retrieved from the meshtracker with various Getters
That's all there is to it!
If you have any questions or issues that can't be found in this manual please feel free to contact us!
If you like this extension take a look at some of our other offerings!