Sprite.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 intersectPoint = new Vector3();
  18. var worldPosition = new Vector3();
  19. var worldScale = new Vector3();
  20. return function raycast( raycaster, intersects ) {
  21. worldPosition.setFromMatrixPosition( this.matrixWorld );
  22. raycaster.ray.closestPointToPoint( worldPosition, intersectPoint );
  23. worldScale.setFromMatrixScale( this.matrixWorld );
  24. var guessSizeSq = worldScale.x * worldScale.y / 4;
  25. if ( worldPosition.distanceToSquared( intersectPoint ) > guessSizeSq ) return;
  26. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  27. if ( distance < raycaster.near || distance > raycaster.far ) return;
  28. intersects.push( {
  29. distance: distance,
  30. point: intersectPoint.clone(),
  31. face: null,
  32. object: this
  33. } );
  34. };
  35. }() ),
  36. clone: function () {
  37. return new this.constructor( this.material ).copy( this );
  38. }
  39. } );
  40. export { Sprite };
粤ICP备19079148号