Skip to content

Commit e4bfc5d

Browse files
CahierXcahierchenMugen87
authored andcommitted
Octree: Add clear(). (mrdoob#27160)
* feature: add octree clear method * Update Octree.js --------- Co-authored-by: cahierchen <[email protected]> Co-authored-by: Michael Herzog <[email protected]>
1 parent 0a55eb3 commit e4bfc5d

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

examples/jsm/math/Octree.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,18 @@ function lineToLineClosestPoints( line1, line2, target1 = null, target2 = null )
8282

8383
class Octree {
8484

85-
8685
constructor( box ) {
8786

88-
this.triangles = [];
8987
this.box = box;
88+
this.bounds = new Box3();
89+
9090
this.subTrees = [];
91+
this.triangles = [];
9192

9293
}
9394

9495
addTriangle( triangle ) {
9596

96-
if ( ! this.bounds ) this.bounds = new Box3();
97-
9897
this.bounds.min.x = Math.min( this.bounds.min.x, triangle.a.x, triangle.b.x, triangle.c.x );
9998
this.bounds.min.y = Math.min( this.bounds.min.y, triangle.a.y, triangle.b.y, triangle.c.y );
10099
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 {
524523

525524
}
526525

526+
clear() {
527+
528+
this.box = null;
529+
this.bounds.makeEmpty();
530+
531+
this.subTrees.length = 0;
532+
this.triangles.length = 0;
533+
534+
return this;
535+
536+
}
537+
527538
}
528539

529540
export { Octree };

0 commit comments

Comments
 (0)