diff --git a/src/Text/GLTF/Loader/Gltf.hs b/src/Text/GLTF/Loader/Gltf.hs index fc7da11..7ff4917 100644 --- a/src/Text/GLTF/Loader/Gltf.hs +++ b/src/Text/GLTF/Loader/Gltf.hs @@ -241,6 +241,8 @@ data MeshPrimitive = MeshPrimitive meshPrimitiveNormals :: Vector (V3 Float), -- | A Vector of vertex positions. meshPrimitivePositions :: Vector (V3 Float), + -- | A Vector of vertex tangents + meshPrimitiveTangents :: Vector (V4 Float), -- | A Vector of vertex texture coordinates meshPrimitiveTexCoords :: Vector (V2 Float), -- | A Vector of vertex colors. diff --git a/src/Text/GLTF/Loader/Internal/Adapter.hs b/src/Text/GLTF/Loader/Internal/Adapter.hs index d05409b..187f7a5 100644 --- a/src/Text/GLTF/Loader/Internal/Adapter.hs +++ b/src/Text/GLTF/Loader/Internal/Adapter.hs @@ -54,6 +54,9 @@ attributePosition = "POSITION" attributeNormal :: Text attributeNormal = "NORMAL" +attributeTangent :: Text +attributeTangent = "TANGENT" + attributeTexCoord :: Text attributeTexCoord = "TEXCOORD_0" @@ -296,6 +299,7 @@ adaptMeshPrimitive Mesh.MeshPrimitive{..} = do meshPrimitiveMode = adaptMeshPrimitiveMode mode, meshPrimitiveNormals = maybe mempty (vertexNormals gltf buffers') normals, meshPrimitivePositions = maybe mempty (vertexPositions gltf buffers') positions, + meshPrimitiveTangents = maybe mempty (vertexTangents gltf buffers') tangents, meshPrimitiveTexCoords = maybe mempty (vertexTexCoords gltf buffers') texCoords, meshPrimitiveColors = maybe mempty (fmap (mapV4 toRatio) . vertexColors gltf buffers') colors @@ -303,6 +307,7 @@ adaptMeshPrimitive Mesh.MeshPrimitive{..} = do where positions = attributes HashMap.!? attributePosition normals = attributes HashMap.!? attributeNormal + tangents = attributes HashMap.!? attributeTangent texCoords = attributes HashMap.!? attributeTexCoord colors = attributes HashMap.!? attributeColors toRatio w = fromIntegral w / fromIntegral (maxBound :: Word16) diff --git a/src/Text/GLTF/Loader/Internal/BufferAccessor.hs b/src/Text/GLTF/Loader/Internal/BufferAccessor.hs index d5e8934..1e9ff6a 100644 --- a/src/Text/GLTF/Loader/Internal/BufferAccessor.hs +++ b/src/Text/GLTF/Loader/Internal/BufferAccessor.hs @@ -11,6 +11,7 @@ module Text.GLTF.Loader.Internal.BufferAccessor vertexPositions, vertexNormals, vertexTexCoords, + vertexTangents, vertexColors, imageDataRaw, ) where @@ -109,6 +110,10 @@ vertexPositions = readBufferWithGet getPositions vertexNormals :: GlTF -> Vector GltfBuffer -> AccessorIx -> Vector (V3 Float) vertexNormals = readBufferWithGet getNormals +-- | Decode vertex tangents +vertexTangents :: GlTF -> Vector GltfBuffer -> AccessorIx -> Vector (V4 Float) +vertexTangents = readBufferWithGet getTangents + -- | Decode texture coordinates. Note that we only use the first one. vertexTexCoords :: GlTF -> Vector GltfBuffer -> AccessorIx -> Vector (V2 Float) vertexTexCoords = readBufferWithGet getTexCoords diff --git a/src/Text/GLTF/Loader/Internal/Decoders.hs b/src/Text/GLTF/Loader/Internal/Decoders.hs index 09b779d..c182d43 100644 --- a/src/Text/GLTF/Loader/Internal/Decoders.hs +++ b/src/Text/GLTF/Loader/Internal/Decoders.hs @@ -4,6 +4,7 @@ module Text.GLTF.Loader.Internal.Decoders getIndices32, getPositions, getNormals, + getTangents, getTexCoords, getColors, @@ -46,6 +47,10 @@ getPositions = getVec3 getFloat getNormals :: Get (Vector (V3 Float)) getNormals = getVec3 getFloat +-- | Vertex tangents binary decoder +getTangents :: Get (Vector (V4 Float)) +getTangents = getVec4 getFloat + -- | Texture coordinates binary decoder getTexCoords :: Get (Vector (V2 Float)) getTexCoords = getVec2 getFloat