diff --git a/libraries/fbx/src/FBX.h b/libraries/fbx/src/FBX.h index 7d3328a2dd..2ec847104c 100644 --- a/libraries/fbx/src/FBX.h +++ b/libraries/fbx/src/FBX.h @@ -224,7 +224,7 @@ public: QVector texCoords; QVector texCoords1; QVector clusterIndices; - QVector clusterWeights; + QVector clusterWeights; QVector originalIndices; QVector clusters; diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index e4fea00a34..b1db5992e7 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -1727,9 +1727,9 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS } if (totalWeight > 0.0f) { const float ALMOST_HALF = 0.499f; - float weightScalingFactor = (float)(UINT8_MAX) / totalWeight; + float weightScalingFactor = (float)(UINT16_MAX) / totalWeight; for (int k = j; k < j + WEIGHTS_PER_VERTEX; ++k) { - extracted.mesh.clusterWeights[k] = (uint8_t)(weightScalingFactor * weightAccumulators[k] + ALMOST_HALF); + extracted.mesh.clusterWeights[k] = (uint16_t)(weightScalingFactor * weightAccumulators[k] + ALMOST_HALF); } } } diff --git a/libraries/fbx/src/FBXReader_Mesh.cpp b/libraries/fbx/src/FBXReader_Mesh.cpp index c64cbcc90d..f76435c216 100644 --- a/libraries/fbx/src/FBXReader_Mesh.cpp +++ b/libraries/fbx/src/FBXReader_Mesh.cpp @@ -583,7 +583,7 @@ void FBXReader::buildModelMesh(FBXMesh& extractedMesh, const QString& url) { // we need 16 bits instead of just 8 for clusterIndices clusterIndicesSize *= 2; } - int clusterWeightsSize = fbxMesh.clusterWeights.size() * sizeof(uint8_t); + int clusterWeightsSize = fbxMesh.clusterWeights.size() * sizeof(uint16_t); int normalsOffset = 0; int tangentsOffset = normalsOffset + normalsSize; @@ -662,7 +662,7 @@ void FBXReader::buildModelMesh(FBXMesh& extractedMesh, const QString& url) { if (clusterWeightsSize) { mesh->addAttribute(gpu::Stream::SKIN_CLUSTER_WEIGHT, model::BufferView(attribBuffer, clusterWeightsOffset, clusterWeightsSize, - gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::XYZW))); + gpu::Element(gpu::VEC4, gpu::NUINT16, gpu::XYZW))); } diff --git a/libraries/render-utils/src/CauterizedModel.cpp b/libraries/render-utils/src/CauterizedModel.cpp index 5be93304ab..7bac720b86 100644 --- a/libraries/render-utils/src/CauterizedModel.cpp +++ b/libraries/render-utils/src/CauterizedModel.cpp @@ -113,12 +113,7 @@ void CauterizedModel::updateClusterMatrices() { for (int i = 0; i < (int)_meshStates.size(); i++) { Model::MeshState& state = _meshStates[i]; const FBXMesh& mesh = geometry.meshes.at(i); -#if defined(SKIN_DQ) - // HACK: FOR DQ go thru reverse order! - for (int j = mesh.clusters.size() - 1; j >= 0; j--) { -#else for (int j = 0; j < mesh.clusters.size(); j++) { -#endif const FBXCluster& cluster = mesh.clusters.at(j); auto jointMatrix = _rig.getJointTransform(cluster.jointIndex); @@ -132,25 +127,6 @@ void CauterizedModel::updateClusterMatrices() { glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, m); AnimPose p(m); state.clusterTransforms[j] = Model::TransformDualQuaternion(m); - - // AJT: HACK n^2!!!! fix me, find parent clusterTransform. - int parentIndex = _rig.getJointParentIndex(cluster.jointIndex); - int parentClusterIndex = -1; - // scan for parent! - for (int ii = mesh.clusters.size() - 1; ii > j; ii--) { - if (mesh.clusters[ii].jointIndex == parentIndex) { - parentClusterIndex = ii; - break; - } - } - - // ensure that we have the same polarity as our parent! - if (parentClusterIndex >= 0) { - //if (state.clusterTransforms[parentClusterIndex]._dq.dot(state.clusterTransforms[j]._dq) < 0.0f) { - if (glm::dot(state.clusterTransforms[parentClusterIndex]._dq.real(), state.clusterTransforms[j]._dq.real()) < 0.0f) { - state.clusterTransforms[j]._dq = -state.clusterTransforms[j]._dq; - } - } #else glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterTransforms[j]); #endif @@ -171,12 +147,7 @@ void CauterizedModel::updateClusterMatrices() { Model::MeshState& state = _cauterizeMeshStates[i]; const FBXMesh& mesh = geometry.meshes.at(i); -#if defined(SKIN_DQ) - // HACK: FOR DQ go thru reverse order! - for (int j = mesh.clusters.size() - 1; j >= 0; j--) { -#else - for (int j = 0; j < mesh.clusters.size(); j++) { -#endif + for (int j = 0; j < mesh.clusters.size(); j++) { const FBXCluster& cluster = mesh.clusters.at(j); auto jointMatrix = _rig.getJointTransform(cluster.jointIndex); @@ -194,25 +165,6 @@ void CauterizedModel::updateClusterMatrices() { glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, m); AnimPose p(m); state.clusterTransforms[j] = Model::TransformDualQuaternion(m); - - // AJT: HACK n^2!!!! fix me, find parent clusterTransform. - int parentIndex = _rig.getJointParentIndex(cluster.jointIndex); - int parentClusterIndex = -1; - // scan for parent! - for (int ii = mesh.clusters.size() - 1; ii > j; ii--) { - if (mesh.clusters[ii].jointIndex == parentIndex) { - parentClusterIndex = ii; - break; - } - } - - // ensure that we have the same polarity as our parent! - if (parentClusterIndex >= 0) { - //if (state.clusterTransforms[parentClusterIndex]._dq.dot(state.clusterTransforms[j]._dq) < 0.0f) { - if (glm::dot(state.clusterTransforms[parentClusterIndex]._dq.real(), state.clusterTransforms[j]._dq.real()) < 0.0f) { - state.clusterTransforms[j]._dq = -state.clusterTransforms[j]._dq; - } - } #else glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterTransforms[j]); #endif diff --git a/libraries/render-utils/src/Skinning.slh b/libraries/render-utils/src/Skinning.slh index bdba724d43..c11455a575 100644 --- a/libraries/render-utils/src/Skinning.slh +++ b/libraries/render-utils/src/Skinning.slh @@ -56,10 +56,8 @@ void skinPosition(ivec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPositio float dqClusterWeight = clusterWeight; if (i == 0) { prevR = real; - } else { - if (dot(prevR, real) < 0) { - dqClusterWeight = -clusterWeight; - } + } else if (dot(prevR, real) < 0) { + dqClusterWeight = -clusterWeight; } sAccum += scale * clusterWeight; @@ -123,10 +121,8 @@ void skinPositionNormal(ivec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inP float dqClusterWeight = clusterWeight; if (i == 0) { prevR = real; - } else { - if (dot(prevR, real) < 0) { - dqClusterWeight = -clusterWeight; - } + } else if (dot(prevR, real) < 0) { + dqClusterWeight = -clusterWeight; } sAccum += scale * clusterWeight; @@ -191,10 +187,8 @@ void skinPositionNormalTangent(ivec4 skinClusterIndex, vec4 skinClusterWeight, v float dqClusterWeight = clusterWeight; if (i == 0) { prevR = real; - } else { - if (dot(prevR, real) < 0) { - dqClusterWeight = -clusterWeight; - } + } else if (dot(prevR, real) < 0) { + dqClusterWeight = -clusterWeight; } sAccum += scale * clusterWeight;