A USD viewer on the web.
Open USD Viewer
There are two main parts:
npm install
npm run start
http://localhost:<port>
in your browser (Note: 0.0.0.0 won't work since it doesn't have SharedArrayBuffer permissions)The three.js Hydra Delegate is in public/ThreeJsRenderDelegate.js
.
Loading and rendering are currently intermingled in public/index.html
.
NOTE: Origins for these instructions can be found here
./emsdk install 3.1.55
./emsdk activate 3.1.55
source ./emsdk_env.sh
emsdk install 3.1.55
emsdk activate 3.1.55
PATH="/Applications/CMake.app/Contents/bin":"$PATH"
git clone --recursive https://git.autodesk.com/autodesk-forks/usd/tree/adsk/feature/webgpu
cd usd_repo
python3 ./build_scripts/build_usd.py --build-target wasm ../build_dir
emHdBindings.js
emHdBindings.wasm
emHdBindings.worker.js
emHdBindings.data
pxr/base/arch/hints.h
, removing all comments from line 1-26 allowed the build to complete successfullywasm-opt -Oz -o "../build_dir/bin/emHdBindings.wasm" "../build_dir/bin/emHdBindings.wasm" --enable-bulk-memory --enable-threads
to shrink the wasm file more.patch emHdBindings.js < patches/arguments_1.patch
patch emHdBindings.js < patches/arguments_2.patch
return function (
moduleArg = {
// module overrides can be supplied here
locateFile: (path, prefix) => {
if (!prefix)
prefix = _scriptDir.substr(0, _scriptDir.lastIndexOf("/") + 1);
return prefix + path;
},
...args,
},
) {
And replace this line:
return function (moduleArg = {}) {
patch emHdBindings.js < patches/abort.patch
patch emHdBindings.js < patches/fileSystem.patch
Module["FS_readdir"] = FS.readdir;
Module["FS_analyzePath"] = FS.analyzePath;
right after
Module["PThread"] = PThread;
-Oz
use -O3 -g
cd usd_repo
python3 ./build_scripts/build_usd.py --build-target wasm --build-variant debug ../build_dir
emHdBindings.js
emHdBindings.wasm
emHdBindings.worker.js
emHdBindings.data
pxr/base/arch/hints.h
, removing all comments from line 1-26 allowed the build to complete successfullypatch emHdBindings.js < arguments_1.patch
patch emHdBindings.js < arguments_2.patch
return function (
moduleArg = {
// module overrides can be supplied here
locateFile: (path, prefix) => {
if (!prefix)
prefix = _scriptDir.substr(0, _scriptDir.lastIndexOf("/") + 1);
return prefix + path;
},
...args,
},
) {
And replace this line:
return function (moduleArg = {}) {
patch emHdBindings.js < abort.patch
patch emHdBindings.js < fileSystem.patch
Module["FS_readdir"] = FS.readdir;
Module["FS_analyzePath"] = FS.analyzePath;
right after
Module["PThread"] = PThread;
npm start
There is a build script here which tries to make building easier. Set the mode, build directory and destination directory to deal with the file movement.
Usage: ./buildAndMove.sh --mode release --build-dir ../build-wasm --destination-dir /Users/andrewbeers/git/needle/usd-viewer/public
NOTE: this does not support patching yet as patching doesn't completely work yet NOTE: this does not update CMakeLists.txt for debug mode automatically
Based on autodesk-forks.github.io/USD/usd_for_web_demos
Code here: github.com/autodesk-forks/USD/tree/gh-pages
This project: github.com/needle-tools/usd-viewer
Some JavaScript features used here require specific HTTP headers (SharedArrayBuffers).
This was originally achieved by using the service worker from here: github.com/gzuidhof/coi-serviceworker.
Now, headers are set server-side which should have wider support / better caching.
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
By @hybridherbst
🌵 Needle & prefrontal cortex