Sprite.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @author mikael emtinger / http://gomo.se/
  3. */
  4. THREE.Sprite = function( parameters ) {
  5. THREE.Object3D.call( this );
  6. if( parameters.material !== undefined ) {
  7. this.material = parameters.material;
  8. this.map = undefined;
  9. this.blending = material.blending;
  10. } else if( parameters.map !== undefined ) {
  11. this.map = parameters.map instanceof THREE.Texture ? parameters.map : THREE.ImageUtils.loadTexture( parameters.map );
  12. this.material = undefined;
  13. this.blending = parameters.blending !== undefined ? parameters.blending : THREE.NormalBlending;
  14. }
  15. this.useScreenCoordinates = parameters.useScreenCoordinates !== undefined ? parameters.useScreenCoordinates : true;
  16. this.mergeWith3D = parameters.mergeWith3D !== undefined ? parameters.mergeWith3D : !this.useScreenCoordinates;
  17. this.affectedByDistance = parameters.affectedByDistance !== undefined ? parameters.affectedByDistance : !this.useScreenCoordinates;
  18. this.scaleByViewport = parameters.scaleByViewport !== undefined ? parameters.scaleByViewport : !this.affectedByDistance;
  19. this.alignment = parameters.alignment instanceof THREE.Vector2 ? parameters.alignment : THREE.SpriteAlignment.center;
  20. this.rotation3d = this.rotation;
  21. this.rotation = 0;
  22. this.opacity = 1;
  23. this.uvOffset = new THREE.Vector2( 0, 0 );
  24. this.uvScale = new THREE.Vector2( 1, 1 );
  25. };
  26. THREE.Sprite.prototype = new THREE.Object3D();
  27. THREE.Sprite.prototype.constructor = THREE.Sprite;
  28. THREE.Sprite.prototype.supr = THREE.Object3D.prototype;
  29. /*
  30. * Custom update matrix
  31. */
  32. THREE.Sprite.prototype.updateMatrix = function () {
  33. this.matrix.setPosition( this.position );
  34. this.rotation3d.set( 0, 0, this.rotation );
  35. this.matrix.setRotationFromEuler( this.rotation3d );
  36. if ( this.scale.x !== 1 || this.scale.y !== 1 ) {
  37. this.matrix.scale( this.scale );
  38. this.boundRadiusScale = Math.max( this.scale.x, this.scale.y );
  39. }
  40. this.matrixWorldNeedsUpdate = true;
  41. };
  42. /*
  43. * Alignment
  44. */
  45. THREE.SpriteAlignment = {};
  46. THREE.SpriteAlignment.topLeft = new THREE.Vector2( 1, -1 );
  47. THREE.SpriteAlignment.topCenter = new THREE.Vector2( 0, -1 );
  48. THREE.SpriteAlignment.topRight = new THREE.Vector2( -1, -1 );
  49. THREE.SpriteAlignment.centerLeft = new THREE.Vector2( 1, 0 );
  50. THREE.SpriteAlignment.center = new THREE.Vector2( 0, 0 );
  51. THREE.SpriteAlignment.centerRight = new THREE.Vector2( -1, 0 );
  52. THREE.SpriteAlignment.bottomLeft = new THREE.Vector2( 1, 1 );
  53. THREE.SpriteAlignment.bottomCenter = new THREE.Vector2( 0, 1 );
  54. THREE.SpriteAlignment.bottomRight = new THREE.Vector2( -1, 1 );
粤ICP备19079148号