Skip to content

Commit

Permalink
feat(event-display): handle camera position differently for AR
Browse files Browse the repository at this point in the history
  • Loading branch information
9inpachi committed Jun 24, 2021
1 parent a5481e1 commit 5894cac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class ARManager extends XRManager {
private previousValues = {
sceneScale: 1,
cameraNear: 10,
cameraPosition: new Vector3(1, 0, 1),
};

/**
Expand All @@ -38,10 +37,8 @@ export class ARManager extends XRManager {
protected async onXRSessionStarted(session: any) {
this.previousValues.sceneScale = this.scene.scale.x;
this.previousValues.cameraNear = this.camera.near;
this.previousValues.cameraPosition = this.camera.position.clone();
this.scaleScene(0.00001);
this.camera.near = 0.01;
this.camera.position.set(0, 0, 0.1);
this.renderer.xr.setReferenceSpaceType('local');
await super.onXRSessionStarted(session);
}
Expand All @@ -53,7 +50,6 @@ export class ARManager extends XRManager {
protected onXRSessionEnded() {
this.scaleScene(this.previousValues.sceneScale);
this.camera.near = this.previousValues.cameraNear;
this.camera.position.copy(this.previousValues.cameraPosition);
super.onXRSessionEnded();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Camera, Group, WebGLRenderer, XRSessionInit } from 'three';
import { Camera, Group, Vector3, WebGLRenderer, XRSessionInit } from 'three';

// NOTE: This was created on 28/06/2021
// It might get outdated given how WebXR is still a work in progress
Expand Down Expand Up @@ -111,7 +111,11 @@ export class XRManager {
.copy(camera.clone() as Camera);
this.xrCamera.name = 'XR_CAMERA';

this.cameraGroup.position.copy(this.xrCamera.position);
const cameraPosition =
this.sessionType === XRSessionType.VR
? this.xrCamera.position
: new Vector3(0, 0, 0.1);
this.cameraGroup.position.copy(cameraPosition);
this.cameraGroup.add(this.xrCamera);
}

Expand Down

0 comments on commit 5894cac

Please sign in to comment.