@needle-tools/gltf-progressive 3.0.0-next.90239b7 → 3.0.0-next.d16d57f

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.
@@ -1,10 +1,11 @@
1
1
  import { Box3, Clock, Matrix4, Mesh, MeshStandardMaterial, Sphere, Vector3 } from "three";
2
2
  import { NEEDLE_progressive } from "./extension.js";
3
3
  import { createLoaders } from "./loaders.js";
4
- import { getParam, isMobileDevice } from "./utils.internal.js";
4
+ import { getParam, isDevelopmentServer, isMobileDevice } from "./utils.internal.js";
5
5
  import { plugins } from "./plugins/plugin.js";
6
6
  import { getRaycastMesh } from "./utils.js";
7
7
  import { applyDebugSettings, debug, debug_OverrideLodLevel } from "./lods.debug.js";
8
+ import { PromiseGroup } from "./lods.loading.js";
8
9
  const debugProgressiveLoading = getParam("debugprogressive");
9
10
  const suppressProgressiveLoading = getParam("noprogressive");
10
11
  const $lodsManager = Symbol("Needle:LODSManager");
@@ -78,8 +79,8 @@ export class LODsManager {
78
79
  renderer[$lodsManager] = lodsManager;
79
80
  return lodsManager;
80
81
  }
81
- context;
82
82
  renderer;
83
+ context;
83
84
  projectionScreenMatrix = new Matrix4();
84
85
  /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
85
86
  get plugins() { return plugins; }
@@ -111,6 +112,37 @@ export class LODsManager {
111
112
  * @default false
112
113
  */
113
114
  manual = false;
115
+ _newPromiseGroups = [];
116
+ _promiseGroupIds = 0;
117
+ /**
118
+ * Call to await LODs loading during the next render cycle.
119
+ */
120
+ awaitLoading(opts) {
121
+ const id = this._promiseGroupIds++;
122
+ const newGroup = new PromiseGroup(this.#frame, { ...opts, });
123
+ this._newPromiseGroups.push(newGroup);
124
+ const start = performance.now();
125
+ newGroup.ready.finally(() => {
126
+ const index = this._newPromiseGroups.indexOf(newGroup);
127
+ if (index >= 0) {
128
+ this._newPromiseGroups.splice(index, 1);
129
+ if (isDevelopmentServer())
130
+ performance.measure("LODsManager:awaitLoading", {
131
+ start,
132
+ detail: { id, name: opts?.name, awaited: newGroup.awaitedCount, resolved: newGroup.resolvedCount }
133
+ });
134
+ }
135
+ });
136
+ return newGroup.ready;
137
+ }
138
+ _postprocessPromiseGroups() {
139
+ if (this._newPromiseGroups.length === 0)
140
+ return;
141
+ for (let i = this._newPromiseGroups.length - 1; i >= 0; i--) {
142
+ const group = this._newPromiseGroups[i];
143
+ group.update(this.#frame);
144
+ }
145
+ }
114
146
  _lodchangedlisteners = [];
115
147
  addEventListener(evt, listener) {
116
148
  if (evt === "changed") {
@@ -232,6 +264,7 @@ export class LODsManager {
232
264
  return;
233
265
  }
234
266
  this.internalUpdate(scene, camera);
267
+ this._postprocessPromiseGroups();
235
268
  }
236
269
  }
237
270
  /**
@@ -368,9 +401,10 @@ export class LODsManager {
368
401
  }
369
402
  if (update) {
370
403
  material[$currentLOD] = level;
371
- NEEDLE_progressive.assignTextureLOD(material, level).then(_ => {
404
+ const promise = NEEDLE_progressive.assignTextureLOD(material, level).then(_ => {
372
405
  this._lodchangedlisteners.forEach(l => l({ type: "texture", level, object: material }));
373
406
  });
407
+ PromiseGroup.addPromise("texture", promise, this._newPromiseGroups);
374
408
  }
375
409
  }
376
410
  /** Load progressive meshes for the given mesh
@@ -391,19 +425,14 @@ export class LODsManager {
391
425
  if (update) {
392
426
  mesh[$currentLOD] = level;
393
427
  const originalGeometry = mesh.geometry;
394
- return NEEDLE_progressive.assignMeshLOD(mesh, level).then(res => {
428
+ const promise = NEEDLE_progressive.assignMeshLOD(mesh, level).then(res => {
395
429
  if (res && mesh[$currentLOD] == level && originalGeometry != mesh.geometry) {
396
430
  this._lodchangedlisteners.forEach(l => l({ type: "mesh", level, object: mesh }));
397
- // if (this.handles) {
398
- // for (const inst of this.handles) {
399
- // // if (inst["LOD"] < level) continue;
400
- // // inst["LOD"] = level;
401
- // inst.setGeometry(mesh.geometry);
402
- // }
403
- // }
404
431
  }
405
432
  return res;
406
433
  });
434
+ PromiseGroup.addPromise("mesh", promise, this._newPromiseGroups);
435
+ return promise;
407
436
  }
408
437
  return Promise.resolve(null);
409
438
  }
@@ -1,4 +1,4 @@
1
- import { LODsManager } from "../lods_manager.js";
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");
@@ -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;
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-progressive",
3
- "version": "3.0.0-next.90239b7",
3
+ "version": "3.0.0-next.d16d57f",
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": {