User Tools

Site Tools


LAB3: Resources

This lab is only losely based on Chapter 6 on resource management in the text book. The focus here is on being able to create a new resource (a 3d model) and bringing it into an Ogre 3D scene.


Discussion thread for this lab is here: Lab 3 Discussion Thread


The primary goal with this lab is to go through the process of creating an original external resource (a 3D model in Blender) and bringing it “unharmed” into an Ogre 3D scene. The secondary goal is to gain familiarity with the Ogre 3D “mesh” and “material” file formats.


You need to do the following to set up the right tools:

  • Download and install the Blender 3D modeling and rendering environment, use the latest version (2.65)
  • Install the Blender2Ogre Plug-in for Blender 2.65 and above
    • Download the file (if you use Blender 2.65)
    • Run Blender and from File→User Preferences… choose the Addons panel and click the Install Add-On button. Navigate to and select your downloaded ZIP archive.
    • Once Blender has processed the ZIP file you should see the exporter listed, but grayed out. Check the check-box next to it to activate it.
    • Now you can run the exporter from the Blender File→Export menu (pick the Ogre 3D export) and make sure that the object you want to export has been selected in the 3D scene.
  • Make sure that the OgreXMLConverter.exe (or OgreXMLConverter_d.exe) that comes with Ogre is in your executable system path, you will find this tool inside your Ogre bin\Release (or bin\Debug) folder

Lab Project

Follow these steps to complete the lab project:

  1. Create a New Project Create a new empty project called “Lab3” in the same solution as the previous lab project and copy your source files over there (make sure you copy them in the file system and don't just drag them around in the solutions browser, because by default the browser creates a symbolic link to the original file instead of copying). Rename source files as necessary. Unfortunately you'll have to review the configuration properties again for this project (see the instructions for Lab1), it is quite silly that those can't easily be copied between projects. After this step is done, you should have a new project that compiles and runs (and does the same thing as the previous lab). Make this new project the ACTIVE PROJECT my right clicking on it in the solutions browser and selecting Set as StartUp Project
  2. Create a custom Model Folder Go to the folder where your compiled executables end up (e.g. in the solution's Debug folder) and create a sub-folder called Models. In order for this folder to be found by your Ogre application, you need to add it to the list of FileSystems in your application's resources_d.cfg file. You can use a relative path (e.g. FileSystem=Models).
  3. Create a 3D Model in Blender If you are completely new to Blender, then you can even just use the default cube you get when you start up the Blender environment. However, you should try to modify the cube a little bit if you can. There are a lot of good resources on Blender modeling, including the Official Getting Started tutorials out on the Internet.
    • It is a good idea to save your model in the Blender file format early and often
    • Pay attention to what you name your geometry, this becomes the name of the exported mesh. You can browse your object hierarchy in the upper right corner of the Blender screen. Right-click on the cube mesh node and select Rename to give the mesh a different name.
  4. Export and Convert Model Export the model using the Blender2Ogre exporter and save it in your application's Models folder. Make sure that any texture imported, baked or generated is saved as a file in the same folder. Run the OgreXMLConverter command line tool on the exported XML mesh file to turn it into a binary Ogre mesh file
  5. Create a New Entity In your createScene method in your application, you should now create a new Entity that gets associated with the model resource you just created. Make sure that your code makes this new Entity visible in the scene by attaching it to the scene graph.
    • In C++ it would look like this:
      Ogre::Entity* mycube = _sceneManager->createEntity("MyCube", "MyCubeMesh.mesh");
      Ogre::SceneNode* cubeNode = _sceneManager->getRootSceneNode()->createChildSceneNode();
      cubeNode->setScale(50,10,50); // You may have to scale your object to see it well\\
  6. Play with Mesh File Open up your exported mesh XML file and make sure you understand its structure. Try changing values inside it and observe the changes in your Ogre application, but remember to run the OgreXMLConverter again!
  7. Play with Material File Notice that inside the XML file the submesh refers to a Material by name, find the corresponding *.material file in your model folder (it got exported along with the mesh XML file) and read through it. This is the material that Ogre reads in along with the mesh. Try changing values of the material (e.g. the diffuse values) inside the exported material file and observe the changes in your Ogre application (you do not have to run the OgreXMLConverter again for this, the material is already in the right format)
  8. Create more Entities Create more entities from the same mesh, but assign different materials to them. Note that you can still use the _sceneManager→createEntity(“MyCube2”, “MyCubeMesh.mesh”); method. The resource manager is clever enough not to load the model twice from disk. Create a new material inside the same material file you looked at earlier, by copy-pasting the material definition within the same file and changing its name (e.g. into BlueMaterial) and give it different values (e.g. making the diffuse color blue). Aassign the new material to a new entity in your Ogre application with the setMaterialName method like this:

When You Are Finished

Upload your commented source files into Lab3 in MySchool (zip them up if more than one). The lab projects will not be graded, but their completion counts towards your participation grade.

/var/www/ailab/WWW/wiki/data/pages/public/t-gede-13-1/lab3.txt · Last modified: 2013/01/29 15:31 by hannes