w0rm/elm-obj-file/1.3.1

NOTE: the latest version is 1.4.0

Obj.Encode

Turn different geometry into OBJ files.

Encoding

encode : (Length -> Float) -> Geometry -> String

Encode geometry in the OBJ format, parametrized by the function, that knows how to convert units.

obj =
    encode Length.inMeters (triangles mesh)

To encode multipart files, control precision or add various metadata, see Advanced Encoding.

Represents encoded geometry.

Primitives

triangles : TriangularMesh (Point3d Meters coords) -> Geometry

Encode positions.

TriangularMesh
{ a
| position : Point3d Meters coords
, normal : Vector3d Unitless coords
}

Encode positions and normal vectors.

TriangularMesh
{ a | position : Point3d Meters coords, uv : ( Float, Float ) }

Encode positions and UV (texture) coordinates.

TriangularMesh
{ a
| position : Point3d Meters coords
, normal : Vector3d Unitless coords
, uv : ( Float, Float )
}

Encode positions, UV and normal vectors.

polylines : List (Polyline3d Meters coords) -> Geometry
points : List (Point3d Meters coords) -> Geometry

Advanced Encoding

encodeMultipart : (Length -> Float) -> List Geometry -> String

Like encode, but for files made of multiple parts.

multipartObj =
    encodeMultipart Length.inMeters
        [ triangles roofMesh
        , triangles wallsMesh
        ]
encodeCompact : (Length -> Float) -> List Geometry -> String

Like encodeMultipart, but reindexes triangular meshes. This is slower, but produces smaller result, because it deduplicates stored data.

type alias Options =
{ precision : Int
, object : Maybe String
, groups : List String
, material : Maybe String
}

Set decimal precision for geometry and label it with object, groups or material. May be useful for labeling parts in a multipart OBJ file.

multipartObj =
    encodeMultipart Length.inMeters
        [ trianglesWith { defaultOptions | object = Just "roof" } roofMesh
        , trianglesWith { defaultOptions | object = Just "walls" } wallsMesh
        ]

Note: the precision is clamped between 1 and 10, string options are stripped of whitespace.

defaultOptions : Options

Default options for geometry.

defaultOptions =
    { precision = 6
    , object = Nothing
    , groups = []
    , material = Nothing
    }


triangles =
    trianglesWith defaultOptions
trianglesWith : Options -> TriangularMesh (Point3d Meters coords) -> Geometry
Options
-> TriangularMesh
{ a
| position : Point3d Meters coords
, normal : Vector3d Unitless coords
}
Options
-> TriangularMesh
{ a | position : Point3d Meters coords, uv : ( Float, Float ) }
Options
-> TriangularMesh
{ a
| position : Point3d Meters coords
, normal : Vector3d Unitless coords
, uv : ( Float, Float )
}
polylinesWith : Options -> List (Polyline3d Meters coords) -> Geometry
pointsWith : Options -> List (Point3d Meters coords) -> Geometry