Skip to content

Commit

Permalink
2.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jsantell committed May 13, 2020
1 parent 7814e20 commit 0202e9d
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 43 deletions.
72 changes: 52 additions & 20 deletions build/webxr-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ const POLYFILL_REQUEST_SESSION_ERROR =
or navigator.xr.requestSession('inline') prior to requesting an immersive
session. This is a limitation specific to the WebXR Polyfill and does not apply
to native implementations of the API.`;
class XR extends EventTarget {
class XRSystem extends EventTarget {
constructor(devicePromise) {
super();
this[PRIVATE$4] = {
Expand Down Expand Up @@ -1523,10 +1523,10 @@ class XRSession$1 extends EventTarget {
}
this[PRIVATE$15].ended = true;
this[PRIVATE$15].stopDeviceFrameLoop();
device.removeEventListener('@webvr-polyfill/vr-present-end', this[PRIVATE$15].onPresentationEnd);
device.removeEventListener('@webvr-polyfill/vr-present-start', this[PRIVATE$15].onPresentationStart);
device.removeEventListener('@@webvr-polyfill/input-select-start', this[PRIVATE$15].onSelectStart);
device.removeEventListener('@@webvr-polyfill/input-select-end', this[PRIVATE$15].onSelectEnd);
device.removeEventListener('@@webxr-polyfill/vr-present-end', this[PRIVATE$15].onPresentationEnd);
device.removeEventListener('@@webxr-polyfill/vr-present-start', this[PRIVATE$15].onPresentationStart);
device.removeEventListener('@@webxr-polyfill/input-select-start', this[PRIVATE$15].onSelectStart);
device.removeEventListener('@@webxr-polyfill/input-select-end', this[PRIVATE$15].onSelectEnd);
this.dispatchEvent('end', new XRSessionEvent('end', { session: this }));
};
device.addEventListener('@@webxr-polyfill/vr-present-end', this[PRIVATE$15].onPresentationEnd);
Expand Down Expand Up @@ -1651,13 +1651,13 @@ class XRSession$1 extends EventTarget {
}
if (this[PRIVATE$15].immersive) {
this[PRIVATE$15].ended = true;
this[PRIVATE$15].device.removeEventListener('@@webvr-polyfill/vr-present-start',
this[PRIVATE$15].device.removeEventListener('@@webxr-polyfill/vr-present-start',
this[PRIVATE$15].onPresentationStart);
this[PRIVATE$15].device.removeEventListener('@@webvr-polyfill/vr-present-end',
this[PRIVATE$15].device.removeEventListener('@@webxr-polyfill/vr-present-end',
this[PRIVATE$15].onPresentationEnd);
this[PRIVATE$15].device.removeEventListener('@@webvr-polyfill/input-select-start',
this[PRIVATE$15].device.removeEventListener('@@webxr-polyfill/input-select-start',
this[PRIVATE$15].onSelectStart);
this[PRIVATE$15].device.removeEventListener('@@webvr-polyfill/input-select-end',
this[PRIVATE$15].device.removeEventListener('@@webxr-polyfill/input-select-end',
this[PRIVATE$15].onSelectEnd);
this.dispatchEvent('end', new XRSessionEvent('end', { session: this }));
}
Expand Down Expand Up @@ -1766,7 +1766,7 @@ class XRReferenceSpaceEvent extends Event {
}

var API = {
XR,
XRSystem,
XRSession: XRSession$1,
XRSessionEvent,
XRFrame,
Expand Down Expand Up @@ -1932,6 +1932,13 @@ var getChromeVersion = function () {
return value;
};
}();
var isSafariWithoutDeviceMotion = function () {
var value = false;
value = isIOS() && isSafari() && navigator.userAgent.indexOf('13_4') !== -1;
return function () {
return value;
};
}();
var isChromeWithoutDeviceMotion = function () {
var value = false;
if (getChromeVersion() === 65) {
Expand Down Expand Up @@ -2407,6 +2414,7 @@ function CardboardDistorter(gl, cardboardUI, bufferScale, dirtySubmitFrameBindin
this.bufferScale = bufferScale;
this.dirtySubmitFrameBindings = dirtySubmitFrameBindings;
this.ctxAttribs = gl.getContextAttributes();
this.instanceExt = gl.getExtension('ANGLE_instanced_arrays');
this.meshWidth = 20;
this.meshHeight = 20;
this.bufferWidth = gl.drawingBufferWidth;
Expand Down Expand Up @@ -2684,6 +2692,12 @@ CardboardDistorter.prototype.submitFrame = function () {
}
glPreserveState(gl, glState, function (gl) {
self.realBindFramebuffer.call(gl, gl.FRAMEBUFFER, null);
var positionDivisor = 0;
var texCoordDivisor = 0;
if (self.instanceExt) {
positionDivisor = gl.getVertexAttrib(self.attribs.position, self.instanceExt.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
texCoordDivisor = gl.getVertexAttrib(self.attribs.texCoord, self.instanceExt.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
}
if (self.cullFace) {
self.realDisable.call(gl, gl.CULL_FACE);
}
Expand Down Expand Up @@ -2712,6 +2726,14 @@ CardboardDistorter.prototype.submitFrame = function () {
gl.enableVertexAttribArray(self.attribs.texCoord);
gl.vertexAttribPointer(self.attribs.position, 2, gl.FLOAT, false, 20, 0);
gl.vertexAttribPointer(self.attribs.texCoord, 3, gl.FLOAT, false, 20, 8);
if (self.instanceExt) {
if (positionDivisor != 0) {
self.instanceExt.vertexAttribDivisorANGLE(self.attribs.position, 0);
}
if (texCoordDivisor != 0) {
self.instanceExt.vertexAttribDivisorANGLE(self.attribs.texCoord, 0);
}
}
gl.activeTexture(gl.TEXTURE0);
gl.uniform1i(self.uniforms.diffuse, 0);
gl.bindTexture(gl.TEXTURE_2D, self.renderTarget);
Expand Down Expand Up @@ -2748,6 +2770,14 @@ CardboardDistorter.prototype.submitFrame = function () {
if (self.ctxAttribs.alpha || !self.ctxAttribs.preserveDrawingBuffer) {
self.realClearColor.apply(gl, self.clearColor);
}
if (self.instanceExt) {
if (positionDivisor != 0) {
self.instanceExt.vertexAttribDivisorANGLE(self.attribs.position, positionDivisor);
}
if (texCoordDivisor != 0) {
self.instanceExt.vertexAttribDivisorANGLE(self.attribs.texCoord, texCoordDivisor);
}
}
});
if (isIOS()) {
var canvas = gl.canvas;
Expand Down Expand Up @@ -3743,7 +3773,7 @@ function FusionPoseSensor(kFilter, predictionTime, yawOnly, isDebug) {
this.isIOS = isIOS();
var chromeVersion = getChromeVersion();
this.isDeviceMotionInRadians = !this.isIOS && chromeVersion && chromeVersion < 66;
this.isWithoutDeviceMotion = isChromeWithoutDeviceMotion();
this.isWithoutDeviceMotion = isChromeWithoutDeviceMotion() || isSafariWithoutDeviceMotion();
this.filterToWorldQ = new Quaternion();
if (isIOS()) {
this.filterToWorldQ.setFromAxisAngle(new Vector3(1, 0, 0), Math.PI / 2);
Expand Down Expand Up @@ -3859,16 +3889,18 @@ FusionPoseSensor.prototype.updateDeviceMotion_ = function (deviceMotion) {
return;
}
this.accelerometer.set(-accGravity.x, -accGravity.y, -accGravity.z);
if (isR7()) {
this.gyroscope.set(-rotRate.beta, rotRate.alpha, rotRate.gamma);
} else {
this.gyroscope.set(rotRate.alpha, rotRate.beta, rotRate.gamma);
}
if (!this.isDeviceMotionInRadians) {
this.gyroscope.multiplyScalar(Math.PI / 180);
if (rotRate) {
if (isR7()) {
this.gyroscope.set(-rotRate.beta, rotRate.alpha, rotRate.gamma);
} else {
this.gyroscope.set(rotRate.alpha, rotRate.beta, rotRate.gamma);
}
if (!this.isDeviceMotionInRadians) {
this.gyroscope.multiplyScalar(Math.PI / 180);
}
this.filter.addGyroMeasurement(this.gyroscope, timestampS);
}
this.filter.addAccelMeasurement(this.accelerometer, timestampS);
this.filter.addGyroMeasurement(this.gyroscope, timestampS);
this.previousTimestampS = timestampS;
};
FusionPoseSensor.prototype.onOrientationChange_ = function (screenOrientation) {
Expand Down Expand Up @@ -6100,7 +6132,7 @@ host this content on a secure origin for the best user experience.
}
_patchNavigatorXR() {
let devicePromise = requestXRDevice(this.global, this.config);
this.xr = new API.XR(devicePromise);
this.xr = new API.XRSystem(devicePromise);
Object.defineProperty(this.global.navigator, 'xr', {
value: this.xr,
configurable: true,
Expand Down
2 changes: 1 addition & 1 deletion build/webxr-polyfill.min.js

Large diffs are not rendered by default.

72 changes: 52 additions & 20 deletions build/webxr-polyfill.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ const POLYFILL_REQUEST_SESSION_ERROR =
or navigator.xr.requestSession('inline') prior to requesting an immersive
session. This is a limitation specific to the WebXR Polyfill and does not apply
to native implementations of the API.`;
class XR extends EventTarget {
class XRSystem extends EventTarget {
constructor(devicePromise) {
super();
this[PRIVATE$4] = {
Expand Down Expand Up @@ -1517,10 +1517,10 @@ class XRSession$1 extends EventTarget {
}
this[PRIVATE$15].ended = true;
this[PRIVATE$15].stopDeviceFrameLoop();
device.removeEventListener('@webvr-polyfill/vr-present-end', this[PRIVATE$15].onPresentationEnd);
device.removeEventListener('@webvr-polyfill/vr-present-start', this[PRIVATE$15].onPresentationStart);
device.removeEventListener('@@webvr-polyfill/input-select-start', this[PRIVATE$15].onSelectStart);
device.removeEventListener('@@webvr-polyfill/input-select-end', this[PRIVATE$15].onSelectEnd);
device.removeEventListener('@@webxr-polyfill/vr-present-end', this[PRIVATE$15].onPresentationEnd);
device.removeEventListener('@@webxr-polyfill/vr-present-start', this[PRIVATE$15].onPresentationStart);
device.removeEventListener('@@webxr-polyfill/input-select-start', this[PRIVATE$15].onSelectStart);
device.removeEventListener('@@webxr-polyfill/input-select-end', this[PRIVATE$15].onSelectEnd);
this.dispatchEvent('end', new XRSessionEvent('end', { session: this }));
};
device.addEventListener('@@webxr-polyfill/vr-present-end', this[PRIVATE$15].onPresentationEnd);
Expand Down Expand Up @@ -1645,13 +1645,13 @@ class XRSession$1 extends EventTarget {
}
if (this[PRIVATE$15].immersive) {
this[PRIVATE$15].ended = true;
this[PRIVATE$15].device.removeEventListener('@@webvr-polyfill/vr-present-start',
this[PRIVATE$15].device.removeEventListener('@@webxr-polyfill/vr-present-start',
this[PRIVATE$15].onPresentationStart);
this[PRIVATE$15].device.removeEventListener('@@webvr-polyfill/vr-present-end',
this[PRIVATE$15].device.removeEventListener('@@webxr-polyfill/vr-present-end',
this[PRIVATE$15].onPresentationEnd);
this[PRIVATE$15].device.removeEventListener('@@webvr-polyfill/input-select-start',
this[PRIVATE$15].device.removeEventListener('@@webxr-polyfill/input-select-start',
this[PRIVATE$15].onSelectStart);
this[PRIVATE$15].device.removeEventListener('@@webvr-polyfill/input-select-end',
this[PRIVATE$15].device.removeEventListener('@@webxr-polyfill/input-select-end',
this[PRIVATE$15].onSelectEnd);
this.dispatchEvent('end', new XRSessionEvent('end', { session: this }));
}
Expand Down Expand Up @@ -1760,7 +1760,7 @@ class XRReferenceSpaceEvent extends Event {
}

var API = {
XR,
XRSystem,
XRSession: XRSession$1,
XRSessionEvent,
XRFrame,
Expand Down Expand Up @@ -1926,6 +1926,13 @@ var getChromeVersion = function () {
return value;
};
}();
var isSafariWithoutDeviceMotion = function () {
var value = false;
value = isIOS() && isSafari() && navigator.userAgent.indexOf('13_4') !== -1;
return function () {
return value;
};
}();
var isChromeWithoutDeviceMotion = function () {
var value = false;
if (getChromeVersion() === 65) {
Expand Down Expand Up @@ -2401,6 +2408,7 @@ function CardboardDistorter(gl, cardboardUI, bufferScale, dirtySubmitFrameBindin
this.bufferScale = bufferScale;
this.dirtySubmitFrameBindings = dirtySubmitFrameBindings;
this.ctxAttribs = gl.getContextAttributes();
this.instanceExt = gl.getExtension('ANGLE_instanced_arrays');
this.meshWidth = 20;
this.meshHeight = 20;
this.bufferWidth = gl.drawingBufferWidth;
Expand Down Expand Up @@ -2678,6 +2686,12 @@ CardboardDistorter.prototype.submitFrame = function () {
}
glPreserveState(gl, glState, function (gl) {
self.realBindFramebuffer.call(gl, gl.FRAMEBUFFER, null);
var positionDivisor = 0;
var texCoordDivisor = 0;
if (self.instanceExt) {
positionDivisor = gl.getVertexAttrib(self.attribs.position, self.instanceExt.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
texCoordDivisor = gl.getVertexAttrib(self.attribs.texCoord, self.instanceExt.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
}
if (self.cullFace) {
self.realDisable.call(gl, gl.CULL_FACE);
}
Expand Down Expand Up @@ -2706,6 +2720,14 @@ CardboardDistorter.prototype.submitFrame = function () {
gl.enableVertexAttribArray(self.attribs.texCoord);
gl.vertexAttribPointer(self.attribs.position, 2, gl.FLOAT, false, 20, 0);
gl.vertexAttribPointer(self.attribs.texCoord, 3, gl.FLOAT, false, 20, 8);
if (self.instanceExt) {
if (positionDivisor != 0) {
self.instanceExt.vertexAttribDivisorANGLE(self.attribs.position, 0);
}
if (texCoordDivisor != 0) {
self.instanceExt.vertexAttribDivisorANGLE(self.attribs.texCoord, 0);
}
}
gl.activeTexture(gl.TEXTURE0);
gl.uniform1i(self.uniforms.diffuse, 0);
gl.bindTexture(gl.TEXTURE_2D, self.renderTarget);
Expand Down Expand Up @@ -2742,6 +2764,14 @@ CardboardDistorter.prototype.submitFrame = function () {
if (self.ctxAttribs.alpha || !self.ctxAttribs.preserveDrawingBuffer) {
self.realClearColor.apply(gl, self.clearColor);
}
if (self.instanceExt) {
if (positionDivisor != 0) {
self.instanceExt.vertexAttribDivisorANGLE(self.attribs.position, positionDivisor);
}
if (texCoordDivisor != 0) {
self.instanceExt.vertexAttribDivisorANGLE(self.attribs.texCoord, texCoordDivisor);
}
}
});
if (isIOS()) {
var canvas = gl.canvas;
Expand Down Expand Up @@ -3737,7 +3767,7 @@ function FusionPoseSensor(kFilter, predictionTime, yawOnly, isDebug) {
this.isIOS = isIOS();
var chromeVersion = getChromeVersion();
this.isDeviceMotionInRadians = !this.isIOS && chromeVersion && chromeVersion < 66;
this.isWithoutDeviceMotion = isChromeWithoutDeviceMotion();
this.isWithoutDeviceMotion = isChromeWithoutDeviceMotion() || isSafariWithoutDeviceMotion();
this.filterToWorldQ = new Quaternion();
if (isIOS()) {
this.filterToWorldQ.setFromAxisAngle(new Vector3(1, 0, 0), Math.PI / 2);
Expand Down Expand Up @@ -3853,16 +3883,18 @@ FusionPoseSensor.prototype.updateDeviceMotion_ = function (deviceMotion) {
return;
}
this.accelerometer.set(-accGravity.x, -accGravity.y, -accGravity.z);
if (isR7()) {
this.gyroscope.set(-rotRate.beta, rotRate.alpha, rotRate.gamma);
} else {
this.gyroscope.set(rotRate.alpha, rotRate.beta, rotRate.gamma);
}
if (!this.isDeviceMotionInRadians) {
this.gyroscope.multiplyScalar(Math.PI / 180);
if (rotRate) {
if (isR7()) {
this.gyroscope.set(-rotRate.beta, rotRate.alpha, rotRate.gamma);
} else {
this.gyroscope.set(rotRate.alpha, rotRate.beta, rotRate.gamma);
}
if (!this.isDeviceMotionInRadians) {
this.gyroscope.multiplyScalar(Math.PI / 180);
}
this.filter.addGyroMeasurement(this.gyroscope, timestampS);
}
this.filter.addAccelMeasurement(this.accelerometer, timestampS);
this.filter.addGyroMeasurement(this.gyroscope, timestampS);
this.previousTimestampS = timestampS;
};
FusionPoseSensor.prototype.onOrientationChange_ = function (screenOrientation) {
Expand Down Expand Up @@ -6094,7 +6126,7 @@ host this content on a secure origin for the best user experience.
}
_patchNavigatorXR() {
let devicePromise = requestXRDevice(this.global, this.config);
this.xr = new API.XR(devicePromise);
this.xr = new API.XRSystem(devicePromise);
Object.defineProperty(this.global.navigator, 'xr', {
value: this.xr,
configurable: true,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webxr-polyfill",
"version": "2.0.2",
"version": "2.0.3",
"homepage": "https://github.com/immersive-web/webxr-polyfill",
"main": "build/webxr-polyfill.js",
"module": "build/webxr-polyfill.module.js",
Expand Down

0 comments on commit 0202e9d

Please sign in to comment.