@needle-tools/gltf-progressive 4.0.0-alpha.4 → 4.0.0-alpha.6

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/lib/loaders.js CHANGED
@@ -29,7 +29,8 @@ if (typeof window !== "undefined") {
29
29
  }
30
30
  })
31
31
  .finally(() => {
32
- prepareLoaders();
32
+ if (preloadLoaders)
33
+ prepareLoaders();
33
34
  });
34
35
  }
35
36
  // #region Loader Configuration
@@ -79,15 +80,25 @@ export function setKTX2TranscoderLocation(location) {
79
80
  * @returns The loaders/decoders.
80
81
  */
81
82
  export function createLoaders(renderer) {
82
- prepareLoaders();
83
+ preloadLoaders = true;
84
+ const loaders = prepareLoaders();
83
85
  if (renderer) {
84
- ktx2Loader.detectSupport(renderer);
86
+ loaders.ktx2Loader.detectSupport(renderer);
85
87
  }
86
88
  else if (renderer !== null)
87
89
  console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail");
88
- return { dracoLoader, ktx2Loader, meshoptDecoder };
90
+ return loaders;
91
+ }
92
+ /** Release the shared Draco and KTX2 workers when no engine context uses them. */
93
+ export function disposeLoaders() {
94
+ preloadLoaders = false;
95
+ dracoLoader?.dispose();
96
+ ktx2Loader?.dispose();
97
+ dracoLoader = undefined;
98
+ ktx2Loader = undefined;
89
99
  }
90
100
  export function addDracoAndKTX2Loaders(loader) {
101
+ const { dracoLoader, ktx2Loader, meshoptDecoder } = prepareLoaders();
91
102
  if (!loader.dracoLoader)
92
103
  loader.setDRACOLoader(dracoLoader);
93
104
  if (!loader.ktx2Loader)
@@ -97,6 +108,7 @@ export function addDracoAndKTX2Loaders(loader) {
97
108
  }
98
109
  // #region internal
99
110
  const $dracoDecoderPath = Symbol("dracoDecoderPath");
111
+ let preloadLoaders = true;
100
112
  let dracoLoader;
101
113
  let meshoptDecoder;
102
114
  let ktx2Loader;
@@ -119,6 +131,7 @@ function prepareLoaders() {
119
131
  if (!meshoptDecoder) {
120
132
  meshoptDecoder = MeshoptDecoder;
121
133
  }
134
+ return { dracoLoader, ktx2Loader, meshoptDecoder };
122
135
  }
123
136
  const gltfLoaderConfigurations = new WeakMap();
124
137
  export function configureLoader(loader, opts) {
@@ -106,14 +106,9 @@ export class PromiseQueue {
106
106
  constructor(maxConcurrent, opts = {}) {
107
107
  this.maxConcurrent = maxConcurrent;
108
108
  this.debug = opts.debug ?? false;
109
- // Dedicated workers can have requestAnimationFrame when they are owned by a window.
110
- // Other worker-like scopes do not, so keep the frame-based tick when available and fall back to timers otherwise.
111
- if (typeof globalThis.requestAnimationFrame === "function") {
112
- globalThis.requestAnimationFrame(this.tick);
113
- }
114
- else {
115
- setTimeout(this.tick, 0);
116
- }
109
+ // Start with a timer, not requestAnimationFrame: window rAF does not fire while an immersive WebXR session
110
+ // is presenting (e.g. a page reloaded straight into VR via sessiongranted), so the queue would never tick.
111
+ setTimeout(this.tick, 0);
117
112
  }
118
113
  tick = () => {
119
114
  this.internalUpdate();
package/lib/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // replaced at build time
2
- export const version = "4.0.0-alpha.4";
2
+ export const version = "4.0.0-alpha.6";
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": "4.0.0-alpha.4",
3
+ "version": "4.0.0-alpha.6",
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": {