565 lines
14 KiB
C#
565 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace ProBuilder2.Common
|
|
{
|
|
// Token: 0x0200005A RID: 90
|
|
public class pb_Vertex : IEquatable<pb_Vertex>
|
|
{
|
|
// Token: 0x06000298 RID: 664 RVA: 0x0001FB4D File Offset: 0x0001DF4D
|
|
public pb_Vertex(bool hasAllValues = false)
|
|
{
|
|
this.hasPosition = hasAllValues;
|
|
this.hasColor = hasAllValues;
|
|
this.hasNormal = hasAllValues;
|
|
this.hasTangent = hasAllValues;
|
|
this.hasUv0 = hasAllValues;
|
|
this.hasUv2 = hasAllValues;
|
|
this.hasUv3 = hasAllValues;
|
|
this.hasUv4 = hasAllValues;
|
|
}
|
|
|
|
// Token: 0x06000299 RID: 665 RVA: 0x0001FB90 File Offset: 0x0001DF90
|
|
public pb_Vertex(pb_Vertex v)
|
|
{
|
|
this.position = v.position;
|
|
this.hasPosition = v.hasPosition;
|
|
this.color = v.color;
|
|
this.hasColor = v.hasColor;
|
|
this.uv0 = v.uv0;
|
|
this.hasUv0 = v.hasUv0;
|
|
this.normal = v.normal;
|
|
this.hasNormal = v.hasNormal;
|
|
this.tangent = v.tangent;
|
|
this.hasTangent = v.hasTangent;
|
|
this.uv2 = v.uv2;
|
|
this.hasUv2 = v.hasUv2;
|
|
this.uv3 = v.uv3;
|
|
this.hasUv3 = v.hasUv3;
|
|
this.uv4 = v.uv4;
|
|
this.hasUv4 = v.hasUv4;
|
|
}
|
|
|
|
// Token: 0x0600029A RID: 666 RVA: 0x0001FC63 File Offset: 0x0001E063
|
|
public override bool Equals(object other)
|
|
{
|
|
return other is pb_Vertex && this.Equals(other as pb_Vertex);
|
|
}
|
|
|
|
// Token: 0x0600029B RID: 667 RVA: 0x0001FC80 File Offset: 0x0001E080
|
|
public bool Equals(pb_Vertex other)
|
|
{
|
|
return other != null && (this.position.Approx3(other.position, 0.0001f) && this.color.ApproxC(other.color, 0.0001f) && this.normal.Approx3(other.normal, 0.0001f) && this.tangent.Approx4(other.tangent, 0.0001f) && this.uv0.Approx2(other.uv0, 0.0001f) && this.uv2.Approx2(other.uv2, 0.0001f) && this.uv3.Approx4(other.uv3, 0.0001f)) && this.uv4.Approx4(other.uv4, 0.0001f);
|
|
}
|
|
|
|
// Token: 0x0600029C RID: 668 RVA: 0x0001FD6C File Offset: 0x0001E16C
|
|
public override int GetHashCode()
|
|
{
|
|
int num = 783 + pb_Vector.GetHashCode(this.position);
|
|
num = num * 29 + pb_Vector.GetHashCode(this.uv0);
|
|
return num * 31 + pb_Vector.GetHashCode(this.normal);
|
|
}
|
|
|
|
// Token: 0x0600029D RID: 669 RVA: 0x0001FDB0 File Offset: 0x0001E1B0
|
|
public static pb_Vertex operator +(pb_Vertex a, pb_Vertex b)
|
|
{
|
|
pb_Vertex pb_Vertex = new pb_Vertex(a);
|
|
pb_Vertex.Add(b);
|
|
return pb_Vertex;
|
|
}
|
|
|
|
// Token: 0x0600029E RID: 670 RVA: 0x0001FDCC File Offset: 0x0001E1CC
|
|
public void Add(pb_Vertex b)
|
|
{
|
|
this.position += b.position;
|
|
this.color += b.color;
|
|
this.normal += b.normal;
|
|
this.tangent += b.tangent;
|
|
this.uv0 += b.uv0;
|
|
this.uv2 += b.uv2;
|
|
this.uv3 += b.uv3;
|
|
this.uv4 += b.uv4;
|
|
}
|
|
|
|
// Token: 0x0600029F RID: 671 RVA: 0x0001FE94 File Offset: 0x0001E294
|
|
public static pb_Vertex operator -(pb_Vertex a, pb_Vertex b)
|
|
{
|
|
pb_Vertex pb_Vertex = new pb_Vertex(a);
|
|
pb_Vertex.Subtract(b);
|
|
return pb_Vertex;
|
|
}
|
|
|
|
// Token: 0x060002A0 RID: 672 RVA: 0x0001FEB0 File Offset: 0x0001E2B0
|
|
public void Subtract(pb_Vertex b)
|
|
{
|
|
this.position -= b.position;
|
|
this.color -= b.color;
|
|
this.normal -= b.normal;
|
|
this.tangent -= b.tangent;
|
|
this.uv0 -= b.uv0;
|
|
this.uv2 -= b.uv2;
|
|
this.uv3 -= b.uv3;
|
|
this.uv4 -= b.uv4;
|
|
}
|
|
|
|
// Token: 0x060002A1 RID: 673 RVA: 0x0001FF78 File Offset: 0x0001E378
|
|
public static pb_Vertex operator *(pb_Vertex a, float value)
|
|
{
|
|
pb_Vertex pb_Vertex = new pb_Vertex(a);
|
|
pb_Vertex.Multiply(value);
|
|
return pb_Vertex;
|
|
}
|
|
|
|
// Token: 0x060002A2 RID: 674 RVA: 0x0001FF94 File Offset: 0x0001E394
|
|
public void Multiply(float value)
|
|
{
|
|
this.position *= value;
|
|
this.color *= value;
|
|
this.normal *= value;
|
|
this.tangent *= value;
|
|
this.uv0 *= value;
|
|
this.uv2 *= value;
|
|
this.uv3 *= value;
|
|
this.uv4 *= value;
|
|
}
|
|
|
|
// Token: 0x060002A3 RID: 675 RVA: 0x00020034 File Offset: 0x0001E434
|
|
public static pb_Vertex operator /(pb_Vertex a, float value)
|
|
{
|
|
pb_Vertex pb_Vertex = new pb_Vertex(a);
|
|
pb_Vertex.Divide(value);
|
|
return pb_Vertex;
|
|
}
|
|
|
|
// Token: 0x060002A4 RID: 676 RVA: 0x00020050 File Offset: 0x0001E450
|
|
public void Divide(float value)
|
|
{
|
|
this.position /= value;
|
|
this.color /= value;
|
|
this.normal /= value;
|
|
this.tangent /= value;
|
|
this.uv0 /= value;
|
|
this.uv2 /= value;
|
|
this.uv3 /= value;
|
|
this.uv4 /= value;
|
|
}
|
|
|
|
// Token: 0x060002A5 RID: 677 RVA: 0x000200F0 File Offset: 0x0001E4F0
|
|
public void Normalize()
|
|
{
|
|
this.position.Normalize();
|
|
Vector4 vector = this.color;
|
|
vector.Normalize();
|
|
this.color.r = vector.x;
|
|
this.color.g = vector.y;
|
|
this.color.b = vector.z;
|
|
this.color.a = vector.w;
|
|
this.normal.Normalize();
|
|
this.tangent.Normalize();
|
|
this.uv0.Normalize();
|
|
this.uv2.Normalize();
|
|
this.uv3.Normalize();
|
|
this.uv4.Normalize();
|
|
}
|
|
|
|
// Token: 0x060002A6 RID: 678 RVA: 0x000201A5 File Offset: 0x0001E5A5
|
|
public override string ToString()
|
|
{
|
|
return this.position.ToString();
|
|
}
|
|
|
|
// Token: 0x060002A7 RID: 679 RVA: 0x000201B8 File Offset: 0x0001E5B8
|
|
public static pb_Vertex[] GetVertices(pb_Object pb, IList<int> indices = null)
|
|
{
|
|
int vertexCount = pb.vertexCount;
|
|
int num = ((indices == null) ? pb.vertexCount : indices.Count);
|
|
pb_Vertex[] array = new pb_Vertex[num];
|
|
Vector3[] vertices = pb.vertices;
|
|
Color[] colors = pb.colors;
|
|
Vector2[] uv = pb.uv;
|
|
Vector3[] normals = pb.msh.normals;
|
|
Vector4[] tangents = pb.msh.tangents;
|
|
Vector2[] array2 = pb.msh.uv2;
|
|
List<Vector4> list = new List<Vector4>();
|
|
List<Vector4> list2 = new List<Vector4>();
|
|
pb.GetUVs(2, list);
|
|
pb.GetUVs(3, list2);
|
|
bool flag = vertices != null && vertices.Count<Vector3>() == vertexCount;
|
|
bool flag2 = colors != null && colors.Count<Color>() == vertexCount;
|
|
bool flag3 = normals != null && normals.Count<Vector3>() == vertexCount;
|
|
bool flag4 = tangents != null && tangents.Count<Vector4>() == vertexCount;
|
|
bool flag5 = uv != null && uv.Count<Vector2>() == vertexCount;
|
|
bool flag6 = array2 != null && array2.Count<Vector2>() == vertexCount;
|
|
bool flag7 = list != null && list.Count<Vector4>() == vertexCount;
|
|
bool flag8 = list2 != null && list2.Count<Vector4>() == vertexCount;
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
array[i] = new pb_Vertex(false);
|
|
int num2 = ((indices != null) ? indices[i] : i);
|
|
if (flag)
|
|
{
|
|
array[i].hasPosition = true;
|
|
array[i].position = vertices[num2];
|
|
}
|
|
if (flag2)
|
|
{
|
|
array[i].hasColor = true;
|
|
array[i].color = colors[num2];
|
|
}
|
|
if (flag3)
|
|
{
|
|
array[i].hasNormal = true;
|
|
array[i].normal = normals[num2];
|
|
}
|
|
if (flag4)
|
|
{
|
|
array[i].hasTangent = true;
|
|
array[i].tangent = tangents[num2];
|
|
}
|
|
if (flag5)
|
|
{
|
|
array[i].hasUv0 = true;
|
|
array[i].uv0 = uv[num2];
|
|
}
|
|
if (flag6)
|
|
{
|
|
array[i].hasUv2 = true;
|
|
array[i].uv2 = array2[num2];
|
|
}
|
|
if (flag7)
|
|
{
|
|
array[i].hasUv3 = true;
|
|
array[i].uv3 = list[num2];
|
|
}
|
|
if (flag8)
|
|
{
|
|
array[i].hasUv4 = true;
|
|
array[i].uv4 = list2[num2];
|
|
}
|
|
}
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x060002A8 RID: 680 RVA: 0x00020464 File Offset: 0x0001E864
|
|
public static pb_Vertex[] GetVertices(Mesh m)
|
|
{
|
|
if (m == null)
|
|
{
|
|
return null;
|
|
}
|
|
int vertexCount = m.vertexCount;
|
|
pb_Vertex[] array = new pb_Vertex[vertexCount];
|
|
Vector3[] vertices = m.vertices;
|
|
Color[] colors = m.colors;
|
|
Vector3[] normals = m.normals;
|
|
Vector4[] tangents = m.tangents;
|
|
Vector2[] uv = m.uv;
|
|
Vector2[] array2 = m.uv2;
|
|
List<Vector4> list = new List<Vector4>();
|
|
List<Vector4> list2 = new List<Vector4>();
|
|
m.GetUVs(2, list);
|
|
m.GetUVs(3, list2);
|
|
bool flag = vertices != null && vertices.Count<Vector3>() == vertexCount;
|
|
bool flag2 = colors != null && colors.Count<Color>() == vertexCount;
|
|
bool flag3 = normals != null && normals.Count<Vector3>() == vertexCount;
|
|
bool flag4 = tangents != null && tangents.Count<Vector4>() == vertexCount;
|
|
bool flag5 = uv != null && uv.Count<Vector2>() == vertexCount;
|
|
bool flag6 = array2 != null && array2.Count<Vector2>() == vertexCount;
|
|
bool flag7 = list != null && list.Count<Vector4>() == vertexCount;
|
|
bool flag8 = list2 != null && list2.Count<Vector4>() == vertexCount;
|
|
for (int i = 0; i < vertexCount; i++)
|
|
{
|
|
array[i] = new pb_Vertex(false);
|
|
if (flag)
|
|
{
|
|
array[i].hasPosition = true;
|
|
array[i].position = vertices[i];
|
|
}
|
|
if (flag2)
|
|
{
|
|
array[i].hasColor = true;
|
|
array[i].color = colors[i];
|
|
}
|
|
if (flag3)
|
|
{
|
|
array[i].hasNormal = true;
|
|
array[i].normal = normals[i];
|
|
}
|
|
if (flag4)
|
|
{
|
|
array[i].hasTangent = true;
|
|
array[i].tangent = tangents[i];
|
|
}
|
|
if (flag5)
|
|
{
|
|
array[i].hasUv0 = true;
|
|
array[i].uv0 = uv[i];
|
|
}
|
|
if (flag6)
|
|
{
|
|
array[i].hasUv2 = true;
|
|
array[i].uv2 = array2[i];
|
|
}
|
|
if (flag7)
|
|
{
|
|
array[i].hasUv3 = true;
|
|
array[i].uv3 = list[i];
|
|
}
|
|
if (flag8)
|
|
{
|
|
array[i].hasUv4 = true;
|
|
array[i].uv4 = list2[i];
|
|
}
|
|
}
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x060002A9 RID: 681 RVA: 0x000206DC File Offset: 0x0001EADC
|
|
public static void GetArrays(IList<pb_Vertex> vertices, out Vector3[] position, out Color[] color, out Vector2[] uv0, out Vector3[] normal, out Vector4[] tangent, out Vector2[] uv2, out List<Vector4> uv3, out List<Vector4> uv4)
|
|
{
|
|
int count = vertices.Count;
|
|
position = new Vector3[count];
|
|
color = new Color[count];
|
|
uv0 = new Vector2[count];
|
|
normal = new Vector3[count];
|
|
tangent = new Vector4[count];
|
|
uv2 = new Vector2[count];
|
|
uv3 = new List<Vector4>(count);
|
|
uv4 = new List<Vector4>(count);
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
position[i] = vertices[i].position;
|
|
color[i] = vertices[i].color;
|
|
uv0[i] = vertices[i].uv0;
|
|
normal[i] = vertices[i].normal;
|
|
tangent[i] = vertices[i].tangent;
|
|
uv2[i] = vertices[i].uv2;
|
|
uv3.Add(vertices[i].uv3);
|
|
uv4.Add(vertices[i].uv4);
|
|
}
|
|
}
|
|
|
|
// Token: 0x060002AA RID: 682 RVA: 0x00020808 File Offset: 0x0001EC08
|
|
public static void SetMesh(Mesh m, IList<pb_Vertex> vertices)
|
|
{
|
|
Vector3[] array = null;
|
|
Color[] array2 = null;
|
|
Vector2[] array3 = null;
|
|
Vector3[] array4 = null;
|
|
Vector4[] array5 = null;
|
|
Vector2[] array6 = null;
|
|
List<Vector4> list = null;
|
|
List<Vector4> list2 = null;
|
|
pb_Vertex.GetArrays(vertices, out array, out array2, out array3, out array4, out array5, out array6, out list, out list2);
|
|
m.Clear();
|
|
pb_Vertex pb_Vertex = vertices[0];
|
|
if (pb_Vertex.hasPosition)
|
|
{
|
|
m.vertices = array;
|
|
}
|
|
if (pb_Vertex.hasColor)
|
|
{
|
|
m.colors = array2;
|
|
}
|
|
if (pb_Vertex.hasUv0)
|
|
{
|
|
m.uv = array3;
|
|
}
|
|
if (pb_Vertex.hasNormal)
|
|
{
|
|
m.normals = array4;
|
|
}
|
|
if (pb_Vertex.hasTangent)
|
|
{
|
|
m.tangents = array5;
|
|
}
|
|
if (pb_Vertex.hasUv2)
|
|
{
|
|
m.uv2 = array6;
|
|
}
|
|
if (pb_Vertex.hasUv3 && list != null)
|
|
{
|
|
m.SetUVs(2, list);
|
|
}
|
|
if (pb_Vertex.hasUv4 && list2 != null)
|
|
{
|
|
m.SetUVs(3, list2);
|
|
}
|
|
}
|
|
|
|
// Token: 0x060002AB RID: 683 RVA: 0x000208FC File Offset: 0x0001ECFC
|
|
public static pb_Vertex Average(IList<pb_Vertex> vertices, IList<int> indices = null)
|
|
{
|
|
pb_Vertex pb_Vertex = new pb_Vertex(false);
|
|
int num = ((indices == null) ? vertices.Count : indices.Count);
|
|
int num2 = 0;
|
|
int num3 = 0;
|
|
int num4 = 0;
|
|
int num5 = 0;
|
|
int num6 = 0;
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
int num7 = ((indices != null) ? indices[i] : i);
|
|
pb_Vertex.position += vertices[num7].position;
|
|
pb_Vertex.color += vertices[num7].color;
|
|
pb_Vertex.uv0 += vertices[num7].uv0;
|
|
if (vertices[num7].hasNormal)
|
|
{
|
|
num2++;
|
|
pb_Vertex.normal += vertices[num7].normal;
|
|
}
|
|
if (vertices[num7].hasTangent)
|
|
{
|
|
num3++;
|
|
pb_Vertex.tangent += vertices[num7].tangent;
|
|
}
|
|
if (vertices[num7].hasUv2)
|
|
{
|
|
num4++;
|
|
pb_Vertex.uv2 += vertices[num7].uv2;
|
|
}
|
|
if (vertices[num7].hasUv3)
|
|
{
|
|
num5++;
|
|
pb_Vertex.uv3 += vertices[num7].uv3;
|
|
}
|
|
if (vertices[num7].hasUv4)
|
|
{
|
|
num6++;
|
|
pb_Vertex.uv4 += vertices[num7].uv4;
|
|
}
|
|
}
|
|
pb_Vertex.position *= 1f / (float)num;
|
|
pb_Vertex.color *= 1f / (float)num;
|
|
pb_Vertex.uv0 *= 1f / (float)num;
|
|
pb_Vertex.normal *= 1f / (float)num2;
|
|
pb_Vertex.tangent *= 1f / (float)num3;
|
|
pb_Vertex.uv2 *= 1f / (float)num4;
|
|
pb_Vertex.uv3 *= 1f / (float)num5;
|
|
pb_Vertex.uv4 *= 1f / (float)num6;
|
|
return pb_Vertex;
|
|
}
|
|
|
|
// Token: 0x060002AC RID: 684 RVA: 0x00020B94 File Offset: 0x0001EF94
|
|
public static pb_Vertex Mix(pb_Vertex x, pb_Vertex y, float a)
|
|
{
|
|
float num = 1f - a;
|
|
pb_Vertex pb_Vertex = new pb_Vertex(false);
|
|
pb_Vertex.position = x.position * num + y.position * a;
|
|
pb_Vertex.color = x.color * num + y.color * a;
|
|
pb_Vertex.uv0 = x.uv0 * num + y.uv0 * a;
|
|
if (x.hasNormal && y.hasNormal)
|
|
{
|
|
pb_Vertex.normal = x.normal * num + y.normal * a;
|
|
}
|
|
else if (x.hasNormal)
|
|
{
|
|
pb_Vertex.normal = x.normal;
|
|
}
|
|
else if (y.hasNormal)
|
|
{
|
|
pb_Vertex.normal = y.normal;
|
|
}
|
|
if (x.hasTangent && y.hasTangent)
|
|
{
|
|
pb_Vertex.tangent = x.tangent * num + y.tangent * a;
|
|
}
|
|
else if (x.hasTangent)
|
|
{
|
|
pb_Vertex.tangent = x.tangent;
|
|
}
|
|
else if (y.hasTangent)
|
|
{
|
|
pb_Vertex.tangent = y.tangent;
|
|
}
|
|
if (x.hasUv2 && y.hasUv2)
|
|
{
|
|
pb_Vertex.uv2 = x.uv2 * num + y.uv2 * a;
|
|
}
|
|
else if (x.hasUv2)
|
|
{
|
|
pb_Vertex.uv2 = x.uv2;
|
|
}
|
|
else if (y.hasUv2)
|
|
{
|
|
pb_Vertex.uv2 = y.uv2;
|
|
}
|
|
if (x.hasUv3 && y.hasUv3)
|
|
{
|
|
pb_Vertex.uv3 = x.uv3 * num + y.uv3 * a;
|
|
}
|
|
else if (x.hasUv3)
|
|
{
|
|
pb_Vertex.uv3 = x.uv3;
|
|
}
|
|
else if (y.hasUv3)
|
|
{
|
|
pb_Vertex.uv3 = y.uv3;
|
|
}
|
|
if (x.hasUv4 && y.hasUv4)
|
|
{
|
|
pb_Vertex.uv4 = x.uv4 * num + y.uv4 * a;
|
|
}
|
|
else if (x.hasUv4)
|
|
{
|
|
pb_Vertex.uv4 = x.uv4;
|
|
}
|
|
else if (y.hasUv4)
|
|
{
|
|
pb_Vertex.uv4 = y.uv4;
|
|
}
|
|
return pb_Vertex;
|
|
}
|
|
|
|
// Token: 0x040001D9 RID: 473
|
|
public Vector3 position;
|
|
|
|
// Token: 0x040001DA RID: 474
|
|
public Color color;
|
|
|
|
// Token: 0x040001DB RID: 475
|
|
public Vector3 normal;
|
|
|
|
// Token: 0x040001DC RID: 476
|
|
public Vector4 tangent;
|
|
|
|
// Token: 0x040001DD RID: 477
|
|
public Vector2 uv0;
|
|
|
|
// Token: 0x040001DE RID: 478
|
|
public Vector2 uv2;
|
|
|
|
// Token: 0x040001DF RID: 479
|
|
public Vector4 uv3;
|
|
|
|
// Token: 0x040001E0 RID: 480
|
|
public Vector4 uv4;
|
|
|
|
// Token: 0x040001E1 RID: 481
|
|
public bool hasPosition;
|
|
|
|
// Token: 0x040001E2 RID: 482
|
|
public bool hasColor;
|
|
|
|
// Token: 0x040001E3 RID: 483
|
|
public bool hasNormal;
|
|
|
|
// Token: 0x040001E4 RID: 484
|
|
public bool hasTangent;
|
|
|
|
// Token: 0x040001E5 RID: 485
|
|
public bool hasUv0;
|
|
|
|
// Token: 0x040001E6 RID: 486
|
|
public bool hasUv2;
|
|
|
|
// Token: 0x040001E7 RID: 487
|
|
public bool hasUv3;
|
|
|
|
// Token: 0x040001E8 RID: 488
|
|
public bool hasUv4;
|
|
}
|
|
}
|