public static (Mesh subtract, Mesh intersect) IntersectAndSubtract(Mesh recieveSubtraction, Mesh recieveIntersection, Action <string, double> reporter, CancellationToken cancellationToken) { if (recieveSubtraction.Faces.Count == 0) { return(recieveSubtraction, recieveIntersection); } if (recieveIntersection.Faces.Count == 0) { return(recieveSubtraction, recieveIntersection); } reporter?.Invoke("Mesh to Solid A", 0); var A = SolidFromMesh(recieveSubtraction); reporter?.Invoke("Mesh to Solid B", .2); var B = SolidFromMesh(recieveIntersection); reporter?.Invoke("BooleanModeller", .4); var modeller = new BooleanModeller(A, B, (status, progress0To1) => { reporter?.Invoke(status, .4 + progress0To1 * .2); }, cancellationToken); reporter?.Invoke("Intersection", .6); var intersection = modeller.GetIntersection(); reporter?.Invoke("Difference", .6); var difference = modeller.GetDifference(); reporter?.Invoke("Solid to Mesh", .8); var results = (MeshFromSolid(difference), MeshFromSolid(intersection)); reporter?.Invoke("Solid to Mesh", 1); return(results); }
public static Mesh Intersect(Mesh a, Mesh b, Action <string, double> reporter, CancellationToken cancellationToken) { if (a.Faces.Count == 0) { return(b); } if (b.Faces.Count == 0) { return(a); } reporter?.Invoke("Mesh to Solid A", 0); var A = SolidFromMesh(a); reporter?.Invoke("Mesh to Solid B", .2); var B = SolidFromMesh(b); reporter?.Invoke("BooleanModeller", .4); var modeller = new BooleanModeller(A, B); reporter?.Invoke("Intersection", .6); var result = modeller.GetIntersection(); reporter?.Invoke("Solid to Mesh", 1); return(MeshFromSolid(result)); }
public static Mesh Subtract(this Mesh a, Mesh b, Action <string, double> reporter, CancellationToken cancellationToken) { if (a.Faces.Count == 0) { return(b); } if (b.Faces.Count == 0) { return(a); } reporter?.Invoke("Mesh to Solid A", 0); var A = SolidFromMesh(a); reporter?.Invoke("Mesh to Solid B", .2); var B = SolidFromMesh(b); reporter?.Invoke("BooleanModeller", .4); var modeller = new BooleanModeller(A, B, (status, progress0To1) => { reporter?.Invoke(status, .4 + progress0To1 * .2); }, cancellationToken); reporter?.Invoke("Difference", .6); var result = modeller.GetDifference(); reporter?.Invoke("Solid to Mesh", .8); var solidMesh = MeshFromSolid(result); reporter?.Invoke("Solid to Mesh", 1); return(solidMesh); }
public static Mesh GetIntersection(MeshFilter meshF1, MeshFilter meshF2) { using (var booleanModeller = new BooleanModeller(meshF1.ToSolidInWCS(), meshF2.ToSolidInWCS())) { var end = booleanModeller.GetIntersection(); return(OperateAndMerge(end, meshF1.transform)); } }
public static GeometryMesh Intersection(GeometryMesh A, GeometryMesh B) { Solid SolidA = new Solid(A.Vertices.Select((V) => V.Position).ToArray(), A.Indices, A.Vertices.Select((V) => V.Color).ToArray()); Solid SolidB = new Solid(B.Vertices.Select((V) => V.Position).ToArray(), B.Indices, B.Vertices.Select((V) => V.Color).ToArray()); BooleanModeller Modeller = new BooleanModeller(SolidA, SolidB); return(SolidToMesh(Modeller.getIntersection())); }
public override void UpdateWorld() { if (baseStructure != null) { Solid current = baseStructure; foreach (ICutoff cutoff in transform.parent.GetComponentsInChildren <ICutoff>()) { if (cutoff.GetCutoff() != null) { current = new BooleanModeller(current, cutoff.GetCutoff()).getDifference(); } } Mesh msh = Utils.Solid2Mesh(current); AddUVToMesh(msh); GetComponent <MeshCollider>().sharedMesh = msh; GetComponent <MeshFilter>().mesh = msh; } }
// Use this for initialization void Start() { // Prepare for an operation on solids - grab them. solidA = objectA.GetComponent <CSGObject> ().GetSolid(); if (solidA == null) { Debug.LogError("ObjectA is not a CSGObject."); return; } solidB = objectB.GetComponent <CSGObject> ().GetSolid(); if (solidB == null) { Debug.LogError("ObjectB is not a CSGObject."); return; } modeller = new Net3dBool.BooleanModeller(solidA, solidB); // Do check... lastop = (OperatorType)(1 - (int)operation); lasten = !enableOperator; }
public override bool Calculate() { if (!allInputsReady()) { return(false); } if (Inputs [0].connection != null) { Input1Val = Inputs [0].connection.GetValue <GameObject> (); CSGObject csg = Input1Val.GetComponent <CSGObject>(); if (csg == null) { csg = Input1Val.AddComponent <CSGObject>(); } csg.GenerateSolid(); } if (Inputs [1].connection != null) { Input2Val = Inputs [1].connection.GetValue <GameObject> (); CSGObject csg = Input2Val.GetComponent <CSGObject> (); if (csg == null) { csg = Input2Val.AddComponent <CSGObject> (); } csg.GenerateSolid(); } if ((Input1Val != null) && (Input2Val != null)) { solid1 = Input1Val.GetComponent <CSGObject> ().GetSolid(); solid2 = Input2Val.GetComponent <CSGObject> ().GetSolid(); modeller = new BooleanModeller(solid1, solid2); output = null; switch (type) { case CalcType.Union: output = modeller.getUnion(); break; case CalcType.Intersection: output = modeller.getIntersection(); break; case CalcType.Difference: output = modeller.getDifference(); break; } if (output != null) { string goname = string.Format("CSGOut_{0}", (int)this.GetHashCode()); GameObject gout = GameObject.Find(goname); if (gout == null) { gout = new GameObject(goname); } CSGObject csg = gout.GetComponent <CSGObject>(); if (csg == null) { csg = gout.AddComponent <CSGObject>(); } csg.AssignSolid(output); CSGGameObject.GenerateMesh(gout, objectMaterial, output); Outputs [0].SetValue <GameObject> (gout); } } else { return(false); } return(true); }