@needle-tools/usd 0.0.1-alpha.4 → 0.0.1-c92147f

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/README.md CHANGED
@@ -9,9 +9,8 @@ For commercial use please contact hi@needle.tools
9
9
 
10
10
 
11
11
 
12
- ## Usage
12
+ ## Use with Needle Engine
13
13
 
14
- ### Needle Engine
15
14
 
16
15
  ```ts
17
16
  import { get } from "svelte/store";
@@ -27,7 +26,7 @@ export function addUsdPlugin() {
27
26
  ```
28
27
 
29
28
 
30
- ### Other
29
+ ### Use with other three.js based viewers
31
30
 
32
31
 
33
32
  See full example in [examples](./examples/src/main.ts)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/usd",
3
- "version": "0.0.1-alpha.4",
3
+ "version": "0.0.1-c92147f",
4
4
  "main": "src/index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "type": "module",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "peerDependencies": {
39
39
  "three": "^0.164.1",
40
- "@needle-tools/engine": ">= 4.5.0-alpha.4"
40
+ "@needle-tools/engine": ">= 4.6.0-0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "vite": "^5.2.13",
@@ -47,4 +47,4 @@
47
47
  "access": "public",
48
48
  "registry": "https://registry.npmjs.org/"
49
49
  }
50
- }
50
+ }
@@ -56,10 +56,22 @@ export async function getUsdModule(opts) {
56
56
 
57
57
  return usd_module_promise = getUsdModuleFn({
58
58
  mainScriptUrlOrBlob: bindings.default,// "./emHdBindings.js",
59
+ ...opts,
59
60
  setStatus: (status) => {
60
- console.debug("🧊 USD STATUS", status);
61
+ // TODO: would be nice to have a progress event
62
+ // for now we parse the log 'Downloading data... (219516/849069)'
63
+ if (opts?.onDownloadProgress && status.includes("Downloading data...")) {
64
+ const start = status.indexOf("(");
65
+ const end = status.indexOf("/");
66
+ const start2 = status.indexOf("/", end);
67
+ const end2 = status.indexOf(")", start2);
68
+ const startNum = parseInt(status.substring(start + 1, end));
69
+ const endNum = parseInt(status.substring(end + 1, end2));
70
+ opts.onDownloadProgress(startNum, endNum);
71
+ }
72
+ if (opts?.setStatus) opts.setStatus(status);
73
+ else console.debug("🧊 USD STATUS", status);
61
74
  },
62
- ...opts,
63
75
  locateFile: (file) => {
64
76
  // if (opts?.debug === true) console.warn("LOCATE FILE:", file)
65
77
 
@@ -60,10 +60,11 @@ export type GetUsdModuleOptions = {
60
60
  locateFile?: (path: string) => string,
61
61
  getPreloadedPackage?: (file: string, size: number) => ArrayBuffer | null,
62
62
  setStatus?: (status: string) => void,
63
+ onDownloadProgress?: (downloaded: number, total: number) => void,
63
64
  /** Returns a transferable object that can be resolved to an ArrayBuffer,
64
65
  * or an URL that can be fetched to get an ArrayBuffer.
65
66
  */
66
- urlModifier?: (url: string) =>
67
+ urlModifier?: (url: string) =>
67
68
  Promise<
68
69
  ArrayBuffer | File | FileSystemFileHandle | FileSystemFileEntry | string
69
70
  > | ArrayBuffer | File | FileSystemFileHandle | FileSystemFileEntry | string,