I've try to follow the TestSharedNode example, but uf I use SharedNode instead a Node the model isn't rendered. why?
I want make sure i load a model only one time and then reuse it, here the working code, with the "right" instruction (what i want do) commented. please help!!
public static Node loadModelXML(String name){
Node loadedNode=null;// = loadedModel.get(name);
if (loadedNode == null){
URL f = null;
try {
f = new URL("file:"+name);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("loading: "+name+" "+f);
try {
loadedNode=(Node) xmlImporter.load( f );
loadedNode.setLocalScale(0.5f); //to box2d scale
loadedNode.setName(name);
loadedNode.setLocalTranslation(0, 0, 0);
loadedNode.setModelBound( new BoundingBox() );
loadedNode.updateModelBound();
loadedModel.put(name, loadedNode);
I think you have to keep a reference to the original node because otherwise it will get garbage collected, also did you updateRenderstate() your rootNode after attaching?
I put the loaded Node in an HashMap, so I load the xml file only one time and then use a shared node for every object that try to load it... so 1 load for X objects :) ah ant becouse the Node is in an hashmap it will not be garbage
And i'm doung updateRenderstate() and updateGeometricState(...) at the end of every gamestate update, I'm also calling the method every time I change an object or create it but nothing appear...
here the actual class loader code:
public class ModelLoaderXML {
static XMLImporter xmlImporter = XMLImporter.getInstance();
static HashMap<String, Node> loadedModel = new HashMap<String, Node>();
static int i=0;
public static Node loadModelXML(String name){
Node loadedNode=loadedModel.get(name);
if (loadedNode == null){
URL f = null;
try {
f = new URL("file:"+name);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("loading: "+name+" "+f);
try {
loadedNode=(Node) xmlImporter.load( f );
loadedNode.setLocalScale(0.5f); //to box2d scale
loadedNode.setName(name);
loadedNode.setLocalTranslation(0, 0, 0);
loadedNode.setModelBound( new BoundingBox() );
loadedNode.updateModelBound();
loadedNode.updateRenderState();
loadedModel.put(name, loadedNode);