@needle-tools/gltf-progressive 4.0.0-alpha.1 → 4.0.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/LICENSE +21 -0
  3. package/README.md +47 -11
  4. package/examples/modelviewer-multiple.html +4 -4
  5. package/examples/modelviewer.html +4 -4
  6. package/examples/offscreen/index.html +15 -0
  7. package/examples/offscreen/main.js +98 -0
  8. package/examples/react-three-fiber/index.html +2 -2
  9. package/examples/react-three-fiber/package-lock.json +482 -484
  10. package/examples/react-three-fiber/package.json +4 -4
  11. package/examples/react-three-fiber/src/App.tsx +76 -21
  12. package/examples/react-three-fiber/src/styles.css +2 -4
  13. package/examples/react-three-fiber/vite.config.js +2 -2
  14. package/examples/shared/example-utils.js +297 -0
  15. package/examples/shared/example.css +44 -0
  16. package/examples/shared/runtime.js +34 -0
  17. package/examples/threejs/index.html +6 -10
  18. package/examples/threejs/main.js +5 -23
  19. package/examples/webgpu/index.html +15 -0
  20. package/examples/webgpu/main.js +105 -0
  21. package/examples/worker-rendering/index.html +15 -0
  22. package/examples/worker-rendering/main.js +109 -0
  23. package/examples/worker-rendering/worker.js +166 -0
  24. package/gltf-progressive.js +1025 -669
  25. package/gltf-progressive.min.js +9 -9
  26. package/gltf-progressive.umd.cjs +9 -9
  27. package/lib/extension.d.ts +73 -7
  28. package/lib/extension.js +351 -111
  29. package/lib/index.d.ts +1 -1
  30. package/lib/index.js +1 -1
  31. package/lib/loaders.js +17 -3
  32. package/lib/lods.debug.js +2 -2
  33. package/lib/lods.manager.d.ts +93 -15
  34. package/lib/lods.manager.js +331 -157
  35. package/lib/lods.promise.js +1 -1
  36. package/lib/plugins/modelviewer.js +1 -1
  37. package/lib/utils.internal.js +20 -6
  38. package/lib/version.js +1 -1
  39. package/lib/worker/loader.mainthread.js +4 -1
  40. package/package.json +10 -3
@@ -32,9 +32,10 @@ export function isDebugMode() {
32
32
  return debug;
33
33
  }
