Skip to content

Commit 1d886be

Browse files
committed
Update v3.0.8.5
2 parents 44f0d03 + cc9b0cb commit 1d886be

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

xivModdingFramework/Models/Helpers/ModelModifiers.cs

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

2830
namespace xivModdingFramework.Models.Helpers
2931
{
@@ -1140,7 +1142,6 @@ public static async Task RaceConvert(TTModel incomingModel, XivRace targetRace,
11401142
public static async Task RaceConvertRecursive(TTModel model, XivRace targetRace, XivRace originalRace, Action<bool, string> loggingFunction = null, ModTransaction tx = null)
11411143
{
11421144
await INTERNAL_RaceConvertRecursive(model, targetRace, originalRace, loggingFunction, tx);
1143-
await CalculateTangents(model, loggingFunction, true);
11441145
}
11451146
private static async Task INTERNAL_RaceConvertRecursive(TTModel model, XivRace targetRace, XivRace originalRace, Action<bool, string> loggingFunction = null, ModTransaction tx = null)
11461147
{
@@ -1357,6 +1358,7 @@ public static async Task ApplyRacialDeform(TTModel model, XivRace targetRace, bo
13571358
Vector3 normal = Vector3.Zero;
13581359
Vector3 binormal = Vector3.Zero;
13591360
Vector3 tangent = Vector3.Zero;
1361+
Vector3 flow = Vector3.Zero;
13601362

13611363
// And each bone in that vertex.
13621364
for (var b = 0; b < v.Weights.Length; b++)
@@ -1379,14 +1381,19 @@ public static async Task ApplyRacialDeform(TTModel model, XivRace targetRace, bo
13791381

13801382
position += MatrixTransform(v.Position, matrix) * boneWeight;
13811383
normal += MatrixTransform(v.Normal, normalMatrix) * boneWeight;
1382-
binormal += MatrixTransform(v.Binormal, normalMatrix) * boneWeight;
1383-
tangent += MatrixTransform(v.Tangent, normalMatrix) * boneWeight;
1384+
binormal += MatrixTransform(v.Binormal, matrix) * boneWeight;
1385+
tangent += MatrixTransform(v.Tangent, matrix) * boneWeight;
1386+
if (v.FlowDirection != Vector3.Zero)
1387+
{
1388+
flow += MatrixTransform(v.FlowDirection, matrix) * boneWeight;
1389+
}
13841390
}
13851391

13861392
v.Position = position;
13871393
v.Normal = normal;
13881394
v.Binormal = binormal;
13891395
v.Tangent = tangent;
1396+
v.FlowDirection = flow;
13901397
}
13911398

13921399
// Same thing, but for the Shape Data parts.
@@ -1398,6 +1405,7 @@ public static async Task ApplyRacialDeform(TTModel model, XivRace targetRace, bo
13981405
Vector3 normal = Vector3.Zero;
13991406
Vector3 binormal = Vector3.Zero;
14001407
Vector3 tangent = Vector3.Zero;
1408+
Vector3 flow = Vector3.Zero;
14011409

14021410
// And each bone in that vertex.
14031411
for (var b = 0; b < v.Weights.Length; b++)
@@ -1420,14 +1428,19 @@ public static async Task ApplyRacialDeform(TTModel model, XivRace targetRace, bo
14201428

14211429
position += MatrixTransform(v.Position, matrix) * boneWeight;
14221430
normal += MatrixTransform(v.Normal, normalMatrix) * boneWeight;
1423-
binormal += MatrixTransform(v.Binormal, normalMatrix) * boneWeight;
1424-
tangent += MatrixTransform(v.Tangent, normalMatrix) * boneWeight;
1431+
binormal += MatrixTransform(v.Binormal, matrix) * boneWeight;
1432+
tangent += MatrixTransform(v.Tangent, matrix) * boneWeight;
1433+
if (v.FlowDirection != Vector3.Zero)
1434+
{
1435+
flow += MatrixTransform(v.FlowDirection, matrix) * boneWeight;
1436+
}
14251437
}
14261438

14271439
v.Position = position;
14281440
v.Normal = normal;
14291441
v.Binormal = binormal;
14301442
v.Tangent = tangent;
1443+
v.FlowDirection = flow;
14311444
}
14321445
}
14331446

@@ -1440,6 +1453,34 @@ public static async Task ApplyRacialDeform(TTModel model, XivRace targetRace, bo
14401453
}
14411454
}
14421455

1456+
private static Vector3 MulVec(Matrix<float> mat, Vector3 v, float lastCol = 1.0f)
1457+
{
1458+
var r = Vector3.Zero;
1459+
var vec = Vector<float>.Build.Dense(4);
1460+
vec[0] = v.X;
1461+
vec[1] = v.Y;
1462+
vec[2] = v.Z;
1463+
vec[3] = lastCol;
1464+
var res = mat * vec;
1465+
r.X += res[0];
1466+
r.Y += res[1];
1467+
r.Z += res[2];
1468+
return r;
1469+
}
1470+
1471+
private static Matrix<float> ConvertMatrix(Matrix m)
1472+
{
1473+
var pMatrix = Matrix<float>.Build.Dense(4, 4);
1474+
for (int i = 0; i < 16; i++)
1475+
{
1476+
var x = i / 4;
1477+
var y = (i % 4);
1478+
var v = m[i];
1479+
pMatrix[x, y] = v;
1480+
}
1481+
return pMatrix;
1482+
}
1483+
14431484

14441485
/// <summary>
14451486
/// 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)