Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 beta is now available for download.
    Dismiss Notice

OBJ Loader

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

  1. wccrawford

    wccrawford

    Joined:
    Sep 30, 2011
    Posts:
    1,963
    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.