Problems loading the .material file


09-03-2013 09:57:43

Hello dear forum,

I am writing an Editor for a game in C# with Visual Studio 2012. This game uses .mesh and .scene files for its 3D graphics. With my editor, I want to be able to view these meshes together with their according materials.
First, I could successfully build my own MOGRE with the great MogreBuilder. I then imporpted the built Mogre.dll and the MogreTutorialFramework.dll (From the SDK) into my application. Of course I also copied all the necessary files (Plugins, *.cfgs..) in the folder of my programm and I am compiling for x86 in Release mode. The following function is being called with the Path to the .mesh file. The game requieres that in the same folder, there has to be a "Scene.material" file and the according textures.
void CreateRenderWindowFromResource(string resource)
//Create new Window
var window = new MogreFramework.OgreWindow();
window.Show(); //Show it

window.InitializeOgre(); //Initialize OGRE
//Set the Shadows
window.SceneManager.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_MODULATIVE;
window.SceneManager.AmbientLight = ColourValue.White;
//Add the folder where the mesh is dynamicly to the ressources
window.Root.AddResourceLocation(System.IO.Path.GetDirectoryName(resource), "FileSystem");
//Create the Entity itself
var mesh2 = window.SceneManager.CreateEntity("Custom", Path.GetFileName(resource));
//let it cast shadows
mesh2.CastShadows = true;
//Set the material from the Scene.material file
//Create a Node, scale it with factor 5 (because the models are sometimes really small
SceneNode node2 = window.SceneManager.RootSceneNode.CreateChildSceneNode("Custom");
node2.Scale(5,5,5); //5-Fach scalen
node2.ShowBoundingBox = true; //just a little gimick

node2.AttachObject(mesh2); //Atach the mesh to the node


However, all I get when loading a mesh is this:

It doesn't load the textures or cast any shadows.
The Scene.material files of that mesh looks like this:
material Airship
receive_shadows on
cull_hardware none
ambient 1.000000 1.000000 1.000000 1.000000
diffuse 1.000000 1.000000 1.000000 1.000000
specular 0.153002 0.153002 0.153002 1.000000 12.500000
emissive 0.000000 0.000000 0.000000 1.000000
texture airship_uv.png
tex_address_mode wrap
filtering trilinear

And as you can see from the filesystem tree in the editor in the left, the textures ARE there.
Another example. It's a textureless sword mesh. It gets displayed this way:

But every common editor (here e.g. MeshEditor) shows it this way:

What am I doing wrong here?


23-03-2013 06:51:59

A material name is not the same as a filename. A single .material file could contain any number of materials. The actual name of the material is what appears to the right of the word 'material' in your Scene.material file. In your case that is 'Airship'.

Usually, the .mesh file will already have the correct material name applied to it, so you may be able to completely remove this line:

//Set the material from the Scene.material file


26-03-2013 12:18:16

I've seen this problem before. Switch your application to neutral (invariant) culture info. I had a similar problem when my system (german setup) was using a different decimal point (comma) than the files (point).

Invariant: 1,000.0
German: 1.000,0

The problem is that a value of 1.0 would be interpreted as 10 if the culture info to parse the file is not correct.


22-05-2013 19:08:22

Sorry for resurrecting such an old thread, but I really need your help. None of the things suggested here worked, neither removing the line where the material is set nor changing the culture info to neutral. However, I do have some new information for you, the Ogre.log. Here's what it looks like when I try to load the Airship's Graphics.mesh:
18:42:13: Finished parsing scripts for resource group General
18:42:13: Parsing scripts for resource group Internal
18:42:13: Finished parsing scripts for resource group Internal
18:42:13: Added resource location 'C:\Users\Maxi\Downloads\openclonk-snapshot-20130225-f727c2eca0-win32-amd64-mingw\temp\Objects.ocd\Vehicles.ocd\Airship.ocd\Airship3DGraphics.ocd' of type 'FileSystem' to resource group 'General'
18:42:13: Added resource location 'C:\Users\Maxi\Downloads\openclonk-snapshot-20130225-f727c2eca0-win32-amd64-mingw\temp\Objects.ocd\Vehicles.ocd\Airship.ocd\Airship3DGraphics.ocd\airship_burnt.png' of type 'FileSystem' to resource group 'General'
18:42:13: Added resource location 'C:\Users\Maxi\Downloads\openclonk-snapshot-20130225-f727c2eca0-win32-amd64-mingw\temp\Objects.ocd\Vehicles.ocd\Airship.ocd\Airship3DGraphics.ocd\airship_uv.png' of type 'FileSystem' to resource group 'General'
18:42:13: Added resource location 'C:\Users\Maxi\Downloads\openclonk-snapshot-20130225-f727c2eca0-win32-amd64-mingw\temp\Objects.ocd\Vehicles.ocd\Airship.ocd\Airship3DGraphics.ocd\Scene.material' of type 'FileSystem' to resource group 'General'
18:42:16: Mesh: Loading Graphics.mesh.
18:42:16: Skeleton: Loading Airship.skeleton
18:42:16: WARNING: Graphics.mesh is an older format ([MeshSerializer_v1.40]); you should upgrade it as soon as possible using the OgreMeshUpgrade tool.
18:42:16: Can't assign material Airship to SubEntity of Custom because this Material does not exist. Have you forgotten to define it in a .material script?
18:42:16: Texture: spot_shadow_fade.png: Loading 1 faces(PF_R8G8B8,128x128x1) with hardware generated mipmaps from Image. Internal format is PF_X8R8G8B8,128x128x1.
18:42:19: DefaultWorkQueue('Root') shutting down on thread main.
18:42:19: *-*-* OGRE Shutdown

Now here it says that it couldn't assign the material to the Submesh, because the Materialdoes not exist o_O. However, as you can see at the lines above, I included the Scene.material file to the ressources, as well as the whole folder and all the textures. Yet, is says the material does not exist?
I did a bit of research and the stumbled across a thread which states:
Materials found in resource paths aren't parsed (and therefore available) until after you call Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(). The init call needs to be after resource locations have been added but before creating entities that use those materials.
So I have to parse / initialize them before they can be used? How can I do that within Mogre that I can dynamicly add a .material file, then parse / initialize it sothat the material becomes available to be used on meshes? I'm really getting desperate here, but I feel that I've gotten a few steps closer to the solution.


27-10-2013 14:23:46

Sorry for my late answer.

How can I do that within Mogre that I can dynamicly add a .material file, then parse / initialize it sothat the material becomes available to be used on meshes?
In common case all material files are already created, when you start your Mogre application.
So you add all directories with resource files to the resource.cfg file. Ogre/Mogre looks to the files to find out, which material names, image files, etc. are defined.
The content of all materials will not be stored in the memory, just a "reference" by name. So don't worry if you have a huge amount of media files. Ogre/Mogre will load it, when it need it.

If you want to create materials on-the-fly, it's no problem. I did such things by code.
A tiny example I added to the wiki: (first block of code)
I suppose you also can load additional files even on runtime. In this case I would search for related methods in the Ogre class reference (e.g. Ogre::Resources, Ogre::ResourceGroupManager, Ogre::MaterialManager). Alternatively ask in the Ogre main forum, because there are many active users and the content is the same for Ogre and Mogre.