Load Models From Outside Classpath?

I'm trying to load models from outside of the filepath by using a FileDialog…



This is what the code essentially looks like, it's just spread out over a few classes.  (yes, the information is getting from place to place correctly…


// first
if(fileDialog.getFile()!=null){
     File fileToConvert = fileDialog.getFile();
}

// later
ColladaImporter.load(fileToConvert.toURI().toURL().openStream(), design.getName());




I get this error after an NPE in the console:
baseDir can not be null


Any ideas?  I normally use the ResourceLocator tools when working off the classpath, but we're looking to load in models from users, so it's kind of tough for them to have the COLLADA's on the application's classpath :)

Can you post the whole stack trace?

Momoko_Fan said:

Can you post the whole stack trace?


Sure, this is my current problem: (the baseDir can't be null was when I tried using ResourceLocators, but this is 'more correct')


Oct 22, 2009 1:45:16 AM com.jmex.model.collada.ThreadSafeColladaImporter load
INFO: Doc creation took 12
Oct 22, 2009 1:45:16 AM com.jmex.model.collada.ThreadSafeColladaImporter load
INFO: Load took 122
Oct 22, 2009 1:45:16 AM com.jmex.model.collada.ThreadSafeColladaImporter load
INFO: Version: 1.4.1
Oct 22, 2009 1:45:16 AM com.jme.util.resource.ResourceLocatorTool locateResource
WARNING: Unable to locate: ./texture_alignment_guide.jpg
Oct 22, 2009 1:45:16 AM com.jmex.model.collada.ThreadSafeColladaImporter loadTexture
WARNING: Invalid or missing texture: "./texture_alignment_guide.jpg"
Oct 22, 2009 1:45:16 AM com.jme.scene.Node <init>
INFO: Node created.
Oct 22, 2009 1:45:16 AM com.jme.scene.Node attachChild
INFO: Child "pCubeShape1-initialShadingGroup" attached to this node "pCubeShape1"
Oct 22, 2009 1:45:16 AM com.jme.scene.Node <init>
INFO: Node created.
Oct 22, 2009 1:45:16 AM com.jmex.model.collada.ExtraPluginManager processExtra
WARNING: Could not process extra of type: OpenCOLLADAMaya
Oct 22, 2009 1:45:16 AM com.jme.scene.Node <init>
INFO: Node created.
Oct 22, 2009 1:45:16 AM com.jme.scene.Node attachChild
INFO: Child "pCube1" attached to this node "VisualSceneNode"
Oct 22, 2009 1:45:16 AM com.jme.scene.Node <init>
INFO: Node created.
Oct 22, 2009 1:45:16 AM com.jme.scene.Node attachChild
INFO: Child "pCubeShape1-initialShadingGroup" attached to this node "pCubeShape1"
Oct 22, 2009 1:45:16 AM com.jme.scene.Node attachChild
INFO: Child "pCubeShape1" attached to this node "pCube1"
Oct 22, 2009 1:45:16 AM com.jme.scene.Node attachChild
INFO: Child "VisualSceneNode" attached to this node ""
Oct 22, 2009 1:45:16 AM com.jmex.model.collada.ThreadSafeColladaImporter load
INFO: Parse took 141



Textures are in the same folder as the .dae, same results using './texture.jpg' or 'texture.jpg'

For kicks, here's the function that loads the model:


public static Node ColladaLoader(final IGenericDesign design, final IGPSCoordinate centerMap, URL modelURL) {
      Node modelNode = new Node(design.getName());
      try {
         ColladaImporter.load(modelURL.openStream(), design.getName());
      } catch (IOException e) {
         ErrorDialog error = new ErrorDialog();
         error.setVisible(true);
         error.setError("Could not load model!");
      }
      modelNode = ColladaImporter.getModel();
      modelNode.setModelBound(new BoundingBox());
      modelNode.updateModelBound();
      return modelNode;
   }

Solved.



I tried using the AbsoluteResourceLocator from blaine but didn't have much luck…  After a few more hours of tinkering, I came up with this:



ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_MODEL,
               new SimpleResourceLocator(modelURL));
         ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,
               new SimpleResourceLocator(textureURL))
         ColladaImporter.load(modelURL.openStream(), design.getName());



Aye, it is simple.. should've done that long ago.  But it works and I hope someone in distress find this useful someday :)