summaryrefslogtreecommitdiffstats
path: root/AssetLoader/src/GLTFLoader.cpp
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-01-08 05:36:58 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-01-08 05:36:58 +0000
commita6339f1cb8757a1f349083e8c5e5ee2c2c342e5d (patch)
treee8471cbfb4ce195bd7e98aa29d3d26dc74f23c6e /AssetLoader/src/GLTFLoader.cpp
parentUpdated more copyright notices (diff)
downloadDiligentTools-a6339f1cb8757a1f349083e8c5e5ee2c2c342e5d.tar.gz
DiligentTools-a6339f1cb8757a1f349083e8c5e5ee2c2c342e5d.zip
GLTF Loader: added camera loading
Diffstat (limited to 'AssetLoader/src/GLTFLoader.cpp')
-rw-r--r--AssetLoader/src/GLTFLoader.cpp44
1 files changed, 42 insertions, 2 deletions
diff --git a/AssetLoader/src/GLTFLoader.cpp b/AssetLoader/src/GLTFLoader.cpp
index 72862b8..a48969e 100644
--- a/AssetLoader/src/GLTFLoader.cpp
+++ b/AssetLoader/src/GLTFLoader.cpp
@@ -223,9 +223,10 @@ float4x4 Node::GetMatrix() const
void Node::UpdateTransforms()
{
+ const auto NodeTransform = (pMesh || pCamera) ? GetMatrix() : float4x4::Identity();
if (pMesh)
{
- pMesh->Transforms.matrix = GetMatrix();
+ pMesh->Transforms.matrix = NodeTransform;
if (pSkin != nullptr)
{
// Update join matrices
@@ -241,6 +242,11 @@ void Node::UpdateTransforms()
}
}
+ if (pCamera)
+ {
+ pCamera->matrix = NodeTransform;
+ }
+
for (auto& child : Children)
{
child->UpdateTransforms();
@@ -311,7 +317,7 @@ void Model::LoadNode(IRenderDevice* pDevice,
}
// Node contains mesh data
- if (gltf_node.mesh > -1)
+ if (gltf_node.mesh >= 0)
{
const tinygltf::Mesh& gltf_mesh = gltf_model.meshes[gltf_node.mesh];
std::unique_ptr<Mesh> pNewMesh{new Mesh{pDevice, NewNode->Matrix}};
@@ -552,6 +558,40 @@ void Model::LoadNode(IRenderDevice* pDevice,
NewNode->pMesh = std::move(pNewMesh);
}
+ // Node contains camera
+ if (gltf_node.camera >= 0)
+ {
+ const auto& gltf_cam = gltf_model.cameras[gltf_node.camera];
+
+ std::unique_ptr<Camera> pNewCamera{new Camera{}};
+ pNewCamera->Name = gltf_cam.name;
+
+ if (gltf_cam.type == "perspective")
+ {
+ pNewCamera->Type = Camera::Projection::Perspective;
+ pNewCamera->Perspective.AspectRatio = static_cast<float>(gltf_cam.perspective.aspectRatio);
+ pNewCamera->Perspective.YFov = static_cast<float>(gltf_cam.perspective.yfov);
+ pNewCamera->Perspective.ZNear = static_cast<float>(gltf_cam.perspective.znear);
+ pNewCamera->Perspective.ZFar = static_cast<float>(gltf_cam.perspective.zfar);
+ }
+ else if (gltf_cam.type == "orthographic")
+ {
+ pNewCamera->Type = Camera::Projection::Orthographic;
+ pNewCamera->Orthographic.XMag = static_cast<float>(gltf_cam.orthographic.xmag);
+ pNewCamera->Orthographic.YMag = static_cast<float>(gltf_cam.orthographic.ymag);
+ pNewCamera->Orthographic.ZNear = static_cast<float>(gltf_cam.orthographic.znear);
+ pNewCamera->Orthographic.ZFar = static_cast<float>(gltf_cam.orthographic.zfar);
+ }
+ else
+ {
+ UNEXPECTED("Unexpected camera type: ", gltf_cam.type);
+ pNewCamera.reset();
+ }
+
+ if (pNewCamera)
+ NewNode->pCamera = std::move(pNewCamera);
+ }
+
LinearNodes.push_back(NewNode.get());
if (parent)
{