Skip to main content

History: Basic knowledge about Resources

Source of version: 3

Copy to clipboard
            Currently this is "no professional" page. 
It contains some __basic information__, wich were replied to questions of an __Ogre newcomer__ in the forum ([http://www.ogre3d.org/addonforums/viewtopic.php?p=79569#p79569|here]).
The question was how to load resources and what's the difference between the many related Ogre classes (e.g. Mesh, ManualObject, ResourceGroupManager, MeshManager, MeshSerializer, ...).


!!Basics

Here is an overview of classes which inherit from the abstract class ((-MovableObject|MovableObject)). Most of them are for display of something.
{img fileId="2020"} 

If you want to learn details about specific classes, have a look to the [http://www.ogre3d.org/docs/api/html/index.html|Ogre Class Reference], which describes the classes and lists the class members (e.g. functions). [http://www.ogre3d.org/docs/api/html/classOgre_1_1MovableObject.html|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:

__Mesh:__
There are different kinds of resource files. 3D objects you call ((-Mesh|Mesh)).

__Entity:__
When you want to load a Mesh, you create an ((-Entity|Entity)) which loads the 3D information of the Mesh.

__ManualObject:__
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, ((-Texture|textures)), etc.

__SceneNode:__
To make visible a Mesh, ManualObject, etc. you attach it to a ((-SceneNode|SceneNode)).
By "help" of the SceneNode you can scale, move, rotate and hide the attached objects.

__MeshSerializer:__
It's just a "helper class". Common users don't need to care about this 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. 


!!How to load resources

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. ...... TODO: Add code snippets?''

The __ResourceManager__ of Ogre keep them all in "mind".
When the user (programmer) wants 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 ((-Material|materials)) or ((-Texture|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.

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

Note 2:
I use ((Tools: Blender|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 are 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:
{img fileId="2018"} 

''This page was originally written by user ((user:Beauty|Beauty)) in March 2011.''
''If you want do modify the content, just do it.''


!!See also

* ((Resources and ResourceManagers)) - Outlines in detail the process by which resources are loaded, unloaded, reloaded and destroyed. Shows how to create a new resource type, and a manager to go with it
* ((Basic Tutorial 1)) - An introduction to the most basic Ogre constructs: SceneManager, SceneNode, and Entity objects.
* ((Tutorials)) - Many useful tutorials, especially for beginners


        

History

Information Version
Mon 18 of Aug, 2014 22:38 GMT-0000 waterstar 10
Mon 15 of Oct, 2012 15:02 GMT-0000 SerialVelocity Fixed syntax errors. 9
Sun 05 of Aug, 2012 05:11 GMT-0000 fsxfreak 8
Fri 27 of Apr, 2012 01:20 GMT-0000 fsxfreak fix c++ syntax errors 7
Sun 31 of Jul, 2011 22:58 GMT-0000 jacmoe 6
Sun 06 of Mar, 2011 17:07 GMT-0000 Beauty added details about Entity ...... (Thanks to a tutorial of MadMarx) 5
Sun 06 of Mar, 2011 16:57 GMT-0000 Beauty added code snippets ........ PLEASE CHECK if the C++ code is CORRECT. I ported it from C# and I'm not shure if it's right. .... maybe "attachObject(e)" needs an AND "&" Symbol?? 4
Sun 06 of Mar, 2011 16:46 GMT-0000 Beauty replaced first picture by a modified one ... (now the with is ~150px smaller) 3
Sun 06 of Mar, 2011 16:27 GMT-0000 Beauty added pictures 2
Sun 06 of Mar, 2011 16:18 GMT-0000 Beauty NEW PAGE 1