Files
Dec2017-Script-Dump/ProBuilderMeshOps-Unity5/Parabox/CSG/CSG_Plane.cs
T
2026-06-04 11:42:34 +02:00

128 lines
3.5 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
namespace Parabox.CSG
{
// Token: 0x02000018 RID: 24
internal class CSG_Plane
{
// Token: 0x060000B7 RID: 183 RVA: 0x0000DC8B File Offset: 0x0000C08B
public CSG_Plane()
{
this.normal = Vector3.zero;
this.w = 0f;
}
// Token: 0x060000B8 RID: 184 RVA: 0x0000DCA9 File Offset: 0x0000C0A9
public CSG_Plane(Vector3 a, Vector3 b, Vector3 c)
{
this.normal = Vector3.Cross(b - a, c - a);
this.w = Vector3.Dot(this.normal, a);
}
// Token: 0x060000B9 RID: 185 RVA: 0x0000DCDC File Offset: 0x0000C0DC
public bool Valid()
{
return this.normal.magnitude > 0f;
}
// Token: 0x060000BA RID: 186 RVA: 0x0000DCF0 File Offset: 0x0000C0F0
public void Flip()
{
this.normal *= -1f;
this.w *= -1f;
}
// Token: 0x060000BB RID: 187 RVA: 0x0000DD1C File Offset: 0x0000C11C
public void SplitPolygon(CSG_Polygon polygon, List<CSG_Polygon> coplanarFront, List<CSG_Polygon> coplanarBack, List<CSG_Polygon> front, List<CSG_Polygon> back)
{
CSG_Plane.EPolygonType epolygonType = CSG_Plane.EPolygonType.Coplanar;
List<CSG_Plane.EPolygonType> list = new List<CSG_Plane.EPolygonType>();
for (int i = 0; i < polygon.vertices.Count; i++)
{
float num = Vector3.Dot(this.normal, polygon.vertices[i].position) - this.w;
CSG_Plane.EPolygonType epolygonType2 = ((num >= -1E-05f) ? ((num <= 1E-05f) ? CSG_Plane.EPolygonType.Coplanar : CSG_Plane.EPolygonType.Front) : CSG_Plane.EPolygonType.Back);
epolygonType |= epolygonType2;
list.Add(epolygonType2);
}
switch (epolygonType)
{
case CSG_Plane.EPolygonType.Coplanar:
if (Vector3.Dot(this.normal, polygon.plane.normal) > 0f)
{
coplanarFront.Add(polygon);
}
else
{
coplanarBack.Add(polygon);
}
break;
case CSG_Plane.EPolygonType.Front:
front.Add(polygon);
break;
case CSG_Plane.EPolygonType.Back:
back.Add(polygon);
break;
case CSG_Plane.EPolygonType.Spanning:
{
List<CSG_Vertex> list2 = new List<CSG_Vertex>();
List<CSG_Vertex> list3 = new List<CSG_Vertex>();
for (int j = 0; j < polygon.vertices.Count; j++)
{
int num2 = (j + 1) % polygon.vertices.Count;
CSG_Plane.EPolygonType epolygonType3 = list[j];
CSG_Plane.EPolygonType epolygonType4 = list[num2];
CSG_Vertex csg_Vertex = polygon.vertices[j];
CSG_Vertex csg_Vertex2 = polygon.vertices[num2];
if (epolygonType3 != CSG_Plane.EPolygonType.Back)
{
list2.Add(csg_Vertex);
}
if (epolygonType3 != CSG_Plane.EPolygonType.Front)
{
list3.Add(csg_Vertex);
}
if ((epolygonType3 | epolygonType4) == CSG_Plane.EPolygonType.Spanning)
{
float num3 = (this.w - Vector3.Dot(this.normal, csg_Vertex.position)) / Vector3.Dot(this.normal, csg_Vertex2.position - csg_Vertex.position);
CSG_Vertex csg_Vertex3 = CSG_Vertex.Interpolate(csg_Vertex, csg_Vertex2, num3);
list2.Add(csg_Vertex3);
list3.Add(csg_Vertex3);
}
}
if (list2.Count >= 3)
{
front.Add(new CSG_Polygon(list2));
}
if (list3.Count >= 3)
{
back.Add(new CSG_Polygon(list3));
}
break;
}
}
}
// Token: 0x04000036 RID: 54
public Vector3 normal;
// Token: 0x04000037 RID: 55
public float w;
// Token: 0x02000019 RID: 25
[Flags]
private enum EPolygonType
{
// Token: 0x04000039 RID: 57
Coplanar = 0,
// Token: 0x0400003A RID: 58
Front = 1,
// Token: 0x0400003B RID: 59
Back = 2,
// Token: 0x0400003C RID: 60
Spanning = 3
}
}
}