Skip to content

Commit

Permalink
Octree: Add clear(). (mrdoob#27160)
Browse files Browse the repository at this point in the history
* feature: add octree clear method

* Update Octree.js

---------

Co-authored-by: cahierchen <cahierchen@tencent.com>
Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
  • Loading branch information
3 people authored and AdaRoseCannon committed Jan 15, 2024
1 parent 0a55eb3 commit e4bfc5d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions examples/jsm/math/Octree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 };

0 comments on commit e4bfc5d

Please sign in to comment.