Ejemplo n.º 1
0
        /// <summary>
        /// Return a new CSG solid representing space both this solid and in the
        /// solid `csg`. Neither this solid nor the solid `csg` are modified.
        /// </summary>
        /// <remarks>
        /// A.intersect(B)
        ///
        ///    +-------+
        ///    |       |
        ///    |   A   |
        ///    |    +--+----+   =   +--+
        ///    +----+--+    |       +--+
        ///         |   B   |
        ///         |       |
        ///         +-------+
        /// </remarks>
        /// <param name="csg"></param>
        /// <returns>CSG of the intersection</returns>
        public CSG intersect(CSG csg)
        {
            Node a = new Node(this.polygons);
            Node b = new Node(csg.polygons);

            a.invert();
            b.invert();
            a.clipTo(b);
            b.clipTo(a);
            a.build(b.allPolygons());
            return(CSG.fromPolygons(a.allPolygons()).inverse());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Return a new CSG solid representing space in this solid but not in the
        /// solid `csg`. Neither this solid nor the solid `csg` are modified.
        /// </summary>
        /// <remarks>
        /// A.subtract(B)
        ///    +-------+            +-------+
        ///    |       |            |       |
        ///    |   A   |            |       |
        ///    |    +--+----+   =   |    +--+
        ///    +----+--+    |       +----+
        ///         |   B   |
        ///         |       |
        ///         +-------+
        /// </remarks>
        /// <param name="csg"></param>
        /// <returns></returns>
        public CSG subtract(CSG csg)
        {
            Node a = new Node(this.polygons);
            Node b = new Node(csg.polygons);

            //Debug.Log(this.clone().polygons.Count + " -- " + csg.clone().polygons.Count);
            //Debug.Log("CSG.subtract: Node a = " + a.polygons.Count + " polys, Node b = " + b.polygons.Count + " polys.");
            a.invert();
            a.clipTo(b);
            b.clipTo(a);
            b.invert();
            b.clipTo(a);
            b.invert();
            a.build(b.allPolygons());
            a.invert();
            return(CSG.fromPolygons(a.allPolygons()));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Return a new CSG solid representing space both this solid and in the
        /// solid `csg`. Neither this solid nor the solid `csg` are modified.
        /// </summary>
        /// <remarks>
        /// A.intersect(B)
        ///
        ///    +-------+
        ///    |       |
        ///    |   A   |
        ///    |    +--+----+   =   +--+
        ///    +----+--+    |       +--+
        ///         |   B   |
        ///         |       |
        ///         +-------+
        /// </remarks>
        /// <param name="csg"></param>
        /// <returns>CSG of the intersection</returns>
        public CSG intersect(CSG csg)
        {
            Node a = new Node(this.polygons);
            Node b = new Node(csg.polygons);

            a.invert();
            //Debug.Log("Intersect 1 polygons: " + a.polygons.Count);
            b.invert();
            //Debug.Log("Intersect 2 polygons: " + b.polygons.Count);
            a.clipTo(b);
            //Debug.Log("Intersect 3 polygons: " + a.polygons.Count);
            b.clipTo(a);
            //Debug.Log("Intersect 5 polygons: " + b.polygons.Count);
            a.build(b.allPolygons());
            //Debug.Log("Intersect 6 polygons: " + a.polygons.Count);
            //Debug.Log("Intersect 7 all polygons: " + a.allPolygons().Count);
            //Debug.Log("Intersect 8 polygons finalll cgs: " + CSG.fromPolygons(a.allPolygons()).inverse().polygons.Count);
            return(CSG.fromPolygons(a.allPolygons()).inverse());
        }
Ejemplo n.º 4
0
        public CSG subtract(GameObject targetGo, GameObject brushGo)
        {
            Model.submeshIndices = new List <List <int> >();

            Model csg_model_a = new Model(targetGo.gameObject, false, false);
            Model csg_model_b = new Model(brushGo.gameObject, true, false);

            Node a = new Node(csg_model_a.ToPolygons());
            Node b = new Node(csg_model_b.ToPolygons());

            //Debug.Log(this.clone().polygons.Count + " -- " + csg.clone().polygons.Count);
            //Debug.Log("CSG.subtract: Node a = " + a.polygons.Count + " polys, Node b = " + b.polygons.Count + " polys.");
            a.invert();
            a.clipTo(b);
            b.clipTo(a);
            b.invert();
            b.clipTo(a);
            b.invert();
            a.build(b.allPolygons());
            a.invert();
            return(CSG.fromPolygons(a.allPolygons()));
        }
Ejemplo n.º 5
0
Archivo: CSG.cs Proyecto: icegbq/csg.cs
 /// <summary>
 /// Return a new CSG solid representing space both this solid and in the
 /// solid `csg`. Neither this solid nor the solid `csg` are modified.
 /// </summary>
 /// <remarks>
 /// A.intersect(B)
 /// 
 ///    +-------+
 ///    |       |
 ///    |   A   |
 ///    |    +--+----+   =   +--+
 ///    +----+--+    |       +--+
 ///         |   B   |
 ///         |       |
 ///         +-------+
 /// </remarks>
 /// <param name="csg"></param>
 /// <returns>CSG of the intersection</returns>
 public CSG intersect(CSG csg)
 {
     Node a = new Node(this.polygons);
     Node b = new Node(csg.polygons);
     a.invert();
     b.invert();
     a.clipTo(b);
     b.clipTo(a);
     a.build(b.allPolygons());
     return CSG.fromPolygons(a.allPolygons()).inverse();
 }
Ejemplo n.º 6
0
Archivo: CSG.cs Proyecto: icegbq/csg.cs
 /// <summary>
 /// Return a new CSG solid representing space in this solid but not in the
 /// solid `csg`. Neither this solid nor the solid `csg` are modified.
 /// </summary>
 /// <remarks>
 /// A.subtract(B)
 ///    +-------+            +-------+
 ///    |       |            |       |
 ///    |   A   |            |       |
 ///    |    +--+----+   =   |    +--+
 ///    +----+--+    |       +----+
 ///         |   B   |
 ///         |       |
 ///         +-------+
 /// </remarks>
 /// <param name="csg"></param>
 /// <returns></returns>
 public CSG subtract(CSG csg)
 {
     Node a = new Node(this.polygons);
     Node b = new Node(csg.polygons);
     //Debug.Log(this.clone().polygons.Count + " -- " + csg.clone().polygons.Count);
     //Debug.Log("CSG.subtract: Node a = " + a.polygons.Count + " polys, Node b = " + b.polygons.Count + " polys.");
     a.invert();
     a.clipTo(b);
     b.clipTo(a);
     b.invert();
     b.clipTo(a);
     b.invert();
     a.build(b.allPolygons());
     a.invert();
     return CSG.fromPolygons(a.allPolygons());
 }