Material.d.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. stencilMask?: number;
  52. stencilFail?: StencilOp;
  53. stencilZFail?: StencilOp;
  54. stencilZPass?: StencilOp;
  55. userData?: any;
  56. }
  57. /**
  58. * 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.
  59. */
  60. export class Material extends EventDispatcher {
  61. constructor();
  62. /**
  63. * Sets the alpha value to be used when running an alpha test. Default is 0.
  64. * @default 0
  65. */
  66. alphaTest: number;
  67. /**
  68. * Blending destination. It's one of the blending mode constants defined in Three.js. Default is {@link OneMinusSrcAlphaFactor}.
  69. * @default THREE.OneMinusSrcAlphaFactor
  70. */
  71. blendDst: BlendingDstFactor;
  72. /**
  73. * The tranparency of the .blendDst. Default is null.
  74. * @default null
  75. */
  76. blendDstAlpha: number | null;
  77. /**
  78. * Blending equation to use when applying blending. It's one of the constants defined in Three.js. Default is {@link AddEquation}.
  79. * @default THREE.AddEquation
  80. */
  81. blendEquation: BlendingEquation;
  82. /**
  83. * The tranparency of the .blendEquation. Default is null.
  84. * @default null
  85. */
  86. blendEquationAlpha: number | null;
  87. /**
  88. * Which blending to use when displaying objects with this material. Default is {@link NormalBlending}.
  89. * @default THREE.NormalBlending
  90. */
  91. blending: Blending;
  92. /**
  93. * Blending source. It's one of the blending mode constants defined in Three.js. Default is {@link SrcAlphaFactor}.
  94. * @default THREE.SrcAlphaFactor
  95. */
  96. blendSrc: BlendingSrcFactor | BlendingDstFactor;
  97. /**
  98. * The tranparency of the .blendSrc. Default is null.
  99. * @default null
  100. */
  101. blendSrcAlpha: number | null;
  102. /**
  103. * Changes the behavior of clipping planes so that only their intersection is clipped, rather than their union. Default is false.
  104. * @default false
  105. */
  106. clipIntersection: boolean;
  107. /**
  108. * 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.
  109. * @default null
  110. */
  111. clippingPlanes: any;
  112. /**
  113. * Defines whether to clip shadows according to the clipping planes specified on this material. Default is false.
  114. * @default false
  115. */
  116. clipShadows: boolean;
  117. /**
  118. * 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.
  119. * @default true
  120. */
  121. colorWrite: boolean;
  122. /**
  123. * 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 }.
  124. * The pairs are defined in both vertex and fragment shaders. Default is undefined.
  125. * @default undefined
  126. */
  127. defines: undefined | { [key: string]: any };
  128. /**
  129. * Which depth function to use. Default is {@link LessEqualDepth}. See the depth mode constants for all possible values.
  130. * @default THREE.LessEqualDepth
  131. */
  132. depthFunc: DepthModes;
  133. /**
  134. * Whether to have depth test enabled when rendering this material. Default is true.
  135. * @default true
  136. */
  137. depthTest: boolean;
  138. /**
  139. * Whether rendering this material has any effect on the depth buffer. Default is true.
  140. * 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.
  141. * @default true
  142. */
  143. depthWrite: boolean;
  144. /**
  145. * Whether the material is affected by fog. Default is true.
  146. * @default fog
  147. */
  148. fog: boolean;
  149. /**
  150. * Unique number of this material instance.
  151. */
  152. id: number;
  153. /**
  154. * Whether rendering this material has any effect on the stencil buffer. Default is *false*.
  155. * @default false
  156. */
  157. stencilWrite: boolean;
  158. /**
  159. * The stencil comparison function to use. Default is {@link AlwaysStencilFunc}. See stencil operation constants for all possible values.
  160. * @default THREE.AlwaysStencilFunc
  161. */
  162. stencilFunc: StencilFunc;
  163. /**
  164. * The value to use when performing stencil comparisons or stencil operations. Default is *0*.
  165. * @default 0
  166. */
  167. stencilRef: number;
  168. /**
  169. * The bit mask to use when comparing against or writing to the stencil buffer. Default is *0xFF*.
  170. * @default 0xff
  171. */
  172. stencilMask: number;
  173. /**
  174. * Which stencil operation to perform when the comparison function returns false. Default is {@link KeepStencilOp}. See the stencil operation constants for all possible values.
  175. * @default THREE.KeepStencilOp
  176. */
  177. stencilFail: StencilOp;
  178. /**
  179. * 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.
  180. * @default THREE.KeepStencilOp
  181. */
  182. stencilZFail: StencilOp;
  183. /**
  184. * 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.
  185. * @default THREE.KeepStencilOp
  186. */
  187. stencilZPass: StencilOp;
  188. /**
  189. * Used to check whether this or derived classes are materials. Default is true.
  190. * You should not change this, as it used internally for optimisation.
  191. */
  192. readonly isMaterial: true;
  193. /**
  194. * Material name. Default is an empty string.
  195. * @default ''
  196. */
  197. name: string;
  198. /**
  199. * 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.
  200. * This property is automatically set to true when instancing a new material.
  201. * @default false
  202. */
  203. needsUpdate: boolean;
  204. /**
  205. * Opacity. Default is 1.
  206. * @default 1
  207. */
  208. opacity: number;
  209. /**
  210. * Whether to use polygon offset. Default is false. This corresponds to the POLYGON_OFFSET_FILL WebGL feature.
  211. * @default false
  212. */
  213. polygonOffset: boolean;
  214. /**
  215. * Sets the polygon offset factor. Default is 0.
  216. * @default 0
  217. */
  218. polygonOffsetFactor: number;
  219. /**
  220. * Sets the polygon offset units. Default is 0.
  221. * @default 0
  222. */
  223. polygonOffsetUnits: number;
  224. /**
  225. * Override the renderer's default precision for this material. Can be "highp", "mediump" or "lowp". Defaults is null.
  226. * @default null
  227. */
  228. precision: 'highp' | 'mediump' | 'lowp' | null;
  229. /**
  230. * Whether to premultiply the alpha (transparency) value. See WebGL / Materials / Transparency for an example of the difference. Default is false.
  231. * @default false
  232. */
  233. premultipliedAlpha: boolean;
  234. /**
  235. * Whether to apply dithering to the color to remove the appearance of banding. Default is false.
  236. * @default false
  237. */
  238. dithering: boolean;
  239. /**
  240. * Define whether the material is rendered with flat shading. Default is false.
  241. * @default false
  242. */
  243. flatShading: boolean;
  244. /**
  245. * Defines which of the face sides will be rendered - front, back or both.
  246. * Default is THREE.FrontSide. Other options are THREE.BackSide and THREE.DoubleSide.
  247. * @default THREE.FrontSide
  248. */
  249. side: Side;
  250. /**
  251. * Defines which of the face sides will cast shadows. Default is *null*.
  252. * If *null*, the value is opposite that of side, above.
  253. * @default null
  254. */
  255. shadowSide: Side;
  256. /**
  257. * Defines whether this material is tone mapped according to the renderer's toneMapping setting.
  258. * Default is true.
  259. * @default true
  260. */
  261. toneMapped: boolean;
  262. /**
  263. * 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.
  264. * When set to true, the extent to which the material is transparent is controlled by setting it's .opacity property.
  265. * Default is false.
  266. * @default false
  267. */
  268. transparent: boolean;
  269. /**
  270. * Value is the string 'Material'. This shouldn't be changed, and can be used to find all objects of this type in a scene.
  271. * @default 'Material'
  272. */
  273. type: string;
  274. /**
  275. * UUID of this material instance. This gets automatically assigned, so this shouldn't be edited.
  276. */
  277. uuid: string;
  278. /**
  279. * Defines whether vertex coloring is used. Default is false.
  280. * @default false
  281. */
  282. vertexColors: boolean;
  283. /**
  284. * Defines whether this material is visible. Default is true.
  285. * @default true
  286. */
  287. visible: boolean;
  288. /**
  289. * 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.
  290. * @default {}
  291. */
  292. userData: any;
  293. /**
  294. * This starts at 0 and counts how many times .needsUpdate is set to true.
  295. * @default 0
  296. */
  297. version: number;
  298. /**
  299. * Return a new material with the same parameters as this material.
  300. */
  301. clone(): this;
  302. /**
  303. * Copy the parameters from the passed material into this material.
  304. * @param material
  305. */
  306. copy( material: Material ): this;
  307. /**
  308. * This disposes the material. Textures of a material don't get disposed. These needs to be disposed by {@link Texture}.
  309. */
  310. dispose(): void;
  311. /**
  312. * 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.
  313. * @param shader Source code of the shader
  314. * @param renderer WebGLRenderer Context that is initializing the material
  315. */
  316. onBeforeCompile ( shader : Shader, renderer : WebGLRenderer ) : void;
  317. /**
  318. * 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.
  319. */
  320. customProgramCacheKey(): string;
  321. /**
  322. * Sets the properties based on the values.
  323. * @param values A container with parameters.
  324. */
  325. setValues( values: MaterialParameters ): void;
  326. /**
  327. * Convert the material to three.js JSON format.
  328. * @param meta Object containing metadata such as textures or images for the material.
  329. */
  330. toJSON( meta?: any ): any;
  331. }
粤ICP备19079148号