import { BufferGeometry, Material, Mesh, Texture } from "three"; import { type GLTF, type GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader.js"; import { NEEDLE_ext_progressive_mesh, NEEDLE_ext_progressive_texture } from "./extension.model.js"; export declare const EXTENSION_NAME = "NEEDLE_progressive"; /** * This is the result of a progressive texture loading event for a material's texture slot in {@link NEEDLE_progressive.assignTextureLOD} * @internal */ type ProgressiveMaterialTextureLoadingResult = { /** the material the progressive texture was loaded for */ material: Material; /** the slot in the material where the texture was loaded */ slot: string; /** the texture that was loaded (if any) */ texture: Texture | null; /** the level of detail that was loaded */ level: number; }; type TextureLODsMinMaxInfo = { min_count: number; max_count: number; lods: Array<{ min_height: number; max_height: number; }>; }; /** * The NEEDLE_progressive extension for the GLTFLoader is responsible for loading progressive LODs for meshes and textures. * This extension can be used to load different resolutions of a mesh or texture at runtime (e.g. for LODs or progressive textures). * @example * ```javascript * const loader = new GLTFLoader(); * loader.register(new NEEDLE_progressive()); * loader.load("model.glb", (gltf) => { * const mesh = gltf.scene.children[0] as Mesh; * NEEDLE_progressive.assignMeshLOD(context, sourceId, mesh, 1).then(mesh => { * console.log("Mesh with LOD level 1 loaded", mesh); * }); * }); * ``` */ export declare class NEEDLE_progressive implements GLTFLoaderPlugin { /** The name of the extension */ get name(): string; static getMeshLODExtension(geo: BufferGeometry): NEEDLE_ext_progressive_mesh | null; static getPrimitiveIndex(geo: BufferGeometry): number; static getMaterialMinMaxLODsCount(material: Material | Material[], minmax?: TextureLODsMinMaxInfo): TextureLODsMinMaxInfo; /** Check if a LOD level is available for a mesh or a texture * @param obj the mesh or texture to check * @param level the level of detail to check for (0 is the highest resolution). If undefined, the function checks if any LOD level is available * @returns true if the LOD level is available (or if any LOD level is available if level is undefined) */ static hasLODLevelAvailable(obj: Mesh | BufferGeometry | Texture | Material | Material[], level?: number): boolean; /** Load a different resolution of a mesh (if available) * @param context the context * @param source the sourceid of the file from which the mesh is loaded (this is usually the component's sourceId) * @param mesh the mesh to load the LOD for * @param level the level of detail to load (0 is the highest resolution) * @returns a promise that resolves to the mesh with the requested LOD level * @example * ```javascript * const mesh = this.gameObject as Mesh; * NEEDLE_progressive.assignMeshLOD(context, sourceId, mesh, 1).then(mesh => { * console.log("Mesh with LOD level 1 loaded", mesh); * }); * ``` */ static assignMeshLOD(mesh: Mesh, level: number): Promise; /** Load a different resolution of a texture (if available) * @param context the context * @param source the sourceid of the file from which the texture is loaded (this is usually the component's sourceId) * @param materialOrTexture the material or texture to load the LOD for (if passing in a material all textures in the material will be loaded) * @param level the level of detail to load (0 is the highest resolution) - currently only 0 is supported * @returns a promise that resolves to the material or texture with the requested LOD level */ static assignTextureLOD(materialOrTexture: Material, level: number): Promise | null>; static assignTextureLOD(materialOrTexture: Mesh, level: number): Promise | null>; static assignTextureLOD(materialOrTexture: Texture, level: number): Promise; /** * Set the maximum number of concurrent loading tasks for LOD resources. This limits how many LOD resources (meshes or textures) can be loaded at the same time to prevent overloading the network or GPU. If the limit is reached, additional loading requests will be queued and processed as previous ones finish. * @default 50 on desktop, 20 on mobile devices */ static set maxConcurrentLoadingTasks(value: number); static get maxConcurrentLoadingTasks(): number; private static assignTextureLODForSlot; private readonly parser; private readonly url; constructor(parser: GLTFParser); private _isLoadingMesh; loadMesh: (meshIndex: number) => Promise | null; afterRoot(gltf: GLTF): null; /** * Register a texture with LOD information */ static registerTexture: (url: string, tex: Texture, level: number, index: number, ext: NEEDLE_ext_progressive_texture) => void; /** * Register a mesh with LOD information */ static registerMesh: (url: string, key: string, mesh: Mesh, level: number, index: number, ext: NEEDLE_ext_progressive_mesh) => void; /** * Dispose cached resources to free memory. * Call this when a model is removed from the scene to allow garbage collection of its LOD resources. * Calls three.js `.dispose()` on cached Textures and BufferGeometries to free GPU memory. * Also clears reference counts for disposed textures. * @param guid Optional GUID to dispose resources for a specific model. If omitted, all cached resources are cleared. */ static dispose(guid?: string): void; /** Dispose a single cache entry's three.js resource(s) to free GPU memory. */ private static _disposeCacheEntry; /** A map of key = asset uuid and value = LOD information */ private static readonly lodInfos; /** cache of already loaded mesh lods. Uses WeakRef for single resources to allow garbage collection when unused. */ private static readonly cache; /** this contains the geometry/textures that were originally loaded. Uses WeakRef to allow garbage collection when unused. */ private static readonly lowresCache; /** Reference counting for textures to track usage across multiple materials/objects */ private static readonly textureRefCounts; /** * FinalizationRegistry to automatically clean up `previouslyLoaded` cache entries * when their associated three.js resources are garbage collected by the browser. * The held value is the cache key string used in `previouslyLoaded`. */ private static readonly _resourceRegistry; /** * Track texture usage by incrementing reference count */ private static trackTextureUsage; /** * Untrack texture usage by decrementing reference count. * Automatically disposes the texture when reference count reaches zero. * @returns true if the texture was disposed, false otherwise */ private static untrackTextureUsage; private static readonly workers; private static _workersIndex; private static getOrLoadLOD; private static queue; private static assignLODInformation; private static getAssignedLODInformation; private static copySettings; } export {};