Browse Source

OctreeHelper: Add `update()`. (#24641)

* added OctreeHelper.update()

* dispose geometry when vertices changed size

* dispose of previous geometry unconditionally

* Update OctreeHelper.js

* OctreeHelper.dispose()

Co-authored-by: Michael Herzog <[email protected]>
Eran Geva 2 years ago
parent
commit
ee3b5adf4d
1 changed files with 22 additions and 8 deletions
  1. 22 8
      examples/jsm/helpers/OctreeHelper.js

+ 22 - 8
examples/jsm/helpers/OctreeHelper.js

@@ -9,6 +9,19 @@ class OctreeHelper extends LineSegments {
 
 	constructor( octree, color = 0xffff00 ) {
 
+		super( new BufferGeometry(), new LineBasicMaterial( { color: color, toneMapped: false } ) );
+
+		this.octree = octree;
+		this.color = color;
+
+		this.type = 'OctreeHelper';
+
+		this.update();
+
+	}
+
+	update() {
+
 		const vertices = [];
 
 		function traverse( tree ) {
@@ -39,20 +52,21 @@ class OctreeHelper extends LineSegments {
 
 		}
 
-		traverse( octree.subTrees );
+		traverse( this.octree.subTrees );
 
-		const geometry = new BufferGeometry();
-		geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
+		this.geometry.dispose();
 
-		super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
+		this.geometry = new BufferGeometry();
+		this.geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 
-		this.octree = octree;
-		this.color = color;
+	}
 
-		this.type = 'OctreeHelper';
+	dispose() {
 
-	}
+		this.geometry.dispose();
+		this.material.dispose();
 
+	}
 }
 
 export { OctreeHelper };