Blender to Ogre        

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.

  1. In Blender
    1. 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]
    2. 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.
    3. Now select UV/ImageEditor mode in the second window. Image → Open and Load(MMB) any texture from your ogrenew/samples/media/material/texture directory.
    4. 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.
      1. Change the Select mode in the 3D view Edit window to FACE
      2. Select a single face in the EDIT window
      3. Move to the UV window and press G to move that face away from the rest
      4. 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.
      5. 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.
      6. Now goto the UV/image editor window and press AKEY twice. It should select all your faces.
      7. Press S to scale your faces up or down until they fit within the grid (or your image).
      8. 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.
    5. Move to the 3d View window and press Alt + Z and you will now see the textured object.
    6. 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.
    7. 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.
  2. Blender Quick Tips
    1. 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.
      1. Make sure this option is not set before exporting the file as explained below.
    2. 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 have had trouble in the steps above, please post your problem to the BlenderArtists Modeling or Texturing forum accordingly.

  1. In Blender: Exporting the file
    1. File → Export → OgreXML and select Game Engine Material.
    2. Export
    3. 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.

  1. Out of Blender
    1. 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.
    2. 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)
    3. Specify in the "resources.cfg" file where to find everything (or leave it as is and do the following two steps).
    4. Now copy Cube.mesh into the /models folder (somewhere under your "ogrenew" folder). Copy Scene.material to /material/scripts/ folder.
    5. Copy "your texture" to /material/texture/ folder, if you applied some other texture other than those supplied with Ogre.
    6. 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:
      1. Cube.mesh is found using "resources.cfg"
      2. 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"
      3. Scene.material applies our texture which is also loaded using "resources.cfg" (as you can see: "resources.cfg" is essential).
    7. 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