Example #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);
                }
            }
        }
Example #2
0
        public static CSGObject AddComponent(GameObject obj)
        {
            Mesh mesh = obj.GetComponent <MeshFilter>() != null?obj.GetComponent <MeshFilter>().sharedMesh : null;

            if (mesh)
            {
                // TODO: add bsp tree generation on add...
                CSGObject  csg    = obj.AddComponent <CSGObject>();
                MeshFilter filter = obj.GetComponent <MeshFilter>();

                // clone mesh as every csg object needs his own mesh
                filter.sharedMesh = ObjectCloner.CloneMesh(filter.sharedMesh);
                //
                csg.CreateFromMesh();

                return(csg);
            }
            else
            {
                Debug.Log("No Mesh on GameObject");
                return(null);
            }
        }