Fixes for desktop/cardboard use
This commit is contained in:
parent
a36f696389
commit
0e6ae0b958
|
@ -73,7 +73,7 @@ export async function startEngine(
|
||||||
const { scene, floorMeshes } = await createScene(canvas, engine);
|
const { scene, floorMeshes } = await createScene(canvas, engine);
|
||||||
|
|
||||||
const xr = await scene.createDefaultXRExperienceAsync({});
|
const xr = await scene.createDefaultXRExperienceAsync({});
|
||||||
const xrAvailable = xr.baseExperience !== void 0;
|
const xrAvailable = xr?.baseExperience !== void 0;
|
||||||
|
|
||||||
let camera: FreeCamera;
|
let camera: FreeCamera;
|
||||||
if (xrAvailable) {
|
if (xrAvailable) {
|
||||||
|
@ -120,20 +120,22 @@ export async function startEngine(
|
||||||
|
|
||||||
for (const gp of Array.from(navigator.getGamepads())) {
|
for (const gp of Array.from(navigator.getGamepads())) {
|
||||||
if (gp !== null) {
|
if (gp !== null) {
|
||||||
const pos = new Vector3((gp.axes[0]), (-gp.axes[1]), (-gp.axes[3]));
|
if (sm) {
|
||||||
if (pos.length() > 0.0625) {
|
const pos = new Vector3((gp.axes[0]), (-gp.axes[1]), (-gp.axes[3]));
|
||||||
if (leanBase === null) {
|
if (pos.length() > 0.0625) {
|
||||||
leanBase = { position: xr.baseExperience.camera.position };
|
if (leanBase === null) {
|
||||||
|
leanBase = { position: xr.baseExperience.camera.position };
|
||||||
|
}
|
||||||
|
xr.baseExperience.camera.position =
|
||||||
|
pos.applyRotationQuaternion(xr.baseExperience.camera.absoluteRotation)
|
||||||
|
.scale(0.25)
|
||||||
|
.add(leanBase.position);
|
||||||
|
} else {
|
||||||
|
if (leanBase !== null) {
|
||||||
|
xr.baseExperience.camera.position = leanBase.position;
|
||||||
|
}
|
||||||
|
leanBase = null;
|
||||||
}
|
}
|
||||||
xr.baseExperience.camera.position =
|
|
||||||
pos.applyRotationQuaternion(xr.baseExperience.camera.absoluteRotation)
|
|
||||||
.scale(0.25)
|
|
||||||
.add(leanBase.position);
|
|
||||||
} else {
|
|
||||||
if (leanBase !== null) {
|
|
||||||
xr.baseExperience.camera.position = leanBase.position;
|
|
||||||
}
|
|
||||||
leanBase = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sm && latch(gp, 0)) {
|
if (sm && latch(gp, 0)) {
|
||||||
|
@ -158,12 +160,18 @@ export async function startEngine(
|
||||||
if (sm && latch(gp, 3)) {
|
if (sm && latch(gp, 3)) {
|
||||||
enableVR();
|
enableVR();
|
||||||
}
|
}
|
||||||
if (sm && latch(gp, 5)) {
|
if (latch(gp, 5)) {
|
||||||
const q = xr.baseExperience.camera.rotationQuaternion;
|
const r = sm
|
||||||
const r = q.toEulerAngles();
|
? xr.baseExperience.camera.rotationQuaternion.toEulerAngles()
|
||||||
|
: camera.rotation;
|
||||||
r.y += Math.PI;
|
r.y += Math.PI;
|
||||||
r.y %= 2 * Math.PI;
|
r.y %= 2 * Math.PI;
|
||||||
q.copyFrom(Quaternion.FromEulerAngles(r.x, r.y, r.z));
|
if (sm) {
|
||||||
|
xr.baseExperience.camera.rotationQuaternion.copyFrom(r.toQuaternion());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sm && latch(gp, 4)) {
|
||||||
|
xr.baseExperience.camera.rotationQuaternion.copyFrom(initialRotation.toQuaternion());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue