Better OBJ model loading in Processing

OBJ model loaded in Processing

Processing is a great at many things, it’s so easy to do so much, including displaying things in 3D. Still it’s easy to make things grind to a halt when trying to do to much. But there are a lot of things you can do to speed things up like PShape recording, using Vertex Arrays to display lots of points, or writing GLSL Shaders.

Loading a .obj model in Processing is as easy as using loadShape(), but loading a reasonably complicated textured obj models things slow down dramatically. Things seem to run happily when there are no textures involved. I think it’s something to do with the fact that each face of the model is loaded as an individual PShape, that are all lumped together (but it’s for a good reason).

Spinning heart obj model

You can pretty easily speed things up by taking the PShape made by loadShape and grabbing all the child shapes and putting them into a single PShape. You can’t mix quads and triangles in a single PShape, and different textures and material properties would need to be split up too. Still from a crawling 4 fps, we easily get back up to 60 fps. Which is cool, hopefully that’s helpful to someone, as it took me ages to figure out why things were going so slowly. And at some point I might have a crack at writing my own version of the OBJ loader.

 

FacebookTwitterGoogle+PinterestTumblrRedditPocketShare


3 responses to “Better OBJ model loading in Processing”

  1. Erick says:

    Hello,

    Thanks for this piece of code. Just a question:

    Why do you start the for cycle in createShape on 100?

  2. […] Fortunately a work around has been created by a blogger (http://www.cutsquash.com/2015/04/better-obj-model-loading-in-processing/) who has written some code which redraws any loaded shape using the createShape command. I will […]

  3. Rick Tewell says:

    Is it possible to get heartDecim.obj and HeartC.JPG? I would like to work with your code a bit.

    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *