This is a small tutorial on how to use the Blender Exporter script to use your textured models created with Blender in Ogre. This document works with Ogre 1.06 and newer and Blender 2.49b.
The procedure will be same on any Operating System because all programs used are cross-platform.
- In Blender
- In Blender, press TAB to enter EDIT mode, scale up your cube. Make a wall, a fort or anything. Make sure the cube is selected. [note: if you do scaling in object mode you must Object->Clear/Apply->'Apply Scale/Rotation to ObData' or else the scale will not export to Ogre properly]
- Move your cursor to the upper boundary till you see a two sided arrow. Right click, left klick on Split Area and afterwards determine the size of the second window by another left click.
- Now select UV/ImageEditor mode in the second window. Image → Open and Load(MMB) any texture from your ogrenew/samples/media/material/texture directory.
- Within the 3d view Edit window, press UKEY and Select Cube Projection or anything that suits you. Unwrap (smart projections) is often the best option.
- Change the Select mode in the 3D view Edit window to FACE
- Select a single face in the EDIT window
- Move to the UV window and press G to move that face away from the rest
- Select each face one at a time from the 3D view and move it in the UV image editor so that they do not overlap, but are reasonably connected, ie a t for the cube. (It doesn't need to be a t, you can make any shape you want, even overlapping or separate. The faces take the texture of the image beneath them.) You can also rotate etc the faces.
- Once you have them basically where you need to be, goto the 3D view and select all the faces with AKEY. You might see the faces are overlapping correctly or not touching etc. Move to the UV window and press AKEY again; they will deselect but still be there. Select one vertex of an incorrect face, then press Select -> Linked Uvs (or press CTRL-L). Now use GKEY to move the face precisely where it needs to be. Repeat with each face to place precisely.
- Now goto the UV/image editor window and press AKEY twice. It should select all your faces.
- Press S to scale your faces up or down until they fit within the grid (or your image).
- To verify you have done this correctly, you should see 6 separate squares in your UV window. Each time you click on a face in the 3D view Edit window, one of the squares in the UV window should highlight and the rest disappear.
- Move to the 3d View window and press Alt + Z and you will now see the textured object.
- If the texture is not facing the correct direction, go back to UV/Image Editor and move the appropriate faces so the texture looks correct on your object.
- If your model look jolted in Ogre press Ctrl + A in the Object Mode. The point is that Blender does not have all the mesh data transformed/rotated/scaled as you would presume by having a look at the screen. Therefore, before exporting you have to tell it to actually apply all the mesh changes (that you can already see in Blender) to the actual data that will get exported.
- Blender Quick Tips
- If you would like to render the object in Blender, be sure to press F5 and then click on the "TexFace" option in the "Material" panel at the bottom of the screen first.
- Make sure this option is not set before exporting the file as explained below.
- If you are unsure how faces in the 3D View correspond to those in the UV/Image Editor, use a test pattern image as a texture (such as the one in this tutorial).
- If you would like to render the object in Blender, be sure to press F5 and then click on the "TexFace" option in the "Material" panel at the bottom of the screen first.
If you have had trouble in the steps above, please post your problem to the BlenderArtists Modeling or Texturing forum accordingly.
- In Blender: Exporting the file
- File → Export → OgreXML and select Game Engine Material.
- Export
- Quit Blender. Just now you exported Cube.mesh.xml and Scene.material. Cube.mesh.xml is the Mesh itself and Scene.material contains the name of the texture applied and how it is applied. Where textures are stored is set in the resources.cfg file (/material/texture). Models are stored in /models, .material scripts in /material/scripts.
- Out of Blender
- Open up the Terminal (on Windows it's called Command prompt) and type "OgreXMLConverter Cube.mesh.xml". Press Enter. Your xml file has been converted to Ogre's .mesh format.
- Now you have Cube.mesh (which is the Mesh itself) and a Scene.material (which contains the name of the texture applied to Cube.mesh)
- Specify in the "resources.cfg" file where to find everything (or leave it as is and do the following two steps).
- Now copy Cube.mesh into the /models folder (somewhere under your "ogrenew" folder). Copy Scene.material to /material/scripts/ folder.
- Copy "your texture" to /material/texture/ folder, if you applied some other texture other than those supplied with Ogre.
- Open your working Ogre program and replace robot.mesh with Cube.mesh in your createEntity() function. When you change the line, the following happens during loading:
- Cube.mesh is found using "resources.cfg"
- Cube.mesh has a refernece to Scene.material (name of associated .material file is written inside Cube.mesh) and will be loaded using "resources.cfg"
- Scene.material applies our texture which is also loaded using "resources.cfg" (as you can see: "resources.cfg" is essential).
- Run your application.
You should now see your textured object loaded. If you have had troubles in these steps, please post your problem to The Ogre 3D Forums.
Alias: Blender_to_Ogre