Refactor Weight::deform
diff --git a/include/rive/bones/weight.hpp b/include/rive/bones/weight.hpp index 7145d59..2d3ba14 100644 --- a/include/rive/bones/weight.hpp +++ b/include/rive/bones/weight.hpp
@@ -14,10 +14,8 @@ StatusCode onAddedDirty(CoreContext* context) override; - static Vec2D deform(Vec2D inPoint, - unsigned int indices, + static Mat2D deform(unsigned int indices, unsigned int weights, - const Mat2D& world, const float* boneTransforms); }; } // namespace rive
diff --git a/src/bones/weight.cpp b/src/bones/weight.cpp index 9f00714..c454e57 100644 --- a/src/bones/weight.cpp +++ b/src/bones/weight.cpp
@@ -22,11 +22,9 @@ return (data >> (index * 8)) & 0xFF; } -Vec2D Weight::deform(Vec2D inPoint, - unsigned int indices, - unsigned int weights, - const Mat2D& world, - const float* boneTransforms) { +Mat2D Weight::deform(unsigned int indices, + unsigned int weights, + const float* boneTransforms) { float xx = 0, xy = 0, yx = 0, yy = 0, tx = 0, ty = 0; for (int i = 0; i < 4; i++) { int weight = encodedWeightValue(i, weights); @@ -44,6 +42,5 @@ tx += boneTransforms[startBoneTransformIndex++] * normalizedWeight; ty += boneTransforms[startBoneTransformIndex++] * normalizedWeight; } - - return Mat2D(xx, xy, yx, yy, tx, ty) * (world * inPoint); + return Mat2D(xx, xy, yx, yy, tx, ty); }
diff --git a/src/shapes/cubic_vertex.cpp b/src/shapes/cubic_vertex.cpp index 5964ede..c817e2e 100644 --- a/src/shapes/cubic_vertex.cpp +++ b/src/shapes/cubic_vertex.cpp
@@ -57,16 +57,10 @@ Super::deform(worldTransform, boneTransforms); auto cubicWeight = weight<CubicWeight>(); + auto matrix = Weight::deform(cubicWeight->inIndices(), + cubicWeight->inValues(), + boneTransforms) * worldTransform;; - cubicWeight->inTranslation() = Weight::deform(inPoint(), - cubicWeight->inIndices(), - cubicWeight->inValues(), - worldTransform, - boneTransforms); - - cubicWeight->outTranslation() = Weight::deform(outPoint(), - cubicWeight->outIndices(), - cubicWeight->outValues(), - worldTransform, - boneTransforms); + cubicWeight->inTranslation() = matrix * inPoint(); + cubicWeight->outTranslation() = matrix * outPoint(); }
diff --git a/src/shapes/vertex.cpp b/src/shapes/vertex.cpp index a7c6890..78233c6 100644 --- a/src/shapes/vertex.cpp +++ b/src/shapes/vertex.cpp
@@ -13,9 +13,7 @@ void Vertex::yChanged() { markGeometryDirty(); } void Vertex::deform(const Mat2D& worldTransform, const float* boneTransforms) { - m_Weight->translation() = Weight::deform(Vec2D(x(), y()), - m_Weight->indices(), + m_Weight->translation() = Weight::deform(m_Weight->indices(), m_Weight->values(), - worldTransform, - boneTransforms); + boneTransforms) * (worldTransform * Vec2D(x(), y())); } \ No newline at end of file