Skip to content

Commit 16f04d8

Browse files
committed
don't repath normals for skin
1 parent 28789cb commit 16f04d8

File tree

3 files changed

+132
-48
lines changed

3 files changed

+132
-48
lines changed

xivModdingFramework/Models/DataContainers/TTModel.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System;
88
using System.Collections.Generic;
99
using System.Data.SQLite;
10+
using System.Diagnostics;
1011
using System.IO;
1112
using System.Linq;
1213
using System.Text.RegularExpressions;
@@ -1201,6 +1202,56 @@ public int GetMeshGroupCount(EMeshType type)
12011202
return MeshGroups.Count(x => x.MeshType == type);
12021203
}
12031204

1205+
public (bool UsesVColor2, bool UsesUv2, bool NeedsEightWeights) GetUsageInfo()
1206+
{
1207+
bool usesVcolor2 = false;
1208+
bool usesUv2 = false;
1209+
bool needs8Weight = false;
1210+
1211+
foreach (var m in MeshGroups)
1212+
{
1213+
foreach(var p in m.Parts)
1214+
{
1215+
foreach(var v in p.Vertices)
1216+
{
1217+
if (!needs8Weight)
1218+
{
1219+
if(v.Weights.Length > 4)
1220+
{
1221+
for(int i = 4; i < v.Weights.Length; i++)
1222+
{
1223+
if (v.Weights[i] > 0 || v.BoneIds[i] > 0)
1224+
{
1225+
needs8Weight = true;
1226+
break;
1227+
}
1228+
}
1229+
}
1230+
}
1231+
1232+
if (!usesUv2)
1233+
{
1234+
if (v.UV2 != Vector2.Zero)
1235+
{
1236+
usesUv2 = true;
1237+
}
1238+
}
1239+
1240+
if (!usesVcolor2)
1241+
{
1242+
if(v.VertexColor2.Any(x => x != 0))
1243+
{
1244+
usesVcolor2 = true;
1245+
}
1246+
}
1247+
1248+
}
1249+
}
1250+
}
1251+
1252+
return (usesVcolor2, usesUv2, needs8Weight);
1253+
}
1254+
12041255
/// <summary>
12051256
/// Creates a bone set from the model and group information.
12061257
/// </summary>
@@ -1311,6 +1362,10 @@ public static TTModel LoadFromFile(string filePath, Action<bool, string> logging
13111362
{
13121363
loggingFunction = ModelModifiers.NoOp;
13131364
}
1365+
if(settings == null)
1366+
{
1367+
settings = new ModelImportOptions();
1368+
}
13141369

13151370
var connectionString = "Data Source=" + filePath + ";Pooling=True;";
13161371
TTModel model = new TTModel();
@@ -2524,6 +2579,10 @@ public static TTModel FromRaw(XivMdl rawMdl, Action<bool, string> loggingFunctio
25242579

25252580
ModelModifiers.FixUpSkinReferences(ttModel, rawMdl.MdlPath);
25262581

2582+
var sum = ttModel.MeshGroups.Sum(m => m.Parts.Sum(p => p.Vertices.Count + p.ShapeParts.Sum(z => z.Value.Vertices.Count)));
2583+
var indices = ttModel.MeshGroups.Sum(m => m.Parts.Sum(p => p.TriangleIndices.Count));
2584+
Trace.WriteLine("Vertex Count: " + sum);
2585+
Trace.WriteLine("Index Count: " + indices);
25272586
return ttModel;
25282587
}
25292588

xivModdingFramework/Models/FileTypes/Mdl.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,9 +2042,9 @@ public static async Task<TTModel> LoadExternalModel(string externalPath, ModelIm
20422042
/// <param name="ogMdl"></param>
20432043
/// <param name="loggingFunction"></param>
20442044
/// <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)
20462046
{
2047-
var mdl = MakeUncompressedMdlFile(ttModel, ogMdl, loggingFunction);
2047+
var mdl = MakeUncompressedMdlFile(ttModel, ogMdl, loggingFunction, upgradePrecision);
20482048
var compressed = await CompressMdlFile(mdl);
20492049
return compressed;
20502050
}
@@ -2371,14 +2371,15 @@ public static async Task<byte[]> MakeUncompressedMdlFile(TTModel model, string t
23712371
return MakeUncompressedMdlFile(model, xivMdl, loggingFunction);
23722372

23732373
}
2374+
23742375
/// <summary>
23752376
/// Creates a new Uncompressed MDL file from the given information.
23762377
/// OGMdl is used to fill in gaps in data types we do not know about.
23772378
/// TODO: It should be possible at this point to adjust this function to accomodate [null] ogMDLs.
23782379
/// </summary>
23792380
/// <param name="ttModel">The ttModel to import</param>
23802381
/// <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)
23822383
{
23832384
var mdlVersion = ttModel.MdlVersion > 0 ? ttModel.MdlVersion : ogMdl.MdlVersion;
23842385

@@ -2393,10 +2394,6 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
23932394

23942395
byte _LoDCount = 1;
23952396

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-
24002397
// Distance used for model LoD settings. 0 is infinite.
24012398
float _ModelLoDDistance = 0.0f;
24022399

@@ -2411,6 +2408,8 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
24112408

24122409
try
24132410
{
2411+
var usageInfo = ttModel.GetUsageInfo();
2412+
24142413
ttModel.OrderMeshGroupsForImport();
24152414
var rawShapeData = ttModel.GetRawShapeParts();
24162415

@@ -2493,7 +2492,7 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
24932492
vertexStreamCounts.Add(source.Max(x => x.DataBlock) + 1);
24942493

24952494
// 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)
24972496
{
24982497
// Add precomputed tangent data.
24992498
var tangentCount = source.Count(x => x.DataUsage == VertexUsageType.Tangent);
@@ -2508,21 +2507,23 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
25082507
DataType = VertexDataType.Ubyte4n,
25092508
DataUsage = VertexUsageType.Tangent
25102509
});
2511-
25122510
}
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)
25182513
{
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)
25202518
{
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+
}
25262527
}
25272528
}
25282529

