MeshMatcapMaterial.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import { TangentSpaceNormalMap } from '../constants.js';
  2. import { Material } from './Material.js';
  3. import { Vector2 } from '../math/Vector2.js';
  4. import { Color } from '../math/Color.js';
  5. /**
  6. * This material is defined by a MatCap (or Lit Sphere) texture, which encodes the
  7. * material color and shading.
  8. *
  9. * `MeshMatcapMaterial` does not respond to lights since the matcap image file encodes
  10. * baked lighting. It will cast a shadow onto an object that receives shadows
  11. * (and shadow clipping works), but it will not self-shadow or receive
  12. * shadows.
  13. *
  14. * @augments Material
  15. */
  16. class MeshMatcapMaterial extends Material {
  17. /**
  18. * Constructs a new mesh matcap material.
  19. *
  20. * @param {Object} [parameters] - An object with one or more properties
  21. * defining the material's appearance. Any property of the material
  22. * (including any property from inherited materials) can be passed
  23. * in here. Color values can be passed any type of value accepted
  24. * by {@link Color#set}.
  25. */
  26. constructor( parameters ) {
  27. super();
  28. /**
  29. * This flag can be used for type testing.
  30. *
  31. * @type {boolean}
  32. * @readonly
  33. * @default true
  34. */
  35. this.isMeshMatcapMaterial = true;
  36. this.defines = { 'MATCAP': '' };
  37. this.type = 'MeshMatcapMaterial';
  38. /**
  39. * Color of the material.
  40. *
  41. * @type {Color}
  42. * @default (1,1,1)
  43. */
  44. this.color = new Color( 0xffffff ); // diffuse
  45. /**
  46. * The matcap map.
  47. *
  48. * @type {?Texture}
  49. * @default null
  50. */
  51. this.matcap = null;
  52. /**
  53. * The color map. May optionally include an alpha channel, typically combined
  54. * with {@link Material#transparent} or {@link Material#alphaTest}. The texture map
  55. * color is modulated by the diffuse `color`.
  56. *
  57. * @type {?Texture}
  58. * @default null
  59. */
  60. this.map = null;
  61. /**
  62. * The texture to create a bump map. The black and white values map to the
  63. * perceived depth in relation to the lights. Bump doesn't actually affect
  64. * the geometry of the object, only the lighting. If a normal map is defined
  65. * this will be ignored.
  66. *
  67. * @type {?Texture}
  68. * @default null
  69. */
  70. this.bumpMap = null;
  71. /**
  72. * How much the bump map affects the material. Typical range is `[0,1]`.
  73. *
  74. * @type {number}
  75. * @default 1
  76. */
  77. this.bumpScale = 1;
  78. /**
  79. * The texture to create a normal map. The RGB values affect the surface
  80. * normal for each pixel fragment and change the way the color is lit. Normal
  81. * maps do not change the actual shape of the surface, only the lighting. In
  82. * case the material has a normal map authored using the left handed
  83. * convention, the `y` component of `normalScale` should be negated to compensate
  84. * for the different handedness.
  85. *
  86. * @type {?Texture}
  87. * @default null
  88. */
  89. this.normalMap = null;
  90. /**
  91. * The type of normal map.
  92. *
  93. * @type {(TangentSpaceNormalMap|ObjectSpaceNormalMap)}
  94. * @default TangentSpaceNormalMap
  95. */
  96. this.normalMapType = TangentSpaceNormalMap;
  97. /**
  98. * How much the normal map affects the material. Typical value range is `[0,1]`.
  99. *
  100. * @type {Vector2}
  101. * @default (1,1)
  102. */
  103. this.normalScale = new Vector2( 1, 1 );
  104. /**
  105. * The displacement map affects the position of the mesh's vertices. Unlike
  106. * other maps which only affect the light and shade of the material the
  107. * displaced vertices can cast shadows, block other objects, and otherwise
  108. * act as real geometry. The displacement texture is an image where the value
  109. * of each pixel (white being the highest) is mapped against, and
  110. * repositions, the vertices of the mesh.
  111. *
  112. * @type {?Texture}
  113. * @default null
  114. */
  115. this.displacementMap = null;
  116. /**
  117. * How much the displacement map affects the mesh (where black is no
  118. * displacement, and white is maximum displacement). Without a displacement
  119. * map set, this value is not applied.
  120. *
  121. * @type {number}
  122. * @default 0
  123. */
  124. this.displacementScale = 1;
  125. /**
  126. * The offset of the displacement map's values on the mesh's vertices.
  127. * The bias is added to the scaled sample of the displacement map.
  128. * Without a displacement map set, this value is not applied.
  129. *
  130. * @type {number}
  131. * @default 0
  132. */
  133. this.displacementBias = 0;
  134. /**
  135. * The alpha map is a grayscale texture that controls the opacity across the
  136. * surface (black: fully transparent; white: fully opaque).
  137. *
  138. * Only the color of the texture is used, ignoring the alpha channel if one
  139. * exists. For RGB and RGBA textures, the renderer will use the green channel
  140. * when sampling this texture due to the extra bit of precision provided for
  141. * green in DXT-compressed and uncompressed RGB 565 formats. Luminance-only and
  142. * luminance/alpha textures will also still work as expected.
  143. *
  144. * @type {?Texture}
  145. * @default null
  146. */
  147. this.alphaMap = null;
  148. /**
  149. * Whether the material is rendered with flat shading or not.
  150. *
  151. * @type {boolean}
  152. * @default false
  153. */
  154. this.flatShading = false;
  155. /**
  156. * Whether the material is affected by fog or not.
  157. *
  158. * @type {boolean}
  159. * @default true
  160. */
  161. this.fog = true;
  162. this.setValues( parameters );
  163. }
  164. copy( source ) {
  165. super.copy( source );
  166. this.defines = { 'MATCAP': '' };
  167. this.color.copy( source.color );
  168. this.matcap = source.matcap;
  169. this.map = source.map;
  170. this.bumpMap = source.bumpMap;
  171. this.bumpScale = source.bumpScale;
  172. this.normalMap = source.normalMap;
  173. this.normalMapType = source.normalMapType;
  174. this.normalScale.copy( source.normalScale );
  175. this.displacementMap = source.displacementMap;
  176. this.displacementScale = source.displacementScale;
  177. this.displacementBias = source.displacementBias;
  178. this.alphaMap = source.alphaMap;
  179. this.flatShading = source.flatShading;
  180. this.fog = source.fog;
  181. return this;
  182. }
  183. }
  184. export { MeshMatcapMaterial };
粤ICP备19079148号