Fix blend shapes transformation applying

#2459
This commit is contained in:
Wojtek Figat
2024-04-20 16:16:01 +02:00
parent 5e086809ae
commit 6aacea99ab
3 changed files with 21 additions and 14 deletions

View File

@@ -508,6 +508,22 @@ void MeshData::TransformBuffer(const Matrix& matrix)
Matrix::Invert(matrix, inverseTransposeMatrix);
Matrix::Transpose(inverseTransposeMatrix, inverseTransposeMatrix);
// Transform blend shapes
for (auto& blendShape : BlendShapes)
{
const auto vv = blendShape.Vertices.Get();
for (int32 i = 0; i < blendShape.Vertices.Count(); i++)
{
auto& v = vv[i];
Float3 p = Positions[v.VertexIndex], vp;
Float3::Transform(p + v.PositionDelta, matrix, vp);
Float3::Transform(p, matrix, p);
v.PositionDelta = vp - p;
Float3::TransformNormal(v.NormalDelta, inverseTransposeMatrix, v.NormalDelta);
v.NormalDelta.Normalize();
}
}
// Transform positions
const auto pp = Positions.Get();
for (int32 i = 0; i < Positions.Count(); i++)
@@ -531,18 +547,6 @@ void MeshData::TransformBuffer(const Matrix& matrix)
Float3::TransformNormal(t, inverseTransposeMatrix, t);
t.Normalize();
}
// Transform blend shapes
for (auto& blendShape : BlendShapes)
{
for (int32 i = 0; i < blendShape.Vertices.Count(); i++)
{
auto& v = blendShape.Vertices[i];
Float3::Transform(v.PositionDelta, matrix, v.PositionDelta);
Float3::TransformNormal(v.NormalDelta, inverseTransposeMatrix, v.NormalDelta);
v.NormalDelta.Normalize();
}
}
}
void MeshData::NormalizeBlendWeights()