@needle-tools/usd 0.0.2-next.de2e82b → 1.0.0-next.4d692f6
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 +36 -1
- package/README.md +245 -28
- package/package.json +46 -10
- package/src/bindings/emHdBindings.js +5 -12227
- package/src/bindings/emHdBindings.wasm +0 -0
- package/src/bindings/index.js +130 -47
- package/src/bindings/openusd-build-info.json +40 -0
- package/src/create.three.js +368 -53
- package/src/hydra/ThreeJsRenderDelegate.js +1128 -75
- package/src/plugins/index.js +1 -2
- package/src/plugins/needle.js +38 -2
- package/src/types/bindings.d.ts +296 -3
- package/src/types/create.three.d.ts +87 -7
- package/src/types/hydra.d.ts +7 -5
- package/src/types/plugins.d.ts +7 -0
- package/src/types/usd-core-bindings.d.ts +240 -0
- package/src/utils.js +3 -3
- package/src/vite/index.js +13 -1
- package/examples/index.html +0 -58
- package/examples/package-lock.json +0 -1548
- package/examples/package.json +0 -24
- package/examples/public/HttpReferences copy.usda +0 -46
- package/examples/public/HttpReferences.usda +0 -44
- package/examples/public/gingerbread/GingerbreadHouse.usda +0 -35
- 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 +0 -1
- package/examples/src/fileHandling.ts +0 -256
- package/examples/src/main.ts +0 -167
- package/examples/src/three.ts +0 -140
- package/examples/src/vite-env.d.ts +0 -1
- package/examples/tsconfig.json +0 -23
- package/examples/vite.config.js +0 -21
- package/src/bindings/emHdBindings.data +0 -19331
- package/src/bindings/emHdBindings.worker.js +0 -124
|
Binary file
|
package/src/bindings/index.js
CHANGED
|
@@ -1,10 +1,58 @@
|
|
|
1
|
-
import "./emHdBindings.js";
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @type {Promise<import("..").USD> | null}
|
|
5
3
|
*/
|
|
6
4
|
let usd_module_promise = null;
|
|
7
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @type {Promise<import("..").getUsdModule> | null}
|
|
8
|
+
*/
|
|
9
|
+
let node_get_usd_module_promise = null;
|
|
10
|
+
|
|
11
|
+
function isNodeRuntime() {
|
|
12
|
+
return !!globalThis.process?.versions?.node && globalThis.process?.type !== "renderer";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function getNodeUsdModuleFn() {
|
|
16
|
+
if (node_get_usd_module_promise) {
|
|
17
|
+
return node_get_usd_module_promise;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
node_get_usd_module_promise = (async () => {
|
|
21
|
+
const [
|
|
22
|
+
{ createRequire },
|
|
23
|
+
{ readFile, writeFile, mkdtemp },
|
|
24
|
+
{ dirname, join },
|
|
25
|
+
{ tmpdir },
|
|
26
|
+
{ fileURLToPath },
|
|
27
|
+
] = await Promise.all([
|
|
28
|
+
import(/* @vite-ignore */ "node:module"),
|
|
29
|
+
import(/* @vite-ignore */ "node:fs/promises"),
|
|
30
|
+
import(/* @vite-ignore */ "node:path"),
|
|
31
|
+
import(/* @vite-ignore */ "node:os"),
|
|
32
|
+
import(/* @vite-ignore */ "node:url"),
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
const sourcePath = fileURLToPath(new URL("./emHdBindings.js", import.meta.url));
|
|
36
|
+
const tempDir = await mkdtemp(join(tmpdir(), "needle-usd-bindings-"));
|
|
37
|
+
const cjsPath = join(tempDir, "emHdBindings.cjs");
|
|
38
|
+
await writeFile(cjsPath, await readFile(sourcePath));
|
|
39
|
+
|
|
40
|
+
const require = createRequire(import.meta.url);
|
|
41
|
+
const getUsdModuleFn = require(cjsPath);
|
|
42
|
+
getUsdModuleFn.__needleUsdBindingsDir = dirname(sourcePath);
|
|
43
|
+
return getUsdModuleFn;
|
|
44
|
+
})();
|
|
45
|
+
|
|
46
|
+
return node_get_usd_module_promise;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function ensureBrowserBindingsImported() {
|
|
50
|
+
if (globalThis["NEEDLE:USD:GET"]) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
await import("./emHdBindings.js");
|
|
54
|
+
}
|
|
55
|
+
|
|
8
56
|
|
|
9
57
|
/**
|
|
10
58
|
* @param {undefined | import("..").GetUsdModuleOptions} opts
|
|
@@ -16,47 +64,81 @@ export async function getUsdModule(opts) {
|
|
|
16
64
|
}
|
|
17
65
|
|
|
18
66
|
|
|
67
|
+
if (isNodeRuntime()) {
|
|
68
|
+
const [
|
|
69
|
+
{ join },
|
|
70
|
+
getUsdModuleFn,
|
|
71
|
+
] = await Promise.all([
|
|
72
|
+
import(/* @vite-ignore */ "node:path"),
|
|
73
|
+
getNodeUsdModuleFn(),
|
|
74
|
+
]);
|
|
75
|
+
|
|
76
|
+
return usd_module_promise = getUsdModuleFn({
|
|
77
|
+
...opts,
|
|
78
|
+
locateFile: (file) => {
|
|
79
|
+
const userResult = opts?.locateFile?.(file);
|
|
80
|
+
if (userResult) {
|
|
81
|
+
return userResult;
|
|
82
|
+
}
|
|
83
|
+
return join(getUsdModuleFn.__needleUsdBindingsDir, file);
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
await ensureBrowserBindingsImported();
|
|
89
|
+
|
|
19
90
|
/**
|
|
20
91
|
* @type {import("..").getUsdModule}
|
|
21
92
|
*/
|
|
22
93
|
const getUsdModuleFn = globalThis["NEEDLE:USD:GET"];
|
|
23
|
-
|
|
24
94
|
if (!getUsdModuleFn) {
|
|
25
95
|
throw new Error("\"NEEDLE:USD:GET\" not found in globalThis - please modify \"emHdBindings.js\" and add: globalThis[\"NEEDLE:USD:GET\"] = getUsdModule;");
|
|
26
96
|
}
|
|
27
97
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
const isProd = import.meta.env?.PROD ?? true;
|
|
34
|
-
|
|
98
|
+
const bindingsUrl = new URL("./emHdBindings.js", import.meta.url).href;
|
|
99
|
+
const wasmUrl = new URL("./emHdBindings.wasm", import.meta.url).href;
|
|
100
|
+
const assetFetches = new Map();
|
|
35
101
|
|
|
36
102
|
/**
|
|
37
|
-
*
|
|
103
|
+
* @param {{ url?: string, state?: string, loaded?: number, total?: number, error?: string }} detail
|
|
38
104
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
105
|
+
function handleAssetFetchProgress(detail) {
|
|
106
|
+
const url = detail.url ?? "";
|
|
107
|
+
if (url) {
|
|
108
|
+
if (detail.state === "done" || detail.state === "error") {
|
|
109
|
+
assetFetches.delete(url);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
assetFetches.set(url, detail);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let loaded = 0;
|
|
117
|
+
let total = 0;
|
|
118
|
+
for (const entry of assetFetches.values()) {
|
|
119
|
+
const entryLoaded = entry.loaded ?? 0;
|
|
120
|
+
loaded += entryLoaded;
|
|
121
|
+
total += Math.max(entry.total ?? 0, entryLoaded);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const payload = {
|
|
125
|
+
url,
|
|
126
|
+
state: detail.state ?? "progress",
|
|
127
|
+
loaded: detail.loaded ?? 0,
|
|
128
|
+
total: detail.total ?? 0,
|
|
129
|
+
error: detail.error,
|
|
130
|
+
active: assetFetches.size,
|
|
131
|
+
loadedTotal: loaded,
|
|
132
|
+
totalBytes: total,
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
opts?.onAssetFetchProgress?.(payload);
|
|
136
|
+
}
|
|
56
137
|
|
|
57
138
|
return usd_module_promise = getUsdModuleFn({
|
|
58
|
-
mainScriptUrlOrBlob:
|
|
139
|
+
mainScriptUrlOrBlob: bindingsUrl,
|
|
59
140
|
...opts,
|
|
141
|
+
onAssetFetchProgress: handleAssetFetchProgress,
|
|
60
142
|
setStatus: (status) => {
|
|
61
143
|
// TODO: would be nice to have a progress event
|
|
62
144
|
// for now we parse the log 'Downloading data... (219516/849069)'
|
|
@@ -83,16 +165,9 @@ export async function getUsdModule(opts) {
|
|
|
83
165
|
/** resolved filepath */
|
|
84
166
|
let res = null;
|
|
85
167
|
|
|
86
|
-
if (file.includes("emHdBindings.
|
|
87
|
-
res =
|
|
88
|
-
}
|
|
89
|
-
else if (file.includes("emHdBindings.wasm")) {
|
|
90
|
-
res = wasm.default;
|
|
168
|
+
if (file.includes("emHdBindings.wasm")) {
|
|
169
|
+
res = wasmUrl;
|
|
91
170
|
}
|
|
92
|
-
else if (file.includes("emHdBindings.worker.js")) {
|
|
93
|
-
res = worker.default;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
171
|
// if (url?.startsWith("data:text/javascript;base64")) {
|
|
97
172
|
// // we're client side and Buffer and atob are not available
|
|
98
173
|
// // so we need to convert the base64 to a blob
|
|
@@ -110,15 +185,23 @@ export async function getUsdModule(opts) {
|
|
|
110
185
|
getPreloadedPackage(name, size) {
|
|
111
186
|
const userResult = opts?.getPreloadedPackage?.(name, size);
|
|
112
187
|
if (userResult) return userResult;
|
|
113
|
-
|
|
114
|
-
// For debugging if the data file isnt loaded or the size might be wrong
|
|
115
|
-
// Make sure to clear the vite cache. See https://linear.app/needle/issue/NE-4851#comment-2a9538e3
|
|
116
|
-
if (name.includes("emHdBindings.data")) {
|
|
117
|
-
if (preloaded_data.byteLength !== size) {
|
|
118
|
-
throw new Error(`emHdBindings.data size mismatch: expected ${size} but got ${preloaded_data.byteLength}\n${data.default}`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
188
|
return null;
|
|
122
189
|
},
|
|
123
190
|
});
|
|
124
|
-
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @param {import("..").USD} USD
|
|
195
|
+
* @returns {import("..").OpenUsdBuildInfo}
|
|
196
|
+
*/
|
|
197
|
+
export function getOpenUsdBuildInfo(USD) {
|
|
198
|
+
return JSON.parse(USD.GetBuildInfoJson());
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @param {undefined | import("..").GetUsdModuleOptions} opts
|
|
203
|
+
* @returns {Promise<import("..").OpenUsdBuildInfo>}
|
|
204
|
+
*/
|
|
205
|
+
export async function loadOpenUsdBuildInfo(opts) {
|
|
206
|
+
return getOpenUsdBuildInfo(await getUsdModule(opts));
|
|
207
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema": 1,
|
|
3
|
+
"openusd": {
|
|
4
|
+
"version": "0.26.5",
|
|
5
|
+
"pxrVersion": 2605,
|
|
6
|
+
"gitSha": "9f211a656877c26b39e8170f9ed53810094254d5",
|
|
7
|
+
"gitDirty": false
|
|
8
|
+
},
|
|
9
|
+
"toolchain": {
|
|
10
|
+
"emscripten": "emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.23 (7a5d93b50f6a3a35e85a0d2fc9e667b8498e6aed)",
|
|
11
|
+
"cxxCompiler": "/Users/herbst/git/emsdk/upstream/emscripten/em++",
|
|
12
|
+
"cmakeBuildType": "Release"
|
|
13
|
+
},
|
|
14
|
+
"modules": {
|
|
15
|
+
"usdImaging": true,
|
|
16
|
+
"hydraBridge": true,
|
|
17
|
+
"materialX": true,
|
|
18
|
+
"openSubdiv": true,
|
|
19
|
+
"usdGltf": true
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"openSubdiv": {
|
|
23
|
+
"version": "3.6.1"
|
|
24
|
+
},
|
|
25
|
+
"materialX": {
|
|
26
|
+
"prefix": "/Users/herbst/MaterialX-1.39.5-wasm-openusd/lib/cmake/MaterialX",
|
|
27
|
+
"gitSha": "ab218c56f016a9a2d398e8d306f3aeb439ae9e9e",
|
|
28
|
+
"gitDirty": false
|
|
29
|
+
},
|
|
30
|
+
"usdGltf": {
|
|
31
|
+
"prefix": "/Users/herbst/USD-Fileformat-plugins-2026.03-wasm-probe",
|
|
32
|
+
"gitSha": "ca3c2de5553648ae280077ddde079b6f3362a830",
|
|
33
|
+
"gitDirty": false
|
|
34
|
+
},
|
|
35
|
+
"emsdk": {
|
|
36
|
+
"gitSha": "af78ec5c14c4ae7d14cfef39fc46a6c43ccd844f",
|
|
37
|
+
"gitDirty": false
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|