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 4 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.
As always before, create a new project based. Use the guides in Lab 1 or 2 in-case you have forgotten.
You need to do the following to set up the right tools:
Follow these steps to complete the lab project:
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=../LabFiles/Models
). 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.Ogre::Entity* myModel = _sceneManager->createEntity("MyModel", "MyModelMesh.mesh"); Ogre::SceneNode* modelNode = _sceneManager->getRootSceneNode()->createChildSceneNode(); modelNode->attachObject(myModel); modelNode->setScale(50,10,50); // You may have to scale your object to see it well\\
_sceneManager→createEntity(“MyModel2”, “MyModelMesh.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: myModel->setMaterialName("BlueMaterial");
Sinbad.zip
in the folder “../OgreSDK/media/pakcs/”
. There are various files that are related to mr. Sinbad. Including a Material file, some textures and extra mesh for Sinbads swords._SinbadEnt→getSubEntity( number here )
0 -> Eyes. 1 -> Green Skin. 2 -> Jewelry, cuffs, belt buckle. 3 -> Teeth. 4 -> Sword Sheaths. 5 -> Accessory spikes. 6 -> Boots, Pants, hat, accessories color.
MyMaterial.material
and save it in a folder Materials
next to the Model folder.FileSystem=../LabFiles/Materials
to the resources_d.cfg
MyMaterial.material
material Sinbad/Body2 { receive_shadows on technique { pass { ambient 0.75 0.75 0.75 diffuse 1 1 1 1 texture_unit { texture my_sinbad_body.png } } } }
Materials
And now finally apply this mesh to the body of Sinbad, you can tweak the texture if that's your fancy :) // In the MyApplication::createScene function _SinbadEnt->getSubEntity(1)->setMaterialName("Sinbad/Body2");
Sinbad.zip
pack file, there was also a mesh for his sword sword.mesh
.Entity*
for each sword using the sword.mesh
as a mesh file.Ogre::Entity::attachObjectToBone(std::string boneName, Ogre::Entity* object); // Usage would be like _sinbadEnt->attachObjectToBone("OhMyBone", mySword);
(Briefly about bones: Bones are the logical structure of an animatable 3D object, bones are points of a skeleton that you can move, and assigned vertices will be transformed with the bones thus giving the illusion that the model has joints and movable limbs that follow a skeleton. Objects can be attached to those bones and they will be inserted to that bones transformation space.)
// Create a bone iterator. Ogre::Skeleton::BoneIterator biter = _Sinbad->sinbadEnt->getSkeleton()->getBoneIterator(); // Iterate over the available bones and write their names to the console. while (biter.hasMoreElements()) { Ogre::Bone *bone = biter.getNext(); std::cout << bone->getName() << std::endl; }
HandsRelaxed and HandsClosed
Upload your commented if necessary SOURCE files, no solution or project files please into Lab4 in MySchool (zip them up if more than one) also include the required files such as materials or mesh files.