103 lines
2.9 KiB
C#
103 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Parabox.CSG
|
|
{
|
|
// Token: 0x02000016 RID: 22
|
|
internal class CSG_Model
|
|
{
|
|
// Token: 0x060000A6 RID: 166 RVA: 0x0000D479 File Offset: 0x0000B879
|
|
public CSG_Model()
|
|
{
|
|
this.vertices = new List<CSG_Vertex>();
|
|
this.indices = new List<int>();
|
|
}
|
|
|
|
// Token: 0x060000A7 RID: 167 RVA: 0x0000D498 File Offset: 0x0000B898
|
|
public CSG_Model(GameObject go)
|
|
{
|
|
this.vertices = new List<CSG_Vertex>();
|
|
Mesh sharedMesh = go.GetComponent<MeshFilter>().sharedMesh;
|
|
Transform component = go.GetComponent<Transform>();
|
|
Vector3[] array = sharedMesh.vertices;
|
|
Vector3[] normals = sharedMesh.normals;
|
|
Vector2[] uv = sharedMesh.uv;
|
|
Color[] colors = sharedMesh.colors;
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
this.vertices.Add(new CSG_Vertex(component.TransformPoint(array[i]), component.TransformDirection(normals[i]), uv[i], colors[i]));
|
|
}
|
|
this.indices = new List<int>(sharedMesh.triangles);
|
|
}
|
|
|
|
// Token: 0x060000A8 RID: 168 RVA: 0x0000D564 File Offset: 0x0000B964
|
|
public CSG_Model(List<CSG_Polygon> list)
|
|
{
|
|
this.vertices = new List<CSG_Vertex>();
|
|
this.indices = new List<int>();
|
|
int num = 0;
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
CSG_Polygon csg_Polygon = list[i];
|
|
for (int j = 2; j < csg_Polygon.vertices.Count; j++)
|
|
{
|
|
this.vertices.Add(csg_Polygon.vertices[0]);
|
|
this.indices.Add(num++);
|
|
this.vertices.Add(csg_Polygon.vertices[j - 1]);
|
|
this.indices.Add(num++);
|
|
this.vertices.Add(csg_Polygon.vertices[j]);
|
|
this.indices.Add(num++);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x060000A9 RID: 169 RVA: 0x0000D644 File Offset: 0x0000BA44
|
|
public List<CSG_Polygon> ToPolygons()
|
|
{
|
|
List<CSG_Polygon> list = new List<CSG_Polygon>();
|
|
for (int i = 0; i < this.indices.Count; i += 3)
|
|
{
|
|
List<CSG_Vertex> list2 = new List<CSG_Vertex>
|
|
{
|
|
this.vertices[this.indices[i]],
|
|
this.vertices[this.indices[i + 1]],
|
|
this.vertices[this.indices[i + 2]]
|
|
};
|
|
list.Add(new CSG_Polygon(list2));
|
|
}
|
|
return list;
|
|
}
|
|
|
|
// Token: 0x060000AA RID: 170 RVA: 0x0000D6E4 File Offset: 0x0000BAE4
|
|
public Mesh ToMesh()
|
|
{
|
|
Mesh mesh = new Mesh();
|
|
int count = this.vertices.Count;
|
|
Vector3[] array = new Vector3[count];
|
|
Vector3[] array2 = new Vector3[count];
|
|
Vector2[] array3 = new Vector2[count];
|
|
Color[] array4 = new Color[count];
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
array[i] = this.vertices[i].position;
|
|
array2[i] = this.vertices[i].normal;
|
|
array3[i] = this.vertices[i].uv;
|
|
array4[i] = this.vertices[i].color;
|
|
}
|
|
mesh.vertices = array;
|
|
mesh.normals = array2;
|
|
mesh.colors = array4;
|
|
mesh.uv = array3;
|
|
mesh.triangles = this.indices.ToArray();
|
|
return mesh;
|
|
}
|
|
|
|
// Token: 0x04000030 RID: 48
|
|
public List<CSG_Vertex> vertices;
|
|
|
|
// Token: 0x04000031 RID: 49
|
|
public List<int> indices;
|
|
}
|
|
}
|