/// <summary> /// Cuts elements inside this tree and removes ones that end up inside another one. /// </summary> /// <param name="bsp">A root of another BSP tree.</param> public void CutTreeOut(BspNode <T> bsp) { this.Elements = bsp.FilterList(this.Elements); if (this.Front != null) { this.Front.CutTreeOut(bsp); } if (this.Back != null) { this.Back.CutTreeOut(bsp); } }
/// <summary> /// Adds given BSP tree to this one. /// </summary> /// <param name="another">BSP tree to add.</param> public void Unite(BspNode <T> another) { // Cut overlapping geometry. this.CutTreeOut(another); another.CutTreeOut(this); // Remove overlapping coplanar faces. another.Invert(); another.CutTreeOut(this); another.Invert(); // Combine geometry. this.AddElements(another.AllElements); }
private static void AssignBranch(BspNode <T> branch, IList <T> elements) { if (branch == null) { // ReSharper disable RedundantAssignment // This is not a redundant assignment, since we are dealing with a reference type. branch = new BspNode <T>(elements); // ReSharper restore RedundantAssignment } else { branch.AddElements(elements); } }
/// <summary> /// Inverts this BSP tree. /// </summary> public void Invert() { if (!this.IsNotInitialized()) { this.Plane.Flip(); } if (!this.Elements.IsNullOrEmpty()) { this.Elements.ForEach(x => x.Invert()); } if (this.Front != null) { this.Front.Invert(); } if (this.Back != null) { this.Back.Invert(); } BspNode <T> temp = this.Front; this.Front = this.Back; this.Back = temp; }