34
34
  export function getParam(name) {
35
- if (typeof window === "undefined")
35
+ const href = globalThis.location?.href;
36
+ if (!href)
36
37
  return false;
37
- const url = new URL(window.location.href);
38
+ const url = new URL(href);
38
39
  const param = url.searchParams.get(name);
39
40
  if (param == null || param === "0" || param === "false")
40
41
  return false;
@@ -73,7 +74,8 @@ export function resolveUrl(source, uri) {
73
74
  export function isMobileDevice() {
74
75
  if (_ismobile !== undefined)
75
76
  return _ismobile;
76
- _ismobile = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent);
77
+ const userAgent = globalThis.navigator?.userAgent || "";
78
+ _ismobile = /iPhone|iPad|iPod|Android|IEMobile/i.test(userAgent);
77
79
  if (getParam("debugprogressive"))
78
80
  console.log("[glTF Progressive]: isMobileDevice", _ismobile);
79
81
  return _ismobile;
@@ -84,9 +86,10 @@ let _ismobile;
84
86
  * @returns `true` if we are running in a development server (localhost or ip address).
85
87
  */
86
88
  export function isDevelopmentServer() {
87
- if (typeof window === "undefined")
89
+ const href = globalThis.location?.href;
90
+ if (!href)
88
91
  return false;
89
- const url = new URL(window.location.href);
92
+ const url = new URL(href);
90
93
  const isLocalhostOrIpAddress = url.hostname === "localhost" || /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(url.hostname);
91
94
  const isDevelopment = url.hostname === "127.0.0.1" || isLocalhostOrIpAddress;
92
95
  return isDevelopment;
@@ -103,7 +106,14 @@ export class PromiseQueue {
103
106
  constructor(maxConcurrent, opts = {}) {
104
107
  this.maxConcurrent = maxConcurrent;
105
108
  this.debug = opts.debug ?? false;
106
- window.requestAnimationFrame(this.tick);
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
+ }
107
117
  }
108
118
  tick = () => {
109
119
  this.internalUpdate();
@@ -206,6 +216,10 @@ export function detectGPUMemory() {
206
216
  if (rendererInfo !== undefined) {
207
217
  return rendererInfo?.estimatedMemory;
208
218
  }
219
+ if (typeof document === "undefined") {
220
+ rendererInfo = null;
221
+ return undefined;
222
+ }
209
223
  const canvas = document.createElement('canvas');
210
224
  const powerPreference = "high-performance";
211
225
  const gl = canvas.getContext('webgl', { powerPreference }) || canvas.getContext('experimental-webgl', { powerPreference });
package/lib/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // replaced at build time
2
- export const version = "4.0.0-alpha";
2
+ export const version = "4.0.0-alpha.2";
3
3
  globalThis["GLTF_PROGRESSIVE_VERSION"] = version;
4
4
  console.debug(`[gltf-progressive] version ${version || "-"}`);
@@ -51,7 +51,10 @@ class GLTFLoaderWorker {
51
51
  url = URL.createObjectURL(new Blob([url]));
52
52
  }
53
53
  else if (!url.startsWith("blob:") && !url.startsWith("http:") && !url.startsWith("https:")) {
54
- url = new URL(url, window.location.href).toString();
54
+ const base = globalThis.location?.href;
55
+ if (base) {
56
+ url = new URL(url, base).toString();
57
+ }
55
58
  }
56
59
  const options = {
57
60
  type: "load",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-progressive",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.2",
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": {
@@ -12,6 +12,7 @@
12
12
  "type": "git",
13
13
  "url": "git+https://github.com/needle-tools/gltf-progressive"
14
14
  },
15
+ "license": "MIT",
15
16
  "readme": "README.md",
16
17
  "keywords": [
17
18
  "three.js",
@@ -41,7 +42,8 @@
41
42
  "gltf-progressive.js",
42
43
  "gltf-progressive.min.js",
43
44
  "gltf-progressive.umd.cjs",
44
- "NEEDLE_progressive"
45
+ "NEEDLE_progressive",
46
+ "LICENSE"
45
47
  ],
46
48
  "watch": {
47
49
  "build:lib": {
@@ -57,10 +59,13 @@
57
59
  "three": ">= 0.183.0"
58
60
  },
59
61
  "devDependencies": {
62
+ "@needle-tools/engine": "^5.1.0-alpha.6",
63
+ "@needle-tools/three-test-matrix": "^0.1.0",
60
64
  "@stylistic/eslint-plugin-ts": "^1.5.4",
61
65
  "@types/three": "0.183.1",
62
66
  "@typescript-eslint/eslint-plugin": "^6.2.0",
63
67
  "@typescript-eslint/parser": "^6.2.0",
68
+ "@vitest/browser-playwright": "^4.1.8",
64
69
  "eslint": "^8.56.0",
65
70
  "eslint-plugin-import": "^2.29.1",
66
71
  "eslint-plugin-no-secrets": "^0.8.9",
@@ -69,8 +74,10 @@
69
74
  "eslint-plugin-xss": "^0.1.12",
70
75
  "nodemon": "^3.1.4",
71
76
  "npm-watch": "^0.13.0",
77
+ "playwright": "^1.60.0",
72
78
  "three": ">= 0.183.0",
73
- "vite": "7"
79
+ "vite": "7",
80
+ "vitest": "^4.1.8"
74
81
  },
75
82
  "types": "./lib/index.d.ts"
76
83
  }