.obj import and usage

Not sure if this is the right forum for this question…



The goal is to have a simple model (a tree) that I can place all over my terrain. I’ve created an object, exported it, changed it to a .j3o. I can load it and display it on screen…once.



And that’s the issue. I can call this once and place a tree…poof, there’s a tree. I call it again at a different location and poof…NO TREE. I can do that over and over and not get another tree…until I scroll so that the first tree is no longer in view. Then the 2nd tree I placed appears. If I scroll away so that those trees are offscreen, the next earliest visible tree appears. Maddening.



The idea is to have an object manager that I can call with several parameters that define what to place and where to place it. In the code, I load the object each time. Is that the right thing to do?



A bit of code:



public int newObject(Vector3f loc, Vector3f vel, Vector3f gravity, float dur, ObjectType type) {

if (type == ObjectType.Tree) {

MyObject me = new MyObject();

me.duration = (long) dur*1000; //convert float seconds into milliseconds

me.location = loc;

me.velocity = vel;

me.gravity.x = gravity.x;

me.gravity.y = gravity.y;

me.gravity.z = gravity.z;

Spatial obj = am.loadModel(“Models/Tree/lowpolytree.j3o”);

obj.setLocalTranslation(loc);

obj.updateModelBound();

me.pObject = obj;

me.id = nextID;

nextID = nextID + 1;

obj.setName(“Tree”+Long.toString(me.id));

drawNode.attachChild(me.pObject);

me.starttime = System.currentTimeMillis();

objects.add(me);

return me.id;

}

So I cleaned up the code a bit (embarrassing to post alpha code) hoping that the jacked up naming and attaching order in the code was the issue. I’m posting the new function here just in case anyone else thinks that it’s the issue in the code above because it isn’t. Still can’t view more than one version of each object. Updated code follows:



public int newObject(Vector3f loc, Vector3f vel, Vector3f gravity, float dur, ObjectType type) {

if (type == ObjectType.Tree) {

MyObject me = new MyObject();

me.duration = (long) dur*1000; //convert float seconds into milliseconds

me.location = loc;

me.velocity = vel;

me.gravity.x = gravity.x;

me.gravity.y = gravity.y;

me.gravity.z = gravity.z;

me.pObject = tree.clone(); //I pre load the spatial into tree so I can just clone it in this function.

//Spatial obj = am.loadModel(“Models/Tree/lowpolytree.j3o”);

me.pObject.setLocalTranslation(loc);

me.pObject.updateModelBound();

me.id = nextID;

me.pObject.setName(“Tree”+Long.toString(me.id));

System.out.println(me.pObject.getName());

nextID = nextID + 1;

drawNode.attachChild(me.pObject);

me.starttime = System.currentTimeMillis();

objects.add(me);

return me.id;

}

return -1;



}

Try to attach it to rootNode instead of the drawNode maybe?

Thanks for the response, but that’s not the issue…I am attaching other stuff to this node (particle effects) and they work fine. I don’t actually attach anything to the root node except the other nodes.



I’m pretty sure it has something to do with the object usage…or some culling flag I need to set. I was hoping that the updateModelBound would solve the problem…but no.



The real question I have is how do the trees appear to be tied to each other? I am creating them as distinct objects (I think)…my guess is that they don’t but somehow the way I’m using the Spatials is confusing the renderer.

Narrowed it to the actual object. Apparently exporting .obj format from Blender 2.57 causes this for every object. I am trying to use the ogre3d xml exporter with little luck…I get some great bright white objects that i can place everywhere and they stay there, but that’s about it.



I’m using a custom overhead cam, and I’ve also found that it’s not so much that it is showing the first placed object as it’s showing the object with the lowest Z coordinate. But again, only with .obj files exported from Blender.

It seems that Blender 2.57 is not exporting normals unless you tell it to; it is proper by the OBJ spec but jME3 lighting cannot function without normals.



For lighting to work, simply check the “Normals” box when you export OBJ from Blender.

Again, maddening. I gave up on 2.57 and reinstalled 2.49. Recreated the object, used the old Ogre exporter, and everything works.



Now of course I decide to add a simple chest object. Start with a cube, move the top down, move two sides in, and do a bevel on two edges so that it looks like every other crappy RPG game chest. Added a texture to it, set up the material as TexFace, and did the Ogre export just as with the other model.



And of course it doesn’t work. I get a perfectly square cube with no texture. I read that you have to use some of the Object->Clear/Apply options. Did that. Exported. Again the perfectly white cube. Not sure why scaling wouldn’t take as it did with the tree model from the above comments…then again, to me at least the entire process is less than intuitive.



Anyone have a link to a decent beginning to end tutorial for using Blender 2.49 to get stuff to work?

And by the way, I do want to thank all the folks who have replied to help me out. Really do appreciate the help, it’s been invaluable in getting this engine integrated into my project.

Wow. All me this time. Well…my team. As fast as one of us was making changes to the models, another of us was changing the object code and left a reference to the wrong model in the code…default generic cube set for every “undefined” object. Please, ignore this thread.