Files
2026-06-04 11:42:34 +02:00

573 lines
14 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ProBuilder2.Common
{
// Token: 0x02000025 RID: 37
[Serializable]
public class pb_Face
{
// Token: 0x06000093 RID: 147 RVA: 0x0000F405 File Offset: 0x0000D805
public pb_Face()
{
}
// Token: 0x06000094 RID: 148 RVA: 0x0000F414 File Offset: 0x0000D814
public pb_Face(int[] i)
{
this.SetIndices(i);
this._uv = new pb_UV();
this._mat = pb_Constant.DefaultMaterial;
this._smoothingGroup = 0;
this.elementGroup = 0;
}
// Token: 0x06000095 RID: 149 RVA: 0x0000F450 File Offset: 0x0000D850
public pb_Face(int[] i, Material m, pb_UV u, int smoothingGroup, int textureGroup, int elementGroup, bool manualUV)
{
this.SetIndices(i);
this._uv = new pb_UV(u);
this._mat = m;
this._smoothingGroup = smoothingGroup;
this.textureGroup = textureGroup;
this.elementGroup = elementGroup;
this.manualUV = manualUV;
}
// Token: 0x06000096 RID: 150 RVA: 0x0000F4A4 File Offset: 0x0000D8A4
public pb_Face(pb_Face face)
{
this._indices = new int[face.indices.Length];
Array.Copy(face.indices, this._indices, face.indices.Length);
this._uv = new pb_UV(face.uv);
this._mat = face.material;
this._smoothingGroup = face.smoothingGroup;
this.textureGroup = face.textureGroup;
this.elementGroup = face.elementGroup;
this.manualUV = face.manualUV;
this.RebuildCaches();
}
// Token: 0x06000097 RID: 151 RVA: 0x0000F540 File Offset: 0x0000D940
public void CopyFrom(pb_Face other)
{
int num = ((other.indices != null) ? other.indices.Length : 0);
this._indices = new int[num];
Array.Copy(other.indices, this._indices, num);
this._smoothingGroup = other.smoothingGroup;
this._uv = new pb_UV(other.uv);
this._mat = other.material;
this.manualUV = other.manualUV;
this.elementGroup = other.elementGroup;
this.RebuildCaches();
}
// Token: 0x1700000F RID: 15
// (get) Token: 0x06000098 RID: 152 RVA: 0x0000F5CC File Offset: 0x0000D9CC
public int[] indices
{
get
{
return this._indices;
}
}
// Token: 0x17000010 RID: 16
// (get) Token: 0x06000099 RID: 153 RVA: 0x0000F5D4 File Offset: 0x0000D9D4
public int[] distinctIndices
{
get
{
return (this._distinctIndices != null) ? this._distinctIndices : this.CacheDistinctIndices();
}
}
// Token: 0x17000011 RID: 17
// (get) Token: 0x0600009A RID: 154 RVA: 0x0000F5F2 File Offset: 0x0000D9F2
public pb_Edge[] edges
{
get
{
return (this._edges != null) ? this._edges : this.CacheEdges();
}
}
// Token: 0x17000012 RID: 18
// (get) Token: 0x0600009B RID: 155 RVA: 0x0000F610 File Offset: 0x0000DA10
// (set) Token: 0x0600009C RID: 156 RVA: 0x0000F618 File Offset: 0x0000DA18
public int smoothingGroup
{
get
{
return this._smoothingGroup;
}
set
{
this._smoothingGroup = value;
}
}
// Token: 0x17000013 RID: 19
// (get) Token: 0x0600009D RID: 157 RVA: 0x0000F621 File Offset: 0x0000DA21
// (set) Token: 0x0600009E RID: 158 RVA: 0x0000F629 File Offset: 0x0000DA29
public Material material
{
get
{
return this._mat;
}
set
{
this._mat = value;
}
}
// Token: 0x17000014 RID: 20
// (get) Token: 0x0600009F RID: 159 RVA: 0x0000F632 File Offset: 0x0000DA32
// (set) Token: 0x060000A0 RID: 160 RVA: 0x0000F63A File Offset: 0x0000DA3A
public pb_UV uv
{
get
{
return this._uv;
}
set
{
this._uv = value;
}
}
// Token: 0x060000A1 RID: 161 RVA: 0x0000F643 File Offset: 0x0000DA43
[Obsolete("Use face.material property.")]
public void SetMaterial(Material material)
{
this._mat = material;
}
// Token: 0x060000A2 RID: 162 RVA: 0x0000F64C File Offset: 0x0000DA4C
[Obsolete("Use face.uv property.")]
public void SetUV(pb_UV uvs)
{
this._uv = uvs;
}
// Token: 0x060000A3 RID: 163 RVA: 0x0000F655 File Offset: 0x0000DA55
[Obsolete("Use face.smoothingGroup property.")]
public void SetSmoothingGroup(int smoothing)
{
this._smoothingGroup = smoothing;
}
// Token: 0x060000A4 RID: 164 RVA: 0x0000F65E File Offset: 0x0000DA5E
public bool IsValid()
{
return this.indices.Length > 2;
}
// Token: 0x060000A5 RID: 165 RVA: 0x0000F66C File Offset: 0x0000DA6C
public Vector3[] GetDistinctVertices(Vector3[] verts)
{
int[] distinctIndices = this.distinctIndices;
Vector3[] array = new Vector3[distinctIndices.Length];
for (int i = 0; i < distinctIndices.Length; i++)
{
array[i] = verts[distinctIndices[i]];
}
return array;
}
// Token: 0x060000A6 RID: 166 RVA: 0x0000F6B8 File Offset: 0x0000DAB8
public int[] GetTriangle(int index)
{
if (index * 3 + 3 > this.indices.Length)
{
return null;
}
return new int[]
{
this.indices[index * 3],
this.indices[index * 3 + 1],
this.indices[index * 3 + 2]
};
}
// Token: 0x060000A7 RID: 167 RVA: 0x0000F70C File Offset: 0x0000DB0C
public pb_Edge[] GetAllEdges()
{
pb_Edge[] array = new pb_Edge[this.indices.Length];
for (int i = 0; i < this.indices.Length; i += 3)
{
array[i] = new pb_Edge(this.indices[i], this.indices[i + 1]);
array[i + 1] = new pb_Edge(this.indices[i + 1], this.indices[i + 2]);
array[i + 2] = new pb_Edge(this.indices[i + 2], this.indices[i]);
}
return array;
}
// Token: 0x060000A8 RID: 168 RVA: 0x0000F795 File Offset: 0x0000DB95
public void SetIndices(int[] i)
{
this._indices = i;
this.RebuildCaches();
}
// Token: 0x060000A9 RID: 169 RVA: 0x0000F7A4 File Offset: 0x0000DBA4
public void ShiftIndices(int offset)
{
for (int i = 0; i < this._indices.Length; i++)
{
this._indices[i] += offset;
}
}
// Token: 0x060000AA RID: 170 RVA: 0x0000F7DC File Offset: 0x0000DBDC
public int SmallestIndexValue()
{
int num = this._indices[0];
for (int i = 0; i < this._indices.Length; i++)
{
if (this._indices[i] < num)
{
num = this._indices[i];
}
}
return num;
}
// Token: 0x060000AB RID: 171 RVA: 0x0000F824 File Offset: 0x0000DC24
public void ShiftIndicesToZero()
{
int num = this.SmallestIndexValue();
for (int i = 0; i < this.indices.Length; i++)
{
this._indices[i] -= num;
}
for (int j = 0; j < this._distinctIndices.Length; j++)
{
this._distinctIndices[j] -= num;
}
for (int k = 0; k < this._edges.Length; k++)
{
this._edges[k].x -= num;
this._edges[k].y -= num;
}
}
// Token: 0x060000AC RID: 172 RVA: 0x0000F8CF File Offset: 0x0000DCCF
public void ReverseIndices()
{
Array.Reverse(this._indices);
this.RebuildCaches();
}
// Token: 0x060000AD RID: 173 RVA: 0x0000F8E2 File Offset: 0x0000DCE2
public void RebuildCaches()
{
this.CacheDistinctIndices();
this.CacheEdges();
}
// Token: 0x060000AE RID: 174 RVA: 0x0000F8F4 File Offset: 0x0000DCF4
private pb_Edge[] CacheEdges()
{
if (this._indices == null)
{
return null;
}
HashSet<pb_Edge> hashSet = new HashSet<pb_Edge>();
List<pb_Edge> list = new List<pb_Edge>();
for (int i = 0; i < this.indices.Length; i += 3)
{
pb_Edge pb_Edge = new pb_Edge(this.indices[i], this.indices[i + 1]);
pb_Edge pb_Edge2 = new pb_Edge(this.indices[i + 1], this.indices[i + 2]);
pb_Edge pb_Edge3 = new pb_Edge(this.indices[i + 2], this.indices[i]);
if (!hashSet.Add(pb_Edge))
{
list.Add(pb_Edge);
}
if (!hashSet.Add(pb_Edge2))
{
list.Add(pb_Edge2);
}
if (!hashSet.Add(pb_Edge3))
{
list.Add(pb_Edge3);
}
}
hashSet.ExceptWith(list);
this._edges = hashSet.ToArray<pb_Edge>();
return this._edges;
}
// Token: 0x060000AF RID: 175 RVA: 0x0000F9D5 File Offset: 0x0000DDD5
private int[] CacheDistinctIndices()
{
if (this._indices == null)
{
return null;
}
this._distinctIndices = new HashSet<int>(this._indices).ToArray<int>();
return this.distinctIndices;
}
// Token: 0x060000B0 RID: 176 RVA: 0x0000FA00 File Offset: 0x0000DE00
public bool Contains(int[] triangle)
{
for (int i = 0; i < this.indices.Length; i += 3)
{
if (triangle.Contains(this.indices[i]) && triangle.Contains(this.indices[i + 1]) && triangle.Contains(this.indices[i + 2]))
{
return true;
}
}
return false;
}
// Token: 0x060000B1 RID: 177 RVA: 0x0000FA68 File Offset: 0x0000DE68
public static int[] AllTriangles(pb_Face[] q)
{
List<int> list = new List<int>(q.Length * 6);
foreach (pb_Face pb_Face in q)
{
list.AddRange(pb_Face.indices);
}
return list.ToArray();
}
// Token: 0x060000B2 RID: 178 RVA: 0x0000FAAC File Offset: 0x0000DEAC
public static int[] AllTriangles(List<pb_Face> q)
{
List<int> list = new List<int>(q.Count * 6);
foreach (pb_Face pb_Face in q)
{
list.AddRange(pb_Face.indices);
}
return list.ToArray();
}
// Token: 0x060000B3 RID: 179 RVA: 0x0000FB1C File Offset: 0x0000DF1C
public static int[] AllTrianglesDistinct(pb_Face[] q)
{
List<int> list = new List<int>();
foreach (pb_Face pb_Face in q)
{
list.AddRange(pb_Face.distinctIndices);
}
return list.ToArray();
}
// Token: 0x060000B4 RID: 180 RVA: 0x0000FB5C File Offset: 0x0000DF5C
public static List<int> AllTrianglesDistinct(List<pb_Face> f)
{
List<int> list = new List<int>();
foreach (pb_Face pb_Face in f)
{
list.AddRange(pb_Face.distinctIndices);
}
return list;
}
// Token: 0x060000B5 RID: 181 RVA: 0x0000FBC0 File Offset: 0x0000DFC0
public void ToQuadOrTriangles(out int[] quadOrTris)
{
if (this.ToQuad(out quadOrTris))
{
return;
}
int num = ((this.indices != null) ? Math.Max(0, this.indices.Length) : 0);
quadOrTris = new int[num];
Array.Copy(this.indices, quadOrTris, num);
}
// Token: 0x060000B6 RID: 182 RVA: 0x0000FC10 File Offset: 0x0000E010
public int[] ToQuad()
{
int[] array;
this.ToQuad(out array);
return array;
}
// Token: 0x060000B7 RID: 183 RVA: 0x0000FC28 File Offset: 0x0000E028
public bool ToQuad(out int[] quad)
{
if (this.indices == null || this.indices.Length != 6)
{
quad = null;
return false;
}
quad = new int[]
{
this.edges[0].x,
this.edges[0].y,
-1,
-1
};
if (this.edges[1].x == quad[1])
{
quad[2] = this.edges[1].y;
}
else if (this.edges[2].x == quad[1])
{
quad[2] = this.edges[2].y;
}
else if (this.edges[3].x == quad[1])
{
quad[2] = this.edges[3].y;
}
if (this.edges[1].x == quad[2])
{
quad[3] = this.edges[1].y;
}
else if (this.edges[2].x == quad[2])
{
quad[3] = this.edges[2].y;
}
else if (this.edges[3].x == quad[2])
{
quad[3] = this.edges[3].y;
}
return true;
}
// Token: 0x060000B8 RID: 184 RVA: 0x0000FD84 File Offset: 0x0000E184
public static int MeshTriangles(pb_Face[] faces, out int[][] submeshes, out Material[] materials)
{
Dictionary<Material, List<pb_Face>> dictionary = new Dictionary<Material, List<pb_Face>>();
int i;
for (i = 0; i < faces.Length; i++)
{
if (faces[i] == null)
{
Debug.LogWarning("Null face found! Skipping these triangles.");
}
else
{
Material material = faces[i].material ?? pb_Constant.UnityDefaultDiffuse;
if (dictionary.ContainsKey(material))
{
dictionary[material].Add(faces[i]);
}
else
{
dictionary.Add(material, new List<pb_Face>(1) { faces[i] });
}
}
}
materials = new Material[dictionary.Count];
submeshes = new int[materials.Length][];
i = 0;
foreach (KeyValuePair<Material, List<pb_Face>> keyValuePair in dictionary)
{
submeshes[i] = pb_Face.AllTriangles(keyValuePair.Value);
materials[i] = keyValuePair.Key;
i++;
}
return submeshes.Length;
}
// Token: 0x060000B9 RID: 185 RVA: 0x0000FE94 File Offset: 0x0000E294
public override string ToString()
{
if (this.indices.Length % 3 != 0)
{
return "Index count is not a multiple of 3.";
}
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < this.indices.Length; i += 3)
{
stringBuilder.Append("[");
stringBuilder.Append(this.indices[i]);
stringBuilder.Append(", ");
stringBuilder.Append(this.indices[i + 1]);
stringBuilder.Append(", ");
stringBuilder.Append(this.indices[i + 2]);
stringBuilder.Append("]");
if (i < this.indices.Length - 3)
{
stringBuilder.Append(", ");
}
}
return stringBuilder.ToString();
}
// Token: 0x060000BA RID: 186 RVA: 0x0000FF58 File Offset: 0x0000E358
public string ToStringDetailed()
{
string text = string.Concat(new object[]
{
"index count: ",
this._indices.Length,
"\nmat name : ",
this.material.name,
"\nisManual : ",
this.manualUV,
"\nsmoothing group: ",
this.smoothingGroup,
"\n"
});
for (int i = 0; i < this.indices.Length; i += 3)
{
string text2 = text;
text = string.Concat(new object[]
{
text2,
"Tri ",
i,
": ",
this._indices[i],
", ",
this._indices[i + 1],
", ",
this._indices[i + 2],
"\n"
});
}
text += "Distinct Indices:\n";
for (int j = 0; j < this.distinctIndices.Length; j++)
{
text = text + this.distinctIndices[j] + ", ";
}
return text;
}
// Token: 0x04000104 RID: 260
public const int MAX_SMOOTH_GROUPS = 24;
// Token: 0x04000105 RID: 261
[SerializeField]
private int[] _indices;
// Token: 0x04000106 RID: 262
[SerializeField]
private int[] _distinctIndices;
// Token: 0x04000107 RID: 263
[SerializeField]
private pb_Edge[] _edges;
// Token: 0x04000108 RID: 264
[SerializeField]
private int _smoothingGroup;
// Token: 0x04000109 RID: 265
[SerializeField]
private pb_UV _uv;
// Token: 0x0400010A RID: 266
[SerializeField]
private Material _mat;
// Token: 0x0400010B RID: 267
public bool manualUV;
// Token: 0x0400010C RID: 268
public int elementGroup;
// Token: 0x0400010D RID: 269
public int textureGroup = -1;
}
}