git.s-ol.nu ~forks/DiligentTools / 8cc4d58
GLTF Loader: added assiduous 11 months ago
2 changed file(s) with 26 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
347347
348348 /// Optional resource cache usage info.
349349 ResourceCacheUseInfo* pCacheInfo = nullptr;
350
351 /// Optional transform to apply to the model
352 const float4x4* pTransform = nullptr;
353350 };
354351 Model(IRenderDevice* pDevice,
355352 IDeviceContext* pContext,
360357 void UpdateAnimation(Uint32 index, float time);
361358
362359 void PrepareGPUResources(IRenderDevice* pDevice, IDeviceContext* pCtx);
360
361 void Transform(const float4x4& Matrix);
363362
364363 IBuffer* GetBuffer(BUFFER_ID BuffId)
365364 {
414413 void LoadMaterials(const tinygltf::Model& gltf_model);
415414 void LoadAnimations(const tinygltf::Model& gltf_model);
416415 void CalculateBoundingBox(Node* node, const Node* parent);
417 void GetSceneDimensions();
416 void CalculateSceneDimensions();
418417 Node* FindNode(Node* parent, Uint32 index);
419418 Node* NodeFromIndex(uint32_t index);
420419
203203
204204 float4x4 Node::LocalMatrix() const
205205 {
206 return Matrix * float4x4::Scale(Scale) * Rotation.ToMatrix() * float4x4::Translation(Translation);
206 // Translation, rotation, and scale properties and local space transformation are
207 // mutually exclusive in GLTF.
208 // We, however, may use non-trivial Matrix with TRS to apply transform to a model.
209 return float4x4::Scale(Scale) * Rotation.ToMatrix() * float4x4::Translation(Translation) * Matrix;
207210 }
208211
209212 float4x4 Node::GetMatrix() const
270273 NewNode->SkinIndex = gltf_node.skin;
271274 NewNode->Matrix = float4x4::Identity();
272275
276 // Any node can define a local space transformation either by supplying a matrix property,
277 // or any of translation, rotation, and scale properties (also known as TRS properties).
278
273279 // Generate local node matrix
274280 //float3 Translation;
275281 if (gltf_node.translation.size() == 3)
306312 if (gltf_node.mesh > -1)
307313 {
308314 const tinygltf::Mesh& gltf_mesh = gltf_model.meshes[gltf_node.mesh];
309 std::unique_ptr<Mesh> pNewMesh{new Mesh(pDevice, NewNode->Matrix)};
315 std::unique_ptr<Mesh> pNewMesh{new Mesh{pDevice, NewNode->Matrix}};
310316 for (size_t j = 0; j < gltf_mesh.primitives.size(); j++)
311317 {
312318 const tinygltf::Primitive& primitive = gltf_mesh.primitives[j];
17641770 PrepareGPUResources(pDevice, pContext);
17651771 }
17661772
1767 GetSceneDimensions();
1773 CalculateSceneDimensions();
17681774 }
17691775
17701776 void Model::CalculateBoundingBox(Node* node, const Node* parent)
17941800 }
17951801 }
17961802
1797 void Model::GetSceneDimensions()
1803 void Model::CalculateSceneDimensions()
17981804 {
17991805 // Calculate binary volume hierarchy for all nodes in the scene
18001806 for (auto* node : LinearNodes)
18951901 }
18961902 }
18971903
1904 void Model::Transform(const float4x4& Matrix)
1905 {
1906 for (auto& root_node : Nodes)
1907 root_node->Matrix *= Matrix;
1908
1909 for (auto* node : LinearNodes)
1910 {
1911 if (node->pMesh)
1912 node->Update();
1913 }
1914
1915 CalculateSceneDimensions();
1916 }
18981917
18991918 Node* Model::FindNode(Node* parent, Uint32 index)
19001919 {