Skip to content

Commit 5f0e4aa

Browse files
committed
Model Import cleanup and additions.
1 parent d611d61 commit 5f0e4aa

File tree

2 files changed

+26
-42
lines changed

2 files changed

+26
-42
lines changed

xivModdingFramework/Models/DataContainers/TTModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ public float[] WorldToTangent(float[] vector)
154154

155155
public float[] TangentToWorld(float[] vector)
156156
{
157+
if(vector.Length == 2)
158+
{
159+
vector = new float[3] { vector[0], vector[1], 0 };
160+
}
161+
157162
var mat = Matrix<float>.Build.Dense(3, 3);
158163

159164
var n = Normal.Normalized();
@@ -171,6 +176,7 @@ public float[] TangentToWorld(float[] vector)
171176
mat[2, 0] = n[0];
172177
mat[2, 1] = n[1];
173178
mat[2, 2] = n[2];
179+
174180
var vec = Vector<float>.Build.Dense(vector);
175181

176182
mat = mat.Transpose();

xivModdingFramework/Models/Helpers/ModelModifiers.cs

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,8 @@ public class ModelImportOptions : ICloneable
3535
{
3636
public bool CopyAttributes { get; set; }
3737
public bool CopyMaterials { get; set; }
38-
public bool UseOriginalShapeData { get; set; }
3938
public bool ShiftImportUV { get; set; }
40-
public bool ClearUV2 { get; set; }
4139
public bool CloneUV2 { get; set; }
42-
public bool ClearVColor { get; set; }
43-
public bool ClearVAlpha { get; set; }
4440
public bool AutoScale { get; set; }
4541
public bool UseImportedTangents { get; set; }
4642
public XivRace SourceRace { get; set; }
@@ -75,13 +71,9 @@ public ModelImportOptions()
7571
{
7672
CopyAttributes = true;
7773
CopyMaterials = true;
78-
UseOriginalShapeData = false;
7974
UseImportedTangents = false;
8075
ShiftImportUV = true;
81-
ClearUV2 = false;
8276
CloneUV2 = false;
83-
ClearVColor = false;
84-
ClearVAlpha = false;
8577
AutoScale = true;
8678
ValidateMaterials = true;
8779
SourceRace = XivRace.All_Races;
@@ -133,26 +125,11 @@ public async Task Apply(TTModel ttModel, XivMdl currentMdl = null, XivMdl origin
133125
ModelModifiers.MergeMaterialData(ttModel, currentMdl, LoggingFunction);
134126
}
135127

136-
if (ClearUV2)
137-
{
138-
ModelModifiers.ClearUV2(ttModel, LoggingFunction);
139-
}
140-
141128
if (CloneUV2)
142129
{
143130
ModelModifiers.CloneUV2(ttModel, LoggingFunction);
144131
}
145132

146-
if (ClearVColor)
147-
{
148-
ModelModifiers.ClearVColor(ttModel, LoggingFunction);
149-
}
150-
151-
if (ClearVAlpha)
152-
{
153-
ModelModifiers.ClearVAlpha(ttModel, LoggingFunction);
154-
}
155-
156133
if(SourceRace != XivRace.All_Races && SourceRace != TargetRace)
157134
{
158135
if(TargetRace == XivRace.All_Races && currentMdl != null)
@@ -173,24 +150,6 @@ public async Task Apply(TTModel ttModel, XivMdl currentMdl = null, XivMdl origin
173150
await ModelModifiers.RaceConvertRecursive(ttModel, TargetRace, SourceRace, LoggingFunction, tx);
174151
}
175152

176-
// We need to load the original unmodified model to get the shape data.
177-
if (UseOriginalShapeData && originalMdl != null)
178-
{
179-
if (originalMdl == null)
180-
{
181-
throw new Exception("Cannot copy settings from null MDL.");
182-
}
183-
ModelModifiers.ClearShapeData(ttModel, LoggingFunction);
184-
try
185-
{
186-
ModelModifiers.MergeShapeData(ttModel, originalMdl, LoggingFunction);
187-
}
188-
catch
189-
{
190-
throw new Exception("Failed to apply the original shape data.\nThis is likely due to changes to the original model without preserving the vertices' order.");
191-
}
192-
}
193-
194153
if (AutoScale && originalMdl != null)
195154
{
196155
if (originalMdl == null)
@@ -988,6 +947,23 @@ public static void ClearUV2_Part(TTMeshPart p)
988947
}
989948
UpdateShapeParts(p);
990949
}
950+
public static void ClearFlow_Part(TTMeshPart p)
951+
{
952+
foreach (var v in p.Vertices)
953+
{
954+
v.FlowDirection = Vector3.Zero;
955+
}
956+
UpdateShapeParts(p);
957+
}
958+
959+
public static void SetFlow_Part(TTMeshPart p, Vector2 tangentDirection)
960+
{
961+
foreach (var v in p.Vertices)
962+
{
963+
v.FlowDirection = new Vector3(v.TangentToWorld(tangentDirection.ToArray()));
964+
}
965+
UpdateShapeParts(p);
966+
}
991967

992968
// Resets Vertex Color to White(c1)/Black(c2)
993969
public static void ClearVColor(TTModel model, Action<bool, string> loggingFunction = null)
@@ -1199,7 +1175,9 @@ public static async Task RaceConvertRecursive(TTModel model, XivRace targetRace,
11991175
// The model is still added but no deforms are applied
12001176
if (loggingFunction != null)
12011177
{
1202-
loggingFunction(true, "Unable to convert racial model.");
1178+
loggingFunction(true, "Unable to convert racial model:" + ex.Message);
1179+
var tempLog = Path.Combine(IOUtil.GetFrameworkTempFolder(), "race_convert_log.txt");
1180+
File.WriteAllText(tempLog, ex.StackTrace);
12031181
} else
12041182
{
12051183
throw;

0 commit comments

Comments
 (0)