Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Octree: Add clear(). #27160

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };