2
0

Box3Helper.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @author WestLangley / http://github.com/WestLangley
  3. */
  4. import { LineSegments } from '../objects/LineSegments.js';
  5. import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
  6. import { BufferAttribute } from '../core/BufferAttribute.js';
  7. import { Float32BufferAttribute } from '../core/BufferAttribute.js';
  8. import { BufferGeometry } from '../core/BufferGeometry.js';
  9. import { Object3D } from '../core/Object3D.js';
  10. function Box3Helper( box, color ) {
  11. this.type = 'Box3Helper';
  12. this.box = box;
  13. color = color || 0xffff00;
  14. var 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 ] );
  15. var 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 ];
  16. var geometry = new BufferGeometry();
  17. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  18. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  19. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  20. this.geometry.computeBoundingSphere();
  21. }
  22. Box3Helper.prototype = Object.create( LineSegments.prototype );
  23. Box3Helper.prototype.constructor = Box3Helper;
  24. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  25. var box = this.box;
  26. if ( box.isEmpty() ) return;
  27. box.getCenter( this.position );
  28. box.getSize( this.scale );
  29. this.scale.multiplyScalar( 0.5 );
  30. Object3D.prototype.updateMatrixWorld.call( this, force );
  31. };
  32. export { Box3Helper };