Help the Noob Load an obj =)

Hi!
I’m making a simple scene to navigate for a class and was wondering if anyone could help me load an obj I exported from Wings3d of Trogdor from Strongbad’s emails. Any quick hints on how to color or texture him would be appreciated too, but that’s not really integral for what I wanna do. I read the tut on loading ase files, but being a poor college student I can’t afford the likes of 3dsmax. :stuck_out_tongue:

thanks!
-Morlem

-edit- I’m asking b/c the site mentions a loader for objs, which I thought would let me avoid porting a class that I made thatreads in all the vertices and then makes the faces listed in the obj file.

A good start would be to download the third party loader if you havn’t already from the Xith toolkit site:
https://xith-tk.dev.java.net/servlets/ProjectDocumentList?folderID=390

Have a play with that and see what you come up with.

Cheers,

Will.

Hey! thanks. that was really helpful. But just to further prove that I really don’t know what Im doing, here is another problem I can’t figure out.

I’m tring to compile and execute the OBJTest.java which is the example that was provided with the code, but everytime I get this message:

Loading: othermodels/tiletest/tile1.obj

then:

java.lang.NullPointerException
        at java.io.Reader.<init>(Reader.java:61)... etc...

Which I’m thinking is approptiate b.c there is no tile1.obj, or that folder . deleted the class file a couple times to make sure it was actiually compiling…

I couldn’t figure that out so I tried making a completely new folder and everything with the files there too, and now I’ve run into a new problem. I either get the NullPointerException or a String out of bound exception and i think I know why, but I don’t know what to do about it.
Here’s some code from the OBJLoader

    public BranchGroup load(String objFile,NodeFactory factory,Vector3f vec) throws IOException {
        System.out.println("Loading: "+objFile);
        String basePath = objFile.substring(0,objFile.lastIndexOf("/"));

given that it sets the basepath to everything preceding a / does that mean it would only work on a Unix type file system since Windows uses \ instead of / ?? I’m getting the String out of Bounds exception b.c I took out the /'s so it never found one OR I’m getting the null pointer exception b.c I am including 's to show where my directory is and it’s never finding the file b.c this is Windows. That’s my current theory anyway. Could I just extract that line from the jar, change the line, recompile and stick it back in?? Thanks again for tolerating my inexperience!

I wrote the OBJ loader, so I know it runs on Windows. ;D

The problem is that the String passed in should a reference in the class path and not a reference to a file path. Hence “/” is right all platforms since its a URL :slight_smile:

However, I’m starting to think that I need to support loading from direct file since I’ve had a bunch of reports of problems with this same issue. I’ll try and add it (to all the loaders) tonight. However, I do think its odd that people are loading from files and not from the classpath. It’ll make life hard when you come to deployment.

Kev

Ahhhhh!! thanks! I think I would’ve been ok If I knew enough to realize it was loading from the classpath. I just assumed it loaded from a file, b/c I’ve never loaded a file from the classpath before. Live and learn! ;D
Thanks again,
for the loader and helping me figure out how to use it!
-Morlem

Added direct file support to OBJ and 3DS loaders. Not tested yet but its available at the same place…

I’ll produce the Java Doc for the whole lot pretty soon. Just as soon as I get a spare day or so :slight_smile:

Kev

No probs - I think I shall start plugging those links a bit more :slight_smile:

Support for both is definitally a good idea IMHO. I use regular paths myself if I am just testing something out. Only if it becomes serious do I switch and whip up an ant script.

Will.

Sorry to be a nuisance, but I really don’t think I’ve emphasised just how inexperienced I really am. I got the OBJ loader to work on the galleon example, but I’ve yet to be able to load one of my own. I’ve tried a few things, but I’ll not go into that and just ask… How do I get my obj onto the classpath?
thanks yet again,
-Morlem

No worries,

Each directory or jar specified in your class path is taken as “base path”. Any model you specify should be relative to one of these base paths. So, if you class path was

“.;models;build”

And you referenced a model at “people/bob.obj” then the following locations would be checked:

./people/bob.obj
models/people/bob.obj
build/people/bob.obj

In that order. Now, the nice bit is when you work with classpaths that you can equally stick a jar file in your class path. Java will then try to access resources in the jar. This means you can distribute all your models/resources/etc in a compressed jar file with no extra work :slight_smile:

If you start this way it stops you having to make a bunch of changes at deployment and its actually just as easy to work from the classpath as it is to work from direct files.

However, like I said, I’ve added file support to the loader now (and the 3DS loader). I don’t really think this is the way to go but if you’re still stuck then you could try that instead. If you are still stuck tho, feel free to come back and post again.

Kev

Hey! I think I figured out the problem. When I copy your obj into one of my own it works fine, but it doesn’t work on mine. What program was your obj generated with? Wings seems to output with a different structure, it the same basic syntax. Maybe I can just load my obj into whatever program you used and then export a new Obj.

I’ve been using Art of Illusion mostly. If its ok could you send your OBJ over… I’d like to find out whats wrong and fix it up…

Kev