Fix material sharing

define_list_fix
Riccardo Balbo 9 years ago
parent 091b8664ad
commit 70ef220c2b
  1. 8
      jme3-plugins/src/ogre/java/com/jme3/scene/plugins/ogre/SceneLoader.java
  2. 26
      jme3-plugins/src/ogre/java/com/jme3/scene/plugins/ogre/SceneMeshLoader.java

@ -71,6 +71,7 @@ public class SceneLoader extends DefaultHandler implements AssetLoader {
private static final Logger logger = Logger.getLogger(SceneLoader.class.getName()); private static final Logger logger = Logger.getLogger(SceneLoader.class.getName());
private SceneMaterialLoader materialLoader = new SceneMaterialLoader(); private SceneMaterialLoader materialLoader = new SceneMaterialLoader();
private SceneMeshLoader meshLoader=new SceneMeshLoader();
private Stack<String> elementStack = new Stack<String>(); private Stack<String> elementStack = new Stack<String>();
private AssetKey key; private AssetKey key;
private String sceneName; private String sceneName;
@ -99,6 +100,7 @@ public class SceneLoader extends DefaultHandler implements AssetLoader {
} }
private void reset() { private void reset() {
meshLoader.reset();
elementStack.clear(); elementStack.clear();
nodeIdx = 0; nodeIdx = 0;
@ -299,8 +301,12 @@ public class SceneLoader extends DefaultHandler implements AssetLoader {
entityNode = new com.jme3.scene.Node(name); entityNode = new com.jme3.scene.Node(name);
OgreMeshKey meshKey = new OgreMeshKey(meshFile, materialList); OgreMeshKey meshKey = new OgreMeshKey(meshFile, materialList);
try { try {
Spatial ogreMesh = assetManager.loadModel(meshKey); try{
Spatial ogreMesh=(Spatial)meshLoader.load(assetManager.locateAsset(meshKey));
entityNode.attachChild(ogreMesh); entityNode.attachChild(ogreMesh);
}catch(IOException e){
throw new AssetNotFoundException(meshKey.toString());
}
} catch (AssetNotFoundException ex) { } catch (AssetNotFoundException ex) {
if (ex.getMessage().equals(meshFile)) { if (ex.getMessage().equals(meshFile)) {
logger.log(Level.WARNING, "Cannot locate {0} for scene {1}", new Object[]{meshKey, key}); 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…
Cancel
Save