Skip to content

Commit

Permalink
Parse node rotations as Linear.Quaternion.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew authored and mrehayden1 committed Feb 24, 2024
1 parent d133575 commit 45c80a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Text/GLTF/Loader/Gltf.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/Text/GLTF/Loader/Internal/Adapter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ((!))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 45c80a6

Please sign in to comment.