123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import {
- LineSegments,
- BufferGeometry,
- Float32BufferAttribute,
- LineBasicMaterial
- } from 'three';
- 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 ) {
- for ( let i = 0; i < tree.length; i ++ ) {
- const min = tree[ i ].box.min;
- const max = tree[ i ].box.max;
- vertices.push( max.x, max.y, max.z ); vertices.push( min.x, max.y, max.z );
- vertices.push( min.x, max.y, max.z ); vertices.push( min.x, min.y, max.z );
- vertices.push( min.x, min.y, max.z ); vertices.push( max.x, min.y, max.z );
- vertices.push( max.x, min.y, max.z ); vertices.push( max.x, max.y, max.z );
- vertices.push( max.x, max.y, min.z ); vertices.push( min.x, max.y, min.z );
- vertices.push( min.x, max.y, min.z ); vertices.push( min.x, min.y, min.z );
- vertices.push( min.x, min.y, min.z ); vertices.push( max.x, min.y, min.z );
- vertices.push( max.x, min.y, min.z ); vertices.push( max.x, max.y, min.z );
- vertices.push( max.x, max.y, max.z ); vertices.push( max.x, max.y, min.z );
- vertices.push( min.x, max.y, max.z ); vertices.push( min.x, max.y, min.z );
- vertices.push( min.x, min.y, max.z ); vertices.push( min.x, min.y, min.z );
- vertices.push( max.x, min.y, max.z ); vertices.push( max.x, min.y, min.z );
- traverse( tree[ i ].subTrees );
- }
- }
- traverse( this.octree.subTrees );
- this.geometry.dispose();
- this.geometry = new BufferGeometry();
- this.geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
- }
-
- dispose() {
- this.geometry.dispose();
- this.material.dispose();
- }
- }
- export { OctreeHelper };
|