Exemplo n.º 1
0
        static void BuildTree()
        {
            for (int i = 0; i < Selection.gameObjects.Length; ++i)
            {
                GameObject go  = Selection.gameObjects[i];
                CSGObject  obj = go.GetComponent <CSGObject>();

                if (obj)
                {
                    obj.CreateFromMesh();

                    BspGen gen = new BspGen(BooleanSettings.BspOptimization);

                    obj.rootNode = gen.GenerateBspTree(obj.faces);
                }
            }
        }
Exemplo n.º 2
0
        //
        public void Perform(ECsgOperation inOper, CSGObject inMaster, CSGObject inSlave)
        {
            // we are processing our slave faces
            processState = EProcessState.Process_Slave;

            // process faces against master tree
            PerformFaces(inMaster.rootNode, inSlave.faces);

            // process face from master tree
            processState = EProcessState.Process_Master;

            // perform master faces on slave bsp tree
            PerformTree(inMaster.rootNode, inSlave.rootNode);

            // check if how do we need to process generated faces
            if (inOper == ECsgOperation.CsgOper_Additive || inOper == ECsgOperation.CsgOper_Subtractive)
            {
                // add deferred faces to master tree...
                for (int i = 0; i < deferredFaces.Count; i++)
                {
                    Face    defFace   = ((DeferredFace)deferredFaces[i]).face;
                    BspNode startNode = ((DeferredFace)deferredFaces[i]).node;

                    // testing
                    startNode = inMaster.rootNode;
                    // add node to master tree
                    BspGen.AddNodeRecursive(startNode, defFace, BspNode.BspFlags_IsNew);
                }
            }
            else
            {
                // clear old faces list
                inMaster.faces.Clear();

                // copy created faces
                for (int i = 0; i < deferredFaces.Count; i++)
                {
                    inMaster.faces.Add(deferredFaces[i].face);
                }
            }

            // clear deferred faces
            deferredFaces.Clear();
        }
Exemplo n.º 3
0
 // Callback for Visitor
 public void AddPlanarFace(Face inFace)
 {
     BspGen.AddNode(currentNode, BspNode.EBspLocation.BspLocation_Planar, inFace, BspNode.BspFlags_IsNew);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Performs CSG Operation on this Object (Master) with given Slaves.
        /// </summary>
        /// <param name='inOper'>
        /// In oper.
        /// </param>
        /// <param name='inSlaves'>
        /// In slaves.
        /// </param>
        public void PerformCSG(CsgOperation.ECsgOperation inOper, CSGObject[] inSlaves)
        {
            //
            CreateFromMesh();

            // create bsp generator
            BspGen gen = new BspGen(BooleanSettings.BspOptimization);

            rootNode = gen.GenerateBspTree(faces);

            List <Face> savedFaces = new List <Face>();

            //
            foreach (var slave in inSlaves)
            {
                // if we have a csg object and we are not our self
                // and intersecting
                if (slave && slave.gameObject != gameObject && intersect(slave))
                {
                    Debug.Log(slave.gameObject.name);

                    //
                    slave.CreateFromMesh();

                    // ....
                    BspGen genSlave = new BspGen(BooleanSettings.BspOptimization);
                    slave.rootNode = genSlave.GenerateBspTree(slave.faces);

                    CsgVisitor visitor = null;

                    switch (inOper)
                    {
                    case CsgOperation.ECsgOperation.CsgOper_Additive:
                        visitor = new UnionVisitor();
                        break;

                    case CsgOperation.ECsgOperation.CsgOper_Subtractive:
                        visitor = new SubtractiveVisitor();
                        break;

                    case CsgOperation.ECsgOperation.CsgOper_Intersect:
                        visitor = new IntersectVisitor();
                        break;

                    case CsgOperation.ECsgOperation.CsgOper_DeIntersect:
                        visitor = new DeIntersectVisitor();
                        break;

                    default:
                        visitor = null;
                        break;
                    }


                    CsgOperation oper = new CsgOperation(visitor);

                    oper.Perform(inOper, this, slave);

                    // save faces
                    savedFaces.AddRange(faces);
                }
            }


            // If we want to merge Coplanars after every Operation
            if (BooleanSettings.MergeCoplanars)
            {
                MergeFaces();
            }

            // for additive or subtracte operation, built faces list from bsp tree
            // for others, use faces directly
            if (inOper == CsgOperation.ECsgOperation.CsgOper_Additive ||
                inOper == CsgOperation.ECsgOperation.CsgOper_Subtractive)
            {
                // create new face list
                List <Face> newFaces = new List <Face>();
                // create faces from bsp nodes
                BspHelper.FacesFromNodes(rootNode, newFaces);
                // copy to face list
                faces = newFaces;
            }
            else
            {
                // copy saved faces
                faces = savedFaces;
            }

            // copy to unity structure
            TransferFacesToMesh();
        }