UNPKG

1.26 kBJavaScriptView Raw
1import { LineSegments } from '../objects/LineSegments.js';
2import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
3import { BufferAttribute } from '../core/BufferAttribute.js';
4import { Float32BufferAttribute } from '../core/BufferAttribute.js';
5import { BufferGeometry } from '../core/BufferGeometry.js';
6
7class Box3Helper extends LineSegments {
8
9 constructor( box, color = 0xffff00 ) {
10
11 const indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );
12
13 const positions = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 1, - 1, 1, - 1, - 1 ];
14
15 const geometry = new BufferGeometry();
16
17 geometry.setIndex( new BufferAttribute( indices, 1 ) );
18
19 geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
20
21 super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
22
23 this.box = box;
24
25 this.type = 'Box3Helper';
26
27 this.geometry.computeBoundingSphere();
28
29 }
30
31 updateMatrixWorld( force ) {
32
33 const box = this.box;
34
35 if ( box.isEmpty() ) return;
36
37 box.getCenter( this.position );
38
39 box.getSize( this.scale );
40
41 this.scale.multiplyScalar( 0.5 );
42
43 super.updateMatrixWorld( force );
44
45 }
46
47}
48
49export { Box3Helper };