Merge pull request #477 from riccardobl/fix_topic35663_issue
Ogre importer: Fix for material sharing
This commit is contained in:
commit
2c1fd47a67
jme3-plugins/src/ogre/java/com/jme3/scene/plugins/ogre
@ -71,6 +71,7 @@ public class SceneLoader extends DefaultHandler implements AssetLoader {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(SceneLoader.class.getName());
|
||||
private SceneMaterialLoader materialLoader = new SceneMaterialLoader();
|
||||
private SceneMeshLoader meshLoader=new SceneMeshLoader();
|
||||
private Stack<String> elementStack = new Stack<String>();
|
||||
private AssetKey key;
|
||||
private String sceneName;
|
||||
@ -99,6 +100,7 @@ public class SceneLoader extends DefaultHandler implements AssetLoader {
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
meshLoader.reset();
|
||||
elementStack.clear();
|
||||
nodeIdx = 0;
|
||||
|
||||
@ -299,8 +301,12 @@ public class SceneLoader extends DefaultHandler implements AssetLoader {
|
||||
entityNode = new com.jme3.scene.Node(name);
|
||||
OgreMeshKey meshKey = new OgreMeshKey(meshFile, materialList);
|
||||
try {
|
||||
Spatial ogreMesh = assetManager.loadModel(meshKey);
|
||||
entityNode.attachChild(ogreMesh);
|
||||
try{
|
||||
Spatial ogreMesh=(Spatial)meshLoader.load(assetManager.locateAsset(meshKey));
|
||||
entityNode.attachChild(ogreMesh);
|
||||
}catch(IOException e){
|
||||
throw new AssetNotFoundException(meshKey.toString());
|
||||
}
|
||||
} catch (AssetNotFoundException ex) {
|
||||
if (ex.getMessage().equals(meshFile)) {
|
||||
logger.log(Level.WARNING, "Cannot locate {0} for scene {1}", new Object[]{meshKey, key});
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.jme3.scene.plugins.ogre;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.jme3.asset.AssetInfo;
|
||||
import com.jme3.asset.AssetKey;
|
||||
import com.jme3.scene.Spatial;
|
||||
|
||||
public class SceneMeshLoader extends MeshLoader{
|
||||
private Map<AssetKey,Spatial> cache=new HashMap<AssetKey,Spatial>();
|
||||
@Override
|
||||
public Object load(AssetInfo info) throws IOException {
|
||||
AssetKey key=info.getKey();
|
||||
Spatial output=cache.get(key);
|
||||
if(output==null){
|
||||
output=(Spatial)super.load(info);
|
||||
cache.put(key,output);
|
||||
}
|
||||
return output.clone(false);
|
||||
}
|
||||
public void reset(){
|
||||
cache.clear();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user