Sprite.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @author mikael emtinger / http://gomo.se/
  3. * @author alteredq / http://alteredqualia.com/
  4. */
  5. THREE.Sprite = ( function () {
  6. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  7. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  8. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  9. var geometry = new THREE.BufferGeometry();
  10. geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  11. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  12. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  13. return function ( material ) {
  14. THREE.Object3D.call( this );
  15. this.type = 'Sprite';
  16. this.geometry = geometry;
  17. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  18. };
  19. } )();
  20. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  21. THREE.Sprite.prototype.constructor = THREE.Sprite;
  22. THREE.Sprite.prototype.raycast = ( function () {
  23. var matrixPosition = new THREE.Vector3();
  24. return function ( raycaster, intersects ) {
  25. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  26. var distance = raycaster.ray.distanceToPoint( matrixPosition );
  27. if ( distance > this.scale.x ) {
  28. return;
  29. }
  30. intersects.push( {
  31. distance: distance,
  32. point: this.position,
  33. face: null,
  34. object: this
  35. } );
  36. };
  37. }() );
  38. THREE.Sprite.prototype.clone = function ( object ) {
  39. if ( object === undefined ) object = new THREE.Sprite( this.material );
  40. THREE.Object3D.prototype.clone.call( this, object );
  41. return object;
  42. };
  43. // Backwards compatibility
  44. THREE.Particle = THREE.Sprite;
粤ICP备19079148号