Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
	    /// <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);
        }
Ejemplo n.º 3
0
 /// <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);
 }
Ejemplo n.º 4
0
 /// <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);
 }
Ejemplo n.º 5
0
 // 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);
     }
 }
Ejemplo n.º 6
0
        /// <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);
            }
        }
Ejemplo n.º 7
0
 // 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));
     }
 }
Ejemplo n.º 8
0
        /// <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);
            }
        }
Ejemplo n.º 9
0
        /// <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));
            }
        }
Ejemplo n.º 10
0
        /// <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));
            }
        }
Ejemplo n.º 11
0
        /// <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);
            }
        }
Ejemplo n.º 12
0
        /// <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);
            }
        }