142 lines
4.4 KiB
C#
142 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace ProBuilder2.Common
|
|
{
|
|
// Token: 0x02000036 RID: 54
|
|
public static class pb_Object_Utility
|
|
{
|
|
// Token: 0x060001AD RID: 429 RVA: 0x00016B4C File Offset: 0x00014F4C
|
|
public static Vector3[] VerticesInWorldSpace(this pb_Object pb)
|
|
{
|
|
Vector3[] array = new Vector3[pb.vertices.Length];
|
|
Array.Copy(pb.vertices, array, array.Length);
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
array[i] = pb.transform.TransformPoint(array[i]);
|
|
}
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x060001AE RID: 430 RVA: 0x00016BB0 File Offset: 0x00014FB0
|
|
public static Vector3[] VerticesInWorldSpace(this pb_Object pb, int[] indices)
|
|
{
|
|
if (indices == null)
|
|
{
|
|
Debug.LogWarning("indices == null -> VerticesInWorldSpace");
|
|
}
|
|
Vector3[] array = pb.vertices.ValuesWithIndices(indices);
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
array[i] = pb.transform.TransformPoint(array[i]);
|
|
}
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x060001AF RID: 431 RVA: 0x00016C12 File Offset: 0x00015012
|
|
public static void TranslateVertices_World(this pb_Object pb, int[] selectedTriangles, Vector3 offset)
|
|
{
|
|
pb.TranslateVertices_World(selectedTriangles, offset, 0f, false, null);
|
|
}
|
|
|
|
// Token: 0x060001B0 RID: 432 RVA: 0x00016C24 File Offset: 0x00015024
|
|
public static void TranslateVertices_World(this pb_Object pb, int[] selectedTriangles, Vector3 offset, float snapValue, bool snapAxisOnly, Dictionary<int, int> lookup)
|
|
{
|
|
int[] array = ((lookup == null) ? pb.sharedIndices.AllIndicesWithValues(selectedTriangles).ToArray<int>() : pb.sharedIndices.AllIndicesWithValues(lookup, selectedTriangles).ToArray<int>());
|
|
Matrix4x4 worldToLocalMatrix = pb.transform.worldToLocalMatrix;
|
|
Vector3 vector = worldToLocalMatrix * offset;
|
|
Vector3[] vertices = pb.vertices;
|
|
if (Mathf.Abs(snapValue) > Mathf.Epsilon)
|
|
{
|
|
Matrix4x4 localToWorldMatrix = pb.transform.localToWorldMatrix;
|
|
Vector3 vector2 = Vector3.zero;
|
|
Vector3 vector3 = ((!snapAxisOnly) ? Vector3.one : offset.ToMask(0.0001f));
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
vector2 = localToWorldMatrix.MultiplyPoint3x4(vertices[array[i]] + vector);
|
|
vertices[array[i]] = worldToLocalMatrix.MultiplyPoint3x4(pb_Snap.SnapValue(vector2, snapValue * vector3));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
vertices[array[i]] += vector;
|
|
}
|
|
}
|
|
pb.SetVertices(vertices);
|
|
pb.msh.vertices = vertices;
|
|
}
|
|
|
|
// Token: 0x060001B1 RID: 433 RVA: 0x00016D6C File Offset: 0x0001516C
|
|
public static void TranslateVertices(this pb_Object pb, int[] selectedTriangles, Vector3 offset)
|
|
{
|
|
int[] array = pb.sharedIndices.AllIndicesWithValues(selectedTriangles).ToArray<int>();
|
|
Vector3[] vertices = pb.vertices;
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
vertices[array[i]] += offset;
|
|
}
|
|
pb.SetVertices(vertices);
|
|
pb.msh.vertices = vertices;
|
|
}
|
|
|
|
// Token: 0x060001B2 RID: 434 RVA: 0x00016DD8 File Offset: 0x000151D8
|
|
public static void SetSharedVertexPosition(this pb_Object pb, int sharedIndex, Vector3 position)
|
|
{
|
|
Vector3[] vertices = pb.vertices;
|
|
int[] array = pb.sharedIndices[sharedIndex].array;
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
vertices[array[i]] = position;
|
|
}
|
|
pb.SetVertices(vertices);
|
|
pb.msh.vertices = vertices;
|
|
}
|
|
|
|
// Token: 0x060001B3 RID: 435 RVA: 0x00016E30 File Offset: 0x00015230
|
|
public static void SetSharedVertexValues(this pb_Object pb, int sharedIndex, pb_Vertex vertex)
|
|
{
|
|
pb_Vertex[] vertices = pb_Vertex.GetVertices(pb, null);
|
|
int[] array = pb.sharedIndices[sharedIndex].array;
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
vertices[array[i]] = vertex;
|
|
}
|
|
pb.SetVertices(vertices, false);
|
|
}
|
|
|
|
// Token: 0x060001B4 RID: 436 RVA: 0x00016E78 File Offset: 0x00015278
|
|
public static bool FaceWithTriangle(this pb_Object pb, int[] tri, out pb_Face face)
|
|
{
|
|
for (int i = 0; i < pb.faces.Length; i++)
|
|
{
|
|
if (pb.faces[i].Contains(tri))
|
|
{
|
|
face = pb.faces[i];
|
|
return true;
|
|
}
|
|
}
|
|
face = null;
|
|
return false;
|
|
}
|
|
|
|
// Token: 0x060001B5 RID: 437 RVA: 0x00016EC4 File Offset: 0x000152C4
|
|
public static bool FaceWithTriangle(this pb_Object pb, int[] tri, out int face)
|
|
{
|
|
for (int i = 0; i < pb.faces.Length; i++)
|
|
{
|
|
if (pb.faces[i].Contains(tri))
|
|
{
|
|
face = i;
|
|
return true;
|
|
}
|
|
}
|
|
face = -1;
|
|
return false;
|
|
}
|
|
}
|
|
}
|