@needle-tools/usd 0.0.1-alpha

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 (46) hide show
  1. package/README.md +71 -0
  2. package/examples/index.html +58 -0
  3. package/examples/package-lock.json +1548 -0
  4. package/examples/package.json +24 -0
  5. package/examples/public/HttpReferences copy.usda +46 -0
  6. package/examples/public/HttpReferences.usda +44 -0
  7. package/examples/public/gingerbread/GingerbreadHouse.usda +35 -0
  8. package/examples/public/gingerbread/house/GingerBreadHouse.usdc +0 -0
  9. package/examples/public/gingerbread/house/textures/color.jpg +0 -0
  10. package/examples/public/gingerbread/house/textures/metallic_roughness.jpg +0 -0
  11. package/examples/public/gingerbread/house/textures/normal.jpg +0 -0
  12. package/examples/public/gingerbread/snowman/Snowman.usdc +0 -0
  13. package/examples/public/gingerbread/snowman/textures/color.jpg +0 -0
  14. package/examples/public/gingerbread/snowman/textures/metallic_roughness.jpg +0 -0
  15. package/examples/public/gingerbread/snowman/textures/normal.jpg +0 -0
  16. package/examples/public/test.usdz +0 -0
  17. package/examples/public/vite.svg +1 -0
  18. package/examples/src/fileHandling.ts +256 -0
  19. package/examples/src/main.ts +167 -0
  20. package/examples/src/three.ts +140 -0
  21. package/examples/src/vite-env.d.ts +1 -0
  22. package/examples/tsconfig.json +23 -0
  23. package/examples/vite.config.js +21 -0
  24. package/package.json +45 -0
  25. package/src/bindings/.gitattributes +2 -0
  26. package/src/bindings/emHdBindings.data +19331 -0
  27. package/src/bindings/emHdBindings.js +12227 -0
  28. package/src/bindings/emHdBindings.wasm +0 -0
  29. package/src/bindings/emHdBindings.worker.js +124 -0
  30. package/src/bindings/index.js +112 -0
  31. package/src/create.three.js +252 -0
  32. package/src/hydra/ThreeJsRenderDelegate.js +872 -0
  33. package/src/hydra/consoleRenderDelegate.js +47 -0
  34. package/src/hydra/index.js +5 -0
  35. package/src/index.d.ts +1 -0
  36. package/src/index.js +6 -0
  37. package/src/plugins/index.js +2 -0
  38. package/src/plugins/needle.js +158 -0
  39. package/src/types/bindings.d.ts +81 -0
  40. package/src/types/create.three.d.ts +65 -0
  41. package/src/types/hydra.d.ts +32 -0
  42. package/src/types/index.d.ts +5 -0
  43. package/src/types/plugins.d.ts +9 -0
  44. package/src/types/vite.d.ts +19 -0
  45. package/src/utils.js +24 -0
  46. package/src/vite/index.js +22 -0
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Needle USD
2
+
3
+ USD wasm runtime and three.js hydra delegate
4
+
5
+ ## Install
6
+ `npm install @needle-tools/usd`
7
+
8
+
9
+
10
+ ## Usage
11
+
12
+
13
+ See full example in [examples](./examples/src/main.ts)
14
+
15
+ ```js
16
+ // Load the USD module
17
+ const usd = await getUsdModule();
18
+ // Load a USD file to be rendered by threejs
19
+ const handle = await createThreeHydra({
20
+ USD: usd,
21
+ scene: ctx.scene,
22
+ usdz: "http://localhost:8081/v1/public/89aa693/89aa693/ImageTrackingNeedleSample.usdz",
23
+ })
24
+ // Call handle.update(dt) in your threejs update loop
25
+ ```
26
+
27
+
28
+
29
+ ## Low Level
30
+
31
+ ### Import
32
+ ```js
33
+ import { getUsdModule } from '@needle-tools/usd';
34
+ ```
35
+
36
+ ### Load the Module
37
+
38
+ ```js
39
+ getUsdModule({
40
+ // We need to override where the initial module is loaded from,
41
+ // since after bundling we can't rely on paths anymore
42
+ mainScriptUrlOrBlob: "/emHdBindings.js",
43
+ }).then(async (Usd: USD) => {
44
+ // use Usd here
45
+ });
46
+ ```
47
+
48
+ ### Load a file into the virtual file system
49
+ ```js
50
+ const blob = await fetch("test.usdz");
51
+ const arrayBuffer = await blob.arrayBuffer();
52
+ // Create a file in the virtual file system
53
+ Usd.FS_createDataFile("", "test.usdz", new Uint8Array(arrayBuffer), true, true, true);
54
+ ```
55
+
56
+ ### Load file into USD
57
+
58
+ ```js
59
+ let driver = new Usd.HdWebSyncDriver(delegate, "test.usdz");
60
+ if (driver instanceof Promise) driver = await driver;
61
+
62
+ // This kicks off asynchronous tasks to look at everything that has changed – _SyncAll –
63
+ // which will then call into the delegate to create and update the scene graph.
64
+ driver.Draw();
65
+ ```
66
+
67
+ ## Useful References
68
+
69
+ Uses Asyncify to handle async calls in emscripten.
70
+ > A synchronous call in C that waits for an asynchronous operation in JS to complete.
71
+ https://emscripten.org/docs/porting/asyncify.html
@@ -0,0 +1,58 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8" />
6
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
7
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8
+ <title>Vite + TS</title>
9
+ <style>
10
+ body {
11
+ margin: 0;
12
+ padding: 0;
13
+ }
14
+ canvas {
15
+ position: absolute;
16
+ left: 0;
17
+ top: 0;
18
+ right: 0;
19
+ bottom: 0;
20
+ }
21
+ .test-buttons {
22
+ position: absolute;
23
+ top: 0;
24
+ left: 0;
25
+ padding: 10px;
26
+ background-color: rgba(0,0,0,0.5);
27
+ color: white;
28
+ z-index: 1000;
29
+ }
30
+
31
+ .test-buttons button {
32
+ margin: 3px;
33
+ color: white;
34
+ background-color: rgb(63, 107, 18);
35
+ border: none;
36
+ outline: none;
37
+ border-radius: 10px;
38
+ cursor: pointer;
39
+ padding: 3px 8px;
40
+ }
41
+
42
+ .test-buttons button:hover {
43
+ background-color: rgba(224, 224, 224, 0.8);
44
+ color: black;
45
+ }
46
+
47
+ .options button {
48
+ background-color: rgb(75, 75, 75);
49
+ }
50
+ </style>
51
+ </head>
52
+
53
+ <body>
54
+ <div id="app"></div>
55
+ <script type="module" src="./src/main.ts"></script>
56
+ </body>
57
+
58
+ </html>