@needle-tools/usd 0.0.1-alpha.4 → 0.0.1-next.62e46e8

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/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-next.62e46e8",
4
4
  "main": "src/index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "type": "module",
@@ -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,