Skip to content

Commit d611d61

Browse files
committed
Use hash calculations to speed up tangent calculation stuff.
1 parent b14e51f commit d611d61

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

xivModdingFramework/Models/DataContainers/TTModel.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ public class TTVertex : ICloneable {
109109
public byte[] BoneIds = new byte[_BONE_ARRAY_LENGTH];
110110
public byte[] Weights = new byte[_BONE_ARRAY_LENGTH];
111111

112+
public int GetWeldHash()
113+
{
114+
unchecked
115+
{
116+
int hash = 17;
117+
hash = hash * 31 + Position.GetHashCode();
118+
hash = hash * 31 + UV1.GetHashCode();
119+
hash = hash * 31 + Normal.GetHashCode();
120+
return hash;
121+
}
122+
}
123+
112124
public Vector3 GetTangentSpaceFlow()
113125
{
114126
var flow = WorldToTangent(FlowDirection.ToArray());

xivModdingFramework/Models/FileTypes/Mdl.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,7 @@ await Task.Run(async () =>
19811981
}
19821982

19831983

1984+
ttModel.Source = internalPath;
19841985

19851986
// At this point we now have a fully populated TTModel entry.
19861987
// Time to pull in the Model Modifier for any extra steps before we pass

xivModdingFramework/Models/Helpers/ModelModifiers.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,7 @@ private static (List<int> Indices, Dictionary<int, List<TTVertex>> VertexTable)
18611861
vertices.AddRange(p.Vertices);
18621862
}
18631863

1864+
Dictionary<int, List<int>> weldHashes = new Dictionary<int, List<int>>();
18641865
Dictionary<int, int> oldToNewVertex = new Dictionary<int, int>();
18651866
List<TTVertex> newVertices = new List<TTVertex>(vertices.Count);
18661867
var vertexTable = new Dictionary<int, List<TTVertex>>();
@@ -1869,19 +1870,24 @@ private static (List<int> Indices, Dictionary<int, List<TTVertex>> VertexTable)
18691870
for (int i = 0; i < vertices.Count; i++)
18701871
{
18711872
var ov = vertices[i];
1873+
var hash = ov.GetWeldHash();
18721874
var found = false;
1873-
for(var ni = 0; ni < newVertices.Count; ni++)
1875+
if (weldHashes.ContainsKey(hash))
18741876
{
1875-
var nv = newVertices[ni];
1876-
1877-
if(nv.UV1 == ov.UV1
1878-
&& nv.Position == ov.Position
1879-
&& nv.Normal == ov.Normal)
1877+
var entries = weldHashes[hash];
1878+
for (var ni = 0; ni < entries.Count; ni++)
18801879
{
1881-
oldToNewVertex.Add(i, ni);
1882-
vertexTable[ni].Add(ov);
1883-
found = true;
1884-
break;
1880+
var nv = vertices[entries[ni]];
1881+
1882+
if (nv.UV1 == ov.UV1
1883+
&& nv.Position == ov.Position
1884+
&& nv.Normal == ov.Normal)
1885+
{
1886+
oldToNewVertex.Add(i, ni);
1887+
vertexTable[ni].Add(ov);
1888+
found = true;
1889+
break;
1890+
}
18851891
}
18861892
}
18871893

@@ -1892,6 +1898,14 @@ private static (List<int> Indices, Dictionary<int, List<TTVertex>> VertexTable)
18921898
vertexTable.Add(ni, new List<TTVertex>());
18931899
vertexTable[ni].Add(ov);
18941900
newVertices.Add(ov);
1901+
if (weldHashes.ContainsKey(hash))
1902+
{
1903+
weldHashes[hash].Add(i);
1904+
}
1905+
else
1906+
{
1907+
weldHashes.Add(hash, new List<int>() { i });
1908+
}
18951909
}
18961910
}
18971911

0 commit comments

Comments
 (0)