@@ -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()
|
||||
|
||||
@@ -800,7 +800,7 @@ bool ProcessMesh(ModelData& result, OpenFbxImporterData& data, const ofbx::Mesh*
|
||||
{
|
||||
// Mirror positions along the Z axis
|
||||
for (int32 i = 0; i < vertexCount; i++)
|
||||
mesh.Positions[i].Z *= -1.0f;
|
||||
mesh.Positions.Get()[i].Z *= -1.0f;
|
||||
for (auto& blendShapeData : mesh.BlendShapes)
|
||||
{
|
||||
for (auto& v : blendShapeData.Vertices)
|
||||
@@ -815,7 +815,7 @@ bool ProcessMesh(ModelData& result, OpenFbxImporterData& data, const ofbx::Mesh*
|
||||
{
|
||||
// Invert the order
|
||||
for (int32 i = 0; i < mesh.Indices.Count(); i += 3)
|
||||
Swap(mesh.Indices[i], mesh.Indices[i + 2]);
|
||||
Swap(mesh.Indices.Get()[i], mesh.Indices.Get()[i + 2]);
|
||||
}
|
||||
|
||||
if ((data.Options.CalculateTangents || !tangents) && mesh.UVs.HasItems())
|
||||
|
||||
@@ -589,6 +589,9 @@ bool ModelTool::ImportData(const String& path, ModelData& data, Options& options
|
||||
{
|
||||
for (auto& n : mesh->Normals)
|
||||
n *= -1;
|
||||
for (auto& shape : mesh->BlendShapes)
|
||||
for (auto& v : shape.Vertices)
|
||||
v.NormalDelta *= -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user