@needle-tools/usd 0.0.1-alpha.3 → 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/CHANGELOG.md CHANGED
@@ -4,5 +4,5 @@ All notable changes to this package will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [0.0.1-alpha.1] - 2025-05-14
7
+ ## [0.0.1-alpha] - 2025-05-14
8
8
  - initial release
package/README.md CHANGED
@@ -9,7 +9,24 @@ For commercial use please contact hi@needle.tools
9
9
 
10
10
 
11
11
 
12
- ## Usage
12
+ ## Use with Needle Engine
13
+
14
+
15
+ ```ts
16
+ import { get } from "svelte/store";
17
+ import { activeFiles } from "..";
18
+ import { addPluginForNeedleEngine } from "@needle-tools/usd/plugins";
19
+
20
+ export function addUsdPlugin() {
21
+ return addPluginForNeedleEngine({
22
+ // USD files to load (first file must be the main file)
23
+ getFiles: () => { return get(activeFiles) as Array<File & { path: string }> }
24
+ })
25
+ }
26
+ ```
27
+
28
+
29
+ ### Use with other three.js based viewers
13
30
 
14
31
 
15
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.3",
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
 
package/src/index.js CHANGED
@@ -2,5 +2,4 @@ export * from "./bindings/index.js";
2
2
  export * from "./hydra/index.js";
3
3
  export * from "./create.three.js";
4
4
  export * from "./vite/index.js";
5
- export * from "./plugins/index.js";
6
5
  export { tryDetermineFileFormat } from "./utils.js"
@@ -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,