@@ -2542,7 +2543,7 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
25422543
// Perform precision updates if requested, and adjustments for MDL version.
25432544
if (dataUsage == VertexUsageType.Position)
25442545
{
2545-
if (_UpgradePrecision)
2546+
if (upgradePrecision)
25462547
{
25472548
dataType = VertexDataType.Float3;
25482549
}
@@ -2554,7 +2555,7 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
25542555

25552556
if (dataUsage == VertexUsageType.BoneWeight)
25562557
{
2557-
if (mdlVersion >= 6 && _UpgradePrecision)
2558+
if (mdlVersion >= 6 && upgradePrecision)
25582559
{
25592560
dataType = VertexDataType.UByte8;
25602561
}
@@ -2566,7 +2567,7 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
25662567

25672568
if (dataUsage == VertexUsageType.BoneIndex)
25682569
{
2569-
if (mdlVersion >= 6 && _UpgradePrecision)
2570+
if (mdlVersion >= 6 && upgradePrecision)
25702571
{
25712572
dataType = VertexDataType.UByte8;
25722573
}
@@ -2578,7 +2579,7 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
25782579

25792580
if (dataUsage == VertexUsageType.Normal)
25802581
{
2581-
if (_UpgradePrecision)
2582+
if (upgradePrecision)
25822583
{
25832584
dataType = VertexDataType.Float3;
25842585
}
@@ -2590,26 +2591,25 @@ public static byte[] MakeUncompressedMdlFile(TTModel ttModel, XivMdl ogMdl, Acti
25902591

25912592
if (dataUsage == VertexUsageType.TextureCoordinate)
25922593
{
2593-
if (_UpgradePrecision)
2594+
if (upgradePrecision)
25942595
{
2595-
if (dataType == VertexDataType.Half2)
2596+
if (usageInfo.UsesUv2)
25962597
{
2597-
dataType = VertexDataType.Float2;
2598+
dataType = VertexDataType.Float4;
25982599
}
2599-
else if (dataType == VertexDataType.Half4)
2600+
else
26002601
{
2601-
dataType = VertexDataType.Float4;
2602+
dataType = VertexDataType.Float2;
26022603
}
26032604
}
26042605
else
26052606
{
2606-
if (dataType == VertexDataType.Float2)
2607-
{
2608-
dataType = VertexDataType.Half2;
2609-
}
2610-
else if (dataType == VertexDataType.Float4)
2607+
if (usageInfo.UsesUv2)
26112608
{
26122609
dataType = VertexDataType.Half4;
2610+
} else
2611+
{
2612+
dataType = VertexDataType.Half2;
26132613
}
26142614
}
26152615
}

xivModdingFramework/Mods/EndwalkerUpgrade.cs

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,40 +2070,65 @@ public static async Task<FileStorageInformation> ValidateTextureSizes(FileStorag
20702070
{ "chara/human/c1401/obj/body/b0101/texture/--c1401b0101_d.tex", "chara/human/c1401/obj/body/b0101/texture/c1401b0101_base.tex" },
20712071
{ "chara/human/c1801/obj/body/b0001/texture/--c1801b0001_d.tex", "chara/human/c1801/obj/body/b0001/texture/c1801b0001_base.tex" },
20722072

2073-
// Base Game Norms
2074-
{ "chara/human/c0201/obj/body/b0001/texture/--c0201b0001_n.tex", "chara/human/c0201/obj/body/b0001/texture/c0201b0001_norm.tex" },
2075-
{ "chara/human/c0401/obj/body/b0001/texture/--c0401b0001_n.tex", "chara/human/c0401/obj/body/b0001/texture/c0401b0001_norm.tex" },
2076-
{ "chara/human/c1401/obj/body/b0001/texture/--c1401b0001_n.tex", "chara/human/c1401/obj/body/b0001/texture/c1401b0001_norm.tex" },
2077-
{ "chara/human/c1401/obj/body/b0101/texture/--c1401b0101_n.tex", "chara/human/c1401/obj/body/b0101/texture/c1401b0101_norm.tex" },
2078-
{ "chara/human/c1801/obj/body/b0001/texture/--c1801b0001_n.tex", "chara/human/c1801/obj/body/b0001/texture/c1801b0001_norm.tex" },
2079-
20802073
// Bibo
20812074
{ "chara/bibo/midlander_d.tex", "chara/bibo_mid_base.tex" },
20822075
{ "chara/bibo/raen_d.tex", "chara/bibo_raen_base.tex" },
20832076
{ "chara/bibo/xaela_d.tex", "chara/bibo_xaela_base.tex" },
20842077
{ "chara/bibo/viera_d.tex", "chara/bibo_viera_base.tex" },
20852078
{ "chara/bibo/highlander_d.tex", "chara/bibo_high_base.tex" },
20862079

2087-
// Bibo Norms
2088-
{ "chara/bibo/midlander_n.tex", "chara/bibo_mid_norm.tex" },
2089-
{ "chara/bibo/raen_n.tex", "chara/bibo_raen_norm.tex" },
2090-
{ "chara/bibo/xaela_n.tex", "chara/bibo_xaela_norm.tex" },
2091-
{ "chara/bibo/viera_n.tex", "chara/bibo_viera_norm.tex" },
2092-
{ "chara/bibo/highlander_n.tex", "chara/bibo_high_norm.tex" },
2093-
20942080
// TBSE
20952081
{ "chara/human/c0101/obj/body/b0001/texture/--c0101b0001_b_d.tex", "chara/human/c0101/obj/body/b0001/texture/c0101b0001_b_d.tex" },
20962082
{ "chara/human/c1301/obj/body/b0001/texture/--c1301b0001_b_d.tex", "chara/human/c1301/obj/body/b0001/texture/c1301b0001_b_d.tex" },
20972083
{ "chara/human/c1301/obj/body/b0101/texture/--c1301b0101_b_d.tex", "chara/human/c1301/obj/body/b0101/texture/c1301b0101_b_d.tex" },
20982084
{ "chara/human/c1701/obj/body/b0001/texture/--c1701b0001_b_d.tex", "chara/human/c1701/obj/body/b0001/texture/c1701b0001_b_d.tex" },
20992085
{ "chara/human/c0301/obj/body/b0001/texture/--c0301b0001_b_d.tex", "chara/human/c0301/obj/body/b0001/texture/c0301b0001_b_d.tex" },
21002086

2087+
2088+
// Au Ra Tails
2089+
{ "chara/human/c1301/obj/tail/t0001/texture/--c1301t0001_etc_d.tex", "chara/human/c1301/obj/tail/t0001/texture/c1301t0001_etc_base.tex" },
2090+
{ "chara/human/c1301/obj/tail/t0002/texture/--c1301t0002_etc_d.tex", "chara/human/c1301/obj/tail/t0002/texture/c1301t0002_etc_base.tex" },
2091+
{ "chara/human/c1301/obj/tail/t0003/texture/--c1301t0003_etc_d.tex", "chara/human/c1301/obj/tail/t0003/texture/c1301t0003_etc_base.tex" },
2092+
{ "chara/human/c1301/obj/tail/t0004/texture/--c1301t0004_etc_d.tex", "chara/human/c1301/obj/tail/t0004/texture/c1301t0004_etc_base.tex" },
2093+
2094+
{ "chara/human/c1301/obj/tail/t0101/texture/--c1301t0101_etc_d.tex", "chara/human/c1301/obj/tail/t0101/texture/c1301t0101_etc_base.tex" },
2095+
{ "chara/human/c1301/obj/tail/t0102/texture/--c1301t0102_etc_d.tex", "chara/human/c1301/obj/tail/t0102/texture/c1301t0102_etc_base.tex" },
2096+
{ "chara/human/c1301/obj/tail/t0103/texture/--c1301t0103_etc_d.tex", "chara/human/c1301/obj/tail/t0103/texture/c1301t0103_etc_base.tex" },
2097+
{ "chara/human/c1301/obj/tail/t0104/texture/--c1301t0104_etc_d.tex", "chara/human/c1301/obj/tail/t0104/texture/c1301t0104_etc_base.tex" },
2098+
2099+
/*
2100+
// Base Game Norms
2101+
{ "chara/human/c0201/obj/body/b0001/texture/--c0201b0001_n.tex", "chara/human/c0201/obj/body/b0001/texture/c0201b0001_norm.tex" },
2102+
{ "chara/human/c0401/obj/body/b0001/texture/--c0401b0001_n.tex", "chara/human/c0401/obj/body/b0001/texture/c0401b0001_norm.tex" },
2103+
{ "chara/human/c1401/obj/body/b0001/texture/--c1401b0001_n.tex", "chara/human/c1401/obj/body/b0001/texture/c1401b0001_norm.tex" },
2104+
{ "chara/human/c1401/obj/body/b0101/texture/--c1401b0101_n.tex", "chara/human/c1401/obj/body/b0101/texture/c1401b0101_norm.tex" },
2105+
{ "chara/human/c1801/obj/body/b0001/texture/--c1801b0001_n.tex", "chara/human/c1801/obj/body/b0001/texture/c1801b0001_norm.tex" },
2106+
21012107
// TBSE Norms
21022108
{ "chara/human/c0101/obj/body/b0001/texture/--c0101b0001_b_n.tex", "chara/human/c0101/obj/body/b0001/texture/c0101b0001_b_n.tex" },
21032109
{ "chara/human/c1301/obj/body/b0001/texture/--c1301b0001_b_n.tex", "chara/human/c1301/obj/body/b0001/texture/c1301b0001_b_n.tex" },
21042110
{ "chara/human/c1301/obj/body/b0101/texture/--c1301b0101_b_n.tex", "chara/human/c1301/obj/body/b0101/texture/c1301b0101_b_n.tex" },
21052111
{ "chara/human/c1701/obj/body/b0001/texture/--c1701b0001_b_n.tex", "chara/human/c1701/obj/body/b0001/texture/c1701b0001_b_n.tex" },
21062112
{ "chara/human/c0301/obj/body/b0001/texture/--c0301b0001_b_n.tex", "chara/human/c0301/obj/body/b0001/texture/c0301b0001_b_n.tex" },
2113+
2114+
// Bibo Norms
2115+
{ "chara/bibo/midlander_n.tex", "chara/bibo_mid_norm.tex" },
2116+
{ "chara/bibo/raen_n.tex", "chara/bibo_raen_norm.tex" },
2117+
{ "chara/bibo/xaela_n.tex", "chara/bibo_xaela_norm.tex" },
2118+
{ "chara/bibo/viera_n.tex", "chara/bibo_viera_norm.tex" },
2119+
{ "chara/bibo/highlander_n.tex", "chara/bibo_high_norm.tex" },
2120+
2121+
// Au Ra Tails - Normals
2122+
{ "chara/human/c1301/obj/tail/t0001/texture/--c1301t0001_etc_n.tex", "chara/human/c1301/obj/tail/t0001/texture/c1301t0001_etc_norm.tex" },
2123+
{ "chara/human/c1301/obj/tail/t0002/texture/--c1301t0002_etc_n.tex", "chara/human/c1301/obj/tail/t0002/texture/c1301t0002_etc_norm.tex" },
2124+
{ "chara/human/c1301/obj/tail/t0003/texture/--c1301t0003_etc_n.tex", "chara/human/c1301/obj/tail/t0003/texture/c1301t0003_etc_norm.tex" },
2125+
{ "chara/human/c1301/obj/tail/t0004/texture/--c1301t0004_etc_n.tex", "chara/human/c1301/obj/tail/t0004/texture/c1301t0004_etc_norm.tex" },
2126+
2127+
{ "chara/human/c1301/obj/tail/t0101/texture/--c1301t0101_etc_n.tex", "chara/human/c1301/obj/tail/t0101/texture/c1301t0101_etc_norm.tex" },
2128+
{ "chara/human/c1301/obj/tail/t0102/texture/--c1301t0102_etc_n.tex", "chara/human/c1301/obj/tail/t0102/texture/c1301t0102_etc_norm.tex" },
2129+
{ "chara/human/c1301/obj/tail/t0103/texture/--c1301t0103_etc_n.tex", "chara/human/c1301/obj/tail/t0103/texture/c1301t0103_etc_norm.tex" },
2130+
{ "chara/human/c1301/obj/tail/t0104/texture/--c1301t0104_etc_n.tex", "chara/human/c1301/obj/tail/t0104/texture/c1301t0104_etc_norm.tex" },
2131+
*/
21072132
};
21082133
}
21092134
}

0 commit comments

Comments
 (0)