Skip to content

Commit 241ed37

Browse files
committed
Adds support for pulling material data from .db files and applying it to a mdl export.
Current supported workflow is using console tools to wrap the db with the switch /mats.
1 parent 49e33ca commit 241ed37

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

xivModdingFramework/Models/DataContainers/TTModel.cs

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ public static async Task<TTModel> LoadFromFile(string filePath, Action<bool, str
14761476
{
14771477
loggingFunction = ModelModifiers.NoOp;
14781478
}
1479-
if(settings == null)
1479+
if (settings == null)
14801480
{
14811481
settings = new ModelImportOptions();
14821482
}
@@ -1519,7 +1519,7 @@ public static async Task<TTModel> LoadFromFile(string filePath, Action<bool, str
15191519
}
15201520
else
15211521
{
1522-
model.MeshGroups[meshNum].MeshType = (EMeshType) Enum.Parse(typeof(EMeshType), t);
1522+
model.MeshGroups[meshNum].MeshType = (EMeshType)Enum.Parse(typeof(EMeshType), t);
15231523
}
15241524

15251525
model.MeshGroups[meshNum].Name = reader.GetString("name");
@@ -1546,7 +1546,7 @@ public static async Task<TTModel> LoadFromFile(string filePath, Action<bool, str
15461546
}
15471547

15481548
// Spawn parts as needed.
1549-
while(model.MeshGroups[meshNum].Parts.Count <= partNum)
1549+
while (model.MeshGroups[meshNum].Parts.Count <= partNum)
15501550
{
15511551
model.MeshGroups[meshNum].Parts.Add(new TTMeshPart());
15521552

@@ -1672,14 +1672,15 @@ public static async Task<TTModel> LoadFromFile(string filePath, Action<bool, str
16721672
vertex.FlowDirection[0] = reader.GetFloat("flow_u");
16731673
vertex.FlowDirection[1] = reader.GetFloat("flow_v");
16741674

1675-
if(vertex.Binormal != Vector3.Zero)
1675+
if (vertex.Binormal != Vector3.Zero)
16761676
{
16771677
var tangent = Vector3.Cross(vertex.Normal, vertex.Binormal).Normalized();
16781678
var dot = Vector3.Dot(tangent, vertex.Tangent);
1679-
if(dot < 0.5f)
1679+
if (dot < 0.5f)
16801680
{
16811681
vertex.Handedness = true;
1682-
} else
1682+
}
1683+
else
16831684
{
16841685
vertex.Handedness = false;
16851686
}
@@ -1693,7 +1694,8 @@ public static async Task<TTModel> LoadFromFile(string filePath, Action<bool, str
16931694
try
16941695
{
16951696
return reader.GetInt32("vertex_id");
1696-
} catch(Exception ex)
1697+
}
1698+
catch (Exception ex)
16971699
{
16981700
throw ex;
16991701
}
@@ -1741,25 +1743,42 @@ public static async Task<TTModel> LoadFromFile(string filePath, Action<bool, str
17411743
}
17421744
}
17431745
}
1744-
db.Close();
1745-
}
17461746

1747-
// Try to make sure the DB is properly unlocked.'
1747+
//Load Mats if applicable
1748+
query = "select * from materials order by material_id";
1749+
using (var cmd = new SQLiteCommand(query, db))
1750+
{
1751+
using (var reader = new CacheReader(cmd.ExecuteReader()))
1752+
{
1753+
while (reader.NextRow())
1754+
{
1755+
var matNum = reader.GetInt32("material_id");
1756+
var materialPath = reader.GetString("name");
1757+
model.MeshGroups[matNum].Material = materialPath;
1758+
}
1759+
}
1760+
17481761

1749-
XivCache.WaitForSqlCleanup();
1762+
db.Close();
1763+
}
17501764

1751-
model.UVState = UVAddressingSpace.Standard;
1765+
// Try to make sure the DB is properly unlocked.'
17521766

1753-
// Convert the model to FFXIV's internal weirdness.
1754-
ModelModifiers.MakeImportReady(model, settings.ShiftImportUV, loggingFunction);
1767+
XivCache.WaitForSqlCleanup();
17551768

1756-
await ModelModifiers.CalculateTangents(model, loggingFunction);
1769+
model.UVState = UVAddressingSpace.Standard;
17571770

1758-
await ModelModifiers.ConvertFlowData(model, loggingFunction);
1771+
// Convert the model to FFXIV's internal weirdness.
1772+
ModelModifiers.MakeImportReady(model, settings.ShiftImportUV, loggingFunction);
17591773

1760-
ModelModifiers.CleanWeights(model, loggingFunction);
1774+
await ModelModifiers.CalculateTangents(model, loggingFunction);
17611775

1762-
return model;
1776+
await ModelModifiers.ConvertFlowData(model, loggingFunction);
1777+
1778+
ModelModifiers.CleanWeights(model, loggingFunction);
1779+
1780+
return model;
1781+
}
17631782
}
17641783

17651784
private static void MigrateImportDb(SQLiteConnection db)

xivModdingFramework/Models/FileTypes/Mdl.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,10 +1911,13 @@ public static async Task<long> ImportModel(string externalFile, string internalF
19111911
/// <exception cref="InvalidDataException"></exception>
19121912
public static async Task<byte[]> FileToUncompressedMdl(string externalPath, string internalPath, ModelImportOptions options = null, ModTransaction tx = null)
19131913
{
1914-
1914+
bool applyOptions = false;
19151915
if (options == null)
19161916
{
19171917
options = new ModelImportOptions();
1918+
} else
1919+
{
1920+
applyOptions = true;
19181921
}
19191922

19201923
if (options.LoggingFunction == null)
@@ -2001,7 +2004,7 @@ await Task.Run(async () =>
20012004
}
20022005
else
20032006
{
2004-
ttModel = await LoadExternalModel(externalPath, options, false);
2007+
ttModel = await LoadExternalModel(externalPath, options, applyOptions);
20052008
}
20062009
#endregion
20072010

0 commit comments

Comments
 (0)