Loading a OBJ model, node or trimesh?

Howdy. I know, second question already. :wink:



So I wrote up my model loading routine… But I hit some trouble. One model I export from Blender is a simple mesh of the word "Quit" (3D, all tris). Another is a character model I made some time ago. Both export just fine (and just 'cause, I convert them to tris, just to be sure). But… When I go to load them… Here's the code:


                // Use the format converter to convert .obj to .jme
                converter.convert(model.openStream(), BO);
                TriMesh mesh = (TriMesh)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
                node.attachChild(mesh);



Or

                // Use the format converter to convert .obj to .jme
                converter.convert(model.openStream(), BO);
                Node tmpnode = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
                node.attachChild(tmpnode);



The TriMesh one is required for the Quit model, and the Node version for the Character, both don't work the other way around. Trouble is, I want to send both models through the same loader. It's the cast that throws the error of incompatible types.

I'd like to think it's somehow the way I'm exporting it, but even be that as it may, it limits my programs capability. I want to be able to detect if it's a TriMesh or not, and deal with it accordingly. Any tips?

Also, a little bit of a side question. I'm using NetBeans for my IDE, and so it's created my directory structure following the Src/Build system. But, when the model loader looks for the texture images, it's not relative to the model files, but to the root of the project folder. Why, and can I change that somehow?

Thanks again!

EDIT: One more question. When I push the camera into these models, I can see the other side (double sided faces, in other words). I'm just not used to that, so I'm having to learn how to deal with that. Can I turn that off? Or is there a way to color the faces that don't get a material from the OBJ's MTL file?
I'd like to think it's somehow the way I'm exporting it, but even be that as it may, it limits my programs capability. I want to be able to detect if it's a TriMesh or not, and deal with it accordingly. Any tips?

Probably the best way is to simply cast to a Spatial (superclass of both TriMesh and Node), you can do nearly anything with the spatial that you can do with a node or a trimesh.
You can check which type of object it is with the instanceof operator and operate on it accordingly:


Spatial s;
if (s instanceof TriMesh){
   TriMesh mesh = (TriMesh) s;
   // work on mesh
}else if (s instanceof Node){
   Node node = (Node) s;
   // work on node
}



Also, a little bit of a side question. I'm using NetBeans for my IDE, and so it's created my directory structure following the Src/Build system. But, when the model loader looks for the texture images, it's not relative to the model files, but to the root of the project folder. Why, and can I change that somehow?

Use ResourceLocators

EDIT: One more question. When I push the camera into these models, I can see the other side (double sided faces, in other words). I'm just not used to that, so I'm having to learn how to deal with that. Can I turn that off? Or is there a way to color the faces that don't get a material from the OBJ's MTL file?

You can cull the back faces using a CullState:


CullState cs = renderer.createCullState();
cs.setCullMode(CullState.CS_BACK);
rootNode.setRenderState(cs);

If what Momoko_Fan wrote wont help (but it probably will ^.-) use search feature, there are few threads about this problem out there, I had same problem and found solution thanks to those ^^



-Cheers-

It worked beautifully. :slight_smile: (And I do apologize for the repeat question. I searched, but nothing came up. Turns out the search function was down while the forum was upgraded, I think.)



Thanks!



Also, the texture locating was solved using the line:

converter.setProperty("texdir", model);


:)