@needle-tools/gltf-progressive 4.0.0-alpha.1 → 4.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -1
- package/LICENSE +21 -0
- package/README.md +47 -11
- package/examples/modelviewer-multiple.html +4 -4
- package/examples/modelviewer.html +4 -4
- package/examples/offscreen/index.html +15 -0
- package/examples/offscreen/main.js +98 -0
- package/examples/react-three-fiber/index.html +2 -2
- package/examples/react-three-fiber/package-lock.json +482 -484
- package/examples/react-three-fiber/package.json +4 -4
- package/examples/react-three-fiber/src/App.tsx +76 -21
- package/examples/react-three-fiber/src/styles.css +2 -4
- package/examples/react-three-fiber/vite.config.js +2 -2
- package/examples/shared/example-utils.js +297 -0
- package/examples/shared/example.css +44 -0
- package/examples/shared/runtime.js +34 -0
- package/examples/threejs/index.html +6 -10
- package/examples/threejs/main.js +5 -23
- package/examples/webgpu/index.html +15 -0
- package/examples/webgpu/main.js +105 -0
- package/examples/worker-rendering/index.html +15 -0
- package/examples/worker-rendering/main.js +109 -0
- package/examples/worker-rendering/worker.js +166 -0
- package/gltf-progressive.js +1025 -669
- package/gltf-progressive.min.js +9 -9
- package/gltf-progressive.umd.cjs +9 -9
- package/lib/extension.d.ts +73 -7
- package/lib/extension.js +351 -111
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/loaders.js +17 -3
- package/lib/lods.debug.js +2 -2
- package/lib/lods.manager.d.ts +93 -15
- package/lib/lods.manager.js +331 -157
- package/lib/lods.promise.js +1 -1
- package/lib/plugins/modelviewer.js +1 -1
- package/lib/utils.internal.js +20 -6
- package/lib/version.js +1 -1
- package/lib/worker/loader.mainthread.js +4 -1
- package/package.json +10 -3
package/lib/extension.d.ts
CHANGED
|
@@ -24,6 +24,10 @@ type TextureLODsMinMaxInfo = {
|
|
|
24
24
|
max_height: number;
|
|
25
25
|
}>;
|
|
26
26
|
};
|
|
27
|
+
export type AssignTextureLODOptions = {
|
|
28
|
+
/** Force the exact requested level. Intended for explicit/debug LOD overrides. */
|
|
29
|
+
force?: boolean;
|
|
30
|
+
};
|
|
27
31
|
/**
|
|
28
32
|
* The NEEDLE_progressive extension for the GLTFLoader is responsible for loading progressive LODs for meshes and textures.
|
|
29
33
|
* This extension can be used to load different resolutions of a mesh or texture at runtime (e.g. for LODs or progressive textures).
|
|
@@ -42,8 +46,31 @@ type TextureLODsMinMaxInfo = {
|
|
|
42
46
|
export declare class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
43
47
|
/** The name of the extension */
|
|
44
48
|
get name(): string;
|
|
49
|
+
/**
|
|
50
|
+
* Get the progressive mesh LOD extension data associated with a geometry.
|
|
51
|
+
* Returns the extension metadata (available LOD levels, vertex/index counts, densities) if the geometry was registered with progressive LODs, or `null` otherwise.
|
|
52
|
+
*
|
|
53
|
+
* @param geo - The buffer geometry to look up.
|
|
54
|
+
* @returns The mesh LOD extension data, or `null` if no progressive LODs are registered for this geometry.
|
|
55
|
+
*/
|
|
45
56
|
static getMeshLODExtension(geo: BufferGeometry): NEEDLE_ext_progressive_mesh | null;
|
|
57
|
+
/**
|
|
58
|
+
* Get the glTF primitive index for a geometry within its parent mesh.
|
|
59
|
+
* A single glTF mesh node can contain multiple primitives (sub-geometries). This returns which primitive the geometry corresponds to.
|
|
60
|
+
*
|
|
61
|
+
* @param geo - The buffer geometry to look up.
|
|
62
|
+
* @returns The zero-based primitive index, or `-1` if no LOD information is assigned to this geometry.
|
|
63
|
+
*/
|
|
46
64
|
static getPrimitiveIndex(geo: BufferGeometry): number;
|
|
65
|
+
/**
|
|
66
|
+
* Compute the minimum and maximum number of texture LOD levels across all textures of a material (or array of materials).
|
|
67
|
+
* Iterates over all texture slots on the material and collects LOD count ranges and per-level resolution bounds.
|
|
68
|
+
* Results are cached on the material so subsequent calls are free.
|
|
69
|
+
*
|
|
70
|
+
* @param material - A single material or an array of materials to inspect.
|
|
71
|
+
* @param minmax - Optional accumulator to merge results into (used internally for recursive calls with material arrays).
|
|
72
|
+
* @returns An object with `min_count` / `max_count` (the range of LOD levels across all textures) and a per-level `lods` array with `min_height` / `max_height`.
|
|
73
|
+
*/
|
|
47
74
|
static getMaterialMinMaxLODsCount(material: Material | Material[], minmax?: TextureLODsMinMaxInfo): TextureLODsMinMaxInfo;
|
|
48
75
|
/** Check if a LOD level is available for a mesh or a texture
|
|
49
76
|
* @param obj the mesh or texture to check
|
|
@@ -65,7 +92,10 @@ export declare class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
|
65
92
|
* });
|
|
66
93
|
* ```
|
|
67
94
|
*/
|
|
68
|
-
static assignMeshLOD(mesh: Mesh, level: number
|
|
95
|
+
static assignMeshLOD(mesh: Mesh, level: number, options?: {
|
|
96
|
+
/** If false, load and return the requested geometry without assigning it to the mesh. Pass a function to apply it manually. */
|
|
97
|
+
apply?: boolean | ((geometry: BufferGeometry, level: number, mesh: Mesh) => boolean | void);
|
|
98
|
+
}): Promise<BufferGeometry | null>;
|
|
69
99
|
/** Load a different resolution of a texture (if available)
|
|
70
100
|
* @param context the context
|
|
71
101
|
* @param source the sourceid of the file from which the texture is loaded (this is usually the component's sourceId)
|
|
@@ -73,9 +103,9 @@ export declare class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
|
73
103
|
* @param level the level of detail to load (0 is the highest resolution) - currently only 0 is supported
|
|
74
104
|
* @returns a promise that resolves to the material or texture with the requested LOD level
|
|
75
105
|
*/
|
|
76
|
-
static assignTextureLOD(materialOrTexture: Material, level: number): Promise<Array<ProgressiveMaterialTextureLoadingResult> | null>;
|
|
77
|
-
static assignTextureLOD(materialOrTexture: Mesh, level: number): Promise<Array<ProgressiveMaterialTextureLoadingResult> | null>;
|
|
78
|
-
static assignTextureLOD(materialOrTexture: Texture, level: number): Promise<Texture | null>;
|
|
106
|
+
static assignTextureLOD(materialOrTexture: Material, level: number, options?: AssignTextureLODOptions): Promise<Array<ProgressiveMaterialTextureLoadingResult> | null>;
|
|
107
|
+
static assignTextureLOD(materialOrTexture: Mesh, level: number, options?: AssignTextureLODOptions): Promise<Array<ProgressiveMaterialTextureLoadingResult> | null>;
|
|
108
|
+
static assignTextureLOD(materialOrTexture: Texture, level: number, options?: AssignTextureLODOptions): Promise<Texture | null>;
|
|
79
109
|
/**
|
|
80
110
|
* 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.
|
|
81
111
|
* @default 50 on desktop, 20 on mobile devices
|
|
@@ -83,6 +113,22 @@ export declare class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
|
83
113
|
static set maxConcurrentLoadingTasks(value: number);
|
|
84
114
|
static get maxConcurrentLoadingTasks(): number;
|
|
85
115
|
private static assignTextureLODForSlot;
|
|
116
|
+
private static trackedTextureSlots;
|
|
117
|
+
private static pendingTextureSlotRequests;
|
|
118
|
+
private static latestTextureSlotRequests;
|
|
119
|
+
private static textureSlotRequestId;
|
|
120
|
+
private static trackCurrentMaterialTextureSlots;
|
|
121
|
+
private static getPendingTextureSlotRequest;
|
|
122
|
+
private static nextTextureSlotRequestId;
|
|
123
|
+
private static getLatestTextureSlotRequest;
|
|
124
|
+
private static shouldApplyStaleTextureSlotLOD;
|
|
125
|
+
private static shouldApplyStaleMeshLOD;
|
|
126
|
+
private static setPendingTextureSlotRequest;
|
|
127
|
+
private static getMaterialTextureSlot;
|
|
128
|
+
private static setMaterialTextureSlot;
|
|
129
|
+
private static assignTrackedTextureSlot;
|
|
130
|
+
private static ensureTrackedTextureSlot;
|
|
131
|
+
private static releaseTrackedTextureSlot;
|
|
86
132
|
private readonly parser;
|
|
87
133
|
private readonly url;
|
|
88
134
|
constructor(parser: GLTFParser);
|
|
@@ -90,11 +136,29 @@ export declare class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
|
90
136
|
loadMesh: (meshIndex: number) => Promise<any> | null;
|
|
91
137
|
afterRoot(gltf: GLTF): null;
|
|
92
138
|
/**
|
|
93
|
-
* Register a texture with LOD information
|
|
139
|
+
* Register a texture with progressive LOD information. This associates the texture with its LOD extension data
|
|
140
|
+
* so the LODs manager can later swap it for higher or lower resolution versions based on screen coverage.
|
|
141
|
+
* Typically called during glTF loading when the progressive extension is parsed.
|
|
142
|
+
*
|
|
143
|
+
* @param url - The source URL of the glTF file this texture was loaded from.
|
|
144
|
+
* @param tex - The three.js Texture instance to register.
|
|
145
|
+
* @param level - The LOD level this texture represents (0 = highest resolution).
|
|
146
|
+
* @param index - The texture index within the glTF file.
|
|
147
|
+
* @param ext - The parsed progressive texture extension data containing all available LOD levels and their dimensions.
|
|
94
148
|
*/
|
|
95
149
|
static registerTexture: (url: string, tex: Texture, level: number, index: number, ext: NEEDLE_ext_progressive_texture) => void;
|
|
96
150
|
/**
|
|
97
|
-
* Register a mesh with LOD information
|
|
151
|
+
* Register a mesh with progressive LOD information. This associates the mesh geometry with its LOD extension data
|
|
152
|
+
* so the LODs manager can later swap it for higher or lower density versions based on screen coverage.
|
|
153
|
+
* Typically called during glTF loading when the progressive extension is parsed.
|
|
154
|
+
* If the mesh is registered at a level > 0 (i.e. not full resolution), a raycast mesh is automatically preserved for accurate picking.
|
|
155
|
+
*
|
|
156
|
+
* @param url - The source URL of the glTF file this mesh was loaded from.
|
|
157
|
+
* @param key - A unique key identifying this mesh's LOD group (typically derived from the extension GUID).
|
|
158
|
+
* @param mesh - The three.js Mesh instance to register.
|
|
159
|
+
* @param level - The LOD level this mesh represents (0 = highest resolution / full density).
|
|
160
|
+
* @param index - The primitive index within the glTF mesh node.
|
|
161
|
+
* @param ext - The parsed progressive mesh extension data containing all available LOD levels with vertex/index counts and densities.
|
|
98
162
|
*/
|
|
99
163
|
static registerMesh: (url: string, key: string, mesh: Mesh, level: number, index: number, ext: NEEDLE_ext_progressive_mesh) => void;
|
|
100
164
|
/**
|
|
@@ -134,7 +198,9 @@ export declare class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
|
134
198
|
private static readonly workers;
|
|
135
199
|
private static _workersIndex;
|
|
136
200
|
private static getOrLoadLOD;
|
|
137
|
-
private static
|
|
201
|
+
private static tryResolveLODCacheEntry;
|
|
202
|
+
private static _queue;
|
|
203
|
+
private static get queue();
|
|
138
204
|
private static assignLODInformation;
|
|
139
205
|
private static getAssignedLODInformation;
|
|
140
206
|
private static copySettings;
|