|
| 1 | +# Work with Blender |
| 2 | + |
| 3 | +Blender is a powerful tool to create and modify existing maps for rmagine. |
| 4 | + |
| 5 | +Some Links to look up: |
| 6 | +- Webpage: https://www.blender.org/ |
| 7 | +- Docs: https://docs.blender.org/manual/en/latest/ |
| 8 | + |
| 9 | +## Useful commands |
| 10 | + |
| 11 | +### Object Mode |
| 12 | + |
| 13 | +| Command | Effect | C | |
| 14 | +|:--------:|:----------:|:----:| |
| 15 | +| Ctrl + G | Move Object | after: type X and "0.5" to move the object 0.5 along the X axis | |
| 16 | +| Ctrl + R | Rotate Object | after: type Z and "45" to rotate the object 45 degree around the X axis | |
| 17 | +| Ctrl + S | Scale Object | after: type X and "2.0" to scale the object 2.0 along the X axis | |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +## Collada (DAE) exports (odyssey of wrong imports) |
| 22 | + |
| 23 | +### UPDATE |
| 24 | +Blender plugin does everything right, Assimp writes the wrong transformation: See last sentence. |
| 25 | + |
| 26 | + |
| 27 | +### Beginning |
| 28 | +Some strange errors happened while exporting blender's scene to collada format. I did the following in Blender (3.2.1): |
| 29 | + |
| 30 | +- Moved the Cube 5 units along the x axis |
| 31 | +- Moved the Cube 2 units along the y axis |
| 32 | +- Moved the Cube 3 units along the z axis |
| 33 | +- Rotated the Cube 45 degrees around the z axis |
| 34 | +- Scaled the Cube with 0.2 (the resulting cube has the dimensions 0.4 x 0.4 x 0.4) |
| 35 | +- Export DAE with default settings to "~/utitled.dae" |
| 36 | + |
| 37 | +After some library fixes to read the scene graph completely, any collada file generated by Blender no longer loads correctly. |
| 38 | +With PLY exports, everything works as before. |
| 39 | +So I inspected the generated outputs of the Blender Collada exports (read by Assimp): |
| 40 | + |
| 41 | + |
| 42 | +```bash |
| 43 | +$:~ ./bin/rmagine_map_info ~/untitled.dae |
| 44 | +#... |
| 45 | +Scene Graph: |
| 46 | +- name: Scene |
| 47 | +- transform: |
| 48 | + M4x4[ |
| 49 | + 1 0 0 0 |
| 50 | + 0 0 1 0 |
| 51 | + 0 -1 0 0 |
| 52 | + 0 0 0 1 |
| 53 | + ] |
| 54 | +- meshes: 0 |
| 55 | +- children: 3 |
| 56 | +#... |
| 57 | + Node 2 |
| 58 | + - name: Cube |
| 59 | + - transform: |
| 60 | + M4x4[ |
| 61 | + 0.141421 -0.141421 0 5 |
| 62 | + 0.141421 0.141421 0 2 |
| 63 | + 0 0 0.2 3 |
| 64 | + 0 0 0 1 |
| 65 | + ] |
| 66 | + - meshes: 1 |
| 67 | + - mesh ref 0 -> 0 |
| 68 | + - children: 0 |
| 69 | +``` |
| 70 | + |
| 71 | +And exactly there is the problem. I guess the "Cube" transformation is correct since it come from Blender directly. |
| 72 | +The problem comes from the global matrix at node named "Scene". |
| 73 | +This matrix switches the y and z axes and negates the z axis (old y axis) afterwards. |
| 74 | +The complete transform of the "Cube" following the transformations to the root is |
| 75 | + |
| 76 | +```v[5,3,-2], E[-1.5708, 0.785398, -1.26441e-07] with scale v[0.2,0.2,0.2]``` |
| 77 | + |
| 78 | +as expected, the total transform holds the axis-switched version of our previously done operations. |
| 79 | +But that is not what we want. |
| 80 | +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. |
| 81 | +So how to fix it? |
| 82 | +Pushing `Export -> Colloda` opens a menu. |
| 83 | +Push the settings button in the top left corner. |
| 84 | +It opens a side panel, holding some values to change for the export. |
| 85 | +My first intuitive choice to set the forward axis to X and the up axis to Z were wrong, incomprehensibly. |
| 86 | +However, by trial and error I came up with setting these values as follows: |
| 87 | + |
| 88 | +``` |
| 89 | +Forward Axis: Z |
| 90 | +Up Axis: -Y |
| 91 | +``` |
| 92 | + |
| 93 | +With these settings the scene is exported exactly as I modelled it. |
| 94 | +Nevertheless, Blender exports the weird axis flip matrix at scene root. |
| 95 | +Every other transformation is adjusted such that every total transformation are valid. |
| 96 | + |
| 97 | +```v[5,2,3], E[0, 0, 0.785398] with scale v[0.2,0.2,0.2]``` |
| 98 | + |
| 99 | +### Not yet fixed |
| 100 | +Importing this exported file into Blender results in a different scene. |
| 101 | +It seems the Blender Collada Importer ignores the top level axis-switch matrix somehow? |
| 102 | +FBX export and import is correct using the axis switch by choice. |
| 103 | + |
| 104 | + |
| 105 | +### FIXED |
| 106 | +The wrong up most transformation is written by Assimp! |
| 107 | + |
| 108 | +- Assimp::Importer io; io.SetPropertyBool(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION, true) |
| 109 | + |
| 110 | +Capsuled in `AssimpIO`-Object ("rmagine/map/AssimpIO.hpp"). |
| 111 | + |
| 112 | +The following code snipped already corrects the wrong transformation imports. |
| 113 | + |
| 114 | +```cpp |
| 115 | +rm::AssimpIO io; |
| 116 | +const aiScene* scene = io.ReadFile("file.dae", 0); |
| 117 | +``` |
| 118 | + |
| 119 | +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. |
| 120 | + |
| 121 | +## Filmbox (FBX) exports |
| 122 | + |
| 123 | +Same problems as in DAE section. Set axis to: |
| 124 | + |
| 125 | +``` |
| 126 | +Scale: 0.01 |
| 127 | +Forward: Y Forward |
| 128 | +Up: Z Up |
| 129 | +``` |
| 130 | + |
| 131 | +Then everything is exported as modelled. Imports into Blender again are working as well. |
| 132 | +Luckilly, the global scene transform is set to identity here. |
| 133 | +Maybe that is why the Import is working again: ignoring the scene transform is not important if its an identity transform. |
| 134 | + |
| 135 | +TODO: check if Gazebo importer ignores the scene transform |
| 136 | + |
| 137 | + |
| 138 | +## Building a 3D map from 2D building plan |
| 139 | + |
| 140 | +Using Blender Version 3.3.1 |
| 141 | + |
| 142 | +### Setting up a 2D Map as Reference image |
| 143 | + |
| 144 | +Make sure to be in Object Mode |
| 145 | + |
| 146 | +1. Click top right on the z-axis to make the view orthograhic top down |
| 147 | +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 |
| 148 | +3. Scale the Image to a size where you think you can work good with. The exact scale can be determined later. |
| 149 | +4. Enable Opacity of Image: Select Image and go to "Object Data Properties" (bottom right). Checkmark the Opacity Button |
| 150 | + |
| 151 | +### Modelling |
| 152 | + |
| 153 | +To place single vertices in the scene we first have to enable an Add-On under `Edit -> Preferences` called `Add Mesh: Extra Objects`. |
| 154 | +Then with Shift+A under the entry `Mesh` the option `Single Vert` should be available. |
| 155 | +Selecting `Single Vert` will place a single vertex in the origin and change to `Edit Mode`. |
| 156 | +A object should appear in the `Scene Collection` panel top right called `Vert`. |
| 157 | + |
| 158 | +1. Move the image so that the first vertex to set is in the origin |
| 159 | +2. Insert a single vertex. A new object should be created. The first vertex is placed in the Origin. |
| 160 | +3. Press `E` to extrude a vertex than click an endpoint to place the second vertex with an edge connecting both. |
| 161 | +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). |
| 162 | +5. Walls: Once you have created a contour of edges go to `Edge Select`-Mode select everything. Press `E`and then `Z` to extrude the edges along the z-axis. Pull the walls to a arbitrary height (The exact scale is determined later). |
| 163 | +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. |
| 164 | + - If Faces are getting to long: Cut Wall-Face in two by selecting in in `Face Select` Mode and then pressing Ctrl+R |
| 165 | + - 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`. |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | + |
| 175 | + |
0 commit comments