@@ -2042,9 +2042,9 @@ public static async Task<TTModel> LoadExternalModel(string externalPath, ModelIm
2042
2042
/// <param name="ogMdl"></param>
2043
2043
/// <param name="loggingFunction"></param>
2044
2044
/// <returns></returns>
2045
- public static async Task < byte [ ] > MakeCompressedMdlFile ( TTModel ttModel , XivMdl ogMdl , Action < bool , string > loggingFunction = null )
2045
+ public static async Task < byte [ ] > MakeCompressedMdlFile ( TTModel ttModel , XivMdl ogMdl , Action < bool , string > loggingFunction = null , bool upgradePrecision = true )
2046
2046
{
2047
- var mdl = MakeUncompressedMdlFile ( ttModel , ogMdl , loggingFunction ) ;
2047
+ var mdl = MakeUncompressedMdlFile ( ttModel , ogMdl , loggingFunction , upgradePrecision ) ;
2048
2048
var compressed = await CompressMdlFile ( mdl ) ;
2049
2049
return compressed ;
2050
2050
}
@@ -2371,14 +2371,15 @@ public static async Task<byte[]> MakeUncompressedMdlFile(TTModel model, string t
2371
2371
return MakeUncompressedMdlFile ( model , xivMdl , loggingFunction ) ;
2372
2372
2373
2373
}
2374
+
2374
2375
/// <summary>
2375
2376
/// Creates a new Uncompressed MDL file from the given information.
2376
2377
/// OGMdl is used to fill in gaps in data types we do not know about.
2377
2378
/// TODO: It should be possible at this point to adjust this function to accomodate [null] ogMDLs.
2378
2379
/// </summary>
2379
2380
/// <param name="ttModel">The ttModel to import</param>
2380
2381
/// <param name="ogMdl">The currently modified Mdl file.</param>
2381
- public static byte [ ] MakeUncompressedMdlFile ( TTModel ttModel , XivMdl ogMdl , Action < bool , string > loggingFunction = null )
2382
+ public static byte [ ] MakeUncompressedMdlFile ( TTModel ttModel , XivMdl ogMdl , Action < bool , string > loggingFunction = null , bool upgradePrecision = true )
2382
2383
{
2383
2384
var mdlVersion = ttModel . MdlVersion > 0 ? ttModel . MdlVersion : ogMdl . MdlVersion ;
2384
2385
@@ -2393,10 +2394,6 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
2393
2394
2394
2395
byte _LoDCount = 1 ;
2395
2396
2396
- // Pipe some user var down here and we could ship this toggle.
2397
- // Not really much reason to ever use lower precision other than file size/perf though.
2398
- bool _UpgradePrecision = true ;
2399
-
2400
2397
// Distance used for model LoD settings. 0 is infinite.
2401
2398
float _ModelLoDDistance = 0.0f ;
2402
2399
@@ -2411,6 +2408,8 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
2411
2408
2412
2409
try
2413
2410
{
2411
+ var usageInfo = ttModel . GetUsageInfo ( ) ;
2412
+
2414
2413
ttModel . OrderMeshGroupsForImport ( ) ;
2415
2414
var rawShapeData = ttModel . GetRawShapeParts ( ) ;
2416
2415
@@ -2493,7 +2492,7 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
2493
2492
vertexStreamCounts . Add ( source . Max ( x => x . DataBlock ) + 1 ) ;
2494
2493
2495
2494
// If we're upgrading precision on a v6 mdl, might as well add all the bells and whistles.
2496
- if ( mdlVersion >= 6 && _UpgradePrecision )
2495
+ if ( mdlVersion >= 6 && upgradePrecision )
2497
2496
{
2498
2497
// Add precomputed tangent data.
2499
2498
var tangentCount = source . Count ( x => x . DataUsage == VertexUsageType . Tangent ) ;
@@ -2508,21 +2507,23 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
2508
2507
DataType = VertexDataType . Ubyte4n ,
2509
2508
DataUsage = VertexUsageType . Tangent
2510
2509
} ) ;
2511
-
2512
2510
}
2513
-
2514
- // Add 2nd color channel for faux-wind simulation.
2515
- var colorCounts = source . Count ( x => x . DataUsage == VertexUsageType . Color ) ;
2516
- var colorIdx = source . FindIndex ( x => x . DataUsage == VertexUsageType . Color ) ;
2517
- if ( colorCounts == 1 )
2511
+
2512
+ if ( usageInfo . UsesVColor2 )
2518
2513
{
2519
- source . Insert ( colorIdx + 1 , new VertexDataStruct ( )
2514
+ // Add 2nd color channel for faux-wind simulation.
2515
+ var colorCounts = source . Count ( x => x . DataUsage == VertexUsageType . Color ) ;
2516
+ var colorIdx = source . FindIndex ( x => x . DataUsage == VertexUsageType . Color ) ;
2517
+ if ( colorCounts == 1 )
2520
2518
{
2521
- DataBlock = 1 ,
2522
- DataOffset = 0 , // Offset doesn't matter since we recalculate it anyways.
2523
- DataType = VertexDataType . Ubyte4n ,
2524
- DataUsage = VertexUsageType . Color
2525
- } ) ;
2519
+ source . Insert ( colorIdx + 1 , new VertexDataStruct ( )
2520
+ {
2521
+ DataBlock = 1 ,
2522
+ DataOffset = 0 , // Offset doesn't matter since we recalculate it anyways.
2523
+ DataType = VertexDataType . Ubyte4n ,
2524
+ DataUsage = VertexUsageType . Color
2525
+ } ) ;
2526
+ }
2526
2527
}
2527
2528
}
2528
2529
@@ -2542,7 +2543,7 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
2542
2543
// Perform precision updates if requested, and adjustments for MDL version.
2543
2544
if ( dataUsage == VertexUsageType . Position )
2544
2545
{
2545
- if ( _UpgradePrecision )
2546
+ if ( upgradePrecision )
2546
2547
{
2547
2548
dataType = VertexDataType . Float3 ;
2548
2549
}
@@ -2554,7 +2555,7 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
2554
2555
2555
2556
if ( dataUsage == VertexUsageType . BoneWeight )
2556
2557
{
2557
- if ( mdlVersion >= 6 && _UpgradePrecision )
2558
+ if ( mdlVersion >= 6 && upgradePrecision )
2558
2559
{
2559
2560
dataType = VertexDataType . UByte8 ;
2560
2561
}
@@ -2566,7 +2567,7 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
2566
2567
2567
2568
if ( dataUsage == VertexUsageType . BoneIndex )
2568
2569
{
2569
- if ( mdlVersion >= 6 && _UpgradePrecision )
2570
+ if ( mdlVersion >= 6 && upgradePrecision )
2570
2571
{
2571
2572
dataType = VertexDataType . UByte8 ;
2572
2573
}
@@ -2578,7 +2579,7 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
2578
2579
2579
2580
if ( dataUsage == VertexUsageType . Normal )
2580
2581
{
2581
- if ( _UpgradePrecision )
2582
+ if ( upgradePrecision )
2582
2583
{
2583
2584
dataType = VertexDataType . Float3 ;
2584
2585
}
@@ -2590,26 +2591,25 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
2590
2591
2591
2592
if ( dataUsage == VertexUsageType . TextureCoordinate )
2592
2593
{
2593
- if ( _UpgradePrecision )
2594
+ if ( upgradePrecision )
2594
2595
{
2595
- if ( dataType == VertexDataType . Half2 )
2596
+ if ( usageInfo . UsesUv2 )
2596
2597
{
2597
- dataType = VertexDataType . Float2 ;
2598
+ dataType = VertexDataType . Float4 ;
2598
2599
}
2599
- else if ( dataType == VertexDataType . Half4 )
2600
+ else
2600
2601
{
2601
- dataType = VertexDataType . Float4 ;
2602
+ dataType = VertexDataType . Float2 ;
2602
2603
}
2603
2604
}
2604
2605
else
2605
2606
{
2606
- if ( dataType == VertexDataType . Float2 )
2607
- {
2608
- dataType = VertexDataType . Half2 ;
2609
- }
2610
- else if ( dataType == VertexDataType . Float4 )
2607
+ if ( usageInfo . UsesUv2 )
2611
2608
{
2612
2609
dataType = VertexDataType . Half4 ;
2610
+ } else
2611
+ {
2612
+ dataType = VertexDataType . Half2 ;
2613
2613
}
2614
2614
}
2615
2615
}
0 commit comments