From d4970525053e3a60a5b10933c3edf55cf9397e2e Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Wed, 23 Oct 2019 17:13:34 -0700 Subject: [PATCH 1/4] Fix GLTF claiming to have no cluster weights when it is skinned --- libraries/fbx/src/GLTFSerializer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/fbx/src/GLTFSerializer.cpp b/libraries/fbx/src/GLTFSerializer.cpp index ea31f74312..021821befd 100755 --- a/libraries/fbx/src/GLTFSerializer.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -1394,6 +1394,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& uint16_t weight = std::round(clusterWeights[weightIndex] * 65535.0); mesh.clusterWeights.push_back(weight); } + mesh.clusterWeightsPerVertex = WEIGHTS_PER_VERTEX; } if (joints.size() == partVerticesCount * jointStride) { From 1fe1321b6ca8b584e830ab7ec700b9312a3dca90 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Thu, 24 Oct 2019 10:53:46 -0700 Subject: [PATCH 2/4] Disable GLTF skinning --- libraries/fbx/src/GLTFSerializer.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libraries/fbx/src/GLTFSerializer.cpp b/libraries/fbx/src/GLTFSerializer.cpp index 021821befd..456bad9346 100755 --- a/libraries/fbx/src/GLTFSerializer.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -1543,6 +1543,24 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& } } + // TODO: Fix skinning and remove this workaround which disables skinning + { + std::vector meshToRootJoint; + meshToRootJoint.resize(hfmModel.meshes.size(), -1); + std::vector meshToClusterSize; + meshToClusterSize.resize(hfmModel.meshes.size()); + for (auto& shape : hfmModel.shapes) { + shape.skinDeformer = hfm::UNDEFINED_KEY; + } + + for (auto& mesh : hfmModel.meshes) { + mesh.clusterWeights.clear(); + mesh.clusterIndices.clear(); + mesh.clusterWeightsPerVertex = 0; + } + + } + return true; } From 83229db45859c7a2a75b153c098f79400225fd98 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Thu, 24 Oct 2019 14:59:09 -0700 Subject: [PATCH 3/4] Fix GLTFSerializer not reading tangents --- libraries/fbx/src/GLTFSerializer.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/libraries/fbx/src/GLTFSerializer.cpp b/libraries/fbx/src/GLTFSerializer.cpp index 456bad9346..16d2962ecc 100755 --- a/libraries/fbx/src/GLTFSerializer.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -1315,8 +1315,6 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& float tanW = tangentStride == 4 ? tangents[n + 3] : 1; mesh.tangents.push_back(glm::vec3(tanW * tangents[n], tangents[n + 1], tanW * tangents[n + 2])); } - } else if (primitiveAttributes.contains("TANGENT")) { - mesh.tangents.resize(mesh.tangents.size() + partVerticesCount); } if (texcoords.size() == partVerticesCount * TEX_COORD_STRIDE) { @@ -1874,7 +1872,6 @@ bool GLTFSerializer::addArrayFromAttribute(GLTFVertexAttribute::Value vertexAttr qWarning(modelformat) << "Invalid accessor type on glTF TANGENT data for model " << _url; return false; } - break; if (!addArrayFromAccessor(accessor, outarray)) { qWarning(modelformat) << "There was a problem reading glTF TANGENT data for model " << _url; From 4e0db5d6414e621c36ee3e4e8172dadb7dad51b6 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Thu, 24 Oct 2019 15:45:06 -0700 Subject: [PATCH 4/4] Fix build warnings --- libraries/animation/src/AnimSkeleton.cpp | 2 +- libraries/fbx/src/GLTFSerializer.cpp | 3 ++- libraries/fbx/src/OBJSerializer.cpp | 4 ++-- libraries/render-utils/src/CauterizedModel.cpp | 3 +-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/animation/src/AnimSkeleton.cpp b/libraries/animation/src/AnimSkeleton.cpp index 5074ac0776..b60fc42f89 100644 --- a/libraries/animation/src/AnimSkeleton.cpp +++ b/libraries/animation/src/AnimSkeleton.cpp @@ -28,7 +28,7 @@ AnimSkeleton::AnimSkeleton(const HFMModel& hfmModel) { const auto& defor = hfmModel.skinDeformers[i]; std::vector dummyClustersList; - for (int j = 0; j < (uint32_t) defor.clusters.size(); j++) { + for (uint32_t j = 0; j < (uint32_t)defor.clusters.size(); j++) { // cast into a non-const reference, so we can mutate the FBXCluster HFMCluster& cluster = const_cast(defor.clusters.at(j)); diff --git a/libraries/fbx/src/GLTFSerializer.cpp b/libraries/fbx/src/GLTFSerializer.cpp index 16d2962ecc..115e7e0ca7 100755 --- a/libraries/fbx/src/GLTFSerializer.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -1389,7 +1389,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& mesh.clusterWeights.reserve(newWeightsEnd); for (int weightIndex = 0; weightIndex < clusterWeights.size(); ++weightIndex) { // Per the GLTF specification - uint16_t weight = std::round(clusterWeights[weightIndex] * 65535.0); + uint16_t weight = std::round(clusterWeights[weightIndex] * 65535.0f); mesh.clusterWeights.push_back(weight); } mesh.clusterWeightsPerVertex = WEIGHTS_PER_VERTEX; @@ -1542,6 +1542,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& } // TODO: Fix skinning and remove this workaround which disables skinning + // TODO: Restore after testing { std::vector meshToRootJoint; meshToRootJoint.resize(hfmModel.meshes.size(), -1); diff --git a/libraries/fbx/src/OBJSerializer.cpp b/libraries/fbx/src/OBJSerializer.cpp index 57fcf79aac..445c259650 100644 --- a/libraries/fbx/src/OBJSerializer.cpp +++ b/libraries/fbx/src/OBJSerializer.cpp @@ -1008,8 +1008,8 @@ HFMModel::Pointer OBJSerializer::read(const hifi::ByteArray& data, const hifi::V modelMaterial->setOpacity(hfmMaterial.opacity); } - // GO over the shapes once more to assign hte material index correctly - for (int i = 0; i < (uint32_t) hfmModel.shapes.size(); ++i) { + // GO over the shapes once more to assign the material index correctly + for (uint32_t i = 0; i < (uint32_t)hfmModel.shapes.size(); ++i) { auto foundMaterialIndex = materialNameToIndex.find(materialNamePerShape[i]); if (foundMaterialIndex != materialNameToIndex.end()) { hfmModel.shapes[i].material = foundMaterialIndex.value(); diff --git a/libraries/render-utils/src/CauterizedModel.cpp b/libraries/render-utils/src/CauterizedModel.cpp index ca26b9739c..69710b2ed1 100644 --- a/libraries/render-utils/src/CauterizedModel.cpp +++ b/libraries/render-utils/src/CauterizedModel.cpp @@ -63,9 +63,8 @@ void CauterizedModel::createRenderItemSet() { Transform::mult(transform, transform, offset); // Run through all of the meshes, and place them into their segregated, but unsorted buckets - int shapeID = 0; const auto& shapes = _renderGeometry->getHFMModel().shapes; - for (shapeID; shapeID < (int) shapes.size(); shapeID++) { + for (int shapeID = 0; shapeID < (int) shapes.size(); shapeID++) { const auto& shape = shapes[shapeID]; _modelMeshRenderItems << std::make_shared(shared_from_this(), shape.mesh, shape.meshPart, shapeID, transform);