@@ -421,7 +421,6 @@ public static void MergeGeometryData(TTModel ttModel, XivMdl rawMdl, Action<bool
421
421
422
422
for ( var pi = 0 ; pi < totalParts ; pi ++ )
423
423
{
424
-
425
424
var ttPart = new TTMeshPart ( ) ;
426
425
ttMesh . Parts . Add ( ttPart ) ;
427
426
ttPart . Name = "Part " + partIdx ;
@@ -431,24 +430,21 @@ public static void MergeGeometryData(TTModel ttModel, XivMdl rawMdl, Action<bool
431
430
var indexStart = fakePart == false ? basePart . IndexOffset - baseMesh . MeshInfo . IndexDataOffset : 0 ;
432
431
var indexCount = fakePart == false ? basePart . IndexCount : baseMesh . MeshInfo . IndexCount ;
433
432
434
- var indices = baseMesh . VertexData . Indices . GetRange ( indexStart , indexCount ) ;
433
+ var indices = baseMesh . VertexData . Indices . Skip ( indexStart ) . Take ( indexCount ) ;
435
434
436
435
// Get the Vertices unique to this part.
437
- var uniqueVertexIdSet = new SortedSet < int > ( indices ) ; // Maximum possible amount is # of indices, though likely it is less.
438
-
439
- foreach ( var ind in indices )
440
- {
441
- uniqueVertexIdSet . Add ( ind ) ;
442
- }
436
+ var uniqueVertexIdSet = new HashSet < int > ( indices ) ;
443
437
444
438
// Need it as a list to have index access to it.
445
- var uniqueVertexIds = uniqueVertexIdSet . ToList ( ) ;
439
+ var uniqueVertexIds = new List < int > ( uniqueVertexIdSet ) ;
440
+ uniqueVertexIds . Sort ( ) ;
446
441
447
442
// Maps old vertex ID to new vertex ID.
448
- var vertDict = new Dictionary < int , int > ( uniqueVertexIds . Count ) ;
443
+ var vertMap = new int [ uniqueVertexIds . Max ( ) + 1 ] ;
449
444
450
445
// Now we need to loop through, copy over the vertex data, keeping track of the new vertex IDs.
451
446
ttPart . Vertices = new List < TTVertex > ( uniqueVertexIds . Count ) ;
447
+
452
448
for ( var i = 0 ; i < uniqueVertexIds . Count ; i ++ )
453
449
{
454
450
var oldVertexId = uniqueVertexIds [ i ] ;
@@ -556,14 +552,14 @@ public static void MergeGeometryData(TTModel ttModel, XivMdl rawMdl, Action<bool
556
552
}
557
553
558
554
ttPart . Vertices . Add ( ttVert ) ;
559
- vertDict . Add ( oldVertexId , ttPart . Vertices . Count - 1 ) ;
555
+ vertMap [ oldVertexId ] = ttPart . Vertices . Count - 1 ;
560
556
}
561
557
562
558
// Now we need to copy in the triangle indices, pointing to the new, part-level vertex IDs.
563
- ttPart . TriangleIndices = new List < int > ( indices . Count ) ;
559
+ ttPart . TriangleIndices = new List < int > ( indexCount ) ;
564
560
foreach ( var oldVertexId in indices )
565
561
{
566
- ttPart . TriangleIndices . Add ( vertDict [ oldVertexId ] ) ;
562
+ ttPart . TriangleIndices . Add ( vertMap [ oldVertexId ] ) ;
567
563
}
568
564
569
565
// Ok, gucci now.
0 commit comments