Material.d.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. import { Plane } from './../math/Plane';
  2. import { EventDispatcher } from './../core/EventDispatcher';
  3. import { WebGLRenderer } from './../renderers/WebGLRenderer';
  4. import { Shader } from './../renderers/shaders/ShaderLib';
  5. import {
  6. BlendingDstFactor,
  7. BlendingEquation,
  8. Blending,
  9. BlendingSrcFactor,
  10. DepthModes,
  11. Side,
  12. StencilFunc,
  13. StencilOp
  14. } from '../constants';
  15. export interface MaterialParameters {
  16. alphaTest?: number;
  17. blendDst?: BlendingDstFactor;
  18. blendDstAlpha?: number;
  19. blendEquation?: BlendingEquation;
  20. blendEquationAlpha?: number;
  21. blending?: Blending;
  22. blendSrc?: BlendingSrcFactor | BlendingDstFactor;
  23. blendSrcAlpha?: number;
  24. clipIntersection?: boolean;
  25. clippingPlanes?: Plane[];
  26. clipShadows?: boolean;
  27. colorWrite?: boolean;
  28. defines?: any;
  29. depthFunc?: DepthModes;
  30. depthTest?: boolean;
  31. depthWrite?: boolean;
  32. fog?: boolean;
  33. name?: string;
  34. opacity?: number;
  35. polygonOffset?: boolean;
  36. polygonOffsetFactor?: number;
  37. polygonOffsetUnits?: number;
  38. precision?: 'highp' | 'mediump' | 'lowp' | null;
  39. premultipliedAlpha?: boolean;
  40. dithering?: boolean;
  41. flatShading?: boolean;
  42. side?: Side;
  43. shadowSide?: Side;
  44. toneMapped?: boolean;
  45. transparent?: boolean;
  46. vertexColors?: boolean;
  47. visible?: boolean;
  48. stencilWrite?: boolean;
  49. stencilFunc?: StencilFunc;
  50. stencilRef?: number;
  51. stencilWriteMask?: number;
  52. stencilFuncMask?: number;
  53. stencilFail?: StencilOp;
  54. stencilZFail?: StencilOp;
  55. stencilZPass?: StencilOp;
  56. userData?: any;
  57. }
  58. /**
  59. * Materials describe the appearance of objects. They are defined in a (mostly) renderer-independent way, so you don't have to rewrite materials if you decide to use a different renderer.
  60. */
  61. export class Material extends EventDispatcher {
  62. constructor();
  63. /**
  64. * Sets the alpha value to be used when running an alpha test. Default is 0.
  65. * @default 0
  66. */
  67. alphaTest: number;
  68. /**
  69. * Blending destination. It's one of the blending mode constants defined in Three.js. Default is {@link OneMinusSrcAlphaFactor}.
  70. * @default THREE.OneMinusSrcAlphaFactor
  71. */
  72. blendDst: BlendingDstFactor;
  73. /**
  74. * The tranparency of the .blendDst. Default is null.
  75. * @default null
  76. */
  77. blendDstAlpha: number | null;
  78. /**
  79. * Blending equation to use when applying blending. It's one of the constants defined in Three.js. Default is {@link AddEquation}.
  80. * @default THREE.AddEquation
  81. */
  82. blendEquation: BlendingEquation;
  83. /**
  84. * The tranparency of the .blendEquation. Default is null.
  85. * @default null
  86. */
  87. blendEquationAlpha: number | null;
  88. /**
  89. * Which blending to use when displaying objects with this material. Default is {@link NormalBlending}.
  90. * @default THREE.NormalBlending
  91. */
  92. blending: Blending;
  93. /**
  94. * Blending source. It's one of the blending mode constants defined in Three.js. Default is {@link SrcAlphaFactor}.
  95. * @default THREE.SrcAlphaFactor
  96. */
  97. blendSrc: BlendingSrcFactor | BlendingDstFactor;
  98. /**
  99. * The tranparency of the .blendSrc. Default is null.
  100. * @default null
  101. */
  102. blendSrcAlpha: number | null;
  103. /**
  104. * Changes the behavior of clipping planes so that only their intersection is clipped, rather than their union. Default is false.
  105. * @default false
  106. */
  107. clipIntersection: boolean;
  108. /**
  109. * User-defined clipping planes specified as THREE.Plane objects in world space. These planes apply to the objects this material is attached to. Points in space whose signed distance to the plane is negative are clipped (not rendered). See the WebGL / clipping /intersection example. Default is null.
  110. * @default null
  111. */
  112. clippingPlanes: any;
  113. /**
  114. * Defines whether to clip shadows according to the clipping planes specified on this material. Default is false.
  115. * @default false
  116. */
  117. clipShadows: boolean;
  118. /**
  119. * Whether to render the material's color. This can be used in conjunction with a mesh's .renderOrder property to create invisible objects that occlude other objects. Default is true.
  120. * @default true
  121. */
  122. colorWrite: boolean;
  123. /**
  124. * Custom defines to be injected into the shader. These are passed in form of an object literal, with key/value pairs. { MY_CUSTOM_DEFINE: '' , PI2: Math.PI * 2 }.
  125. * The pairs are defined in both vertex and fragment shaders. Default is undefined.
  126. * @default undefined
  127. */
  128. defines: undefined | { [key: string]: any };
  129. /**
  130. * Which depth function to use. Default is {@link LessEqualDepth}. See the depth mode constants for all possible values.
  131. * @default THREE.LessEqualDepth
  132. */
  133. depthFunc: DepthModes;
  134. /**
  135. * Whether to have depth test enabled when rendering this material. Default is true.
  136. * @default true
  137. */
  138. depthTest: boolean;
  139. /**
  140. * Whether rendering this material has any effect on the depth buffer. Default is true.
  141. * When drawing 2D overlays it can be useful to disable the depth writing in order to layer several things together without creating z-index artifacts.
  142. * @default true
  143. */
  144. depthWrite: boolean;
  145. /**
  146. * Whether the material is affected by fog. Default is true.
  147. * @default fog
  148. */
  149. fog: boolean;
  150. /**
  151. * Unique number of this material instance.
  152. */
  153. id: number;
  154. /**
  155. * Whether rendering this material has any effect on the stencil buffer. Default is *false*.
  156. * @default false
  157. */
  158. stencilWrite: boolean;
  159. /**
  160. * The stencil comparison function to use. Default is {@link AlwaysStencilFunc}. See stencil operation constants for all possible values.
  161. * @default THREE.AlwaysStencilFunc
  162. */
  163. stencilFunc: StencilFunc;
  164. /**
  165. * The value to use when performing stencil comparisons or stencil operations. Default is *0*.
  166. * @default 0
  167. */
  168. stencilRef: number;
  169. /**
  170. * The bit mask to use when writing to the stencil buffer. Default is *0xFF*.
  171. * @default 0xff
  172. */
  173. stencilWriteMask: number;
  174. /**
  175. * The bit mask to use when comparing against the stencil buffer. Default is *0xFF*.
  176. * @default 0xff
  177. */
  178. stencilFuncMask: number;
  179. /**
  180. * Which stencil operation to perform when the comparison function returns false. Default is {@link KeepStencilOp}. See the stencil operation constants for all possible values.
  181. * @default THREE.KeepStencilOp
  182. */
  183. stencilFail: StencilOp;
  184. /**
  185. * Which stencil operation to perform when the comparison function returns true but the depth test fails. Default is {@link KeepStencilOp}. See the stencil operation constants for all possible values.
  186. * @default THREE.KeepStencilOp
  187. */
  188. stencilZFail: StencilOp;
  189. /**
  190. * Which stencil operation to perform when the comparison function returns true and the depth test passes. Default is {@link KeepStencilOp}. See the stencil operation constants for all possible values.
  191. * @default THREE.KeepStencilOp
  192. */
  193. stencilZPass: StencilOp;
  194. /**
  195. * Used to check whether this or derived classes are materials. Default is true.
  196. * You should not change this, as it used internally for optimisation.
  197. */
  198. readonly isMaterial: true;
  199. /**
  200. * Material name. Default is an empty string.
  201. * @default ''
  202. */
  203. name: string;
  204. /**
  205. * Specifies that the material needs to be updated, WebGL wise. Set it to true if you made changes that need to be reflected in WebGL.
  206. * This property is automatically set to true when instancing a new material.
  207. * @default false
  208. */
  209. needsUpdate: boolean;
  210. /**
  211. * Opacity. Default is 1.
  212. * @default 1
  213. */
  214. opacity: number;
  215. /**
  216. * Whether to use polygon offset. Default is false. This corresponds to the POLYGON_OFFSET_FILL WebGL feature.
  217. * @default false
  218. */
  219. polygonOffset: boolean;
  220. /**
  221. * Sets the polygon offset factor. Default is 0.
  222. * @default 0
  223. */
  224. polygonOffsetFactor: number;
  225. /**
  226. * Sets the polygon offset units. Default is 0.
  227. * @default 0
  228. */
  229. polygonOffsetUnits: number;
  230. /**
  231. * Override the renderer's default precision for this material. Can be "highp", "mediump" or "lowp". Defaults is null.
  232. * @default null
  233. */
  234. precision: 'highp' | 'mediump' | 'lowp' | null;
  235. /**
  236. * Whether to premultiply the alpha (transparency) value. See WebGL / Materials / Transparency for an example of the difference. Default is false.
  237. * @default false
  238. */
  239. premultipliedAlpha: boolean;
  240. /**
  241. * Whether to apply dithering to the color to remove the appearance of banding. Default is false.
  242. * @default false
  243. */
  244. dithering: boolean;
  245. /**
  246. * Define whether the material is rendered with flat shading. Default is false.
  247. * @default false
  248. */
  249. flatShading: boolean;
  250. /**
  251. * Defines which of the face sides will be rendered - front, back or both.
  252. * Default is THREE.FrontSide. Other options are THREE.BackSide and THREE.DoubleSide.
  253. * @default THREE.FrontSide
  254. */
  255. side: Side;
  256. /**
  257. * Defines which of the face sides will cast shadows. Default is *null*.
  258. * If *null*, the value is opposite that of side, above.
  259. * @default null
  260. */
  261. shadowSide: Side;
  262. /**
  263. * Defines whether this material is tone mapped according to the renderer's toneMapping setting.
  264. * Default is true.
  265. * @default true
  266. */
  267. toneMapped: boolean;
  268. /**
  269. * Defines whether this material is transparent. This has an effect on rendering as transparent objects need special treatment and are rendered after non-transparent objects.
  270. * When set to true, the extent to which the material is transparent is controlled by setting it's .opacity property.
  271. * Default is false.
  272. * @default false
  273. */
  274. transparent: boolean;
  275. /**
  276. * Value is the string 'Material'. This shouldn't be changed, and can be used to find all objects of this type in a scene.
  277. * @default 'Material'
  278. */
  279. type: string;
  280. /**
  281. * UUID of this material instance. This gets automatically assigned, so this shouldn't be edited.
  282. */
  283. uuid: string;
  284. /**
  285. * Defines whether vertex coloring is used. Default is false.
  286. * @default false
  287. */
  288. vertexColors: boolean;
  289. /**
  290. * Defines whether this material is visible. Default is true.
  291. * @default true
  292. */
  293. visible: boolean;
  294. /**
  295. * An object that can be used to store custom data about the Material. It should not hold references to functions as these will not be cloned.
  296. * @default {}
  297. */
  298. userData: any;
  299. /**
  300. * This starts at 0 and counts how many times .needsUpdate is set to true.
  301. * @default 0
  302. */
  303. version: number;
  304. /**
  305. * Return a new material with the same parameters as this material.
  306. */
  307. clone(): Material;
  308. /**
  309. * Copy the parameters from the passed material into this material.
  310. * @param material
  311. */
  312. copy( material: Material ): this;
  313. /**
  314. * This disposes the material. Textures of a material don't get disposed. These needs to be disposed by {@link Texture}.
  315. */
  316. dispose(): void;
  317. /**
  318. * An optional callback that is executed immediately before the shader program is compiled. This function is called with the shader source code as a parameter. Useful for the modification of built-in materials.
  319. * @param shader Source code of the shader
  320. * @param renderer WebGLRenderer Context that is initializing the material
  321. */
  322. onBeforeCompile ( shader : Shader, renderer : WebGLRenderer ) : void;
  323. /**
  324. * In case onBeforeCompile is used, this callback can be used to identify values of settings used in onBeforeCompile, so three.js can reuse a cached shader or recompile the shader as needed.
  325. */
  326. customProgramCacheKey(): string;
  327. /**
  328. * Sets the properties based on the values.
  329. * @param values A container with parameters.
  330. */
  331. setValues( values: MaterialParameters ): void;
  332. /**
  333. * Convert the material to three.js JSON format.
  334. * @param meta Object containing metadata such as textures or images for the material.
  335. */
  336. toJSON( meta?: any ): any;
  337. }