scripts
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using KdTree;
|
||||
using KdTree.Math;
|
||||
using ProBuilder2.Common;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ProBuilder2.MeshOperations
|
||||
{
|
||||
// Token: 0x02000014 RID: 20
|
||||
public static class pb_WeldVertices
|
||||
{
|
||||
// Token: 0x060000A1 RID: 161 RVA: 0x0000CF88 File Offset: 0x0000B388
|
||||
public static pb_ActionResult WeldVertices(this pb_Object pb, int[] indices, float neighborRadius, out int[] welds)
|
||||
{
|
||||
pb_Vertex[] vertices = pb_Vertex.GetVertices(pb, null);
|
||||
pb_IntArray[] sharedIndices = pb.sharedIndices;
|
||||
Dictionary<int, int> dictionary = sharedIndices.ToDictionary();
|
||||
HashSet<int> commonIndices = pb_IntArrayUtility.GetCommonIndices(dictionary, indices);
|
||||
int count = commonIndices.Count;
|
||||
int num = Math.Min(32, commonIndices.Count<int>());
|
||||
KdTree<float, int> kdTree = new KdTree<float, int>(3, new FloatMath(), AddDuplicateBehavior.Collect);
|
||||
foreach (int num2 in commonIndices)
|
||||
{
|
||||
Vector3 position = vertices[sharedIndices[num2][0]].position;
|
||||
kdTree.Add(new float[] { position.x, position.y, position.z }, num2);
|
||||
}
|
||||
float[] array = new float[3];
|
||||
Dictionary<int, int> dictionary2 = new Dictionary<int, int>();
|
||||
Dictionary<int, Vector3> dictionary3 = new Dictionary<int, Vector3>();
|
||||
int num3 = sharedIndices.Length;
|
||||
foreach (int num4 in commonIndices)
|
||||
{
|
||||
if (!dictionary2.ContainsKey(num4))
|
||||
{
|
||||
Vector3 position2 = vertices[sharedIndices[num4][0]].position;
|
||||
array[0] = position2.x;
|
||||
array[1] = position2.y;
|
||||
array[2] = position2.z;
|
||||
KdTreeNode<float, int>[] array2 = kdTree.RadialSearch(array, neighborRadius, num);
|
||||
if (num < count && array2.Length >= num)
|
||||
{
|
||||
array2 = kdTree.RadialSearch(array, neighborRadius, count);
|
||||
num = Math.Min(count, array2.Length + array2.Length / 2);
|
||||
}
|
||||
Vector3 zero = Vector3.zero;
|
||||
float num5 = 0f;
|
||||
for (int i = 0; i < array2.Length; i++)
|
||||
{
|
||||
int value = array2[i].Value;
|
||||
if (!dictionary2.ContainsKey(value))
|
||||
{
|
||||
zero.x += array2[i].Point[0];
|
||||
zero.y += array2[i].Point[1];
|
||||
zero.z += array2[i].Point[2];
|
||||
dictionary2.Add(value, num3);
|
||||
num5 += 1f;
|
||||
if (array2[i].Duplicates != null)
|
||||
{
|
||||
for (int j = 0; j < array2[i].Duplicates.Count; j++)
|
||||
{
|
||||
dictionary2.Add(array2[i].Duplicates[j], num3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
zero.x /= num5;
|
||||
zero.y /= num5;
|
||||
zero.z /= num5;
|
||||
dictionary3.Add(num3, zero);
|
||||
num3++;
|
||||
}
|
||||
}
|
||||
welds = new int[dictionary2.Count];
|
||||
int num6 = 0;
|
||||
foreach (KeyValuePair<int, int> keyValuePair in dictionary2)
|
||||
{
|
||||
int[] array3 = sharedIndices[keyValuePair.Key];
|
||||
welds[num6++] = array3[0];
|
||||
for (int k = 0; k < array3.Length; k++)
|
||||
{
|
||||
dictionary[array3[k]] = keyValuePair.Value;
|
||||
vertices[array3[k]].position = dictionary3[keyValuePair.Value];
|
||||
}
|
||||
}
|
||||
pb.SetSharedIndices(dictionary);
|
||||
pb.SetVertices(vertices, false);
|
||||
pb.ToMesh();
|
||||
return new pb_ActionResult(Status.Success, "Weld Vertices");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user