If you don’t know anything about 3D modelling (like me) and you directly install and open Blender to play with, you will spend a lot of time with little or none profit. There are many websites with Blender online tutorials and videos. If you are using the graphic engine Ogre, I recommend to start reading this.
In this post, I will explain how to create a very simple model, export it to the Ogre format, and check it with an external tool. Prerequisites: you need Blender and its Ogre exporter addon installed.
Take into account that a real time game engine needs to precompute as many things as possible. Therefore, surfaces are not suitable for using them in real time, and only meshes can be exported to Ogre. However, it is possible to work with surfaces, if the final result is converted to meshes prior to the exportation.
During the installation process, the exporter must be configured to work with some Ogre command-line tools, because the exporter will create an XML file (with a name ended in .mesh.xml) for each mesh with all its data (e.g. vertices and normals), and this XML mesh file must be compiled into a binary mesh file (with a file name extension .mesh) for run-time loading and usage.
I am a complete Blender noob, but I will try to clearly explain how to model the Earth and export the scene for using it with Ogre. These steps were obtained after applying reverse engineering to this Youtube video:
Watch the video and use the following instructions:
- Open Blender 2.65. Optional: at the upper area, click and drag at right bottom corner, so you can divide the upper client area into two halves. The right half may be switched to the UV/Image Editor with editor type switch at the bottom left. Note that with F12, it is possible to render the scene and see the final result in the right half. At the lower client area switch to the UV/Image Editor, too. We will use this are when editing the UV Map.
- Remove the cube at the left panel in Object Mode with the DEL.
- Create the sphere. Go to the Add menu > Mesh > UV Sphere. A new sphere should appear where the Blender cursor is.
- Parametrize the sphere. At the left, a new section Add UV Sphere, below the Object Tools section, contains the settings to parametrize the object. In this case, I need a mesh with a high resolution for looking at it from a closer point of view, with the sun light showing the day and night cycle.
In order to avoid jagged borders in the illumination set:
- The number of segments to 128.
- The number of rings to 64.
- Size 0.5, because I want a diameter of 1.0.
- Make sure that the position is (0.0, 0.0, 0.0).
- Set the object name to Earth. Your scene should look similar to this one:
- Add material. Go to the right tool box with the properties and click on the material tab:
- Add a new material.
- Change its name to EarthMaterial.
- Now, switch to the texture tab.
- Add a new texture.
- Change its name to EarthTexture.
- Change its type to Image or Movie.
- Find the open button below and browse for the image texture.
- Scroll down to Mapping. Change the projection to UV and leave the projection as Flat. This means that we will create the UVMap manually. It is mandatory to create a UV map for explicitly tell to Ogre how the texture is mapped on the sphere surface.
- The texture is associated to a given path. Therefore, if it is removed from the current location, the material will be broken. To avoid this situation, it is possible to pack the texture. Go to the lower client area and select the texture image instead of the render result. Click on the Image menu and select Pack Image. Save the scene in Blender format as a checkpoint.
- Go to the 3D View, switch to Edit mode, and rotate Earth until one of the poles is clearly visible.
- Select at the Mesh Tools box from the right the Loop Cut and Slide tool. Cut between the last ring and its previous one.
- Slide the cut until you almost touch the last ring.
- Press ALT+RMB (right mouse button) on the old ring, not the new one we have just created using the Loop Cut and Slide tool, to select it.
- Press SHIFT+RMB on the pole vertex for adding it to the selection.
- Change the pivot point to the active selection, which should be the pole vertex.
- Press S, to scale the old ring and shrink it as much as possible.
- Repeat steps 8 through 14 for the opposite pole vertex.
- Now, we are going to unwrap the sphere, and our first step is to define the seam used for cutting the object surface. Use again ALT+RMB on a segment to select it.
- Press CTRL+E and select Mark seam. Note that one everything is deselected, pressing A, the segment color has changed to red.
- Change viewport shading to texture mode.
- Change to select faces, right click on a adjacent face to the seam. Press A to select all faces. Finally, press U to open the UV unwrap menu. Select Follow Active Quads.
- Make sure that your texture image is visible in the lower area. Note that the cursor is at the left bottom corner. Don’t touch it, from now on, you are only allowed to use the MMB (middle mouse button) to pan 🙂 .
- Press A to select all the quads. In this particular case, we need to rotate the quads -90º. Press R, type -90 and press enter. Use only keys S and G to scale and translate the quads. If you want to scale only using the X or Y axis press S and then X or Y, respectively. Remember to use only the MMB to pan, and the mouse wheel to zoom, do not use the other mouse buttons.
- Match the left bottom corners of quad mesh and texture.
- Change the rotation and scaling pivot to 2D Cursor.
- Do the same for the right top corner, and the UV mapping will be almost complete.
- So far, we have mapped every sphere quad to the texture. However, do you remember the “old ring” that we shrink to the pole vertex? The ring and the pole vertex are joined with triangles, not quads. Therefore, these triangles were not included in the UV mapping and we should fix this. Rotate and translate the sphere to make the pole vertex visible. Make sure that vertex selection mode is on. Press CTRL+LMB and draw a circle for selecting the small ring surrounding the pole.
- Press SHIFT+RMB on the pole vertex for adding it to the selection.
- Press ALT+M to merge vertexes At Last. Make sure that every vertex of the ring is selected like in the following picture. You may need to scale the sphere and press CTRL+MMB moving the mouse in order to place as close as possible the pole vertex to the screen.
- We are almost there! Any transformation made to the object will not be exported, unless it is explicitly applied to the object, because it is not really part of it. This concept is very similar to the Ogre scene hierarchy. Every entity is assigned to a scene node. This scene node may have one or more nodes in its path to the root node of the scene tree. The transformations of each node in this path define the eventual transformation of the leaf node. Therefore, an entity and its transformations (translation, orientation and scaling) are decoupled. In Blender, this is identical. The entity is our mesh, and the eventual transformations are our Blender transformations. In short, you must always apply the transformations made to the object before you export it, or they will be lost.
I placed my seam at the segment that crosses the Y axis. The reason is that I want to rotate -90º degreees using the X axis and make the Z axis cross near Africa and Europe, because Ogre uses a different orientation an the Y axis defines the up vector, instead of the Z axis used in Blender. Press R+X, type -90 and ENTER.
Switch to the Object mode. Press CTRL+A and apply location, rotation and scale, if needed.
- We are now ready to export. Go to File > Export > Ogre 3D.
- The generated files should be something similar to this.
- The Earth.mesh file can be checked with Ogre Meshy.
Note: Alternatively, you might also try using a PolySphere, since the spherical surface division into quads is much more regular. However, the unwrapping for building the UV mapping may be more complicated. PolySphere is included with the Extra Object Addon. It looks spheric without the subsurf and smooth shading.
You can enable the Addon via:
File > User Preferences > Addons > Add Mesh > Add Mesh: Extra Objects.
And then add a PolySphere via:
View 3D > Add > Mesh > Extra Objects > PolySphere.