diff options
| author | s-ol <s+removethis@s-ol.nu> | 2021-04-09 12:59:54 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2021-04-12 12:12:40 +0000 |
| commit | 08dd1a975a33aec9dc6f18568b0d014551983b66 (patch) | |
| tree | d80edfa837137e10e3a7ac626cccfc81c650e924 /AssetLoader/src | |
| parent | implement loading GLTF files from memory (diff) | |
| download | DiligentTools-gltf-c-api.tar.gz DiligentTools-gltf-c-api.zip | |
Give access to individual node transformsgltf-c-api
Diffstat (limited to 'AssetLoader/src')
| -rw-r--r-- | AssetLoader/src/GLTFLoader.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/AssetLoader/src/GLTFLoader.cpp b/AssetLoader/src/GLTFLoader.cpp index 9fabac2..9d370f5 100644 --- a/AssetLoader/src/GLTFLoader.cpp +++ b/AssetLoader/src/GLTFLoader.cpp @@ -197,7 +197,7 @@ float4x4 Node::LocalMatrix() const // Translation, rotation, and scale properties and local space transformation are // mutually exclusive in GLTF. // We, however, may use non-trivial Matrix with TRS to apply transform to a model. - return float4x4::Scale(Scale) * Rotation.ToMatrix() * float4x4::Translation(Translation) * Matrix; + return float4x4::Scale(Transform.Scale) * Transform.Rotation.ToMatrix() * float4x4::Translation(Transform.Translation) * Transform.Matrix; } float4x4 Node::GetMatrix() const @@ -276,7 +276,7 @@ void Model::LoadNode(Node* parent, NewNode->Parent = parent; NewNode->Name = gltf_node.name; NewNode->SkinIndex = gltf_node.skin; - NewNode->Matrix = float4x4::Identity(); + NewNode->Transform.Matrix = float4x4::Identity(); // Any node can define a local space transformation either by supplying a matrix property, // or any of translation, rotation, and scale properties (also known as TRS properties). @@ -285,23 +285,23 @@ void Model::LoadNode(Node* parent, //float3 Translation; if (gltf_node.translation.size() == 3) { - NewNode->Translation = float3::MakeVector(gltf_node.translation.data()); + NewNode->Transform.Translation = float3::MakeVector(gltf_node.translation.data()); } if (gltf_node.rotation.size() == 4) { - NewNode->Rotation.q = float4::MakeVector(gltf_node.rotation.data()); + NewNode->Transform.Rotation.q = float4::MakeVector(gltf_node.rotation.data()); //NewNode->rotation = glm::mat4(q); } if (gltf_node.scale.size() == 3) { - NewNode->Scale = float3::MakeVector(gltf_node.scale.data()); + NewNode->Transform.Scale = float3::MakeVector(gltf_node.scale.data()); } if (gltf_node.matrix.size() == 16) { - NewNode->Matrix = float4x4::MakeMatrix(gltf_node.matrix.data()); + NewNode->Transform.Matrix = float4x4::MakeMatrix(gltf_node.matrix.data()); } // Node with children @@ -318,7 +318,7 @@ void Model::LoadNode(Node* parent, if (gltf_node.mesh >= 0) { const tinygltf::Mesh& gltf_mesh = gltf_model.meshes[gltf_node.mesh]; - std::unique_ptr<Mesh> pNewMesh{new Mesh{NewNode->Matrix}}; + std::unique_ptr<Mesh> pNewMesh{new Mesh{NewNode->Transform.Matrix}}; for (size_t j = 0; j < gltf_mesh.primitives.size(); j++) { const tinygltf::Primitive& primitive = gltf_mesh.primitives[j]; @@ -2017,14 +2017,14 @@ void Model::UpdateAnimation(Uint32 index, float time) case AnimationChannel::PATH_TYPE::TRANSLATION: { float4 trans = lerp(sampler.OutputsVec4[i], sampler.OutputsVec4[i + 1], u); - channel.pNode->Translation = float3(trans); + channel.pNode->Transform.Translation = float3(trans); break; } case AnimationChannel::PATH_TYPE::SCALE: { float4 scale = lerp(sampler.OutputsVec4[i], sampler.OutputsVec4[i + 1], u); - channel.pNode->Scale = float3(scale); + channel.pNode->Transform.Scale = float3(scale); break; } @@ -2042,7 +2042,7 @@ void Model::UpdateAnimation(Uint32 index, float time) q2.q.z = sampler.OutputsVec4[i + 1].z; q2.q.w = sampler.OutputsVec4[i + 1].w; - channel.pNode->Rotation = normalize(slerp(q1, q2, u)); + channel.pNode->Transform.Rotation = normalize(slerp(q1, q2, u)); break; } } @@ -2066,7 +2066,7 @@ void Model::Transform(const float* _Matrix) auto Matrix = float4x4::MakeMatrix(_Matrix); for (auto& root_node : Nodes) { - root_node->Matrix *= Matrix; + root_node->Transform.Matrix *= Matrix; root_node->UpdateTransforms(); } |
