Coder Social home page Coder Social logo

o-o-balance / elm-obj-file Goto Github PK

View Code? Open in Web Editor NEW

This project forked from w0rm/elm-obj-file

0.0 0.0 0.0 3.32 MB

Encode and decode 3D geometry in the OBJ file format

Home Page: https://package.elm-lang.org/packages/w0rm/elm-obj-file/latest

License: BSD 3-Clause "New" or "Revised" License

Shell 0.57% Elm 99.43%

elm-obj-file's Introduction

elm-obj-file

An Elm package to encode and decode 3D geometry in the OBJ file format. Meshes are returned as TriangularMesh values, which makes them easy to render with elm-3d-scene but can also be used with any other 3D graphics system. You could even take the geometric data and use it for 3D printing, physics simulations, finite element analysis or whatever other crazy thing you want to do =)

The “Pod” model by Kolja Wilcke

The “Pod” model by @01k rendered with elm-3d-scene. See it live here.

Make sure to check the viewer example that lets you preview OBJ files.

The examples source code can be found here.

{-| Load a mesh from an HTTP request. -}
getMesh : Cmd Msg
getMesh =
    Http.get
        { url = "Pod.obj.txt"
        , expect =
            Obj.Decode.expectObj GotMesh
                Length.centimeters
                Obj.Decode.texturedFaces
        }

Note the .txt extension: this is currently required to serve files from elm reactor.

Blender Workflow

To export an OBJ file from Blender choose File - Export - Wavefront (.obj). We recommend the following settings:

  • Include: only check “Objects as OBJ Objects”;
  • Transform: use scale 1.00, “Y Forward” and “Z Up” to match the Blender coordinate system;
  • Geometry: only check “Apply Modifiers”, check “Write Normals” for Obj.Decode.faces and Obj.Decode.texturedFaces, “Include UVs” for Obj.Decode.texturedTriangles and Obj.Decode.texturedFaces, optionally check “Write Materials” if you want to decode material names.

Blender collections are not preserved in OBJ groups. To decode individual meshes from the same file, you should rely on the object filter. The object name, that Blender produces, is a concatenation of the corresponding object and geometry. For example, the “Pod Body” object that contains “Mesh.001” can be decoded with Obj.Decode.object "Pod_Body_Mesh.001".

If you want to use the shadow generation functionality from elm-3d-scene, your mesh needs to be watertight. Blender has the 3D Print Toolbox add-on, that lets you detect non manifold edges and fix them by clicking the “Make Manifold” button.

OBJ Format Support

  • different combinations of positions, normal vectors and UV (texture coordinates);
  • face elements f;
  • line elements l;
  • points elements p;
  • object names o;
  • group names g;
  • material names usemtl;
  • smoothing groups s;
  • free-form curves and surfaces and related data;
  • miscellaneous display and rendering data attributes, e.g. mtllib.

elm-obj-file's People

Contributors

w0rm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.