mikaxyz/elm-gltf/4.0.0

NOTE: the latest version is 5.0.0

Gltf

Import 3d assets from glTF (Graphics Library Transmission Format) file format

Types

type alias Asset =
{ version : String
, copyright : Maybe String
, generator : Maybe String
}

Information about the file

type Error
= HttpError Error
| TextureError Error
| SceneNotFound
| NodeNotFound

All possible failures

type Query

Type returned by queries.

Results from a query which can be used to retrieve content.

Wiring

type Msg

Internal Msg type. Handle these in your update function. Your application Msg type should contain:

type Msg
    = GltfMsg Gltf.Msg
type Gltf

Internal state. Your application model should contain one:

type alias Model =
    { gltf : Gltf
    }

Initialize a Gltf and store it in your model:

init : Model
init =
    { gltf = Gltf.init
    }
{ toMsg : Msg -> msg
, onComplete : Result Error QueryResult -> msg
}
-> Msg
-> Gltf
-> ( Gltf, Cmd msg )

Internal update function. Call it in your update something like this:

GltfMsg msg_ ->
    Gltf.update
        { toMsg = GltfMsg
        , onComplete = GltfOnComplete
        }
        msg_
        model.gltf
        |> Tuple.mapFirst (\gltf -> { model | gltf = gltf })

The onComplete function will be called when the query is ready. Your application Msg type should handle these:

type Msg
    = GltfMsg Gltf.Msg
    | GltfOnComplete (Result Gltf.Error Gltf.QueryResult)

In the onComplete handler you can use the content functions to get a tree of nodes, animations, cameras etc.

Load content

getBinary : String -> (Msg -> msg) -> Cmd msg

Get default scene from a file of type .glb

Note: If file does not specify a default scene this returns the first in list

getGltf : String -> (Msg -> msg) -> Cmd msg

Get default scene from a file of type .gltf

Note: If file does not specify a default scene this returns the first in list

getBinaryWithQuery : String -> Query -> (Msg -> msg) -> Cmd msg

Get content from a file of type .glb by supplying one of following queries:

getGltfWithQuery : String -> Query -> (Msg -> msg) -> Cmd msg

Get content from a file of type .gltf by supplying one of following queries:

Queries

Queries the glTF file for the default scene. If no default scene is defined this will query the first scene.

sceneQuery : Int -> Query

Queries the glTF file for scene by index.

query : Query -> (Msg -> msg) -> QueryResult -> Cmd msg

Query an already loaded file

Content

animations : QueryResult -> List Animation

Get all animations

cameras : QueryResult -> List Camera

Get all cameras

nodeTrees : QueryResult -> List (Tree Node)

Get node trees returned by query

scenes : QueryResult -> List Scene

Get information of all scenes

Get all skins

cameraByIndex : Index -> QueryResult -> Maybe Camera

Get camera by index

textureWithIndex : QueryResult -> TextureIndex -> Maybe Texture

Get texture by index.