Browse Source

Octree: Add `clear()`. (#27160)

* feature: add octree clear method

* Update Octree.js

---------

Co-authored-by: cahierchen <[email protected]>
Co-authored-by: Michael Herzog <[email protected]>
Cahier 1 year ago
parent
commit
aa2cfc8147
1 changed files with 15 additions and 4 deletions
  1. 15 4
      examples/jsm/math/Octree.js

+ 15 - 4
examples/jsm/math/Octree.js

@@ -82,19 +82,18 @@ function lineToLineClosestPoints( line1, line2, target1 = null, target2 = null )
 
 class Octree {
 
-
 	constructor( box ) {
 
-		this.triangles = [];
 		this.box = box;
+		this.bounds = new Box3();
+
 		this.subTrees = [];
+		this.triangles = [];
 
 	}
 
 	addTriangle( triangle ) {
 
-		if ( ! this.bounds ) this.bounds = new Box3();
-
 		this.bounds.min.x = Math.min( this.bounds.min.x, triangle.a.x, triangle.b.x, triangle.c.x );
 		this.bounds.min.y = Math.min( this.bounds.min.y, triangle.a.y, triangle.b.y, triangle.c.y );
 		this.bounds.min.z = Math.min( this.bounds.min.z, triangle.a.z, triangle.b.z, triangle.c.z );
@@ -524,6 +523,18 @@ class Octree {
 
 	}
 
+	clear() {
+
+		this.box = null;
+		this.bounds.makeEmpty();
+
+		this.subTrees.length = 0;
+		this.triangles.length = 0;
+
+		return this;
+
+	}
+
 }
 
 export { Octree };