@needle-tools/usd 0.0.1-412624
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 +8 -0
- package/README.md +100 -0
- package/examples/index.html +58 -0
- package/examples/package-lock.json +1548 -0
- package/examples/package.json +24 -0
- package/examples/public/HttpReferences copy.usda +46 -0
- package/examples/public/HttpReferences.usda +44 -0
- package/examples/public/gingerbread/GingerbreadHouse.usda +35 -0
- package/examples/public/gingerbread/house/GingerBreadHouse.usdc +0 -0
- package/examples/public/gingerbread/house/textures/color.jpg +0 -0
- package/examples/public/gingerbread/house/textures/metallic_roughness.jpg +0 -0
- package/examples/public/gingerbread/house/textures/normal.jpg +0 -0
- package/examples/public/gingerbread/snowman/Snowman.usdc +0 -0
- package/examples/public/gingerbread/snowman/textures/color.jpg +0 -0
- package/examples/public/gingerbread/snowman/textures/metallic_roughness.jpg +0 -0
- package/examples/public/gingerbread/snowman/textures/normal.jpg +0 -0
- package/examples/public/test.usdz +0 -0
- package/examples/public/vite.svg +1 -0
- package/examples/src/fileHandling.ts +256 -0
- package/examples/src/main.ts +167 -0
- package/examples/src/three.ts +140 -0
- package/examples/src/vite-env.d.ts +1 -0
- package/examples/tsconfig.json +23 -0
- package/examples/vite.config.js +21 -0
- package/package.json +50 -0
- package/src/bindings/.gitattributes +2 -0
- package/src/bindings/emHdBindings.data +19331 -0
- package/src/bindings/emHdBindings.js +12227 -0
- package/src/bindings/emHdBindings.wasm +0 -0
- package/src/bindings/emHdBindings.worker.js +124 -0
- package/src/bindings/index.js +124 -0
- package/src/create.three.js +252 -0
- package/src/hydra/ThreeJsRenderDelegate.js +872 -0
- package/src/hydra/consoleRenderDelegate.js +47 -0
- package/src/hydra/index.js +5 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +5 -0
- package/src/plugins/index.js +2 -0
- package/src/plugins/needle.js +158 -0
- package/src/types/bindings.d.ts +82 -0
- package/src/types/create.three.d.ts +65 -0
- package/src/types/hydra.d.ts +32 -0
- package/src/types/index.d.ts +5 -0
- package/src/types/plugins.d.ts +9 -0
- package/src/types/vite.d.ts +19 -0
- package/src/utils.js +24 -0
- package/src/vite/index.js +22 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
All notable changes to this package will be documented in this file.
|
|
3
|
+
|
|
4
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
5
|
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [0.0.1-alpha] - 2025-05-14
|
|
8
|
+
- initial release
|
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Needle USD
|
|
2
|
+
|
|
3
|
+
USD wasm runtime and three.js hydra delegate.
|
|
4
|
+
Developed & maintained by [Needle](https://needle.tools)
|
|
5
|
+
For commercial use please contact hi@needle.tools
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
`npm install @needle-tools/usd`
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
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
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
See full example in [examples](./examples/src/main.ts)
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
// Load the USD module
|
|
36
|
+
const usd = await getUsdModule();
|
|
37
|
+
// Load a USD file to be rendered by threejs
|
|
38
|
+
const handle = await createThreeHydra({
|
|
39
|
+
USD: usd,
|
|
40
|
+
scene: ctx.scene,
|
|
41
|
+
usdz: "http://localhost:8081/v1/public/89aa693/89aa693/ImageTrackingNeedleSample.usdz",
|
|
42
|
+
})
|
|
43
|
+
// Call handle.update(dt) in your threejs update loop
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## Low Level
|
|
49
|
+
|
|
50
|
+
### Import
|
|
51
|
+
```js
|
|
52
|
+
import { getUsdModule } from '@needle-tools/usd';
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Load the Module
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
getUsdModule({
|
|
59
|
+
// We need to override where the initial module is loaded from,
|
|
60
|
+
// since after bundling we can't rely on paths anymore
|
|
61
|
+
mainScriptUrlOrBlob: "/emHdBindings.js",
|
|
62
|
+
}).then(async (Usd: USD) => {
|
|
63
|
+
// use Usd here
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Load a file into the virtual file system
|
|
68
|
+
```js
|
|
69
|
+
const blob = await fetch("test.usdz");
|
|
70
|
+
const arrayBuffer = await blob.arrayBuffer();
|
|
71
|
+
// Create a file in the virtual file system
|
|
72
|
+
Usd.FS_createDataFile("", "test.usdz", new Uint8Array(arrayBuffer), true, true, true);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Load file into USD
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
let driver = new Usd.HdWebSyncDriver(delegate, "test.usdz");
|
|
79
|
+
if (driver instanceof Promise) driver = await driver;
|
|
80
|
+
|
|
81
|
+
// This kicks off asynchronous tasks to look at everything that has changed – _SyncAll –
|
|
82
|
+
// which will then call into the delegate to create and update the scene graph.
|
|
83
|
+
driver.Draw();
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Useful References
|
|
87
|
+
|
|
88
|
+
Uses Asyncify to handle async calls in emscripten.
|
|
89
|
+
> A synchronous call in C that waits for an asynchronous operation in JS to complete.
|
|
90
|
+
https://emscripten.org/docs/porting/asyncify.html
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# Contact ✒️
|
|
94
|
+
<b>[🌵 Needle](https://needle.tools)</b> •
|
|
95
|
+
[Github](https://github.com/needle-tools) •
|
|
96
|
+
[Twitter](https://twitter.com/NeedleTools) •
|
|
97
|
+
[Discord](https://discord.needle.tools) •
|
|
98
|
+
[Forum](https://forum.needle.tools) •
|
|
99
|
+
[Youtube](https://www.youtube.com/@needle-tools)
|
|
100
|
+
|
|
@@ -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>
|