/// <summary> /// Subtracts another mesh from this one. /// </summary> /// <param name="anotherMesh">Another mesh.</param> /// <seealso cref="ConstructiveSolidGeometry.Subtract"/> public virtual void Subtract(IMesh anotherMesh) { BspNode <SplittableTriangle> a = this.ToBspTree(); BspNode <SplittableTriangle> b = anotherMesh.ToBspTree(); a.Invert(); a.Unite(b); a.Invert(); this.SetBsp(a); }
/// <summary> /// Intersects this mesh with another. /// </summary> /// <param name="anotherMesh">Another mesh.</param> /// <seealso cref="ConstructiveSolidGeometry.Intersection"/> public virtual void Intersect(IMesh anotherMesh) { BspNode <SplittableTriangle> a = this.ToBspTree(); BspNode <SplittableTriangle> b = anotherMesh.ToBspTree(); a.Invert(); // Cut geometry that is not common for the meshes. b.CutTreeOut(a); // b.Invert(); // a.CutTreeOut(b); // // Clean up remains. b.CutTreeOut(a); // Combine geometry. a.AddElements(b.AllElements); // Invert everything. a.Invert(); this.SetBsp(a); }