Skip to content

Commit 40c6c09

Browse files
committed
Merge remote-tracking branch 'remotes/main_repo/master' into xr-plugin-2-panther
2 parents 17f6b3d + d714c99 commit 40c6c09

File tree

4 files changed

+67
-72
lines changed

4 files changed

+67
-72
lines changed

Build/webxr.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@
134134
this.isARSupported = false;
135135
this.isVRSupported = false;
136136
this.onInputEvent = null;
137-
this.waitingHandheldARHack = false;
138137
this.BrowserObject = null;
139138
this.JSEventsObject = null;
140139
this.init();
@@ -186,32 +185,15 @@
186185

187186
XRManager.prototype.onRequestARSession = function () {
188187
if (!this.isARSupported) return;
189-
// The window on Chrome for Android lose focus when asking permissions.
190-
// A popup is opened and the Canvas is painted with the last frame.
191-
// We want to make sure that the Canvas is transparent when entering Handheld AR Session.
192-
this.waitingHandheldARHack = true;
193-
var thisXRMananger = this;
194-
var tempRender = function () {
195-
thisXRMananger.ctx.clearColor(0, 0, 0, 0);
196-
thisXRMananger.ctx.clear(thisXRMananger.ctx.COLOR_BUFFER_BIT | thisXRMananger.ctx.DEPTH_BUFFER_BIT);
197-
if (thisXRMananger.waitingHandheldARHack)
198-
{
199-
window.requestAnimationFrame( tempRender );
200-
}
201-
}
202-
window.requestAnimationFrame( tempRender );
203188
navigator.xr.requestSession('immersive-ar', {
204189
requiredFeatures: ['local-floor'], // TODO: Get this value from Unity
205190
optionalFeatures: ['hand-tracking', 'hit-test']
206191
}).then(async (session) => {
207-
this.waitingHandheldARHack = false;
208192
session.isImmersive = true;
209193
session.isInSession = true;
210194
session.isAR = true;
211195
this.xrSession = session;
212196
this.onSessionStarted(session);
213-
}).catch((error) => {
214-
thisXRMananger.waitingHandheldARHack = false;
215197
});
216198
}
217199

