using UnityEngine;using System.Collections;using System.Collections.Generic;using CSG;public class Test : MonoBehaviour{ public enum Operation { Subtract, Union, Intersection }; List<Polygon> origPolygons; GameObject gameObjectA; GameObject gameObjectB; Transform[] childs = new Transform[2]; public Operation operation = Operation.Subtract; // Use this for initialization void Start () { gameObjectA = GameObject.Find("Target"); gameObjectB = GameObject.Find("Brush"); childs[0] = gameObjectA.transform; childs[1] = gameObjectB.transform; origPolygons = new List<Polygon>(); CSG.CSG.triIndex = 0; // always set this to zero before all operations CSG.CSG.transform = gameObjectA.transform; CSG.CSG A = CSG.CSG.fromMesh(childs[0].GetComponent<MeshFilter>().sharedMesh, childs[0], true); CSG.CSG B = CSG.CSG.fromMesh(childs[1].GetComponent<MeshFilter>().sharedMesh, childs[1], false); origPolygons.AddRange(A.polygons); origPolygons.AddRange(B.polygons); CSG.CSG result = null; if (operation == Operation.Subtract) { result = A.subtract(B); } if (operation == Operation.Union) { result = A.union(B); } if (operation == Operation.Intersection) { result = A.intersect(B); } if (result != null) { result.toMesh(gameObjectA, gameObjectB); } } // Update is called once per frame void Update () { }}

GameObject BooleanSubtract(GameObject target, GameObject remove) { // Clone target for boolean operation GameObject targetGhost = (GameObject) GameObject.Instantiate(target); // Subtract candidate from target CSG.CSG.triIndex = 0; // always set to 0 before all operations CSG.CSG.transform = target.transform; CSG.CSG A = CSG.CSG.fromMesh(target.GetComponent<MeshFilter>().sharedMesh, target.transform, true); CSG.CSG B = CSG.CSG.fromMesh(remove.GetComponent<MeshFilter>().sharedMesh, remove.transform, false); CSG.CSG result = A.subtract(B); result.toMesh(targetGhost, targetGhost); return targetGhost;}

StackOverflowException: The requested operation caused a stack overflow.CSG.Node.build (System.Collections.Generic.List`1 polys)CSG.Node.build (System.Collections.Generic.List`1 polys)...etc