immersive-web / webxr-polyfill

Use the WebXR Device API today, providing fallbacks to native WebVR 1.1 and Cardboard
Apache License 2.0
386 stars 86 forks source link

inputsourceschange event in XRSession isn't dispatched #37

Closed soadzoor closed 5 years ago

soadzoor commented 6 years ago

Hi,

I created a quick mockup about the issue in the title, you can find it here: https://vrtual.house/development/webxr-polyfill-test/

The problem: I cannot make any interaction on the scene, when the WebXR flag is disabled, and the polyfill is used. In three.js, there are some events for interaction, like selectstart, and selectend, but they're not dispatched when the polyfill is used, only when the flag is set to enabled.

I guess it has something to do with the fact that the inputsourceschange isn't fired either when the polyfill is used. (You can find the lines in question starting from line 21752 in the three.js r96 build): capture

jsantell commented 6 years ago

Looks like this is not yet implemented in the polyfill. I see inputsourceschange in the explainer, but not the actual spec -- @toji should this be implemented here?

jsantell commented 6 years ago

So this event should be added to the spec, submitted: https://github.com/immersive-web/webxr/pull/395

takahirox commented 5 years ago

I want to go with inputsourceschange event support for #81

takahirox commented 5 years ago

I'm thinking how to implement. As I mentioned in #81, inputSources are set up in animation frame (more precisely, onFrameStart()). So, perhaps easiest solution may be replacing

this[PRIVATE].device.onFrameStart(this[PRIVATE].id);
callback(now(), this[PRIVATE].frame);
this[PRIVATE].device.onFrameEnd(this[PRIVATE].id);

https://github.com/immersive-web/webxr-polyfill/blob/master/src/api/XRSession.js#L295-L297

with something like this

this[PRIVATE].device.onFrameStart(this[PRIVATE].id);

const newInputSources = this.inputSources;
const previousInputSources = this[PRIVATE].previousInputSources;

// Here, compare inputSources with previous frame's ones
// and fire inputsourceschange event if different.

this[PRIVATE].previousInputSources = newInputSources;

callback(now(), this[PRIVATE].frame);
this[PRIVATE].device.onFrameEnd(this[PRIVATE].id);

What do you think?

jsantell commented 5 years ago

SGTM!

takahirox commented 5 years ago

I think this issue can be closed because of #91

toji commented 5 years ago

Agreed.