68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using ProBuilder2.Common;
|
|
|
|
namespace ProBuilder2.MeshOperations
|
|
{
|
|
// Token: 0x0200000E RID: 14
|
|
public static class pb_DeleteVertices
|
|
{
|
|
// Token: 0x0600008C RID: 140 RVA: 0x0000B864 File Offset: 0x00009C64
|
|
public static int[] RemoveUnusedVertices(this pb_Object pb)
|
|
{
|
|
List<int> list = new List<int>();
|
|
HashSet<int> hashSet = new HashSet<int>(pb_Face.AllTriangles(pb.faces));
|
|
for (int i = 0; i < pb.vertices.Length; i++)
|
|
{
|
|
if (!hashSet.Contains(i))
|
|
{
|
|
list.Add(i);
|
|
}
|
|
}
|
|
pb.DeleteVerticesWithIndices(list);
|
|
return list.ToArray();
|
|
}
|
|
|
|
// Token: 0x0600008D RID: 141 RVA: 0x0000B8C4 File Offset: 0x00009CC4
|
|
public static void DeleteVerticesWithIndices(this pb_Object pb, IEnumerable<int> distInd)
|
|
{
|
|
if (distInd == null || distInd.Count<int>() < 1)
|
|
{
|
|
return;
|
|
}
|
|
pb_Vertex[] array = pb_Vertex.GetVertices(pb, null);
|
|
int num = array.Length;
|
|
int[] offset = new int[num];
|
|
List<int> sorted = new List<int>(distInd);
|
|
sorted.Sort();
|
|
array = array.SortedRemoveAt(sorted);
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
offset[i] = pbUtil.NearestIndexPriorToValue<int>(sorted, i) + 1;
|
|
}
|
|
foreach (pb_Face pb_Face in pb.faces)
|
|
{
|
|
int[] indices = pb_Face.indices;
|
|
for (int k = 0; k < indices.Length; k++)
|
|
{
|
|
indices[k] -= offset[indices[k]];
|
|
}
|
|
pb_Face.RebuildCaches();
|
|
}
|
|
IEnumerable<KeyValuePair<int, int>> enumerable = from x in pb.sharedIndices.ToDictionary()
|
|
where sorted.BinarySearch(x.Key) < 0
|
|
select x into y
|
|
select new KeyValuePair<int, int>(y.Key - offset[y.Key], y.Value);
|
|
IEnumerable<KeyValuePair<int, int>> enumerable2 = from x in pb.sharedIndicesUV.ToDictionary()
|
|
where sorted.BinarySearch(x.Key) < 0
|
|
select x into y
|
|
select new KeyValuePair<int, int>(y.Key - offset[y.Key], y.Value);
|
|
pb.SetVertices(array, false);
|
|
pb.SetSharedIndices(enumerable);
|
|
pb.SetSharedIndicesUV(enumerable2);
|
|
pb.ToMesh();
|
|
}
|
|
}
|
|
}
|