Sprite.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Sprite
  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 : 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 : false;
  17. this.affectedByDistance = parameters.affectedByDistance !== undefined ? parameters.affectedByDistance : !parameters.useScreenCoordinates;
  18. this.alignment = parameters.alignment instanceof THREE.Vector2 ? parameters.alignment : THREE.SpriteAlignment.center;
  19. this.rotation3d = this.rotation;
  20. this.rotation = 0;
  21. this.opacity = 1;
  22. this.uvOffset = new THREE.Vector2( 0, 0 );
  23. this.uvScale = new THREE.Vector2( 1, 1 );
  24. }
  25. THREE.Sprite.prototype = new THREE.Object3D();
  26. THREE.Sprite.prototype.constructor = THREE.ShadowVolume;
  27. THREE.Sprite.prototype.supr = THREE.Object3D.prototype;
  28. /*
  29. * Custom update matrix
  30. */
  31. THREE.Sprite.prototype.updateMatrix = function () {
  32. this.matrix.setPosition( this.position );
  33. this.rotation3d.set( 0, 0, this.rotation );
  34. this.matrix.setRotationFromEuler( this.rotation3d );
  35. if ( this.scale.x !== 1 || this.scale.y !== 1 ) {
  36. this.scale3d.set( this.scale.x, this.scale.y, 1 );
  37. this.matrix.scale( this.scale3d );
  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号