Sign in to follow this  
mtfr

[java] Java 3D .obj loading problem

Recommended Posts

I took this really simple example of a program that just loads an .obj file and displays it, it apparently works except an error thrown when loading the object file. This is the question I have, is the built-in .obj loader good enough? Because it failed on several files I tried. It worked on an empty file and produced a black window :). It didn't work on a very simple file, giving this error: "[blah blah blah] Expected number on line 4". Here is the .obj file contents: v 0.0 0.0 0.0 v 0.0 1.0 0.0 v 1.0 0.0 0.0 f 1 2 3 And on any file, more complex than the one above (all of those I tried I have taken them from sites with tutorials and examples, so they must have been valid... at least ONE of them), the execution would just hang on loading the file (that was my guess). I don't get it. Also there was another error Java returned when loading an .obj that had some keywords regarding materials... something like matlib default... Is the built-in loader so disastruous I should begin by writing my own one? Or what am I doing wrong?

Share this post


Link to post
Share on other sites
Try looking at the file format it might help explain some of the problems your experiencing.

Object File (javadoc)

The error you are getting about the line number is due to not having a new line('\n') at the end of the file.

Edit: Damned typos.

[Edited by - 5MinuteGaming on April 4, 2006 9:33:25 AM]

Share this post


Link to post
Share on other sites
Thank you, I didn't have problems understanding the format. The problem was that I had no \n at the end of the file. I think that's what you meant too, but I was trying to figure what you mean with "now having..." :)

Share this post


Link to post
Share on other sites
Yea the format is pretty simple. I tried the small snippet that you posted but unfortunately it doesn't display anything but if you want to see a triangle.

v 0.0 0.0 11
v 0.0 11 0.0
v 11 0.0 0.0
f 1 2 3
f 3 2 1

Just as a test.

mtfr: Would you know of any Java 3D editors that use Java3D directly to create scenes?

Share this post


Link to post
Share on other sites
That's right nothing would appear in my example :)

No sorry I don't know any.

But I'm really mad the documentation doesn't say anything about the mandatory new line at the end and besides, I never ever saw a program that would handle a text file so poorly, not taking into account the absence of \n...

Share this post


Link to post
Share on other sites
Yeah, it doesn't seem like it should be a problem since all the java file io classes are good enough to recognize the end of file rather than wait for the newline character. I know it is a problem when doing file io in C/C++

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this