Loading objects into MOGRE


05-03-2011 06:06:48

Hey MOGRE Community,

I've read the basic tutorials on MOGRE and have really found them to shed little to no light on my questions. Instead, they seem to take the "show you code and tell you that they'll explain it in detail later but never do" approach.
Here's my ultimate goal:

I want to be able to import a mesh file and attach it to an entity. This raises several questions:

What is the basic process of loading resources into MOGRE?

I've read the wiki post and I understand kinda the lifecycle of a resource, but can someone shed some more light on this for me?

Where do I go from there?

Where do I head after I load the mesh? There are so many different objects in MOGRE (Mesh, ManualObject, etc.), I'm a bit overwhelmed and I feel like I chicken without a head.
I'm assuming ResourceGroupManager, MeshManager and MeshSerializer have something to do with it.

From what I understand, after you create a mesh, you assign it a name with a string that is stored in some managing object. Then, you can use sceneManager to create an entity by loading the mesh name you assigned earlier. Am I correct?

If someone can answer this, can they provide code with this as well as an explanation of each line?

Thanks guys, you've been so helpful so far with my introduction into MOGRE. It's really hard to find MOGRE-specific documentation and I usually end up looking towards the OgreWiki for more information. Perhaps when I learn a little more, I'll be able to contribute as well.


05-03-2011 19:28:26

Add the location of the mesh to a resource group:
ResourceGroupManager.Singleton.AddResourceLocation([path/to/folder], "FileSystem");
Initialise the resource groups:
Create an entity from the mesh:
Entity e = this.sceneMgr.CreateEntity("MyEntity", [MeshFilename]);
Attach the entity to a SceneNode:
SceneNode sn = this.sceneMgr.RootSceneNode.CreateChildSceneNode("MySceneNode");

The demos load the resource locations from 'resources.cfg'. If you do the same, you can substitute step 1 and 2 by adding the mesh folder to that file or putting the mesh in one the already specified folders.


05-03-2011 20:07:35

Hey Smiley, thanks a lot. I have a couple of questions:

What is a resource group? Is it the directory where I define the resource location?

Do I have to call InitialiseAllResourceGroups every time I load in a resource? What exactly does that do?

How do I load in a single resource?

Also, I saw you showed me how to get from mesh to entity, but how can you get from resource to mesh? I think there's a step missing from part 2 and 3 (or maybe I'm wrong if InitialiseAllResourceGroups does that).

Thanks again.


05-03-2011 21:30:32

What is a resource group?

It's a collection of files.
The above 'AddResourceLocation' puts the files of the specified folder into the default resource group.
Usually with resource related methods, you have to specify a resource group, e.g.:
MaterialManager.Singleton.Load("MyMaterial", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);

Do I have to call InitialiseAllResourceGroups every time I load in a resource? What exactly does that do?

You only have to call it once, after you've added all resource locations for all resource groups.

How do I load in a single resource?

Firstly, you have to declare the resource. That's done by adding the folder with 'ResourceGroupManager.AddResourceLocation' or the single file with 'ResourceGroupManager.DeclareResource' (never used that one).
Then you intialize the resource group. ResourceGroupManager.InitialiseAllResourceGroups or ResourceGroupManager.InitialiseResourceGroup(NameOfResourceGroup).

