Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HdJavaScript and JavaScript API wrappers #2

Draft
wants to merge 15 commits into
base: usdjs
Choose a base branch
from
Draft

Conversation

kaischroeder
Copy link
Collaborator

@kaischroeder kaischroeder commented Feb 2, 2022

Description of Change(s)

This branch adds several experimental features as proofs of concept to the WebAssembly port of USD. Please see the main WebAssembly branch for build instructions: #1

This adds:

  1. hdJavaScript (still called hdEmscripten in the code): A C++ RenderDelegate that does some of the heavy lifting of a RenderDelegate to then forward to a simplified RenderDelegate implemented in JavaScript
  2. A THREE.JS RenderDelegate using the above
  3. JavaScript API wrappers for several of the generic functions and classes to work with a USD stage.

After building this branch and running make install, you get a folder hdEmscripten under the build folder that contains all the files needed to create an app based on this. You can for example copy them into the demo project: https://github.com/autodesk-forks/USD/tree/gh-pages/usd_for_web_demos

The only purpose of this PR today is to make the changes easily viewable and to allow people to play with this code. This is far from being in a form that can be merged.

@kaischroeder kaischroeder marked this pull request as draft February 2, 2022 19:46
Comment on lines +23 to +32
let filetype = undefined;
if (filename.indexOf('.png') >= filename.length - 5) {
filetype = 'image/png';
} else if (filename.indexOf('.jpg') >= filename.length - 5) {
filetype = 'image/jpeg';
} else if (filename.indexOf('.jpeg') >= filename.length - 5) {
filetype = 'image/jpeg';
} else {
throw new Error('Unknown filetype');
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You likely want to do something like this instead:

Suggested change
let filetype = undefined;
if (filename.indexOf('.png') >= filename.length - 5) {
filetype = 'image/png';
} else if (filename.indexOf('.jpg') >= filename.length - 5) {
filetype = 'image/jpeg';
} else if (filename.indexOf('.jpeg') >= filename.length - 5) {
filetype = 'image/jpeg';
} else {
throw new Error('Unknown filetype');
}
let filetype = undefined;
if (REGEX_JPEG.test(filename)) {
filetype = 'image/jpeg';
} else if(REGEX_PNG.test(filename)) {
filetype = 'image/png';
} else {
throw new Error('Unknown filetype');
}

Where at the top of the file you do:

const REGEX_JPEG = /\.(jpg|jpeg)$/i;
const REGEX_PNG = /\.png$/i;

@hybridherbst
Copy link

hybridherbst commented Mar 13, 2022

  1. From what I can see skinned meshes (bones / bind poses) are currently not supported.
    Are there plans to add that? (I'm happy to contribute a couple of test meshes if desired)

  2. Also seems like visibility isn't supported. Here's a test file: VisibleCubeInvisibleSphere.zip. Expected would be that the sphere is hidden while the cube is visible.

  3. There seem to be issues with normals (VisibleCubeVisibleSphere.zip); this file exhibits lots of seams, but only in this web viewer, Omniverse / Unity / QuickLook are fine.
    image

@kaischroeder
Copy link
Collaborator Author

Many thanks for your bug reports.

  1. From what I can see skinned meshes (bones / bind poses) are currently not supported.
    Are there plans to add that? (I'm happy to contribute a couple of test meshes if desired)

It doesn't have the highest priority right now for the team I am on, to be honest, because we are focusing more on CAD models :-) I'll add the two other things to our internal bug tracker.

@hybridherbst
Copy link

hybridherbst commented Mar 17, 2022

Understood, just want to point out that CAD models to occassionally contain skinned mesh data though :) for cables, wires, soft parts, ...
Sometimes also for performance optimization (e.g. one mesh with 1-bone-weights and 300 bone transforms might be faster on some platforms than 300 drawcalls).

@kaischroeder
Copy link
Collaborator Author

Understood, just want to point out that CAD models to occassionally contain skinned mesh data though :) for cables, wires, soft parts, ... Sometimes also for performance optimization (e.g. one mesh with 1-bone-weights and 300 bone transforms might be faster on some platforms than 300 drawcalls).

That's actually pretty clever :-)

@hybridherbst
Copy link

That's actually pretty clever :-)

Haha, let me know if you want to hear more production-proven performance optimization tips regarding bringing CAD to realtime 🚲

The URL pointing to the emscripten version of TBB was not valid anymore. We are updating the URL in this commit.

Co-authored-by: David Koerner <[email protected]>
@hybridherbst
Copy link

Is it planned to get this working on mobile? Seems in some cases the SharedArrayBuffer prevents that but in other cases the wasm instantiation never seems to complete.
For reference, I added some "status logs" in the top left corner here to show what's happening / what errors might appear: https://usd-viewer.glitch.me/

@kaischroeder
Copy link
Collaborator Author

Is it planned to get this working on mobile? Seems in some cases the SharedArrayBuffer prevents that but in other cases the wasm instantiation never seems to complete. For reference, I added some "status logs" in the top left corner here to show what's happening / what errors might appear: https://usd-viewer.glitch.me/

Maybe it is some timing issue depending on the network or phone. It's working for me in Chrome on Android. I can imagine that the problem is related to the hacky service worker we use to enable cross origin isolation on GitHub Pages - required for SharedArrayBuffer.

It would be great if you could try setting proper http headers on Glitch: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements

@hybridherbst
Copy link

@kaischroeder https://usd-viewer.glitch.me/ now sets the headers server-side, I removed the service worker to take that out of the support equation.

(Downside is that it's now not a static page anymore and thus there's a couple seconds spinup delay if the instance happened to go to sleep (after 30mins of inactivity or so))

@kaischroeder
Copy link
Collaborator Author

@hybridherbst I have now found some more time to look into this. the github pages demo indeed stopped working for me as well. your glitch installation also unfortunately does not work for me anymore. I was now able to make it work on mobile with a local https server that sets the right CORS headers.

@hybridherbst
Copy link

hybridherbst commented Apr 8, 2022

@kaischroeder mind checking again? I found a glitch (haha) and fixed it. Working with binary files is a bit strange in their editor (they tend to break if you try to view them).

Works for me again at least :)

@kaischroeder
Copy link
Collaborator Author

@hybridherbst Thanks. It works for me on Desktop. :-) On mobile I had to reload once - the first time I tried I got this error message:

Uncaught (in promise) ReferenceError: Usd is not defined
at loadUsdFileFromArrayBuffer (VM6:109:7)
at HTMLAnchorElement. (VM6:256:13)

@hybridherbst
Copy link

Cool, good to know!
Might have been a cache thing; mobile devices cache more aggressively than desktop in my experience (you might even get an old file after the first reload in favor of faster loading)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants