From 08dd1a975a33aec9dc6f18568b0d014551983b66 Mon Sep 17 00:00:00 2001 From: s-ol Date: Fri, 9 Apr 2021 14:59:54 +0200 Subject: Give access to individual node transforms --- AssetLoader/include/GLTFLoader.hpp | 54 +++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) (limited to 'AssetLoader/include') diff --git a/AssetLoader/include/GLTFLoader.hpp b/AssetLoader/include/GLTFLoader.hpp index 2b9afaf..9f3e10f 100644 --- a/AssetLoader/include/GLTFLoader.hpp +++ b/AssetLoader/include/GLTFLoader.hpp @@ -229,6 +229,16 @@ struct Camera float4x4 matrix; }; +struct GLTF_Transform +{ + float3 Translation; + float _pad0; + float3 Scale = float3{1, 1, 1}; + float _pad1; + Quaternion Rotation; + float4x4 Matrix; +}; + struct Node { std::string Name; @@ -237,14 +247,15 @@ struct Node std::vector> Children; - float4x4 Matrix; std::unique_ptr pMesh; std::unique_ptr pCamera; Skin* pSkin = nullptr; Int32 SkinIndex = -1; - float3 Translation; - float3 Scale = float3{1, 1, 1}; - Quaternion Rotation; + GLTF_Transform Transform; + // float3 Translation; + // float3 Scale = float3{1, 1, 1}; + // Quaternion Rotation; + // float4x4 Matrix; BoundBox BVH; BoundBox AABB; @@ -386,6 +397,41 @@ public: 0; } + virtual bool GetNodeIndex(const char* Name, Uint32* Idx) const override final + { + uint32_t i = 0; + for (auto* node : LinearNodes) + { + if (node->Name.compare(Name) == 0) + { + *Idx = i; + return true; + } + i++; + } + + return false; + } + + virtual void GetNodeTransform(Uint32 Idx, GLTF_Transform* Transform) override final + { + *Transform = LinearNodes[Idx]->Transform; + } + + virtual void SetNodeTransform(Uint32 Idx, GLTF_Transform* Transform) override final + { + LinearNodes[Idx]->Transform = *Transform; + } + + virtual void UpdateTransforms() override final + { + for (auto& root_node : Nodes) + { + root_node->UpdateTransforms(); + } + CalculateSceneDimensions(); + } + private: void LoadFromFile(IRenderDevice* pDevice, IDeviceContext* pContext, -- cgit v1.2.3