Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,6 +100,7 @@ public void endDocument() {
}

private void reset() {
meshLoader.reset();
elementStack.clear();
nodeIdx = 0;

Expand Down Expand Up @@ -299,8 +301,12 @@ private void parseEntity(Attributes attribs) throws SAXException {
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});
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}