ObjLoader

Hi,

I am working on loading an OBJ file in Xith created by the Terragen application. I know a lot about how this is
achieved using Java3D and am trying to apply my knowledge to Xith.

In my Java3D layout the loader extracts the Shape3D object from the BranchGroup (created from the OBJ file)
I was wondering if this is possible from the xith loader. I realise I don’t fully understand how the loader works
in either Java3D or Xith so I feel quite limited in what I am trying to achieve. :-\

Could anyone please either explain how I can create a Shape3D object from an OBJ file or suggest a better way of
loading a Terragen OBJ file into Xith.

Thanks

I don’t know if the OBJ created by Terragen is in a specific format, what I know is the Xith OBJ Loader returns in fact a BranchGroup containing different Shape3D (containing Geoms and Appearances) and the interesting fact is all about node factories. But you may take a look at the source code of the loader, it’s really easy to understand.

Thanks for the reply.

I was wondering if you could expand on the BranchGroup returned by the OBJ Loader.

I’ve had a look at the source code but am still a bit unsure about what it contains.
When I ran a portion of my code intergrated with the ObjLoader, the BranchGroup
had one child node (a Group object) could you explain how this relates to a
Shape3D object?

then the Group is probably a TransformGroup and that one contains your Shape3D

arne, yes it’s probably like that.

Thanks everyone for your advice. I think I am starting to understand how it all fits together.
It turned out to be the child node after the one above that was the Shape3D object so if any
one else is ever trying to load an OBJ file created by Terragen try


        Node grandParentNode = objBranchGroup.getChild(0);
        Node parentNode = ((com.xith3d.scenegraph.Group) grandParentNode).getChild(0);
        Node node = ((com.xith3d.scenegraph.Group) parentNode).getChild(0);

and the ‘node’ object is the Shape3D

I have another query if anyone has any ideas. I was wondering about the objloader and
the boundaries created in the Shape3D object. For instance when you load an OBJ file
using the loader how does it define what type of bounds are used within the Shape3D.

My question relates to what I am working on at present as after I have the Shape3D object
from the branchgroup I want to get the boundary values from it (hopefully by using a
BoundingBox) however the boundary object returned by the Shape3d is a BoundingSphere.
I’d like to change where this is set if possible and if not try to convert it.

I’m sorry I don’t know that much about boundary-thingies in Xith3D, cause I don’t use it (maybe it’s used in the renderer, but anyway I don’t mind about it).
But you may really easily compute the bounding box of your model based on your Geometry (that is contained in your Shape3D). I think you should do you own class for BoundingBox

[quote]I have another query if anyone has any ideas. I was wondering about the objloader and
the boundaries created in the Shape3D object. For instance when you load an OBJ file
using the loader how does it define what type of bounds are used within the Shape3D.
[/quote]
I believe it uses BoundingSphere by default.

Is there any need, why you need BoundingBoxes? BoundingSpheres work also pretty well.

Sorry it’s taken me so long to reply. Been so busy at work.

I am trying to load a terrain map and as this is a cuboid type shape I thought the best bounding object would be
a BoundingBox. I’m trying to use the BoundingBox to get the landlength (length of the x side) and the max and min
height along the z axis.

There must be a way to get these values from the geometry but it escapes me ??? Sorry for being such a noobie,
I’m trying to get better. Could anyone enlighten me on either how I could get these values from a BoundingSphere
or the Geometry.

Dang

Hate to say it but I think when I hit this I had to iterate over the vertex values storing min and max info…sorry

Exactly, it’s very easy. take your Shape3D, use getGeometry() to extract the geometry from it and iterate throug all of it’s vertices with getVertex(int i, Point3f) I think.

I’m also using .obj models with Xith, and the immaturity of it’s .obj loaders actually forced me to write my own to get the functionality I needed. It’s really very easy to do so, once you understand the few tags that are used there. It’s llike parsing HTML files but even more straightforward. :slight_smile:

otelo, if you have improved the OBJ loader, you may post your code here, and I’ll commit it to the Xith-tk. Or even better, you can do it yourself ;D just register at https://xith-tk.dev.java.net/
William will probably give you Developer access soon and then you can commit your changes.

I didn’t really improve it, I just wrote my own .obj file parser to get the functionality I needed, it sure is nothing groundbreaking.

I’d like to encourage other people to do the same, having full control and understanding of the loading process is a great thing and dealing with the .obj format is just too simple to pass on the opportunity.