BoundingBoxHelper.js 954 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { Mesh } from '../../objects/Mesh';
  2. import { MeshBasicMaterial } from '../../materials/MeshBasicMaterial';
  3. import { BoxBufferGeometry } from '../../geometries/BoxBufferGeometry';
  4. import { Box3 } from '../../math/Box3';
  5. /**
  6. * @author WestLangley / http://github.com/WestLangley
  7. */
  8. // a helper to show the world-axis-aligned bounding box for an object
  9. function BoundingBoxHelper( object, hex ) {
  10. var color = ( hex !== undefined ) ? hex : 0x888888;
  11. this.object = object;
  12. this.box = new Box3();
  13. Mesh.call( this, new BoxBufferGeometry( 1, 1, 1 ), new MeshBasicMaterial( { color: color, wireframe: true } ) );
  14. }
  15. BoundingBoxHelper.prototype = Object.create( Mesh.prototype );
  16. BoundingBoxHelper.prototype.constructor = BoundingBoxHelper;
  17. BoundingBoxHelper.prototype.update = function () {
  18. this.box.setFromObject( this.object );
  19. this.box.getSize( this.scale );
  20. this.box.getCenter( this.position );
  21. };
  22. export { BoundingBoxHelper };