ResourceManager and Material Names

fletch27502

17-05-2010 19:00:59

I have a need to dynamically load mesh files together from a collection of scene files. The artist that we work for ocassionally use the same material names in different scene files, so I was thinking that I would try to setup up a material naming scheme that would handle the material name collisions. My first thought was to change all of the names so that I was in control of the names instead of the artist. Has anyone attempted to do something like this when bringing in multiple scenes? Is there an option inside of (M)ogre to deal with this situation?

TIA,
Scott

mstoyke

20-05-2010 00:04:31

The best way to deal with that is some kind of replacement table where you define, maybe based on scene name and material name, which name to use to replace it to get a unique mapping. Simplest solution it can think of is some kind of SCENENAME_MATERIALNAME as the new material name. Then I would write a small batch script that will automatically replace the names in the models (I think there is some kind of tool available that already provides this kind of functionality) and rename the materials in the material file for that scene. You might also just replace the material name at runtime in the loaded models (iirc all you need to do is to set another materialname in the entity or was it the mesh or node? I think you get the idea)

OR

If you only need to use one scene at a time then it might be easier to just put every scene with its related resources and material files into another folder and define resourcegroups in ogre that can be loaded/unloaded (more precisely initialzed/parsed/loaded -> unloaded/uninitialized) whenever you change the scene. Just make sure to unload all resources for the old scene before you switch resourcegroups and load the new scene. This latter case already worked well for me in the past, but it's no help if you need more than one scene be active at the same time.

fletch27502

20-05-2010 13:15:38

"You might also just replace the material name at runtime in the loaded models"

This is exactly the approach that I would like to take.

I thought I would need to do the following.
1. When the .material file was parsed I would change the names and keep a map of <artName,runtimeName> on a per scene basis. Using something very similar to the approach you mentioned runtimeName = sceneName+artName. artName being the exported material name.
2. When the scene is loaded use the map to set the Material properties of the entity.

I understand how to do #2, but could use some help with #1. Is there a way to deal with parsing the material file without writing an entire material parser? Seems like we used to have some code that checked for duplicate names, but I'm not sure how that worked.

TIA, Scott

mstoyke

20-05-2010 17:56:29

I don't know if this is easily possible, but my first attempt would certainly be to look at the material manager to see if there is an easy way to rename materials in the manager after they are loaded/parsed.

The more quick-and-dirty approach would be to read the material files before starting the engine, replace the material names and write them back to another file, maybe in a temp folder. You might have to write a very simple "parser" that will only find the names to replace, no need to write a full blown material parser to replace the original one here.

Or go the hard way and modify the sourcecode of ogre so the material parser will use a table to look up replacements in the existing material parser instead of using the defined name as-is. Downside here is, it will only work with this modified version but I assume that won't be a problem for you.