24
24
using xivModdingFramework . Materials . FileTypes ;
25
25
using System . Security . AccessControl ;
26
26
using xivModdingFramework . Models . Enums ;
27
+ using MathNet . Numerics . LinearAlgebra ;
28
+ using System . Security . Cryptography ;
27
29
28
30
namespace xivModdingFramework . Models . Helpers
29
31
{
@@ -1140,7 +1142,6 @@ public static async Task RaceConvert(TTModel incomingModel, XivRace targetRace,
1140
1142
public static async Task RaceConvertRecursive ( TTModel model , XivRace targetRace , XivRace originalRace , Action < bool , string > loggingFunction = null , ModTransaction tx = null )
1141
1143
{
1142
1144
await INTERNAL_RaceConvertRecursive ( model , targetRace , originalRace , loggingFunction , tx ) ;
1143
- await CalculateTangents ( model , loggingFunction , true ) ;
1144
1145
}
1145
1146
private static async Task INTERNAL_RaceConvertRecursive ( TTModel model , XivRace targetRace , XivRace originalRace , Action < bool , string > loggingFunction = null , ModTransaction tx = null )
1146
1147
{
@@ -1357,6 +1358,7 @@ public static async Task ApplyRacialDeform(TTModel model, XivRace targetRace, bo
1357
1358
Vector3 normal = Vector3 . Zero ;
1358
1359
Vector3 binormal = Vector3 . Zero ;
1359
1360
Vector3 tangent = Vector3 . Zero ;
1361
+ Vector3 flow = Vector3 . Zero ;
1360
1362
1361
1363
// And each bone in that vertex.
1362
1364
for ( var b = 0 ; b < v . Weights . Length ; b ++ )
@@ -1379,14 +1381,19 @@ public static async Task ApplyRacialDeform(TTModel model, XivRace targetRace, bo
1379
1381
1380
1382
position += MatrixTransform ( v . Position , matrix ) * boneWeight ;
1381
1383
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
+ }
1384
1390
}
1385
1391
1386
1392
v . Position = position ;
1387
1393
v . Normal = normal ;
1388
1394
v . Binormal = binormal ;
1389
1395
v . Tangent = tangent ;
1396
+ v . FlowDirection = flow ;
1390
1397
}
1391
1398
1392
1399
// Same thing, but for the Shape Data parts.
@@ -1398,6 +1405,7 @@ public static async Task ApplyRacialDeform(TTModel model, XivRace targetRace, bo
1398
1405
Vector3 normal = Vector3 . Zero ;
1399
1406
Vector3 binormal = Vector3 . Zero ;
1400
1407
Vector3 tangent = Vector3 . Zero ;
1408
+ Vector3 flow = Vector3 . Zero ;
1401
1409
1402
1410
// And each bone in that vertex.
1403
1411
for ( var b = 0 ; b < v . Weights . Length ; b ++ )
@@ -1420,14 +1428,19 @@ public static async Task ApplyRacialDeform(TTModel model, XivRace targetRace, bo
1420
1428
1421
1429
position += MatrixTransform ( v . Position , matrix ) * boneWeight ;
1422
1430
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
+ }
1425
1437
}
1426
1438
1427
1439
v . Position = position ;
1428
1440
v . Normal = normal ;
1429
1441
v . Binormal = binormal ;
1430
1442
v . Tangent = tangent ;
1443
+ v . FlowDirection = flow ;
1431
1444
}
1432
1445
}
1433
1446
@@ -1440,6 +1453,34 @@ public static async Task ApplyRacialDeform(TTModel model, XivRace targetRace, bo
1440
1453
}
1441
1454
}
1442
1455
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
+
1443
1484
1444
1485
/// <summary>
1445
1486
/// 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