/// <summary> /// construct a new bsp tree from unity mesh /// </summary> /// <param name="mesh">unity mesh</param> /// <param name="meshTransform">transformation</param> /// <param name="id">id of the mesh</param> public void Construct(Mesh mesh, Transform meshTransform, int id) { // cache mesh data var trianglesNum = mesh.triangles.Length; var meshTriangles = mesh.triangles; var meshVertices = mesh.vertices; var meshNormals = mesh.normals; var meshUV = mesh.uv; Polygons = new List <CSGPolygon>(trianglesNum / 3); for (var i = 0; i < trianglesNum; i += 3) { var id0 = meshTriangles[i]; var id1 = meshTriangles[i + 1]; var id2 = meshTriangles[i + 2]; Polygons.Add(new CSGPolygon(id, new CSGVertex(meshTransform.TransformPoint(meshVertices[id0]), meshTransform.TransformDirection(meshNormals[id0]), meshUV[id0]), new CSGVertex(meshTransform.TransformPoint(meshVertices[id1]), meshTransform.TransformDirection(meshNormals[id1]), meshUV[id1]), new CSGVertex(meshTransform.TransformPoint(meshVertices[id2]), meshTransform.TransformDirection(meshNormals[id2]), meshUV[id2]))); } root = new CSGNode(); root.Build(Polygons); }
/// <summary> /// construct a new bsp tree from unity mesh /// </summary> /// <param name="mesh">unity mesh</param> /// <param name="meshTransform">transformation</param> /// <param name="id">id of the mesh</param> public void Construct(Mesh mesh, Transform meshTransform, int id) { // cache mesh data var trianglesNum = mesh.triangles.Length; var meshTriangles = mesh.triangles; var meshVertices = mesh.vertices; var meshNormals = mesh.normals; var meshUV = mesh.uv; Polygons = new List<CSGPolygon>(trianglesNum/3); for (int i = 0; i < trianglesNum; i+=3) { var id0 = meshTriangles[i]; var id1 = meshTriangles[i + 1]; var id2 = meshTriangles[i + 2]; Polygons.Add(new CSGPolygon(id, new CSGVertex(meshTransform.TransformPoint(meshVertices[id0]), meshTransform.TransformDirection(meshNormals[id0]), meshUV[id0]), new CSGVertex(meshTransform.TransformPoint(meshVertices[id1]), meshTransform.TransformDirection(meshNormals[id1]), meshUV[id1]), new CSGVertex(meshTransform.TransformPoint(meshVertices[id2]), meshTransform.TransformDirection(meshNormals[id2]), meshUV[id2]))); } root = new CSGNode(); root.Build(Polygons); }
/// <summary> /// copy constructor /// </summary> /// <param name="instance">copy instance</param> public CSG(CSG instance) { Polygons = new List<CSGPolygon>(instance.Polygons.Count); foreach (var polygon in instance.Polygons) { Polygons.Add(new CSGPolygon(polygon)); } root = new CSGNode(); root.Build(Polygons); }
/// <summary> /// copy constructor /// </summary> /// <param name="instance">copy instance</param> public CSG(CSG instance) { Polygons = new List <CSGPolygon>(instance.Polygons.Count); foreach (var polygon in instance.Polygons) { Polygons.Add(new CSGPolygon(polygon)); } root = new CSGNode(); root.Build(Polygons); }
// Token: 0x0600417B RID: 16763 RVA: 0x0014ABC0 File Offset: 0x00148FC0 public void ClipTo(CSGNode node) { this.Polygons = node.ClipPolygons(this.Polygons); if (this.FrontChild != null) { this.FrontChild.ClipTo(node); } if (this.BackChild != null) { this.BackChild.ClipTo(node); } }
/// <summary> /// remove all polygons from this tree that are inside the other tree /// </summary> public void ClipTo(CSGNode node) { Polygons = node.ClipPolygons(Polygons); if (FrontChild != null) { FrontChild.ClipTo(node); } if (BackChild != null) { BackChild.ClipTo(node); } }
// Token: 0x06004178 RID: 16760 RVA: 0x0014A978 File Offset: 0x00148D78 public CSGNode(CSGNode instance) { if (this.Plane != null) { this.Plane = new CSGPlane(instance.Plane); } if (instance.FrontChild != null) { this.FrontChild = new CSGNode(instance.FrontChild); } if (instance.BackChild != null) { this.BackChild = new CSGNode(instance.BackChild); } this.Polygons = new List <CSGPolygon>(instance.Polygons.Count); foreach (CSGPolygon instance2 in instance.Polygons) { this.Polygons.Add(new CSGPolygon(instance2)); } }
/// <summary> /// build new bsp tree from polygons /// </summary> /// <param name="polygons">input polygons</param> public void Build(List <CSGPolygon> polygons) { if (polygons.Count == 0) { return; } if (Plane == null) { Plane = new CSGPlane(polygons[0].Plane); } var frontList = new List <CSGPolygon>(); var backList = new List <CSGPolygon>(); foreach (var polygon in polygons) { Plane.Split(polygon, Polygons, Polygons, frontList, backList); } if (frontList.Count > 0) { if (FrontChild == null) { FrontChild = new CSGNode(); } FrontChild.Build(frontList); } if (backList.Count > 0) { if (BackChild == null) { BackChild = new CSGNode(); } BackChild.Build(backList); } }
/// <summary> /// copy constructor /// </summary> public CSGNode(CSGNode instance) { if (Plane != null) { Plane = new CSGPlane(instance.Plane); } if (instance.FrontChild != null) { FrontChild = new CSGNode(instance.FrontChild); } if (instance.BackChild != null) { BackChild = new CSGNode(instance.BackChild); } Polygons = new List<CSGPolygon>(instance.Polygons.Count); foreach (var polygon in instance.Polygons) { Polygons.Add(new CSGPolygon(polygon)); } }
/// <summary> /// copy constructor /// </summary> public CSGNode(CSGNode instance) { if (Plane != null) { Plane = new CSGPlane(instance.Plane); } if (instance.FrontChild != null) { FrontChild = new CSGNode(instance.FrontChild); } if (instance.BackChild != null) { BackChild = new CSGNode(instance.BackChild); } Polygons = new List <CSGPolygon>(instance.Polygons.Count); foreach (var polygon in instance.Polygons) { Polygons.Add(new CSGPolygon(polygon)); } }
/// <summary> /// build new bsp tree from polygons /// </summary> /// <param name="polygons">input polygons</param> public void Build(List<CSGPolygon> polygons) { if (polygons.Count == 0) { return; } if (Plane == null) { Plane = new CSGPlane(polygons[0].Plane); } var frontList = new List<CSGPolygon>(); var backList = new List<CSGPolygon>(); foreach (var polygon in polygons) { Plane.Split(polygon, Polygons, Polygons, frontList, backList); } if (frontList.Count > 0) { if (FrontChild == null) { FrontChild = new CSGNode(); } FrontChild.Build(frontList); } if (backList.Count > 0) { if (BackChild == null) { BackChild = new CSGNode(); } BackChild.Build(backList); } }