From 79056da4be10105168eb572b9b01b468fb62b79b Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 14 Sep 2019 09:12:08 +0200 Subject: [PATCH] closes https://github.com/assimp/assimp/issues/2613 : merge glTF2 patch. --- code/glTF/glTFAsset.inl | 8 ++++++-- code/glTF/glTFImporter.cpp | 7 +++++-- code/glTF2/glTF2Asset.inl | 7 +++++-- code/glTF2/glTF2Importer.cpp | 16 ++++++++++++++-- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/code/glTF/glTFAsset.inl b/code/glTF/glTFAsset.inl index c06aa7fb5..f31781a3f 100644 --- a/code/glTF/glTFAsset.inl +++ b/code/glTF/glTFAsset.inl @@ -1180,8 +1180,12 @@ inline void Light::SetDefaults() falloffExponent = 0.f; } -inline void Node::Read(Value& obj, Asset& r) -{ +inline +void Node::Read(Value& obj, Asset& r) { + if (name.empty()) { + name = id; + } + if (Value* children = FindArray(obj, "children")) { this->children.reserve(children->Size()); for (unsigned int i = 0; i < children->Size(); ++i) { diff --git a/code/glTF/glTFImporter.cpp b/code/glTF/glTFImporter.cpp index cc7ab7211..3f2afbdf9 100644 --- a/code/glTF/glTFImporter.cpp +++ b/code/glTF/glTFImporter.cpp @@ -475,14 +475,17 @@ void glTFImporter::ImportCameras(glTF::Asset& r) { if (cam.type == Camera::Perspective) { aicam->mAspect = cam.perspective.aspectRatio; - aicam->mHorizontalFOV = cam.perspective.yfov * aicam->mAspect; + aicam->mHorizontalFOV = cam.cameraProperties.perspective.yfov * ((aicam->mAspect == 0.f) ? 1.f : aicam->mAspect); aicam->mClipPlaneFar = cam.perspective.zfar; aicam->mClipPlaneNear = cam.perspective.znear; } else { aicam->mClipPlaneFar = cam.ortographic.zfar; aicam->mClipPlaneNear = cam.ortographic.znear; aicam->mHorizontalFOV = 0.0; - aicam->mAspect = cam.ortographic.xmag / cam.ortographic.ymag; + aicam->mAspect = 1.0f; + if (0.f != cam.cameraProperties.ortographic.ymag) { + aicam->mAspect = cam.cameraProperties.ortographic.xmag / cam.cameraProperties.ortographic.ymag; + } } } } diff --git a/code/glTF2/glTF2Asset.inl b/code/glTF2/glTF2Asset.inl index e5e4a58c1..6b47b1607 100644 --- a/code/glTF2/glTF2Asset.inl +++ b/code/glTF2/glTF2Asset.inl @@ -1098,8 +1098,11 @@ inline void Light::Read(Value& obj, Asset& /*r*/) } } -inline void Node::Read(Value& obj, Asset& r) -{ +inline +void Node::Read(Value& obj, Asset& r) { + if (name.empty()) { + name = id; + } if (Value* children = FindArray(obj, "children")) { this->children.reserve(children->Size()); diff --git a/code/glTF2/glTF2Importer.cpp b/code/glTF2/glTF2Importer.cpp index 6eb71652a..d1871ce0e 100644 --- a/code/glTF2/glTF2Importer.cpp +++ b/code/glTF2/glTF2Importer.cpp @@ -702,14 +702,17 @@ void glTF2Importer::ImportCameras(glTF2::Asset& r) if (cam.type == Camera::Perspective) { aicam->mAspect = cam.cameraProperties.perspective.aspectRatio; - aicam->mHorizontalFOV = cam.cameraProperties.perspective.yfov * aicam->mAspect; + aicam->mHorizontalFOV = cam.cameraProperties.perspective.yfov * ((aicam->mAspect == 0.f) ? 1.f : aicam->mAspect); aicam->mClipPlaneFar = cam.cameraProperties.perspective.zfar; aicam->mClipPlaneNear = cam.cameraProperties.perspective.znear; } else { aicam->mClipPlaneFar = cam.cameraProperties.ortographic.zfar; aicam->mClipPlaneNear = cam.cameraProperties.ortographic.znear; aicam->mHorizontalFOV = 0.0; - aicam->mAspect = cam.cameraProperties.ortographic.xmag / cam.cameraProperties.ortographic.ymag; + aicam->mAspect = 1.0f; + if (0.f != cam.cameraProperties.ortographic.ymag ) { + aicam->mAspect = cam.cameraProperties.ortographic.xmag / cam.cameraProperties.ortographic.ymag; + } } } } @@ -905,6 +908,9 @@ aiNode* ImportNode(aiScene* pScene, glTF2::Asset& r, std::vector& std::vector> weighting(mesh->mNumBones); BuildVertexWeightMapping(node.meshes[0]->primitives[primitiveNo], weighting); + mat4* pbindMatrices = nullptr; + node.skin->inverseBindMatrices->ExtractData(pbindMatrices); + for (uint32_t i = 0; i < mesh->mNumBones; ++i) { aiBone* bone = new aiBone(); @@ -920,6 +926,8 @@ aiNode* ImportNode(aiScene* pScene, glTF2::Asset& r, std::vector& } GetNodeTransform(bone->mOffsetMatrix, *joint); + CopyValue(pbindMatrices[i], bone->mOffsetMatrix); + std::vector& weights = weighting[i]; bone->mNumWeights = static_cast(weights.size()); @@ -935,6 +943,10 @@ aiNode* ImportNode(aiScene* pScene, glTF2::Asset& r, std::vector& } mesh->mBones[i] = bone; } + + if (pbindMatrices) { + delete[] pbindMatrices; + } } }