@needle-tools/gltf-progressive 3.0.0 → 3.0.1
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 +2 -1
- package/gltf-progressive.js +602 -494
- package/gltf-progressive.min.js +7 -7
- package/gltf-progressive.umd.cjs +7 -7
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/lib/{lods_manager.d.ts → lods.manager.d.ts} +15 -3
- package/lib/{lods_manager.js → lods.manager.js} +40 -11
- package/lib/lods.promise.d.ts +61 -0
- package/lib/lods.promise.js +101 -0
- package/lib/plugins/modelviewer.js +1 -1
- package/lib/utils.internal.d.ts +1 -0
- package/lib/utils.internal.js +8 -0
- package/lib/version.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { debug } from "./lods.debug";
|
|
2
|
+
/**
|
|
3
|
+
* A group of promises that can be awaited together.
|
|
4
|
+
* This is used for awaiting LOD
|
|
5
|
+
*/
|
|
6
|
+
export class PromiseGroup {
|
|
7
|
+
static addPromise = (type, object, promise, groups) => {
|
|
8
|
+
groups.forEach(group => {
|
|
9
|
+
group.add(type, object, promise);
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
frame_start;
|
|
13
|
+
frame_capture_end;
|
|
14
|
+
ready;
|
|
15
|
+
_resolve;
|
|
16
|
+
_signal;
|
|
17
|
+
/**
|
|
18
|
+
* The number of promises that have been added to this group so far.
|
|
19
|
+
*/
|
|
20
|
+
get awaitedCount() {
|
|
21
|
+
return this._addedCount;
|
|
22
|
+
}
|
|
23
|
+
get resolvedCount() {
|
|
24
|
+
return this._resolvedCount;
|
|
25
|
+
}
|
|
26
|
+
get currentlyAwaiting() {
|
|
27
|
+
return this._awaiting.length;
|
|
28
|
+
}
|
|
29
|
+
_resolved = false;
|
|
30
|
+
_addedCount = 0;
|
|
31
|
+
_resolvedCount = 0;
|
|
32
|
+
/** These promises are currently being awaited */
|
|
33
|
+
_awaiting = [];
|
|
34
|
+
_maxPromisesPerObject = 1;
|
|
35
|
+
constructor(frame, options) {
|
|
36
|
+
const minFrames = 2; // wait at least 2 frames to capture promises
|
|
37
|
+
const framesToCapture = Math.max(options.frames ?? minFrames, minFrames); // default to 2 frames and make sure it's at least 2 frames
|
|
38
|
+
this.frame_start = frame;
|
|
39
|
+
this.frame_capture_end = frame + framesToCapture;
|
|
40
|
+
this.ready = new Promise((resolve) => {
|
|
41
|
+
this._resolve = resolve;
|
|
42
|
+
});
|
|
43
|
+
this.ready.finally(() => {
|
|
44
|
+
this._resolved = true;
|
|
45
|
+
this._awaiting.length = 0;
|
|
46
|
+
});
|
|
47
|
+
this._signal = options.signal;
|
|
48
|
+
this._signal?.addEventListener("abort", () => {
|
|
49
|
+
this.resolveNow();
|
|
50
|
+
});
|
|
51
|
+
this._maxPromisesPerObject = Math.max(1, options.maxPromisesPerObject ?? 1);
|
|
52
|
+
}
|
|
53
|
+
_currentFrame = 0;
|
|
54
|
+
update(frame) {
|
|
55
|
+
this._currentFrame = frame;
|
|
56
|
+
// If we've passes the frame capture end frame and didn't add any promises, we resolve immediately
|
|
57
|
+
if (this._signal?.aborted || (this._currentFrame > this.frame_capture_end && this._awaiting.length === 0)) {
|
|
58
|
+
this.resolveNow();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
_seen = new WeakMap();
|
|
62
|
+
add(_type, object, promise) {
|
|
63
|
+
if (this._resolved) {
|
|
64
|
+
if (debug)
|
|
65
|
+
console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (this._currentFrame > this.frame_capture_end) {
|
|
69
|
+
return; // we are not capturing any more promises
|
|
70
|
+
}
|
|
71
|
+
if (this._maxPromisesPerObject >= 1) {
|
|
72
|
+
if (this._seen.has(object)) {
|
|
73
|
+
let count = this._seen.get(object);
|
|
74
|
+
if (count >= this._maxPromisesPerObject) {
|
|
75
|
+
if (debug)
|
|
76
|
+
console.warn(`PromiseGroup: Already awaiting object ignoring new promise for it.`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
this._seen.set(object, count + 1);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
this._seen.set(object, 1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
this._awaiting.push(promise);
|
|
86
|
+
this._addedCount++;
|
|
87
|
+
promise.finally(() => {
|
|
88
|
+
this._resolvedCount++;
|
|
89
|
+
this._awaiting.splice(this._awaiting.indexOf(promise), 1);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
resolveNow() {
|
|
93
|
+
if (this._resolved)
|
|
94
|
+
return;
|
|
95
|
+
this._resolve?.({
|
|
96
|
+
awaited_count: this._addedCount,
|
|
97
|
+
resolved_count: this._resolvedCount,
|
|
98
|
+
cancelled: this._signal?.aborted ?? false,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LODsManager } from "../
|
|
1
|
+
import { LODsManager } from "../lods.manager.js";
|
|
2
2
|
import { EXTENSION_NAME, NEEDLE_progressive } from "../extension.js";
|
|
3
3
|
const $meshLODSymbol = Symbol("NEEDLE_mesh_lod");
|
|
4
4
|
const $textureLODSymbol = Symbol("NEEDLE_texture_lod");
|
package/lib/utils.internal.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export declare function getParam(name: string): boolean | string;
|
|
|
3
3
|
export declare function resolveUrl(source: string | undefined, uri: string): string;
|
|
4
4
|
/** @returns `true` if it's a phone or tablet */
|
|
5
5
|
export declare function isMobileDevice(): boolean;
|
|
6
|
+
export declare function isDevelopmentServer(): boolean;
|
package/lib/utils.internal.js
CHANGED
|
@@ -50,3 +50,11 @@ export function isMobileDevice() {
|
|
|
50
50
|
console.log("[glTF Progressive]: isMobileDevice", _ismobile);
|
|
51
51
|
return _ismobile;
|
|
52
52
|
}
|
|
53
|
+
export function isDevelopmentServer() {
|
|
54
|
+
if (typeof window === "undefined")
|
|
55
|
+
return false;
|
|
56
|
+
const url = new URL(window.location.href);
|
|
57
|
+
const isLocalhostOrIpAddress = url.hostname === "localhost" || /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(url.hostname);
|
|
58
|
+
const isDevelopment = url.hostname === "127.0.0.1" || isLocalhostOrIpAddress;
|
|
59
|
+
return isDevelopment;
|
|
60
|
+
}
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/gltf-progressive",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "three.js support for loading glTF or GLB files that contain progressive loading data",
|
|
5
5
|
"homepage": "https://needle.tools",
|
|
6
6
|
"author": {
|
|
@@ -72,4 +72,4 @@
|
|
|
72
72
|
"vite": "<= 4.3.9"
|
|
73
73
|
},
|
|
74
74
|
"types": "./lib/index.d.ts"
|
|
75
|
-
}
|
|
75
|
+
}
|