@needle-tools/gltf-progressive 3.5.0-rc → 3.6.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 +14 -1
- package/LICENSE +21 -0
- package/gltf-progressive.js +896 -636
- package/gltf-progressive.min.js +9 -9
- package/gltf-progressive.umd.cjs +9 -9
- package/lib/extension.d.ts +65 -6
- package/lib/extension.js +278 -110
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/lods.debug.js +1 -1
- package/lib/lods.manager.d.ts +90 -15
- package/lib/lods.manager.js +282 -150
- package/lib/lods.promise.js +1 -1
- package/lib/plugins/modelviewer.js +1 -1
- package/lib/version.js +1 -1
- package/package.json +4 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { version as VERSION } from "./version.js";
|
|
2
2
|
export * from "./extension.js";
|
|
3
3
|
export * from "./plugins/index.js";
|
|
4
|
-
export { LODsManager, type LOD_Results } from "./lods.manager.js";
|
|
4
|
+
export { LODsManager, calculateMeshLODLevel, getLODColor, lodDebugColors, type LOD_Results, type MeshLODSelectionOptions, type MeshLODSelectionResult } from "./lods.manager.js";
|
|
5
5
|
export { setDracoDecoderLocation, setKTX2TranscoderLocation, createLoaders, addDracoAndKTX2Loaders, configureLoader } from "./loaders.js";
|
|
6
6
|
export { getRaycastMesh, registerRaycastMesh, useRaycastMeshes } from "./utils.js";
|
|
7
7
|
import { WebGLRenderer } from "three";
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { version as VERSION } from "./version.js";
|
|
2
2
|
export * from "./extension.js";
|
|
3
3
|
export * from "./plugins/index.js";
|
|
4
|
-
export { LODsManager } from "./lods.manager.js";
|
|
4
|
+
export { LODsManager, calculateMeshLODLevel, getLODColor, lodDebugColors } from "./lods.manager.js";
|
|
5
5
|
export { setDracoDecoderLocation, setKTX2TranscoderLocation, createLoaders, addDracoAndKTX2Loaders, configureLoader } from "./loaders.js";
|
|
6
6
|
export { getRaycastMesh, registerRaycastMesh, useRaycastMeshes } from "./utils.js";
|
|
7
7
|
import { addDracoAndKTX2Loaders, configureLoader, createLoaders } from "./loaders.js";
|
package/lib/lods.debug.js
CHANGED
|
@@ -3,7 +3,7 @@ export const debug = getParam("debugprogressive");
|
|
|
3
3
|
let debug_RenderWireframe = undefined;
|
|
4
4
|
export let debug_OverrideLodLevel = -1; // -1 is automatic
|
|
5
5
|
if (debug) {
|
|
6
|
-
|
|
6
|
+
const maxLevel = 6;
|
|
7
7
|
function debugToggleProgressive() {
|
|
8
8
|
debug_OverrideLodLevel += 1;
|
|
9
9
|
if (debug_OverrideLodLevel >= maxLevel) {
|
package/lib/lods.manager.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Camera, Material, Object3D, Scene, Texture, Vector3, WebGLRenderer } from "three";
|
|
1
|
+
import { Box3, BufferGeometry, Camera, Color, Material, Matrix4, Object3D, Scene, Texture, Vector3, WebGLRenderer } from "three";
|
|
2
2
|
import { NEEDLE_progressive_plugin } from "./plugins/plugin.js";
|
|
3
3
|
import { PromiseGroupOptions } from "./lods.promise.js";
|
|
4
4
|
export type LODManagerContext = {
|
|
@@ -8,6 +8,29 @@ export declare type LOD_Results = {
|
|
|
8
8
|
mesh_lod: number;
|
|
9
9
|
texture_lod: number;
|
|
10
10
|
};
|
|
11
|
+
export declare const lodDebugColors: number[];
|
|
12
|
+
export type MeshLODSelectionOptions = {
|
|
13
|
+
geometry: BufferGeometry;
|
|
14
|
+
matrixWorld: Matrix4;
|
|
15
|
+
camera: Camera;
|
|
16
|
+
projectionScreenMatrix: Matrix4;
|
|
17
|
+
desiredDensity: number;
|
|
18
|
+
canvasHeight?: number;
|
|
19
|
+
currentLevel?: number;
|
|
20
|
+
boundingBox?: Box3 | null;
|
|
21
|
+
xrEnabled?: boolean;
|
|
22
|
+
debugDrawLine?: (a: Vector3, b: Vector3, color: number) => void;
|
|
23
|
+
warnMissingPrimitiveDensities?: boolean;
|
|
24
|
+
target?: MeshLODSelectionResult;
|
|
25
|
+
};
|
|
26
|
+
export type MeshLODSelectionResult = {
|
|
27
|
+
level: number;
|
|
28
|
+
primitiveIndex: number;
|
|
29
|
+
screenCoverage: number;
|
|
30
|
+
screenspaceVolume: Vector3;
|
|
31
|
+
centrality: number;
|
|
32
|
+
};
|
|
33
|
+
export declare function calculateMeshLODLevel(options: MeshLODSelectionOptions): MeshLODSelectionResult;
|
|
11
34
|
declare type LODChangedEventListener = (args: {
|
|
12
35
|
type: "mesh" | "texture";
|
|
13
36
|
level: number;
|
|
@@ -98,17 +121,64 @@ export declare class LODsManager {
|
|
|
98
121
|
private readonly _newPromiseGroups;
|
|
99
122
|
private _promiseGroupIds;
|
|
100
123
|
/**
|
|
101
|
-
*
|
|
124
|
+
* Returns a promise that resolves once all LOD requests initiated during the next render cycles have finished loading.
|
|
125
|
+
* This is useful for hiding low-resolution placeholders (e.g. with a loading overlay or CSS blur) until high-quality assets are ready.
|
|
126
|
+
*
|
|
127
|
+
* By default, the returned promise captures LOD loading requests for 2 frames and resolves when all of them complete.
|
|
128
|
+
* Use `waitForFirstCapture` if no LOD requests may happen immediately (e.g. after a scene switch).
|
|
129
|
+
*
|
|
130
|
+
* @param opts - Optional configuration for how long to capture and what to wait for. See {@link PromiseGroupOptions}.
|
|
131
|
+
* @returns A promise that resolves with `{ cancelled, awaited_count, resolved_count }` once all captured LOD loads complete (or the signal aborts).
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* // Wait for initial LODs to finish loading, then remove a blur overlay
|
|
136
|
+
* const result = await lodsManager.awaitLoading({
|
|
137
|
+
* frames: 5,
|
|
138
|
+
* signal: AbortSignal.timeout(10_000),
|
|
139
|
+
* });
|
|
140
|
+
* console.log(`Loaded ${result.resolved_count} of ${result.awaited_count} LODs`);
|
|
141
|
+
* document.querySelector('.blur-overlay')?.remove();
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* // Wait until at least one LOD starts loading before resolving
|
|
147
|
+
* await lodsManager.awaitLoading({ waitForFirstCapture: true });
|
|
148
|
+
* ```
|
|
102
149
|
*/
|
|
103
150
|
awaitLoading(opts?: PromiseGroupOptions): Promise<{
|
|
104
151
|
cancelled: boolean;
|
|
105
152
|
awaited_count: number;
|
|
106
153
|
resolved_count: number;
|
|
107
154
|
}>;
|
|
155
|
+
/** Track LOD work started outside this manager so {@link awaitLoading} waits for it too. */
|
|
156
|
+
trackLoadingPromise<T>(type: "mesh" | "texture", object: object, promise: Promise<T>): Promise<T>;
|
|
108
157
|
private _postprocessPromiseGroups;
|
|
109
158
|
private readonly _lodchangedlisteners;
|
|
110
|
-
|
|
111
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Register a listener that is called whenever a mesh or texture LOD level has finished loading and has been applied.
|
|
161
|
+
* The listener receives the type of asset (`"mesh"` or `"texture"`), the new LOD level, and the affected object.
|
|
162
|
+
*
|
|
163
|
+
* @param evt - The event type. Currently only `"changed"` is supported.
|
|
164
|
+
* @param listener - Callback invoked after a LOD swap completes.
|
|
165
|
+
* @return A function to unregister the listener.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* lodsManager.addEventListener("changed", ({ type, level, object }) => {
|
|
170
|
+
* console.log(`${type} LOD changed to level ${level}`, object);
|
|
171
|
+
* });
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
addEventListener(evt: "changed", listener: LODChangedEventListener): () => void;
|
|
175
|
+
/**
|
|
176
|
+
* Remove a previously registered `"changed"` event listener.
|
|
177
|
+
* @param evt - The event type (`"changed"`).
|
|
178
|
+
* @param listener - The listener to remove.
|
|
179
|
+
* @return `true` if the listener was found and removed, `false` otherwise.
|
|
180
|
+
*/
|
|
181
|
+
removeEventListener(evt: "changed", listener: LODChangedEventListener): boolean;
|
|
112
182
|
private constructor();
|
|
113
183
|
private _fpsBuffer;
|
|
114
184
|
/**
|
|
@@ -116,6 +186,21 @@ export declare class LODsManager {
|
|
|
116
186
|
*/
|
|
117
187
|
enable(): void;
|
|
118
188
|
disable(): void;
|
|
189
|
+
/**
|
|
190
|
+
* Manually trigger a LOD update for a scene and camera.
|
|
191
|
+
* Only needed when {@link manual} is set to `true` — otherwise LOD updates happen automatically on each render call.
|
|
192
|
+
*
|
|
193
|
+
* @param scene - The scene containing objects with progressive LODs.
|
|
194
|
+
* @param camera - The camera used to determine screen coverage and LOD levels.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* const lodsManager = LODsManager.get(renderer);
|
|
199
|
+
* lodsManager.manual = true;
|
|
200
|
+
* // ... later, trigger an update at a specific point:
|
|
201
|
+
* lodsManager.update(scene, camera);
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
119
204
|
update(scene: Scene, camera: Camera): void;
|
|
120
205
|
private onAfterRender;
|
|
121
206
|
/**
|
|
@@ -138,18 +223,7 @@ export declare class LODsManager {
|
|
|
138
223
|
*/
|
|
139
224
|
private loadProgressiveMeshes;
|
|
140
225
|
private readonly _sphere;
|
|
141
|
-
private readonly _tempBox;
|
|
142
|
-
private readonly _tempBox2;
|
|
143
|
-
private readonly tempMatrix;
|
|
144
226
|
private readonly _tempWorldPosition;
|
|
145
|
-
private readonly _tempBoxSize;
|
|
146
|
-
private readonly _tempBox2Size;
|
|
147
|
-
private static corner0;
|
|
148
|
-
private static corner1;
|
|
149
|
-
private static corner2;
|
|
150
|
-
private static corner3;
|
|
151
|
-
private static readonly _tempPtInside;
|
|
152
|
-
private static isInside;
|
|
153
227
|
private static skinnedMeshBoundsFrameOffsetCounter;
|
|
154
228
|
private static $skinnedMeshBoundsOffset;
|
|
155
229
|
private calculateLodLevel;
|
|
@@ -162,4 +236,5 @@ declare class LOD_state {
|
|
|
162
236
|
readonly lastScreenspaceVolume: Vector3;
|
|
163
237
|
lastCentrality: number;
|
|
164
238
|
}
|
|
239
|
+
export declare function getLODColor(level: number, target: Color): Color;
|
|
165
240
|
export {};
|