UNPKG

threepipe

Version:

A 3D viewer framework built on top of three.js in TypeScript with a focus on quality rendering, modularity and extensibility.

51 lines (43 loc) 1.68 kB
import {IMaterial} from './IMaterial' import {Event, Source, Texture} from 'three' import {ChangeEvent} from 'uiconfig.js' import {IRenderTarget} from '../rendering' export interface ITextureUserData{ mimeType?: string embedUrlImagePreviews?: boolean /** * Automatically dispose texture when not used by any material that's applied to some object in the scene. * Works only after it's applied to a material once. */ disposeOnIdle?: boolean } export type ITextureEventTypes = 'dispose' | 'update' export type ITextureEvent<T extends string = ITextureEventTypes> = Event & { type: T texture?: ITexture uiChangeEvent?: ChangeEvent } export interface ITexture extends Texture { assetType?: 'texture' userData: ITextureUserData readonly isTexture: true isDataTexture?: boolean isCubeTexture?: boolean isVideoTexture?: boolean isCanvasTexture?: boolean isCompressedTexture?: boolean is3DDataTexture?: boolean setDirty?(): void source: Source & { _sourceImgBuffer?: ArrayBuffer|Uint8Array // see KTX2LoadPlugin and serializeTextureInExtras } _appliedMaterials?: Set<IMaterial> // for internal use only. refers to the materials that this texture is applied to _target?: IRenderTarget // for internal use only. refers to the render target that this texture is attached to } export function upgradeTexture(this: ITexture) { this.assetType = 'texture' if (!this.userData) this.userData = {} if (!this._appliedMaterials) this._appliedMaterials = new Set() if (!this.setDirty) this.setDirty = ()=>this.needsUpdate = true // todo: uiconfig, dispose, etc }