Skip to content

Supplementary Blender

Alexander Mock edited this page Oct 22, 2022 · 2 revisions

Work with Blender

Blender is a powerful tool to create and modify existing maps for rmagine.

Some Links to look up:

Useful commands

Object Mode

Command Effect C
Ctrl + G Move Object after: type X and "0.5" to move the object 0.5 along the X axis
Ctrl + R Rotate Object after: type Z and "45" to rotate the object 45 degree around the X axis
Ctrl + S Scale Object after: type X and "2.0" to scale the object 2.0 along the X axis

Collada (DAE) exports (odyssey of wrong imports)

UPDATE

Blender plugin does everything right, Assimp writes the wrong transformation: See last sentence.

Beginning

Some strange errors happened while exporting blender's scene to collada format. I did the following in Blender (3.2.1):

  • Moved the Cube 5 units along the x axis
  • Moved the Cube 2 units along the y axis
  • Moved the Cube 3 units along the z axis
  • Rotated the Cube 45 degrees around the z axis
  • Scaled the Cube with 0.2 (the resulting cube has the dimensions 0.4 x 0.4 x 0.4)
  • Export DAE with default settings to "~/utitled.dae"

After some library fixes to read the scene graph completely, any collada file generated by Blender no longer loads correctly. With PLY exports, everything works as before. So I inspected the generated outputs of the Blender Collada exports (read by Assimp):

$:~ ./bin/rmagine_map_info ~/untitled.dae
#...
Scene Graph: 
- name: Scene
- transform: 
  M4x4[
    1 0 0 0
    0 0 1 0
    0 -1 0 0
    0 0 0 1
  ]
- meshes: 0
- children: 3
#...
  Node 2
    - name: Cube
    - transform: 
      M4x4[
        0.141421 -0.141421 0 5
        0.141421 0.141421 0 2
        0 0 0.2 3
        0 0 0 1
      ]
    - meshes: 1
      - mesh ref 0 -> 0
    - children: 0

And exactly there is the problem. I guess the "Cube" transformation is correct since it come from Blender directly. The problem comes from the global matrix at node named "Scene". This matrix switches the y and z axes and negates the z axis (old y axis) afterwards. The complete transform of the "Cube" following the transformations to the root is

v[5,3,-2], E[-1.5708, 0.785398, -1.26441e-07] with scale v[0.2,0.2,0.2]

as expected, the total transform holds the axis-switched version of our previously done operations. But that is not what we want. Moving something in Blender along the x axis should result in an export with something in it that was moved along the x axis and no other axis. So how to fix it? Pushing Export -> Colloda opens a menu. Push the settings button in the top left corner. It opens a side panel, holding some values to change for the export. My first intuitive choice to set the forward axis to X and the up axis to Z were wrong, incomprehensibly. However, by trial and error I came up with setting these values as follows:

Forward Axis: Z
Up Axis: -Y

With these settings the scene is exported exactly as I modelled it. Nevertheless, Blender exports the weird axis flip matrix at scene root. Every other transformation is adjusted such that every total transformation are valid.

v[5,2,3], E[0, 0, 0.785398] with scale v[0.2,0.2,0.2]

Not yet fixed

Importing this exported file into Blender results in a different scene. It seems the Blender Collada Importer ignores the top level axis-switch matrix somehow? FBX export and import is correct using the axis switch by choice.

FIXED

The wrong up most transformation is written by Assimp!

  • Assimp::Importer io; io.SetPropertyBool(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION, true)

Capsuled in AssimpIO-Object ("rmagine/map/AssimpIO.hpp").

The following code snipped already corrects the wrong transformation imports.

rm::AssimpIO io; 
const aiScene* scene = io.ReadFile("file.dae", 0);  

With that, it is possible to default export Collada files with Blender, import them with rmagine and import them in Blender again, without any errors.

Filmbox (FBX) exports

Same problems as in DAE section. Set axis to:

Scale: 0.01
Forward: Y Forward
Up: Z Up

Then everything is exported as modelled. Imports into Blender again are working as well. Luckilly, the global scene transform is set to identity here. Maybe that is why the Import is working again: ignoring the scene transform is not important if its an identity transform.

TODO: check if Gazebo importer ignores the scene transform

Building a 3D map from 2D building plan

Using Blender Version 3.3.1

Setting up a 2D Map as Reference image

Make sure to be in Object Mode

  1. Click top right on the z-axis to make the view orthograhic top down
  2. In Scene press Shift+A to open the Add Panel. Then select your Image and Load it into scene. The Image should now be located on your xy-plane
  3. Scale the Image to a size where you think you can work good with. The exact scale can be determined later.
  4. Enable Opacity of Image: Select Image and go to "Object Data Properties" (bottom right). Checkmark the Opacity Button

Modelling

To place single vertices in the scene we first have to enable an Add-On under Edit -> Preferences called Add Mesh: Extra Objects. Then with Shift+A under the entry Mesh the option Single Vert should be available. Selecting Single Vert will place a single vertex in the origin and change to Edit Mode. A object should appear in the Scene Collection panel top right called Vert.

  1. Move the image so that the first vertex to set is in the origin
  2. Insert a single vertex. A new object should be created. The first vertex is placed in the Origin.
  3. Press E to extrude a vertex than click an endpoint to place the second vertex with an edge connecting both.
  4. Contour: By again pressing E you can create a path of vertices. I recommend to make a complete path along the contour of the building plan (without doors. Only walls).
  5. Walls: Once you have created a contour of edges go to Edge Select-Mode select everything. Press Eand then Z to extrude the edges along the z-axis. Pull the walls to a arbitrary height (The exact scale is determined later).
  6. Ground Faces: Go to Vertex Select-Mode and select three ground Vertices you want to connect (Hold Shift). Press F to connect them to a Face.
    • If Faces are getting to long: Cut Wall-Face in two by selecting in in Face Select Mode and then pressing Ctrl+R
    • Enable Statistics in Drop-Down Menu "Overlays" top right. If you notice during editing that there is more than one Vertex at one point: Select both of them in Vertex Select-Mode. The Right-Click and Merge Vertices - Collapse.