threepipe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import type {Color, Event, IUniform, Material, MaterialParameters, Shader} from 'three'
  2. import type {IDisposable, IJSONSerializable} from 'ts-browser-helpers'
  3. import type {MaterialExtension} from '../materials'
  4. import type {ChangeEvent, IUiConfigContainer} from 'uiconfig.js'
  5. import type {SerializationMetaType} from '../utils'
  6. import type {IObject3D} from './IObject'
  7. import {ISetDirtyCommonOptions} from './IObject'
  8. import type {ITexture} from './ITexture'
  9. import type {IImportResultUserData} from '../assetmanager'
  10. export type IMaterialParameters = MaterialParameters & {customMaterialExtensions?: MaterialExtension[]}
  11. export type IMaterialEventTypes = 'dispose' | 'materialUpdate' | 'beforeRender' | 'beforeCompile' | 'afterRender' | 'textureUpdate' | 'beforeDeserialize'
  12. export type IMaterialEvent<T extends string = IMaterialEventTypes> = Event & {
  13. type: T
  14. bubbleToObject?: boolean
  15. bubbleToParent?: boolean
  16. material?: IMaterial
  17. texture?: ITexture
  18. oldTexture?: ITexture
  19. uiChangeEvent?: ChangeEvent
  20. }
  21. export interface IMaterialSetDirtyOptions extends ISetDirtyCommonOptions{
  22. /**
  23. * @default true
  24. */
  25. bubbleToObject?: boolean,
  26. /**
  27. * @default true
  28. */
  29. needsUpdate?: boolean,
  30. [key: string]: any
  31. }
  32. export interface IMaterialUserData extends IImportResultUserData{
  33. uuid?: string // adding to userdata also, so that its saved in gltf
  34. /**
  35. * Automatically dispose material when not used by any object in the scene
  36. * @default true
  37. */
  38. disposeOnIdle?: boolean
  39. renderToGBuffer?: boolean
  40. /**
  41. * Same as {@link renderToGBuffer} but for depth only, not normal or flags etc
  42. */
  43. renderToDepth?: boolean
  44. // only for materials that have envMapIntensity
  45. separateEnvMapIntensity?: boolean // default: false
  46. cloneId?: string
  47. cloneCount?: number
  48. __envIntensity?: number // temp storage for envMapIntensity while rendering
  49. __isVariation?: boolean
  50. inverseAlphaMap?: boolean // only for physical material right now
  51. /**
  52. * See {@link MaterialManager.dispose} as {@link BaseGroundPlugin._refreshMaterial}
  53. */
  54. runtimeMaterial?: boolean
  55. /**
  56. * See {@link GBufferPlugin}
  57. */
  58. gBufferData?: {
  59. materialId?: number
  60. /**
  61. * @default true
  62. */
  63. tonemapEnabled?: boolean
  64. [key: string]: any
  65. }
  66. // todo: move these to respective plugins
  67. /**
  68. * For SSCSPlugin
  69. */
  70. sscsDisabled?: boolean
  71. /**
  72. * For SSRPlugin
  73. */
  74. ssreflDisabled?: boolean
  75. /**
  76. * For SSRPlugin
  77. */
  78. ssreflNonPhysical?: boolean
  79. [key: string]: any
  80. // legacy, to be removed
  81. /**
  82. * @deprecated
  83. */
  84. setDirty?: (options?: IMaterialSetDirtyOptions) => void
  85. /**
  86. * @deprecated Use {@link postTonemap.tonemapEnabled} instead. This is kept because used in old files.
  87. */
  88. postTonemap?: boolean
  89. }
  90. export interface IMaterial<E extends IMaterialEvent = IMaterialEvent, ET = IMaterialEventTypes> extends Material<E, ET>, IJSONSerializable, IDisposable, IUiConfigContainer {
  91. constructor: {
  92. TYPE: string
  93. TypeSlug: string
  94. MaterialProperties?: Record<string, any>
  95. MaterialTemplate?: IMaterialTemplate
  96. }
  97. assetType: 'material'
  98. setDirty(options?: IMaterialSetDirtyOptions): void;
  99. // clone?: ()=> any;
  100. needsUpdate: boolean;
  101. // toJSON same as three.js Material.toJSON
  102. // toJSON(meta?: any): any;
  103. // copyProps should be just setValues
  104. setValues(parameters: Material|(MaterialParameters&{type?:string}), allowInvalidType?: boolean, clearCurrentUserData?: boolean): this;
  105. toJSON(meta?: SerializationMetaType, _internal?: boolean): any;
  106. fromJSON(json: any, meta?: SerializationMetaType, _internal?: boolean): this | null;
  107. extraUniformsToUpload: Record<string, IUniform>
  108. materialExtensions: MaterialExtension[]
  109. registerMaterialExtensions: (customMaterialExtensions: MaterialExtension[]) => void;
  110. unregisterMaterialExtensions: (customMaterialExtensions: MaterialExtension[]) => void;
  111. /**
  112. * Managed internally, do not change manually
  113. */
  114. generator?: IMaterialGenerator
  115. /**
  116. * Managed internally, do not change manually
  117. */
  118. appliedMeshes: Set<IObject3D>
  119. lastShader?: Shader
  120. // Note: for userData: add _ in front of for private use, which is preserved while cloning but not serialisation, and __ for private use, which is not preserved while cloning and serialisation
  121. userData: IMaterialUserData
  122. /**
  123. * Disposes the material from the GPU.
  124. * Set force to false if not sure the material is used by any object in the scene.
  125. * // todo add check for visible in scene also? or is that overkill
  126. * @param force - when true, same as three.js dispose. when false, only disposes if disposeOnIdle not false and not used by any object in the scene. default: true
  127. */
  128. dispose(force?: boolean): void
  129. // optional from subclasses, added here for autocomplete
  130. flatShading?: boolean
  131. map?: ITexture | null
  132. alphaMap?: ITexture | null
  133. envMap?: ITexture | null
  134. envMapIntensity?: number
  135. aoMap?: ITexture | null
  136. lightMap?: ITexture | null
  137. normalMap?: ITexture | null
  138. bumpMap?: ITexture | null
  139. displacementMap?: ITexture | null
  140. aoMapIntensity?: number
  141. lightMapIntensity?: number
  142. roughnessMap?: ITexture | null
  143. metalnessMap?: ITexture | null
  144. roughness?: number
  145. metalness?: number
  146. transmissionMap?: ITexture | null
  147. transmission?: number
  148. color?: Color
  149. wireframe?: boolean
  150. linewidth?: number
  151. isRawShaderMaterial?: boolean
  152. isPhysicalMaterial?: boolean
  153. isUnlitMaterial?: boolean
  154. isGBufferMaterial?: boolean
  155. // [key: string]: any
  156. }
  157. export type IMaterialGenerator<T extends IMaterial = IMaterial> = (params: any)=>T
  158. export interface IMaterialTemplate<T extends IMaterial = IMaterial, TP = any>{
  159. templateUUID?: string,
  160. name: string,
  161. typeSlug?: string,
  162. alias?: string[], // alternate names
  163. materialType: string,
  164. generator?: IMaterialGenerator<T>,
  165. params?: TP
  166. }