From 4eddbaa2b7176d5385c1cfd50f6d16e266f4dbf8 Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Wed, 11 Mar 2020 21:33:41 +0930 Subject: [PATCH] Fix negative skinning weight --- src/meshgenerator.cpp | 8 -------- src/poser.cpp | 9 --------- src/projectfacestonodes.cpp | 1 - src/riggenerator.cpp | 17 +++++++++-------- thirdparty/bullet3/src/LinearMath/btVector3.h | 2 +- 5 files changed, 10 insertions(+), 27 deletions(-) diff --git a/src/meshgenerator.cpp b/src/meshgenerator.cpp index d74e9ec8..5b9d6f27 100644 --- a/src/meshgenerator.cpp +++ b/src/meshgenerator.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include "strokemeshbuilder.h" #include "strokemodifier.h" #include "meshrecombiner.h" @@ -1488,13 +1487,6 @@ void MeshGenerator::generate() std::vector> sourceNodes; triangleSourceNodeResolve(*outcome, sourceNodes, &outcome->vertexSourceNodes); - { - for (const auto &it: outcome->vertexSourceNodes) { - if (!it.first.isNull() && !it.second.isNull()) - continue; - std::cout << "source node:" << it.first.toString().toUtf8().constData() << " " << it.second.toString().toUtf8().constData() << std::endl; - } - } outcome->setTriangleSourceNodes(sourceNodes); std::map, QColor> sourceNodeToColorMap; diff --git a/src/poser.cpp b/src/poser.cpp index 10863afd..7ebcf073 100644 --- a/src/poser.cpp +++ b/src/poser.cpp @@ -1,6 +1,5 @@ #include #include -#include #include "poser.h" Poser::Poser(const std::vector &bones) : @@ -96,12 +95,4 @@ void Poser::fetchChains(const std::vector &boneNames, std::map #include #include -#include #include "projectfacestonodes.h" #include "util.h" diff --git a/src/riggenerator.cpp b/src/riggenerator.cpp index 73c40466..908a8419 100644 --- a/src/riggenerator.cpp +++ b/src/riggenerator.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "riggenerator.h" #include "util.h" @@ -166,7 +165,6 @@ void RigGenerator::buildNeighborMap() } //std::vector> debugBoxes; - while (true) { std::vector> groups; groupNodeIndices(m_neighborMap, &groups); @@ -422,6 +420,7 @@ void RigGenerator::buildSkeleton() bone.tailPosition = firstSpineNode.origin; bone.headRadius = 0; bone.tailRadius = firstSpineNode.radius; + bone.color = Theme::white; bone.name = QString("Body"); bone.index = m_resultBones->size(); bone.parent = -1; @@ -788,6 +787,8 @@ void RigGenerator::computeBranchSkinWeights(size_t fromBoneIndex, if (QVector3D::dotProduct(direction, cutNormal) > 0) { float angle = radianBetweenVectors(direction, currentDirection); auto projectedLength = std::cos(angle) * (position - currentBone.headPosition).length(); + if (projectedLength < 0) + projectedLength = 0; if (projectedLength <= endGradientLength) { auto factor = 0.5 * (1.0 - projectedLength / endGradientLength); (*m_resultWeights)[vertexIndex].addBone(previousBoneIndex, factor); @@ -804,6 +805,8 @@ void RigGenerator::computeBranchSkinWeights(size_t fromBoneIndex, } float angle = radianBetweenVectors(direction, -parentDirection); auto projectedLength = std::cos(angle) * (position - currentBone.headPosition).length(); + if (projectedLength < 0) + projectedLength = 0; if (projectedLength <= endGradientLength) { (*m_resultWeights)[vertexIndex].addBone(previousBoneIndex, 0.5 + 0.5 * projectedLength / endGradientLength); (*m_resultWeights)[vertexIndex].addBone(currentBoneIndex, 0.5 * (1.0 - projectedLength / endGradientLength)); @@ -1039,12 +1042,10 @@ void RigGenerator::buildDemoMesh() int blendR = 0, blendG = 0, blendB = 0; for (int i = 0; i < 4; i++) { int boneIndex = weight.boneIndices[i]; - if (boneIndex > 0) { - const auto &bone = resultBones[boneIndex]; - blendR += bone.color.red() * weight.boneWeights[i]; - blendG += bone.color.green() * weight.boneWeights[i]; - blendB += bone.color.blue() * weight.boneWeights[i]; - } + const auto &bone = resultBones[boneIndex]; + blendR += bone.color.red() * weight.boneWeights[i]; + blendG += bone.color.green() * weight.boneWeights[i]; + blendB += bone.color.blue() * weight.boneWeights[i]; } QColor blendColor = QColor(blendR, blendG, blendB, 255); inputVerticesColors[vertexIndex] = blendColor; diff --git a/thirdparty/bullet3/src/LinearMath/btVector3.h b/thirdparty/bullet3/src/LinearMath/btVector3.h index 61fd8d1e..d65ed980 100755 --- a/thirdparty/bullet3/src/LinearMath/btVector3.h +++ b/thirdparty/bullet3/src/LinearMath/btVector3.h @@ -36,7 +36,7 @@ subject to the following restrictions: #pragma warning(disable : 4556) // value of intrinsic immediate argument '4294967239' is out of range '0 - 255' #endif -#define BT_SHUFFLE(x, y, z, w) ((w) << 6 | (z) << 4 | (y) << 2 | (x)) +#define BT_SHUFFLE(x, y, z, w) (((w) << 6 | (z) << 4 | (y) << 2 | (x)) & 0xff) //#define bt_pshufd_ps( _a, _mask ) (__m128) _mm_shuffle_epi32((__m128i)(_a), (_mask) ) #define bt_pshufd_ps(_a, _mask) _mm_shuffle_ps((_a), (_a), (_mask)) #define bt_splat3_ps(_a, _i) bt_pshufd_ps((_a), BT_SHUFFLE(_i, _i, _i, 3))