OBJ Loader

Discussion in 'Works In Progress' started by wccrawford, Dec 3, 2012.

  1. wccrawford

    wccrawford

    Member

    Joined:
    Sep 30, 2011
    Messages:
    1,581
    I recently saw a need for an OBJ loader that had a very permissive open source license. So I wrote one and put it under the MIT license.

    https://github.com/wccrawford/UnityOBJLoader

    It's still pretty shaky and can use some error checking. And there are probably some features of OBJ format that I haven't implemented yet. But it should handle normals, UVs, and polys with more than 3 sides, so long as the poly is convex. (Concave polys are a lot harder to turn into triangles.)

    I was inspired to create this by the folks working on modding Desperate Gods to handle any board game, but I didn't want to have the code end up locked into their non-OS license. This way, those modders can use it, and so can anyone else that wants to.

    I've tried to structure it in such a way that it doesn't matter where the OBJ file comes from, it'll parse it. To that end, you simply pass it a string with the contents of the file. That way you can load it from disk or WWW, and it's all the same.

    MTL support isn't implemented, and neither are groups. I will probably add group support later. But MTL support is another issue. If I support that, I'll likely do it by implementing another separate parser, and making some Unity scripts that will help them work together.

    Oh, and it isn't optimized. It creates a new vertex for every point on every triangle. It should be sharing at least some of them. I'll look into this later.

    I'd love to hear of uses that people find for this, and any features that are missing that are needed. And bug reports, of course.