declension / elm-obj-loader / OBJ.Types

These are the types used by the obj loader.


type alias ObjFile =
Dict String (Dict String Mesh)

A .obj file is optionally divided into different groups/objects. Each group/object is optionally made up of different meshes, each with it's own material.

So the keys of this dictionary are:

Dict GroupNameOrObjectName (Dict MaterialName Mesh)

If no name is specified in the input file, "default" will be used instead.


type Mesh
    = WithoutTexture (MeshWith Vertex)
    | WithTexture (MeshWith VertexWithTexture)
    | WithTextureAndTangent (MeshWith VertexWithTextureAndTangent)

A Mesh loaded by the obj loader is a record with a list of vertices and a list of indices. Depending on the mesh type and the loading options you get a different kind of mesh. They differ on what information a vertex contains.

These meshes are meant to be used with WebGL.indexedTriangles mesh.vertices mesh.indices.


type alias Vertex =
{ position : Math.Vector3.Vec3
, normal : Math.Vector3.Vec3 
}

A 3D position with a normal


type alias VertexWithTexture =
{ position : Math.Vector3.Vec3
, texCoord : Math.Vector2.Vec2
, normal : Math.Vector3.Vec3 
}

A 3D position with a normal and a 2D texture position.


type alias VertexWithTextureAndTangent =
{ position : Math.Vector3.Vec3
, texCoord : Math.Vector2.Vec2
, normal : Math.Vector3.Vec3
, tangent : Math.Vector4.Vec4 
}

The tangent is a vector pointing tangential to the object surface, in the direction of the u texture coordinate. This is needed for doing tangent space normal mapping. The 4th component is either 1 or -1 and has to be used to get the bitangent in the glsl shader, e.g: vec3 bitangent = cross(normal, tangent.xyz) * tangent.w

more info here: https://web.archive.org/web/20160409104130/http://www.terathon.com/code/tangent.html