MeshDistanceMaterial.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import { Material } from './Material.js';
  2. /**
  3. * A material used internally for implementing shadow mapping with
  4. * point lights.
  5. *
  6. * Can also be used to customize the shadow casting of an object by assigning
  7. * an instance of `MeshDistanceMaterial` to {@link Object3D#customDistanceMaterial}.
  8. * The following examples demonstrates this approach in order to ensure
  9. * transparent parts of objects do not cast shadows.
  10. *
  11. * @augments Material
  12. */
  13. class MeshDistanceMaterial extends Material {
  14. /**
  15. * Constructs a new mesh distance material.
  16. *
  17. * @param {Object} [parameters] - An object with one or more properties
  18. * defining the material's appearance. Any property of the material
  19. * (including any property from inherited materials) can be passed
  20. * in here. Color values can be passed any type of value accepted
  21. * by {@link Color#set}.
  22. */
  23. constructor( parameters ) {
  24. super();
  25. /**
  26. * This flag can be used for type testing.
  27. *
  28. * @type {boolean}
  29. * @readonly
  30. * @default true
  31. */
  32. this.isMeshDistanceMaterial = true;
  33. this.type = 'MeshDistanceMaterial';
  34. /**
  35. * The color map. May optionally include an alpha channel, typically combined
  36. * with {@link Material#transparent} or {@link Material#alphaTest}.
  37. *
  38. * @type {?Texture}
  39. * @default null
  40. */
  41. this.map = null;
  42. /**
  43. * The alpha map is a grayscale texture that controls the opacity across the
  44. * surface (black: fully transparent; white: fully opaque).
  45. *
  46. * Only the color of the texture is used, ignoring the alpha channel if one
  47. * exists. For RGB and RGBA textures, the renderer will use the green channel
  48. * when sampling this texture due to the extra bit of precision provided for
  49. * green in DXT-compressed and uncompressed RGB 565 formats. Luminance-only and
  50. * luminance/alpha textures will also still work as expected.
  51. *
  52. * @type {?Texture}
  53. * @default null
  54. */
  55. this.alphaMap = null;
  56. /**
  57. * The displacement map affects the position of the mesh's vertices. Unlike
  58. * other maps which only affect the light and shade of the material the
  59. * displaced vertices can cast shadows, block other objects, and otherwise
  60. * act as real geometry. The displacement texture is an image where the value
  61. * of each pixel (white being the highest) is mapped against, and
  62. * repositions, the vertices of the mesh.
  63. *
  64. * @type {?Texture}
  65. * @default null
  66. */
  67. this.displacementMap = null;
  68. /**
  69. * How much the displacement map affects the mesh (where black is no
  70. * displacement, and white is maximum displacement). Without a displacement
  71. * map set, this value is not applied.
  72. *
  73. * @type {number}
  74. * @default 0
  75. */
  76. this.displacementScale = 1;
  77. /**
  78. * The offset of the displacement map's values on the mesh's vertices.
  79. * The bias is added to the scaled sample of the displacement map.
  80. * Without a displacement map set, this value is not applied.
  81. *
  82. * @type {number}
  83. * @default 0
  84. */
  85. this.displacementBias = 0;
  86. this.setValues( parameters );
  87. }
  88. copy( source ) {
  89. super.copy( source );
  90. this.map = source.map;
  91. this.alphaMap = source.alphaMap;
  92. this.displacementMap = source.displacementMap;
  93. this.displacementScale = source.displacementScale;
  94. this.displacementBias = source.displacementBias;
  95. return this;
  96. }
  97. }
  98. export { MeshDistanceMaterial };
粤ICP备19079148号