Sprite.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { Vector3 } from '../math/Vector3';
  2. import { Object3D } from '../core/Object3D';
  3. import { SpriteMaterial } from '../materials/SpriteMaterial';
  4. /**
  5. * @author mikael emtinger / http://gomo.se/
  6. * @author alteredq / http://alteredqualia.com/
  7. */
  8. function Sprite( material ) {
  9. Object3D.call( this );
  10. this.type = 'Sprite';
  11. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  12. }
  13. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14. constructor: Sprite,
  15. isSprite: true,
  16. raycast: ( function () {
  17. var matrixPosition = new Vector3();
  18. return function raycast( raycaster, intersects ) {
  19. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  20. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  21. var guessSizeSq = this.scale.x * this.scale.y / 4;
  22. if ( distanceSq > guessSizeSq ) {
  23. return;
  24. }
  25. intersects.push( {
  26. distance: Math.sqrt( distanceSq ),
  27. point: this.position,
  28. face: null,
  29. object: this
  30. } );
  31. };
  32. }() ),
  33. clone: function () {
  34. return new this.constructor( this.material ).copy( this );
  35. }
  36. } );
  37. export { Sprite };