From 45c80a6aae967bcbf7e877b8976538136568f281 Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 21 Feb 2024 11:58:43 +0000 Subject: [PATCH] Parse node rotations as Linear.Quaternion. --- src/Text/GLTF/Loader/Gltf.hs | 4 ++-- src/Text/GLTF/Loader/Internal/Adapter.hs | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Text/GLTF/Loader/Gltf.hs b/src/Text/GLTF/Loader/Gltf.hs index 0697230..129df22 100644 --- a/src/Text/GLTF/Loader/Gltf.hs +++ b/src/Text/GLTF/Loader/Gltf.hs @@ -152,7 +152,7 @@ data Node = Node -- | The user-defined name of this object. nodeName :: Maybe Text, -- | The node's unit quaternion rotation. - nodeRotation :: Maybe (V4 Float), + nodeRotation :: Maybe (Quaternion Float), -- | The node's non-uniform scale nodeScale :: Maybe (V3 Float), -- | The node's translation along the x, y, and z axes. @@ -396,7 +396,7 @@ _nodeName :: Lens' Node (Maybe Text) _nodeName = lens nodeName (\node name' -> node { nodeName = name' }) -- | The node's unit quaternion rotation. -_nodeRotation :: Lens' Node (Maybe (V4 Float)) +_nodeRotation :: Lens' Node (Maybe (Quaternion Float)) _nodeRotation = lens nodeRotation (\node rotation' -> node { nodeRotation = rotation' }) -- | The node's non-uniform scale diff --git a/src/Text/GLTF/Loader/Internal/Adapter.hs b/src/Text/GLTF/Loader/Internal/Adapter.hs index 097bd33..1e9034c 100644 --- a/src/Text/GLTF/Loader/Internal/Adapter.hs +++ b/src/Text/GLTF/Loader/Internal/Adapter.hs @@ -28,7 +28,7 @@ import Text.GLTF.Loader.Gltf import Text.GLTF.Loader.Internal.BufferAccessor import Text.GLTF.Loader.Internal.MonadAdapter -import Linear (V3(..), V4(..)) +import Linear (Quaternion(..), V3(..), V4(..)) import RIO import RIO.Partial (toEnum) import RIO.Vector.Partial ((!)) @@ -155,7 +155,7 @@ adaptNode Node.Node{..} = Node { nodeChildren = maybe mempty (fmap Node.unNodeIx) children, nodeMeshId = Mesh.unMeshIx <$> mesh, nodeName = name, - nodeRotation = toV4 <$> rotation, + nodeRotation = toQuaternion <$> rotation, nodeScale = toV3 <$> scale, nodeTranslation = toV3 <$> translation, nodeWeights = maybe [] toList weights @@ -261,3 +261,6 @@ toV3 (x, y, z) = V3 x y z toV4 :: (a, a, a, a) -> V4 a toV4 (w, x, y, z) = V4 w x y z + +toQuaternion :: (a, a, a, a) -> Quaternion a +toQuaternion (x, y, z, w) = Quaternion w (V3 x y z)