V

Avatar

Another .obj file loader for java/processing

I’ve noticed people have been looking for a obj file importer for processing/java.
Many thanks to Fabien Sanglard for his original code. I’ve added few more things i found to be important to me and added support for JOGL and processing. It runs over part of my framework called Vitamin, so if you are a pure processing user you might want to check the objscene.pde and change the rendering code.  I wanted to keep the obj importer independent of any API/Bind, so it can be easily used by different API/frameworks/whatever. Hopefully it will work that way.

Official webpage | Download Version 1.0

—–
This Java OBJ Loader support:
* Groups (+scene management implemented)
* Vertex, Normal, Texture coordinates
* MTL (material) references.

This Java OBJ Loader DOES NOT support:
* Relative vertex references.
* Anything other than GL_TRIANGLE and GL_QUAD polygons

—–
Includes:
1. Library
2. Documentation
3. Example

—–
How to use it:
1. Copy library folder to processing’s folder
2. Run the example

11 Comments, Comment or Ping

  1. jesfish

    Hey, this is EXACTLY what I need for a project I’m working on using JOGL. I don’t really see any JOGL stuff in the code though. Is there a draw method missing from WavefrontObject ? Please let me know how you intended to render into jogl using this library.

  2. victormartins

    Hi. The importer is independent of any java binding, meaning you can use the library to load the obj files into your own data struture and render with whatever you want to. In the example i gave an example of how to use it for processing. It should be easy for you to get it working with JOGL on its own. If not let me know.

  3. jesfish

    Ah, yes. I had never seen .pde files before and assumed them to be some wrapped data, but opening them with a text editor I see it is practically java. Thank you again!

  4. victormartins

    .pde is the extension for the processing “language”. Processing is built on java and it works on JOGL for opengl rendering. I believe that with the library and the OBJScene.pde file, you can get around to make your own JOGL renderer.
    best regards

  5. ekene

    ciao victor. thanks for the library. i ran the examples on processing 1.0.2 and got these exceptions and errors

    java.lang.ClassCastException: java.awt.image.DataBufferInt
    at com.obj.TextureLoader.loadTexture(TextureLoader.java:98)
    at com.obj.TextureLoader.loadTexture(TextureLoader.java:52)
    at com.obj.parser.mtl.KdMapParser.parse(KdMapParser.java:37)
    at com.obj.parser.mtl.MaterialFileParser.parse(MaterialFileParser.java:62)
    at com.obj.WavefrontObject.parseLine(WavefrontObject.java:178)
    at com.obj.WavefrontObject.parse(WavefrontObject.java:148)
    at com.obj.WavefrontObject.(WavefrontObject.java:88)
    at com.obj.WavefrontObject.(WavefrontObject.java:54)
    at wavefrontloader$OBJScene.load(wavefrontloader.java:512)
    at wavefrontloader$OBJScene.load(wavefrontloader.java:507)
    at wavefrontloader.setup(wavefrontloader.java:61)
    at processing.core.PApplet.handleDraw(PApplet.java:1400)
    at processing.core.PApplet.run(PApplet.java:1328)
    at java.lang.Thread.run(Thread.java:613)

    Error on line: map_Kd sun_4.jpg

    java.lang.RuntimeException: Error parsing :’/Users/ekeneijeoma/Documents/Processing/libraries/objimport/examples/wavefrontloader/data/m1.mtl’
    at com.obj.parser.mtl.MaterialFileParser.parse(MaterialFileParser.java:72)
    at com.obj.WavefrontObject.parseLine(WavefrontObject.java:178)
    at com.obj.WavefrontObject.parse(WavefrontObject.java:148)
    at com.obj.WavefrontObject.(WavefrontObject.java:88)
    at com.obj.WavefrontObject.(WavefrontObject.java:54)
    at wavefrontloader$OBJScene.load(wavefrontloader.java:512)
    at wavefrontloader$OBJScene.load(wavefrontloader.java:507)
    at wavefrontloader.setup(wavefrontloader.java:61)
    at processing.core.PApplet.handleDraw(PApplet.java:1400)
    at processing.core.PApplet.run(PApplet.java:1328)
    at java.lang.Thread.run(Thread.java:613)

    Error, could not load obj:/Users/ekeneijeoma/Documents/Processing/libraries/objimport/examples/wavefrontloader/data/m1.obj

  6. victormartins

    Hi ekene,
    I have tracked the problem to the macosx users. I will get a mac so i can test it out.

    Meanwhile if you want to make sure, try loading a scene without textures. that should work just fine.

    thanks for reporting the bugs. I will keep you posted on this one

  7. victormartins

    I’ve tested the library in macosx 10.4 (tiger) and it worked correctly. The same did not happen when i tested it using macosx 10.5 (Leopard). I got the same error you have been sending me. Since i am a windows user i can’t really say what would be the problem, but i will try to figure it out.

    Do you have a chance to compile the library in Leopard and try to run it again? If you do, please do so and post back

  8. jesfish

    hey, I have made a separate jar file that works along side yours for jogl. here is a folder with an example for the jar and the source code. It fixes a few issues with your original code but I know it probably could be optimized.

    http://filer.case.edu/jof1/JOGLobjloader/

    Thanks again for your code! If you find any improvements for mine or want to host it next to yours feel free. I don’t have a blog nearly as nice as yours. Just attribute changes to Jesse Fish.

  9. victormartins

    hey jesfish. i will put up online the zipfile as the JOGL example.
    thanks for your work. keep it up

  10. jesfish

    hey, update. http://code.google.com/p/joglobj/ is the googlecode page for the jogl rendering library that borrowed from your code

  11. victormartins

    Hey Jes.
    I have updated the website with the new link. Thanks for the support!

Reply to “Another .obj file loader for java/processing”

You must be logged in to post a comment.