[SOLVED] Exception loading .obj

I've searched the forums severa times, and still can't seem to figure out why I'm getting a cast exception. I apologize if this is one of those common newbie questions that has been answered a thousand times…



The model has been exported from Blender, making sure to export Normals, Triangulate, Object Groups, and Material Groups. I have no problem importing the resulting .obj in Bryce, Daz, MilkShape, etc. I've made sure to place the textures and the model in the jmetest/data/a/ directory, and it appears to be finding everything alright. It just dies when it gets to "Node r = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));". I'm sure I'm just missing something obvious, still kinda new to jME.

StackTrace wrote:
SEVERE: Exception in game loop
java.lang.ClassCastException: com.jme.scene.TriMesh
at jmetest.renderer.loader.TestObjJmeWrite.simpleInitGame(TestObjJmeWrite.java:89)
at com.jme.app.BaseSimpleGame.initGame(BaseSimpleGame.java:503)
at com.jme.app.BaseGame.start(BaseGame.java:69)
at jmetest.renderer.loader.TestObjJmeWrite.main(TestObjJmeWrite.java:65)

I've replaced simpleInitGame in TestObjJmeWrite with the following:


@Override
protected void simpleInitGame() {
   ObjToJme converter = new ObjToJme();

   try {
      MultiFormatResourceLocator loc2 = new MultiFormatResourceLocator(ResourceLocatorTool.class.getResource("/jmetest/data/a/"), ".jpg", ".png", ".tga");
      ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, loc2);
   } catch (URISyntaxException e) {
      e.printStackTrace();
   }

   try {
      URL objFile = TestObjJmeWrite.class.getClassLoader().getResource("jmetest/data/a/asteroid.obj");
      converter.setProperty("mtllib", objFile);
      ByteArrayOutputStream BO = new ByteArrayOutputStream();
      logger.info("Starting to convert .obj to .jme");
      converter.convert(objFile.openStream(), BO);

      //jbr.setProperty("texurl",new File(".").toURL());
      logger.info("Done converting, now watch how fast it loads!");
      long time = System.currentTimeMillis();
      Node r = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
      logger.info("Finished loading time is " + (System.currentTimeMillis() - time));
      r.setLocalScale(.1f);
      this.rootNode.attachChild(r);
   } catch (IOException e) {
      logger.logp(Level.SEVERE, this.getClass().toString(), "simpleInitGame()", "Exception", e);
   }
}

The reason why it fails is because the model you exported only has 1 mesh, so it is converted to a single TriMesh object by the ObjToJme converter, the test was made to load a specific model and so it expects the model to have several meshes, and thus casts to a Node instead.

Casting to Spatial did the trick. Thanks!