threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ITexture.ts 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import {IMaterial} from './IMaterial'
  2. import {Event, Source, Texture} from 'three'
  3. import {ChangeEvent} from 'uiconfig.js'
  4. import {IRenderTarget} from '../rendering'
  5. export interface ITextureUserData{
  6. mimeType?: string
  7. embedUrlImagePreviews?: boolean
  8. /**
  9. * Automatically dispose texture when not used by any material that's applied to some object in the scene.
  10. * Works only after it's applied to a material once.
  11. */
  12. disposeOnIdle?: boolean
  13. }
  14. export type ITextureEventTypes = 'dispose' | 'update'
  15. export type ITextureEvent<T extends string = ITextureEventTypes> = Event & {
  16. type: T
  17. texture?: ITexture
  18. uiChangeEvent?: ChangeEvent
  19. }
  20. export interface ITexture extends Texture {
  21. assetType?: 'texture'
  22. userData: ITextureUserData
  23. readonly isTexture: true
  24. isDataTexture?: boolean
  25. isCubeTexture?: boolean
  26. isVideoTexture?: boolean
  27. isCanvasTexture?: boolean
  28. isCompressedTexture?: boolean
  29. is3DDataTexture?: boolean
  30. setDirty?(): void
  31. source: Source & {
  32. _sourceImgBuffer?: ArrayBuffer // see KTX2LoadPlugin and serializeTextureInExtras
  33. }
  34. _appliedMaterials?: Set<IMaterial> // for internal use only. refers to the materials that this texture is applied to
  35. _target?: IRenderTarget // for internal use only. refers to the render target that this texture is attached to
  36. }
  37. export function upgradeTexture(this: ITexture) {
  38. this.assetType = 'texture'
  39. if (!this.userData) this.userData = {}
  40. if (!this._appliedMaterials) this._appliedMaterials = new Set()
  41. if (!this.setDirty) this.setDirty = ()=>this.needsUpdate = true
  42. // todo: uiconfig, dispose, etc
  43. }