@needle-tools/gltf-progressive 3.0.0 → 3.1.0-next.f550970

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.
@@ -50,3 +50,60 @@ 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
+ }
61
+ export class PromiseQueue {
62
+ maxConcurrent;
63
+ _running = new Map();
64
+ _queue = [];
65
+ debug = false;
66
+ constructor(maxConcurrent = 100, opts = {}) {
67
+ this.maxConcurrent = maxConcurrent;
68
+ this.debug = opts.debug ?? false;
69
+ window.requestAnimationFrame(this.tick);
70
+ }
71
+ tick = () => {
72
+ this.internalUpdate();
73
+ setTimeout(this.tick, 10);
74
+ };
75
+ /**
76
+ * Request a slot for a promise with a specific key. This function returns a promise with a `use` method that can be called to add the promise to the queue.
77
+ */
78
+ slot(key) {
79
+ if (this.debug)
80
+ console.debug(`[PromiseQueue]: Requesting slot for key ${key}, running: ${this._running.size}, waiting: ${this._queue.length}`);
81
+ return new Promise((resolve) => {
82
+ this._queue.push({ key, resolve });
83
+ });
84
+ }
85
+ add(key, promise) {
86
+ if (this._running.has(key))
87
+ return;
88
+ this._running.set(key, promise);
89
+ promise.finally(() => {
90
+ this._running.delete(key);
91
+ if (this.debug)
92
+ console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${key})`);
93
+ });
94
+ if (this.debug)
95
+ console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${key})`);
96
+ }
97
+ internalUpdate() {
98
+ // Run for as many free slots as we can
99
+ const diff = this.maxConcurrent - this._running.size;
100
+ for (let i = 0; i < diff && this._queue.length > 0; i++) {
101
+ if (this.debug)
102
+ console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);
103
+ const { key, resolve } = this._queue.shift();
104
+ resolve({
105
+ use: (promise) => this.add(key, promise)
106
+ });
107
+ }
108
+ }
109
+ }
package/lib/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // replaced at build time
2
- export const version = "3.0.0-alpha";
2
+ export const version = "3.1.0";
3
3
  globalThis["GLTF_PROGRESSIVE_VERSION"] = version;
4
4
  console.debug(`[gltf-progressive] version ${version || "-"}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-progressive",
3
- "version": "3.0.0",
3
+ "version": "3.1.0-next.f550970",
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": {