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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. __appliedMaterials?: Set<IMaterial>
  14. }
  15. export type ITextureEventTypes = 'dispose' | 'update'
  16. export type ITextureEvent<T extends string = ITextureEventTypes> = Event & {
  17. type: T
  18. texture?: ITexture
  19. uiChangeEvent?: ChangeEvent
  20. }
  21. export interface ITexture extends Texture {
  22. assetType?: 'texture'
  23. userData: ITextureUserData
  24. readonly isTexture: true
  25. isDataTexture?: boolean
  26. isCubeTexture?: boolean
  27. isVideoTexture?: boolean
  28. isCanvasTexture?: boolean
  29. isCompressedTexture?: boolean
  30. is3DDataTexture?: boolean
  31. setDirty?(): void
  32. source: Source & {
  33. _sourceImgBuffer?: ArrayBuffer // see KTX2LoadPlugin and serializeTextureInExtras
  34. }
  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.userData.__appliedMaterials) this.userData.__appliedMaterials = new Set()
  41. if (!this.setDirty) this.setDirty = ()=>this.needsUpdate = true
  42. // todo: uiconfig, dispose, etc
  43. }