@@ -371,6 +353,9 @@
371353
this.viewerHitTestSource.cancel();
372354
this.viewerHitTestSource = null;
373355
} else {
356+
this.xrSession.requestReferenceSpace('local').then((refSpace) => {
357+
this.xrSession.localRefSpace = refSpace;
358+
});
374359
this.xrSession.requestReferenceSpace('viewer').then((refSpace) => {
375360
this.viewerSpace = refSpace;
376361
this.xrSession.requestHitTestSource({space: this.viewerSpace}).then((hitTestSource) => {
@@ -422,9 +407,7 @@
422407
func(time);
423408
});
424409
} else {
425-
if (!thisXRMananger.waitingHandheldARHack) {
426-
window.requestAnimationFrame(func);
427-
}
410+
window.requestAnimationFrame(func);
428411
}
429412
};
430413

@@ -574,6 +557,19 @@
574557
break;
575558
}
576559
}
560+
561+
if (controller.trigger <= 0.02) {
562+
controller.trigger = 0;
563+
} else if (controller.trigger >= 0.98) {
564+
controller.trigger = 1;
565+
}
566+
567+
if (controller.squeeze <= 0.02) {
568+
controller.squeeze = 0;
569+
} else if (controller.squeeze >= 0.98) {
570+
controller.squeeze = 1;
571+
}
572+
577573
for (var j = 0; j < inputSource.gamepad.axes.length; j++) {
578574
switch (j) {
579575
case 0:
@@ -729,10 +725,11 @@
729725
xrData.viewerHitTestPose.frame = xrData.frameNumber;
730726
let viewerHitTestResults = frame.getHitTestResults(this.viewerHitTestSource);
731727
if (viewerHitTestResults.length > 0) {
732-
let hitTestPose = viewerHitTestResults[0].getPose(session.refSpace);
728+
let hitTestPose = viewerHitTestResults[0].getPose(session.localRefSpace);
733729
xrData.viewerHitTestPose.available = 1;
734730
xrData.viewerHitTestPose.position[0] = hitTestPose.transform.position.x;
735-
xrData.viewerHitTestPose.position[1] = hitTestPose.transform.position.y;
731+
let hitTestPoseBase = viewerHitTestResults[0].getPose(session.refSpace); // Ugly hack for y position on Samsung Internet
732+
xrData.viewerHitTestPose.position[1] = hitTestPose.transform.position.y + Math.abs(hitTestPose.transform.position.y - hitTestPoseBase.transform.position.y);
736733
xrData.viewerHitTestPose.position[2] = -hitTestPose.transform.position.z;
737734
xrData.viewerHitTestPose.rotation[0] = -hitTestPose.transform.orientation.x;
738735
xrData.viewerHitTestPose.rotation[1] = -hitTestPose.transform.orientation.y;

Packages/webxr/Hidden~/WebGLTemplates/WebXR/webxr.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@
134134
this.isARSupported = false;
135135
this.isVRSupported = false;
136136
this.onInputEvent = null;
137-
this.waitingHandheldARHack = false;
138137
this.BrowserObject = null;
139138
this.JSEventsObject = null;
140139
this.init();
@@ -186,32 +185,15 @@
186185

187186
XRManager.prototype.onRequestARSession = function () {
188187
if (!this.isARSupported) return;
189-
// The window on Chrome for Android lose focus when asking permissions.
190-
// A popup is opened and the Canvas is painted with the last frame.
191-
// We want to make sure that the Canvas is transparent when entering Handheld AR Session.
192-
this.waitingHandheldARHack = true;
193-
var thisXRMananger = this;
194-
var tempRender = function () {
195-
thisXRMananger.ctx.clearColor(0, 0, 0, 0);
196-
thisXRMananger.ctx.clear(thisXRMananger.ctx.COLOR_BUFFER_BIT | thisXRMananger.ctx.DEPTH_BUFFER_BIT);
197-
if (thisXRMananger.waitingHandheldARHack)
198-
{
199-
window.requestAnimationFrame( tempRender );
200-
}
201-
}
202-
window.requestAnimationFrame( tempRender );
203188
navigator.xr.requestSession('immersive-ar', {
204189
requiredFeatures: ['local-floor'], // TODO: Get this value from Unity
205190
optionalFeatures: ['hand-tracking', 'hit-test']
206191
}).then(async (session) => {
207-
this.waitingHandheldARHack = false;
208192
session.isImmersive = true;
209193
session.isInSession = true;
210194
session.isAR = true;
211195
this.xrSession = session;
212196
this.onSessionStarted(session);
213-
}).catch((error) => {
214-
thisXRMananger.waitingHandheldARHack = false;
215197
});
216198
}
217199

@@ -371,6 +353,9 @@
371353
this.viewerHitTestSource.cancel();
372354
this.viewerHitTestSource = null;
373355
} else {
356+
this.xrSession.requestReferenceSpace('local').then((refSpace) => {
357+
this.xrSession.localRefSpace = refSpace;
358+
});
374359
this.xrSession.requestReferenceSpace('viewer').then((refSpace) => {
375360
this.viewerSpace = refSpace;
376361
this.xrSession.requestHitTestSource({space: this.viewerSpace}).then((hitTestSource) => {
@@ -422,9 +407,7 @@
422407
func(time);
423408
});
424409
} else {
425-
if (!thisXRMananger.waitingHandheldARHack) {
426-
window.requestAnimationFrame(func);
427-
}
410+
window.requestAnimationFrame(func);
428411
}
429412
};
430413

@@ -574,6 +557,19 @@
574557
break;
575558
}
576559
}
560+
561+
if (controller.trigger <= 0.02) {
562+
controller.trigger = 0;
563+
} else if (controller.trigger >= 0.98) {
564+
controller.trigger = 1;
565+
}
566+
567+
if (controller.squeeze <= 0.02) {
568+
controller.squeeze = 0;
569+
} else if (controller.squeeze >= 0.98) {
570+
controller.squeeze = 1;
571+
}
572+
577573
for (var j = 0; j < inputSource.gamepad.axes.length; j++) {
578574
switch (j) {
579575
case 0:
@@ -729,10 +725,11 @@
729725
xrData.viewerHitTestPose.frame = xrData.frameNumber;
730726
let viewerHitTestResults = frame.getHitTestResults(this.viewerHitTestSource);
731727
if (viewerHitTestResults.length > 0) {
732-
let hitTestPose = viewerHitTestResults[0].getPose(session.refSpace);
728+
let hitTestPose = viewerHitTestResults[0].getPose(session.localRefSpace);
733729
xrData.viewerHitTestPose.available = 1;
734730
xrData.viewerHitTestPose.position[0] = hitTestPose.transform.position.x;
735-
xrData.viewerHitTestPose.position[1] = hitTestPose.transform.position.y;
731+
let hitTestPoseBase = viewerHitTestResults[0].getPose(session.refSpace); // Ugly hack for y position on Samsung Internet
732+
xrData.viewerHitTestPose.position[1] = hitTestPose.transform.position.y + Math.abs(hitTestPose.transform.position.y - hitTestPoseBase.transform.position.y);
736733
xrData.viewerHitTestPose.position[2] = -hitTestPose.transform.position.z;
737734
xrData.viewerHitTestPose.rotation[0] = -hitTestPose.transform.orientation.x;
738735
xrData.viewerHitTestPose.rotation[1] = -hitTestPose.transform.orientation.y;

Packages/webxr/Hidden~/WebGLTemplates/WebXRFullView/webxr.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@
134134
this.isARSupported = false;
135135
this.isVRSupported = false;
136136
this.onInputEvent = null;
137-
this.waitingHandheldARHack = false;
138137
this.BrowserObject = null;
139138
this.JSEventsObject = null;
140139
this.init();
@@ -186,32 +185,15 @@
186185

187186
XRManager.prototype.onRequestARSession = function () {
188187
if (!this.isARSupported) return;
189-
// The window on Chrome for Android lose focus when asking permissions.
190-
// A popup is opened and the Canvas is painted with the last frame.
191-
// We want to make sure that the Canvas is transparent when entering Handheld AR Session.
192-
this.waitingHandheldARHack = true;
193-
var thisXRMananger = this;
194-
var tempRender = function () {
195-
thisXRMananger.ctx.clearColor(0, 0, 0, 0);
196-
thisXRMananger.ctx.clear(thisXRMananger.ctx.COLOR_BUFFER_BIT | thisXRMananger.ctx.DEPTH_BUFFER_BIT);
197-
if (thisXRMananger.waitingHandheldARHack)
198-
{
199-
window.requestAnimationFrame( tempRender );
200-
}
201-
}
202-
window.requestAnimationFrame( tempRender );
203188
navigator.xr.requestSession('immersive-ar', {
204189
requiredFeatures: ['local-floor'], // TODO: Get this value from Unity
205190
optionalFeatures: ['hand-tracking', 'hit-test']
206191
}).then(async (session) => {
207-
this.waitingHandheldARHack = false;
208192
session.isImmersive = true;
209193
session.isInSession = true;
210194
session.isAR = true;
211195
this.xrSession = session;
212196
this.onSessionStarted(session);
213-
}).catch((error) => {
214-
thisXRMananger.waitingHandheldARHack = false;
215197
});
216198
}
217199

@@ -371,6 +353,9 @@
371353
this.viewerHitTestSource.cancel();
372354
this.viewerHitTestSource = null;
373355
} else {
356+
this.xrSession.requestReferenceSpace('local').then((refSpace) => {
357+
this.xrSession.localRefSpace = refSpace;
358+
});
374359
this.xrSession.requestReferenceSpace('viewer').then((refSpace) => {
375360
this.viewerSpace = refSpace;
376361
this.xrSession.requestHitTestSource({space: this.viewerSpace}).then((hitTestSource) => {
@@ -422,9 +407,7 @@
422407
func(time);
423408
});
424409
} else {
425-
if (!thisXRMananger.waitingHandheldARHack) {
426-
window.requestAnimationFrame(func);
427-
}
410+
window.requestAnimationFrame(func);
428411
}
429412
};
430413

@@ -574,6 +557,19 @@
574557
break;
575558
}
576559
}
560+
561+
if (controller.trigger <= 0.02) {
562+
controller.trigger = 0;
563+
} else if (controller.trigger >= 0.98) {
564+
controller.trigger = 1;
565+
}
566+
567+
if (controller.squeeze <= 0.02) {
568+
controller.squeeze = 0;
569+
} else if (controller.squeeze >= 0.98) {
570+
controller.squeeze = 1;
571+
}
572+
577573
for (var j = 0; j < inputSource.gamepad.axes.length; j++) {
578574
switch (j) {
579575
case 0:
@@ -729,10 +725,11 @@
729725
xrData.viewerHitTestPose.frame = xrData.frameNumber;
730726
let viewerHitTestResults = frame.getHitTestResults(this.viewerHitTestSource);
731727
if (viewerHitTestResults.length > 0) {
732-
let hitTestPose = viewerHitTestResults[0].getPose(session.refSpace);
728+
let hitTestPose = viewerHitTestResults[0].getPose(session.localRefSpace);
733729
xrData.viewerHitTestPose.available = 1;
734730
xrData.viewerHitTestPose.position[0] = hitTestPose.transform.position.x;
735-
xrData.viewerHitTestPose.position[1] = hitTestPose.transform.position.y;
731+
let hitTestPoseBase = viewerHitTestResults[0].getPose(session.refSpace); // Ugly hack for y position on Samsung Internet
732+
xrData.viewerHitTestPose.position[1] = hitTestPose.transform.position.y + Math.abs(hitTestPose.transform.position.y - hitTestPoseBase.transform.position.y);
736733
xrData.viewerHitTestPose.position[2] = -hitTestPose.transform.position.z;
737734
xrData.viewerHitTestPose.rotation[0] = -hitTestPose.transform.orientation.x;
738735
xrData.viewerHitTestPose.rotation[1] = -hitTestPose.transform.orientation.y;

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,26 @@
22

33
You can [check the live demo here](https://de-panther.github.io/unity-webxr-export)
44

5-
This is a project based on Mozilla's [Unity WebXR Export](https://github.com/MozillaReality/unity-webxr-export) (from when it was WebVR export).
5+
This is a project based on Mozilla's [Unity WebXR Exporter](https://github.com/MozillaReality/unity-webxr-export) (from when it was WebVR exporter).
66

77
WebVR and WebXR, while having lots in common, are different in the way they calling a frame, using controllers, and the fact the WebXR have the ground for support AR and not just VR.
88

99
That, and the fact that I want to use more updated version of Unity Editor and tools/practices, made me to create this fork.
1010

11-
I'm continuing to update this fork as an experimental project, Mozilla's repository is more stable, and I'll merge there features that I tested here.
11+
I'm continuing to update this fork, fix bugs and add features.
1212

1313
I deleted all the docs, as they are no longer relevant.
1414

1515
<hr>
1616

1717
## Compatibility
1818

19-
Important notice regarding this Git repository - This repository use Symlinks. make sure that Symlinks are enabled when you clone.
19+
**Important notice** regarding this Git repository - This repository use Symlinks. make sure that Symlinks are enabled when you clone.
2020

2121
`git config core.symlinks true`
2222

23+
Or just use this as a Unity Package (UPM), more info [here](Packages/webxr/README.md)
24+
2325
### Unity editor version
2426

2527
* `2019.3` and above.
@@ -92,6 +94,8 @@ Much of the WebXR upgrades and API usage made possible thanks to these resources
9294

9395
[The Immersive Web Working Group/Community Group](https://immersive-web.github.io/)
9496

97+
[SimpleWebXR by Rufus31415](https://github.com/Rufus31415/Simple-WebXR-Unity)
98+
9599
## Credits
96100

97101
Special thanks to [needle.tools](https://needle.tools/) for the help in making this a proper package.

0 commit comments

Comments
 (0)