Now, you can use the 'Load' method of the appropriate resource manager to receive a pointer to that resource:
MeshPtr mesh = MeshManager.Singleton.Load("MyMesh.mesh", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
But you can't use that MeshPtr directly to create an Entity.


06-03-2011 01:16:22

Thanks smiley, you've been a great help.

As you said, you haven't used declareResource. I'm having a bit of trouble with it. Could you point me to any articles cause I can't seem to find documentation.


06-03-2011 03:01:42

Forget what I said about 'DeclareResource', you have to use 'AddResourceLocation' with the folder of the mesh.


06-03-2011 04:22:57

Is there any way I can just add a single resource?

Can I use OpenResource? What does DeclareResource do?


06-03-2011 14:27:59

Kwang1imsa, welcome to Mogre. :D

It's nice to see that you read our tutorials and give a feedback about the newcomer problems.
Now I got the idea to create a wiki page which explains some basics.

Ok, I try to explain it a little bit.
Here is an overview of classes which inherit from the abstract class MovableObject. Most of them are for display something.

If you want to learn more about this classes, have a look to the Ogre Class Reference, which describes the classes and shows the class members (e.g. functions). Here is the page from where I got the graphic. Just click onto a "block" in the graphic (e.g. Ogre::Entity) and your browser will load the related page of the class reference.

Well, now a little bit more practical notes for some important classes:

There are different kinds of resource files. 3D objects you call Mesh.

When you want to load a Mesh, you create an Entity which loads the 3D information of the Mesh.

When you want to create a visible object by code then use ManualObject.
This is fine for creation of lines, triangles, boxes, or any other shapes. You can even create very complex 3D objects with several faces, textures, etc.

To make visible a Mesh, ManualObject, etc. you attach it to a SceneNode.
By "help" of the SceneNode you can scale, move, rotate and hide the attached objects.

It's just a "helper class". Ogre use it internally to load the content of a mesh file. By this class it's also possible to save 3D models from the memory to a file. Common users don't need to care about this class.

Now I try to explain how to load 3D objects:
Ogre needs to know where to search for "resource" files.
By default the user define the paths in the file resources.cfg.
Alternatively it can be done by code as smiley80 said.
The ResourceManager of Ogre keep them all in mind.
When the user (programmer) want to load a 3D object from a file, he doesn't need to know the directory of the file. He just tell the name (e.g. myModel.mesh) to the resource manager.
If you have mesh files with the same name, you have 2 choices: Make the file names unique (this I recommend) or use different resource groups for different mesh files. (e.g. for each directory which contains mesh files)

When a 3D object contains materials or textures, then this information is not inside the mesh file. Materials and textures are stored seperately. The mesh file just contains it's name as a reference (e.g. "myRedMaterial"). Material files and texture files are loaded similar to the mesh files. When a Mesh "needs" a material, it just asks the MaterialManager (a "helper" of the ResourceManager) for the material with the specified name (e.g. "myRedMaterial") and then it will be loaded. Important is to keep the material names unique to avoid conflicts.

The name of material files doesn't matter. Ogre just look to the names, which are defined inside the material files. (A material file can contain several material definitions.)

Note 2:
I use Blender for creating mesh files. Inside of Blender I rename the default material names (e.g. "red.001") to a unique name (e.g. "myVehicleName_red"). To be shure it's unique, you can also add a random ID to the material name (e.g. "myVehicleName_red__825103").

Note 3:
You were confused about the different Managers.
The SceneManager is responsible for managing all objects, which are loaded to a scene. It's position, visibility, etc.
The ResourceManager is responsible for loading and handling different types of resources. It has several specialized "helpers". See the picture below:

I hope now you understand this part of Ogre a little bit more.
If something is unclear, just ask.
If something is wrong, please correct me. :wink:


06-03-2011 15:10:24

In the wiki I found 2 very interesting pages:
  1. Resources and ResourceManagers - Outlines in detail the process by which resources are loaded, unloaded, reloaded and destroyed. [/*:m]
  2. Manual Resource Loading - How to load your data without using Ogre's file format.[/*:m][/list:u]


06-03-2011 17:01:26

Wiki work is time killing.
I created a new wiki page and added the content of my post.
Although it's mostly copy&past of my post it tooks one or two hours for the fine details.
Basic knowledge about Resources
If there are mistakes, please correct it.


06-03-2011 20:35:46


This is great, thanks for clearing up so much stuff. For me, I really need to get a good grasp of how OGRE fundamentally works before I can understand more.

So I'm guessing there's no way for me to actually load in 1 single resource?


06-03-2011 20:45:53

Oh, also, if I call addResourceLocation() and I want to use InitializeResourceGroup(), what do I enter in for parameter "name"?

Edit: Nevermind.


07-03-2011 02:07:51

I couldn't find a method with the name InitializeResourceGroup(). There is nothing in the Ogre class reference.
Maybe you mean a similar name?

Related to ResourceGroupManager::addResourceLocation() look to the Ogre class reference:
http://www.ogre3d.org/docs/api/html/cla ... f5f8df7849

If you need information about a method or class, you can search like this.
Add the wanted name to Google and additionally add the search keys ogre reference. Then you should find the related pages quickly.