Box3Helper.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { LineSegments } from '../objects/LineSegments.js';
  2. import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
  3. import { BufferAttribute } from '../core/BufferAttribute.js';
  4. import { Float32BufferAttribute } from '../core/BufferAttribute.js';
  5. import { BufferGeometry } from '../core/BufferGeometry.js';
  6. class Box3Helper extends LineSegments {
  7. constructor( box, color ) {
  8. if ( color === undefined ) color = 0xffff00;
  9. 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 ] );
  10. 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 ];
  11. const geometry = new BufferGeometry();
  12. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  13. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  14. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  15. this.box = box;
  16. this.type = 'Box3Helper';
  17. this.geometry.computeBoundingSphere();
  18. }
  19. updateMatrixWorld( force ) {
  20. const box = this.box;
  21. if ( box.isEmpty() ) return;
  22. box.getCenter( this.position );
  23. box.getSize( this.scale );
  24. this.scale.multiplyScalar( 0.5 );
  25. super.updateMatrixWorld( force );
  26. }
  27. }
  28. export { Box3Helper };
粤ICP备19079148号