Sprite.js 2.3 KB

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