Ogre importer: Fix for material sharing#477
Conversation
|
Looks fine to me, merging |
|
Whats the purpose of sharing the material? It doesn't accelerate rendering, the size of the material data is negligible because all referenced data like textures and material definitions are shared anyway and this change will cause all instances of the material to be changed when you change one (e.g. you want to tint one model blue and the other red)? |
Batching, instancing, everything that need shared materials to work.
This is the expected behaviour for shared materials, if you don't want it, just clone your material like you would do in any other software. |
|
I think you two have a misunderstanding. |
|
Batching and instancing look for the actual parameters, so even if the material is not the same object - if the parameters are the same they will be batched. |
|
Yes, but the point is that if the imported file specifically has shared materials then the user probably did that for a reason and we shouldn't undo it. Anyway, MPOs sort of get rid of the last reason to leave them shared. |
This is not the impression i have from the code.... |
|
In the second case, normen's comment is true... see: But yeah, InstancedNode is not as nice this way. |
|
There are way more reasons than just batching. For example a scene of a house, with 3 different textures(atlas) that can be changed by simply switching the diffuse in the material. |
Fix for the issue reported here: https://hub.jmonkeyengine.org/t/ogre-importer-materials-are-not-shared/35663
Short description of the problem:
We have an Ogre's .scene with two spatials that share the same material.
When this scene is imported in the engine, the two spatials no longer share the material but, instead, they own a new instanced of it.
This happens because the SceneLoader loads the objects through the assetManager as if they were unrelated, the assetManager calls clone(true) on the cached models before returning them, this cause the issue.
This patch loads the models directly with an instance of MeshLoader opportunely extended to have an internal cache that is preserved until the scene is fully loaded.