SpriteMaterial.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { Material } from './Material.js';
  2. import { Color } from '../math/Color.js';
  3. /**
  4. * A material for rendering instances of {@link Sprite}.
  5. *
  6. * ```js
  7. * const map = new THREE.TextureLoader().load( 'textures/sprite.png' );
  8. * const material = new THREE.SpriteMaterial( { map: map, color: 0xffffff } );
  9. *
  10. * const sprite = new THREE.Sprite( material );
  11. * sprite.scale.set(200, 200, 1)
  12. * scene.add( sprite );
  13. * ```
  14. *
  15. * @augments Material
  16. */
  17. class SpriteMaterial extends Material {
  18. /**
  19. * Constructs a new sprite material.
  20. *
  21. * @param {Object} parameters - An object with one or more properties
  22. * defining the material's appearance. Any property of the material
  23. * (including any property from inherited materials) can be passed
  24. * in here. Color values can be passed any type of value accepted
  25. * by {@link Color#set}.
  26. */
  27. constructor( parameters ) {
  28. super();
  29. /**
  30. * This flag can be used for type testing.
  31. *
  32. * @type {boolean}
  33. * @readonly
  34. * @default true
  35. */
  36. this.isSpriteMaterial = true;
  37. this.type = 'SpriteMaterial';
  38. /**
  39. * Color of the material.
  40. *
  41. * @type {Color}
  42. * @default (1,1,1)
  43. */
  44. this.color = new Color( 0xffffff );
  45. /**
  46. * The color map. May optionally include an alpha channel, typically combined
  47. * with {@link Material#transparent} or {@link Material#alphaTest}. The texture map
  48. * color is modulated by the diffuse `color`.
  49. *
  50. * @type {?Texture}
  51. * @default null
  52. */
  53. this.map = null;
  54. /**
  55. * The alpha map is a grayscale texture that controls the opacity across the
  56. * surface (black: fully transparent; white: fully opaque).
  57. *
  58. * Only the color of the texture is used, ignoring the alpha channel if one
  59. * exists. For RGB and RGBA textures, the renderer will use the green channel
  60. * when sampling this texture due to the extra bit of precision provided for
  61. * green in DXT-compressed and uncompressed RGB 565 formats. Luminance-only and
  62. * luminance/alpha textures will also still work as expected.
  63. *
  64. * @type {?Texture}
  65. * @default null
  66. */
  67. this.alphaMap = null;
  68. /**
  69. * The rotation of the sprite in radians.
  70. *
  71. * @type {number}
  72. * @default 0
  73. */
  74. this.rotation = 0;
  75. /**
  76. * Specifies whether size of the sprite is attenuated by the camera depth (perspective camera only).
  77. *
  78. * @type {boolean}
  79. * @default true
  80. */
  81. this.sizeAttenuation = true;
  82. /**
  83. * Overwritten since sprite materials are transparent
  84. * by default.
  85. *
  86. * @type {boolean}
  87. * @default true
  88. */
  89. this.transparent = true;
  90. /**
  91. * Whether the material is affected by fog or not.
  92. *
  93. * @type {boolean}
  94. * @default true
  95. */
  96. this.fog = true;
  97. this.setValues( parameters );
  98. }
  99. copy( source ) {
  100. super.copy( source );
  101. this.color.copy( source.color );
  102. this.map = source.map;
  103. this.alphaMap = source.alphaMap;
  104. this.rotation = source.rotation;
  105. this.sizeAttenuation = source.sizeAttenuation;
  106. this.fog = source.fog;
  107. return this;
  108. }
  109. }
  110. export { SpriteMaterial };
粤ICP备19079148号