git.s-ol.nu ~forks/DiligentTools / 74b40c5
GLTFLoader: fixed variable type/name conflicts assiduous 11 months ago
2 changed file(s) with 44 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
123123 {
124124 ALPHA_MODE_OPAQUE,
125125 ALPHA_MODE_MASK,
126 ALPHA_MODE_BLEND
126 ALPHA_MODE_BLEND,
127 ALPHA_MODE_NUM_MODES
127128 };
128129 ALPHA_MODE AlphaMode = ALPHA_MODE_OPAQUE;
129130
225226 std::vector<std::unique_ptr<Node>> Children;
226227
227228 float4x4 Matrix;
228 std::unique_ptr<Mesh> Mesh;
229 Skin* Skin = nullptr;
229 std::unique_ptr<Mesh> pMesh;
230 Skin* pSkin = nullptr;
230231 Int32 SkinIndex = -1;
231232 float3 Translation;
232233 float3 Scale = float3{1, 1, 1};
251252 SCALE
252253 };
253254 PATH_TYPE PathType;
254 Node* node = nullptr;
255 Node* pNode = nullptr;
255256 Uint32 SamplerIndex = static_cast<Uint32>(-1);
256257 };
257258
219219
220220 void Node::Update()
221221 {
222 if (Mesh)
223 {
224 Mesh->Transforms.matrix = GetMatrix();
225 if (Skin != nullptr)
222 if (pMesh)
223 {
224 pMesh->Transforms.matrix = GetMatrix();
225 if (pSkin != nullptr)
226226 {
227227 // Update join matrices
228 auto InverseTransform = Mesh->Transforms.matrix.Inverse(); // TODO: do not use inverse tranform here
229 if (Mesh->Transforms.jointMatrices.size() != Skin->Joints.size())
230 Mesh->Transforms.jointMatrices.resize(Skin->Joints.size());
231 for (size_t i = 0; i < Skin->Joints.size(); i++)
232 {
233 auto* JointNode = Skin->Joints[i];
234 Mesh->Transforms.jointMatrices[i] =
235 Skin->InverseBindMatrices[i] * JointNode->GetMatrix() * InverseTransform;
228 auto InverseTransform = pMesh->Transforms.matrix.Inverse(); // TODO: do not use inverse tranform here
229 if (pMesh->Transforms.jointMatrices.size() != pSkin->Joints.size())
230 pMesh->Transforms.jointMatrices.resize(pSkin->Joints.size());
231 for (size_t i = 0; i < pSkin->Joints.size(); i++)
232 {
233 auto* JointNode = pSkin->Joints[i];
234 pMesh->Transforms.jointMatrices[i] =
235 pSkin->InverseBindMatrices[i] * JointNode->GetMatrix() * InverseTransform;
236236 }
237237 }
238238 }
312312 if (gltf_node.mesh > -1)
313313 {
314314 const tinygltf::Mesh& gltf_mesh = gltf_model.meshes[gltf_node.mesh];
315 std::unique_ptr<Mesh> NewMesh{new Mesh(pDevice, NewNode->Matrix)};
315 std::unique_ptr<Mesh> pNewMesh{new Mesh(pDevice, NewNode->Matrix)};
316316 for (size_t j = 0; j < gltf_mesh.primitives.size(); j++)
317317 {
318318 const tinygltf::Primitive& primitive = gltf_mesh.primitives[j];
521521 return;
522522 }
523523 }
524 NewMesh->Primitives.emplace_back( //
524 pNewMesh->Primitives.emplace_back( //
525525 indexStart,
526526 indexCount,
527527 vertexCount,
532532 );
533533 }
534534
535 if (!NewMesh->Primitives.empty())
535 if (!pNewMesh->Primitives.empty())
536536 {
537537 // Mesh BB from BBs of primitives
538 NewMesh->BB = NewMesh->Primitives[0].BB;
539 for (size_t prim = 1; prim < NewMesh->Primitives.size(); ++prim)
540 {
541 const auto& PrimBB = NewMesh->Primitives[prim].BB;
542 NewMesh->BB.Min = std::min(NewMesh->BB.Min, PrimBB.Min);
543 NewMesh->BB.Max = std::max(NewMesh->BB.Max, PrimBB.Max);
544 }
545 }
546
547 NewNode->Mesh = std::move(NewMesh);
538 pNewMesh->BB = pNewMesh->Primitives[0].BB;
539 for (size_t prim = 1; prim < pNewMesh->Primitives.size(); ++prim)
540 {
541 const auto& PrimBB = pNewMesh->Primitives[prim].BB;
542 pNewMesh->BB.Min = std::min(pNewMesh->BB.Min, PrimBB.Min);
543 pNewMesh->BB.Max = std::max(pNewMesh->BB.Max, PrimBB.Max);
544 }
545 }
546
547 NewNode->pMesh = std::move(pNewMesh);
548548 }
549549
550550 LinearNodes.push_back(NewNode.get());
13141314 }
13151315
13161316 channel.SamplerIndex = source.sampler;
1317 channel.node = NodeFromIndex(source.target_node);
1318 if (!channel.node)
1317 channel.pNode = NodeFromIndex(source.target_node);
1318 if (!channel.pNode)
13191319 {
13201320 continue;
13211321 }
16921692 // Assign skins
16931693 if (node->SkinIndex >= 0)
16941694 {
1695 node->Skin = Skins[node->SkinIndex].get();
1695 node->pSkin = Skins[node->SkinIndex].get();
16961696 }
16971697
16981698 // Initial pose
1699 if (node->Mesh)
1699 if (node->pMesh)
17001700 {
17011701 node->Update();
17021702 }
17881788 {
17891789 BoundBox parentBvh = parent ? parent->BVH : BoundBox{dimensions.min, dimensions.max};
17901790
1791 if (node->Mesh)
1792 {
1793 if (node->Mesh->IsValidBB())
1794 {
1795 node->AABB = node->Mesh->BB.Transform(node->GetMatrix());
1791 if (node->pMesh)
1792 {
1793 if (node->pMesh->IsValidBB())
1794 {
1795 node->AABB = node->pMesh->BB.Transform(node->GetMatrix());
17961796 if (node->Children.empty())
17971797 {
17981798 node->BVH.Min = node->AABB.Min;
18671867 {
18681868 case AnimationChannel::PATH_TYPE::TRANSLATION:
18691869 {
1870 float4 trans = lerp(sampler.OutputsVec4[i], sampler.OutputsVec4[i + 1], u);
1871 channel.node->Translation = float3(trans);
1870 float4 trans = lerp(sampler.OutputsVec4[i], sampler.OutputsVec4[i + 1], u);
1871 channel.pNode->Translation = float3(trans);
18721872 break;
18731873 }
18741874
18751875 case AnimationChannel::PATH_TYPE::SCALE:
18761876 {
1877 float4 scale = lerp(sampler.OutputsVec4[i], sampler.OutputsVec4[i + 1], u);
1878 channel.node->Scale = float3(scale);
1877 float4 scale = lerp(sampler.OutputsVec4[i], sampler.OutputsVec4[i + 1], u);
1878 channel.pNode->Scale = float3(scale);
18791879 break;
18801880 }
18811881
18931893 q2.q.z = sampler.OutputsVec4[i + 1].z;
18941894 q2.q.w = sampler.OutputsVec4[i + 1].w;
18951895
1896 channel.node->Rotation = normalize(slerp(q1, q2, u));
1896 channel.pNode->Rotation = normalize(slerp(q1, q2, u));
18971897 break;
18981898 }
18991899 }