Skip to content

Add WebXR capturing functionality to Spector.js, and WebXR sample #257

New issue

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

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

Already on GitHub? # to your account

Merged
merged 4 commits into from
May 22, 2023

Conversation

dmliao
Copy link
Contributor

@dmliao dmliao commented Mar 22, 2023

This change adds a new initialization option to Spector.js, called enableXRCapture, that when enabled allows Spector.js to hook onto and capture commands from WebXR sessions.

This works by doing a partial replacement of the WebXR API, so that information such as active sessions and the WebGL context used in the session are visible to Spector.js, and requires Spector.js to be initialized and used like:

var spector = new SPECTOR({ enableXRCapture: true });

...
// enter a WebXR Session here
...

// once we have an active session, we can capture the context with the following:
spector.captureXRContext();

Without the initialization option, Spector.js will not attempt to replace any of the WebXR APIs, and getXRContext() will automatically produce an error. Either way, captures of non-WebXR contexts and canvases should be unchanged.

There is also a new sample to demonstrate WebXR captures under samples/js/webxr.js, which produces a default WebXR scene and allows you to take a capture by pressing the trigger button of either controller.

Caveats

  • The changes to the some of the helpers (formatHelper, readPixelsHelper, and baseWebGLObject) were to deal with errors that showed up from unexpected inputs from commands that would show up in WebXR sessions; I haven't done very thorough testing to see how they would interact with non-XR contexts, nor did I dig super deep to figure out why those changes were needed.
  • Even with the fix to get screencaps working with WebXR, they only operate on sessions that use WebXR Layers; without layers, WebXR produces opaque framebuffers that cannot be read from. This should be documented somewhere, but I haven't put that anywhere yet.
  • In general, I haven't touched the documentation regarding this new feature and would welcome feedback on what / where to put it.

@sebavan
Copy link
Member

sebavan commented Mar 23, 2023

@RaananW would you be able to test it once it will go in ???

@sebavan
Copy link
Member

sebavan commented Mar 23, 2023

Should it be enabled by default in the extension ? It looks good at a first glance, I will have a deeper look on Friday :-)

Copy link
Member

@RaananW RaananW left a comment

Choose a reason for hiding this comment

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

Wow, amazing work!
I am just wondering about emulator(s) support - as the browser-based emulators are providing their own XR implementation - will the order of loading spector and the extension hurt the capture? Or will it work anyhow, since they mainly polyfill the XR object?

@dmliao
Copy link
Contributor Author

dmliao commented Mar 23, 2023

@sebavan - I didn't think it's too relevant for the desktop extension right now since the extension isn't really used with WebXR beyond interacting with browser-based WebXR emulators, and those already work with Spector.js as-is [since the emulators render to a canvas that the existing extension can spy]. The extension doesn't have any ability to actually capture the XR context either, since it isn't added to the available contexts / canvases list. But I mostly know about the WebXR use case for immersive VR experiences; there might be use-cases for MR or AR that I'm overlooking.

@RaananW - Theoretically, if emulators completely replace XR APIs that Spector also replaces, then yes, Spector will have to load after the emulator in order to get access to the XR session. Looking at immersive-web-emulator, it doesn't look like they touch any of the APIs changed here (which are mostly creating sessions and layers), but I can't actually verify. The emulator extensions run before any other client code, so if you load Spector.js into your WebXR experience, it'll always load after the emulator has already polyfilled the WebXR API. I did test the library on experiences using the emulator, and I've seen no issues so far.

Copy link
Member

@sebavan sebavan left a comment

Choose a reason for hiding this comment

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

Could you revert your changes to the dist and extensions folders ?

@sebavan
Copy link
Member

sebavan commented May 10, 2023

@dmliao I wonder if #258 (comment) could be integrated in your PR ? it might be a bit more generic with scope and I d like to avoid breaking changes later :-)

@dmliao dmliao force-pushed the library-webxr-support branch 2 times, most recently from b3f59c9 to 1dd1cad Compare May 12, 2023 05:33
@dmliao dmliao closed this May 18, 2023
@dmliao dmliao force-pushed the library-webxr-support branch from 1dd1cad to 4be6b4c Compare May 18, 2023 21:54
@dmliao dmliao reopened this May 18, 2023
@dmliao
Copy link
Contributor Author

dmliao commented May 18, 2023

The PR got automatically closed when I tried to rebase...anyway, this now incorporates the API changes that were introduced in #259.

@sebavan sebavan merged commit a4f3558 into BabylonJS:master May 22, 2023
@multun
Copy link

multun commented Sep 3, 2023

I believe this change prevents the library from loading on firefox, even with the website examples: Uncaught ReferenceError: XRWebGLBinding is not defined

@sebavan
Copy link
Member

sebavan commented Sep 4, 2023

ohhhh :-( @dmliao could you have a look ?

@dmliao
Copy link
Contributor Author

dmliao commented Sep 5, 2023 via email

@multun
Copy link

multun commented Sep 6, 2023

If you’re willing to wait a week, I can look into this then. I’m currently on holiday and don’t have computer access until then.

enjoy your holidays! thanks for offering to help

If the extension / library has the WebXR flag enabled, see first if turning it off fixes things. The code shouldn’t touch WebXR at all in that case.

The issue occurs at the <script type="text/javascript" src="spector.bundle.js"></script> stage. I think that's because a class inherits from XRWebGLBinding, which is an experimental API unavailable in firefox.

@RaananW
Copy link
Member

RaananW commented Sep 6, 2023

it will probably be possible to "create" these objects (empty objects) if they don't exist, while not expecting WebXR to work in an environment where the objects are not defined. Otherwise there is no way to optionally extend from a different class.

@sebavan
Copy link
Member

sebavan commented Sep 6, 2023

@dmliao no worries enjoy your holidays and let s fix it once you are back :-)

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

Successfully merging this pull request may close these issues.

4 participants