3d Game Programming with Java and libGDX — Determining Model Dimensions with Blender

Or… the journey through the x, y, and z axes through the lens of a computer screen.

TL;DR

As I am coding a 3d game, which is along the lines of a building game, rather than an action game, for the model that I am using (which is the Rhombic Dodecahedron). How do I get the positioning correct when I want to stack to dodecahedron’s together?

I could of course go through the mathematics, which is large, and complex, and involves trigonometry in three dimensions (which thankfully I can still remember). Or… I could just get blender to work it all out for me and then hard-code the values into the programme.

I chose the latter… always about saving the CPU cycles

Note: this is part of a series of articles: See 3d Game Programming with Java and libGDX — Overview of Articles

In this guide

I shall be using the rhombic dodecahedron that I created in another article 3d Game Programming with Java and libGDX — Setting up a Model with Blender

  1. Centring the model (if required)
  2. Determining the position of things

Centring the model (if required)

If you have moved the model around the 3d environment, it is time to centre it back at the origin, so that the offset (or distance) of the model is in absolute terms, rather than having to work out the subtraction of vectors to get the offest.

In the following image, I have moved the model along the x-axis, and now need to centre it back to the 0,0,0 (i.e. the centre of the 3d world)

To do this easily, and absolutely:

  1. Left click on the object to select it, or press the ‘A’ key to Select All — which will only work if it is the only model
  2. Hold the ‘Shift’ key and press the ‘S’ key to bring up a context menu
  3. Select ‘Cursor to World Origin’ from the context menu, or press the ‘1’ key, or press the ‘W’ key, and the cursor will snap back to the world origin (0,0,0)
  4. Again hold the ‘Shift’ key and press the ‘S’ key to bring up a context menu
  5. Select ‘Selection to Cursor (Keep Offset)’ from the context menu, or press the ‘7’ key, or press the ‘K’ key, and the model will snap back to the world origin (0,0,0), with the same size and rotation.

Here is a video of how it all works:

Determining the position of things

Now that we have the model at the centre of the world, it is time to determine what the offset of each of the faces.

Make sure that you are in the ‘Layout’ pane, in ‘Edit Mode’, with the ‘Viewport Shading’ set to ‘Solid’, as shown below.

Also of interest is the selection — either ‘Vertex’, ‘Edge’, or ‘Face

For this example, I am selecting one of the faces, and then I want to see what the offset (or distance) from the centre is.

So

  1. Select the faces that I want to know the distance of (i.e. by left clicking on them)
  2. Hold the ‘Shift’ key and press the ‘S’ key to bring up a context menu
  3. Select ‘Cursor to Selected’ from the context menu, or press the ‘2’ key, or press the ‘T’ key, and the cursor will snap to the centre of the selected face
  4. Pull out the drawer on the right hand side of the pane
  5. View the ‘3D Cursor Location’ details and note down the details (taking into account the scaling details)

In the above video the coordinates are as follows:

  • x: 0.004921 m
  • y: 0
  • z: 0.004921 m

Remember that this is scaled to metres, so the end result is multiplied by 100 to get the final result of:

  • x: 0.4921 cm
  • y: 0
  • z: 0.4921 cm

So, if I wanted to place another dodecahedron on this face I would move it 0.9842cm (which is 2 x 0.4921cm) in the x direction, and 0.9842cm in the y-direction

Wrap-up

Rather than getting into complex mathematics in 3 dimensions, and working out the dimensions on the fly, using blender to accomplish this task:

  • saves time
  • reduces mistakes
  • reduces the number of CPU cycles that are required to compute it

All sorts of interests