Skip to content

Commit 188b41f

Browse files
committed
Fix incorrect matrix multiplication on binormals/tangents during racial conversion and remove post-transform recalculation.
1 parent 44f0d03 commit 188b41f

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

xivModdingFramework/Models/Helpers/ModelModifiers.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using xivModdingFramework.Materials.FileTypes;
2525
using System.Security.AccessControl;
2626
using xivModdingFramework.Models.Enums;
27+
using MathNet.Numerics.LinearAlgebra;
2728

2829
namespace xivModdingFramework.Models.Helpers
2930
{
@@ -1140,7 +1141,6 @@ public static async Task RaceConvert(TTModel incomingModel, XivRace targetRace,
11401141
public static async Task RaceConvertRecursive(TTModel model, XivRace targetRace, XivRace originalRace, Action<bool, string> loggingFunction = null, ModTransaction tx = null)
11411142
{
11421143
await INTERNAL_RaceConvertRecursive(model, targetRace, originalRace, loggingFunction, tx);
1143-
await CalculateTangents(model, loggingFunction, true);
11441144
}
11451145
private static async Task INTERNAL_RaceConvertRecursive(TTModel model, XivRace targetRace, XivRace originalRace, Action<bool, string> loggingFunction = null, ModTransaction tx = null)
11461146
{
@@ -1379,8 +1379,8 @@ public static async Task ApplyRacialDeform(TTModel model, XivRace targetRace, bo
13791379

13801380
position += MatrixTransform(v.Position, matrix) * boneWeight;
13811381
normal += MatrixTransform(v.Normal, normalMatrix) * boneWeight;
1382-
binormal += MatrixTransform(v.Binormal, normalMatrix) * boneWeight;
1383-
tangent += MatrixTransform(v.Tangent, normalMatrix) * boneWeight;
1382+
binormal += MatrixTransform(v.Binormal, matrix) * boneWeight;
1383+
tangent += MatrixTransform(v.Tangent, matrix) * boneWeight;
13841384
}
13851385

13861386
v.Position = position;
@@ -1420,8 +1420,8 @@ public static async Task ApplyRacialDeform(TTModel model, XivRace targetRace, bo
14201420

14211421
position += MatrixTransform(v.Position, matrix) * boneWeight;
14221422
normal += MatrixTransform(v.Normal, normalMatrix) * boneWeight;
1423-
binormal += MatrixTransform(v.Binormal, normalMatrix) * boneWeight;
1424-
tangent += MatrixTransform(v.Tangent, normalMatrix) * boneWeight;
1423+
binormal += MatrixTransform(v.Binormal, matrix) * boneWeight;
1424+
tangent += MatrixTransform(v.Tangent, matrix) * boneWeight;
14251425
}
14261426

14271427
v.Position = position;
@@ -1440,6 +1440,34 @@ public static async Task ApplyRacialDeform(TTModel model, XivRace targetRace, bo
14401440
}
14411441
}
14421442

1443+
private static Vector3 MulVec(Matrix<float> mat, Vector3 v, float lastCol = 1.0f)
1444+
{
1445+
var r = Vector3.Zero;
1446+
var vec = Vector<float>.Build.Dense(4);
1447+
vec[0] = v.X;
1448+
vec[1] = v.Y;
1449+
vec[2] = v.Z;
1450+
vec[3] = lastCol;
1451+
var res = mat * vec;
1452+
r.X += res[0];
1453+
r.Y += res[1];
1454+
r.Z += res[2];
1455+
return r;
1456+
}
1457+
1458+
private static Matrix<float> ConvertMatrix(Matrix m)
1459+
{
1460+
var pMatrix = Matrix<float>.Build.Dense(4, 4);
1461+
for (int i = 0; i < 16; i++)
1462+
{
1463+
var x = i / 4;
1464+
var y = (i % 4);
1465+
var v = m[i];
1466+
pMatrix[x, y] = v;
1467+
}
1468+
return pMatrix;
1469+
}
1470+
14431471

14441472
/// <summary>
14451473
/// This takes a standard Affine Transformation matrix [0,0,0,1 on bottom], and a vector, and applies the transformation to it.

0 commit comments

Comments
 (0)