Skip to content

Commit f3ff4ca

Browse files
committed
Simplify code that handles the camera pose in VR. With the removal of VREffect / VRControls the camera pose udpate is entirely managed by THREE. VRManager falls back to a default 1.6m height when the
VRDevice does not have positional tracking or stageParameters data. One can position the camera in 2D mode. When entering VR the value will be stored and restore upon exiting VR mode. (fix #3315 #3118 #3051 #2487)
1 parent 836f17f commit f3ff4ca

File tree

26 files changed

+90
-323
lines changed

26 files changed

+90
-323
lines changed

docs/components/camera.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ to move and rotate the camera.
1616
A camera situated at the average height of human eye level (1.6 meters).
1717

1818
```html
19-
<a-entity camera="userHeight: 1.6" look-controls></a-entity>
19+
<a-entity position="0 1.6 0" camera look-controls></a-entity>
2020
```
2121

2222
## Properties
@@ -36,22 +36,14 @@ A camera situated at the average height of human eye level (1.6 meters).
3636
If a camera is not specified, A-Frame will inject a default camera:
3737

3838
```html
39-
<a-entity camera="active: true; userHeight: 1.6" look-controls wasd-controls position="0 0 0" data-aframe-default-camera></a-entity>
39+
<a-entity camera="active: true" look-controls wasd-controls position="0 0 0" data-aframe-default-camera></a-entity>
4040
```
4141

4242
If a camera is specified (e.g., our own `<a-camera>` or `<a-entity camera>`),
4343
then the default camera will not be added.
4444

4545
## VR Behavior
4646

47-
When not in VR mode, `userHeight` translates the camera up to approximate
48-
average height of human eye level. The injected camera has this set to 1.6
49-
(meters). When entering VR, this height offset is *removed* such that we used
50-
absolute position returned from the VR headset. The offset is convenient for
51-
experiences that work both in and out of VR, as well as making experiences look
52-
decent from a desktop screen as opposed to clipping the ground if the headset
53-
was resting on the ground.
54-
5547
When exiting VR, the camera will restore its rotation to its rotation *before*
5648
it entered VR. This is so when we exit VR, the rotation of the camera is back
5749
to normal for a desktop screen.

docs/components/look-controls.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ component](camera.md).
2626

2727
[pointer-lock-api]: https://developer.mozilla.org/docs/Web/API/Pointer_Lock_API
2828

29-
| Property | Description | Default Value |
30-
|--------------------|------------------------------------------------------------------|---------------|
31-
| enabled | Whether look controls are enabled. | true |
32-
| hmdEnabled | Whether to use VR headset pose in VR mode. | true |
33-
| reverseMouseDrag | Whether to reverse mouse drag. | false |
34-
| touchEnabled | Whether to use touch controls in magic window mode. | true |
29+
| Property | Description | Default Value |
30+
|------------------|------------------------------------------------------------------|---------------|
31+
| enabled | Whether look controls are enabled. | true |
32+
| hmdEnabled | Whether to use VR headset pose in VR mode. | true |
33+
| reverseMouseDrag | Whether to reverse mouse drag. | false |
34+
| touchEnabled | Whether to use touch controls in magic window mode. | true |
3535
| pointerLockEnabled | Whether to hide the cursor using the [Pointer Lock API][pointer-lock-api]. | true |
36-
| userHeight | Height offset to add to the camera when *not* in VR mode so the camera is not on ground level. The default camera that A-Frame injects or the `<a-camera>` primitive sets this to 1.6 meters. But note the default camera component alone (`<a-entity camera>`) defaults this to 0. | 0 |
3736

3837
## Customizing look-controls
3938

@@ -52,8 +51,7 @@ be left maintaining a wide array of flags.
5251

5352
The component lives within a Browserify/Webpack context so you'll need to
5453
replace the `require` statements with A-Frame globals (e.g.,
55-
`AFRAME.registerComponent`, `window.THREE`,
56-
`AFRAME.constants.DEFAULT_CAMERA_HEIGHT`), and get rid of the `module.exports`.
54+
`AFRAME.registerComponent`, `window.THREE`), and get rid of the `module.exports`.
5755

5856
## Caveats
5957

docs/primitives/a-camera.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ source_code: src/extras/primitives/primitives/a-camera.js
99
The camera primitive determines what the user sees. We can change the viewport
1010
by modifying the camera entity's position and rotation.
1111

12-
[userheight]: ../components/camera.md#vr-behavior
13-
14-
Note that by default, the camera origin will be at `0 1.6 0` in desktop mode
15-
and `0 0 0` in VR mode. Read about the [`camera.userHeight` property][userheight].
16-
1712
## Example
1813

1914
```html
@@ -31,7 +26,6 @@ and `0 0 0` in VR mode. Read about the [`camera.userHeight` property][userheight
3126
| fov | camera.fov | 80 |
3227
| look-controls-enabled | look-controls.enabled | true |
3328
| near | camera.near | 0.5 |
34-
| user-height | camera.userHeight | 1.6 |
3529
| reverse-mouse-drag | look-controls.reverseMouseDrag | false |
3630
| wasd-controls-enabled | wasd-controls.enabled | true |
3731

examples/animation/aframe-logo/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
<a-animation attribute="position" from="0 5 0" to="0 0 0" dur="4000"
1818
easing="ease-out"></a-animation>
1919
<a-entity position="0 880 1290" rotation="-34 0 0">
20-
<a-camera id="camera" near="1000" far="4000" fov="2.2" user-height="0"
21-
wasd-controls-enabled="false" look-controls-enabled="false"></a-camera>
20+
<a-camera id="camera" near="1000" far="4000" fov="2.2" wasd-controls-enabled="false" look-controls-enabled="false"></a-camera>
2221
</a-entity>
2322
</a-entity>
2423

examples/animation/generic-logo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</a-assets>
1515

1616
<a-entity>
17-
<a-camera fov="80" near="0.1" wasd-controls-enabled="false" user-height="0"></a-camera>
17+
<a-camera fov="80" near="0.1" wasd-controls-enabled="false"></a-camera>
1818
</a-entity>
1919

2020
<!-- A generic logo made of animated elements -->

examples/animation/pivots/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</a-assets>
1919

2020
<a-entity position="0 0 8">
21-
<a-camera user-height="0"></a-camera>
21+
<a-camera></a-camera>
2222
</a-entity>
2323

2424
<!-- 1 -->

examples/showcase/anime-UI/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</a-assets>
3232

3333
<a-entity position="1.75 0 1.2" rotation="0 28 0">
34-
<a-camera near="0.1" user-height="0"></a-camera>
34+
<a-camera near="0.1"></a-camera>
3535
</a-entity>
3636

3737
<a-entity position="0 0 -3">

examples/showcase/link-traversal/js/components/ground.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ AFRAME.registerComponent('ground', {
1515
value.geometry.computeFaceNormals();
1616
value.geometry.computeVertexNormals();
1717
value.receiveShadow = true;
18-
value.material.shading = THREE.FlatShading;
18+
value.material.flatShading = THREE.FlatShading;
1919
}
2020
});
2121
self.el.setObject3D('ground', obj);

examples/showcase/tracked-controls/components/grab.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,33 @@ AFRAME.registerComponent('grab', {
1212
this.onHit = this.onHit.bind(this);
1313
this.onGripOpen = this.onGripOpen.bind(this);
1414
this.onGripClose = this.onGripClose.bind(this);
15+
this.currentPosition = new THREE.Vector3();
1516
},
1617

1718
play: function () {
1819
var el = this.el;
1920
el.addEventListener('hit', this.onHit);
20-
el.addEventListener('gripclose', this.onGripClose);
21-
el.addEventListener('gripopen', this.onGripOpen);
22-
el.addEventListener('thumbup', this.onGripClose);
23-
el.addEventListener('thumbdown', this.onGripOpen);
24-
el.addEventListener('pointup', this.onGripClose);
25-
el.addEventListener('pointdown', this.onGripOpen);
21+
el.addEventListener('buttondown', this.onGripClose);
22+
el.addEventListener('buttonup', this.onGripOpen);
2623
},
2724

2825
pause: function () {
2926
var el = this.el;
3027
el.removeEventListener('hit', this.onHit);
31-
el.removeEventListener('gripclose', this.onGripClose);
32-
el.removeEventListener('gripopen', this.onGripOpen);
33-
el.removeEventListener('thumbup', this.onGripClose);
34-
el.removeEventListener('thumbdown', this.onGripOpen);
35-
el.removeEventListener('pointup', this.onGripClose);
36-
el.removeEventListener('pointdown', this.onGripOpen);
28+
el.addEventListener('buttondown', this.onGripClose);
29+
el.addEventListener('buttonup', this.onGripOpen);
3730
},
3831

3932
onGripClose: function (evt) {
33+
if (this.grabbing) { return; }
4034
this.grabbing = true;
35+
this.pressedButtonId = evt.detail.id;
4136
delete this.previousPosition;
4237
},
4338

4439
onGripOpen: function (evt) {
4540
var hitEl = this.hitEl;
41+
if (this.pressedButtonId !== evt.detail.id) { return; }
4642
this.grabbing = false;
4743
if (!hitEl) { return; }
4844
hitEl.removeState(this.GRABBED_STATE);
@@ -74,7 +70,9 @@ AFRAME.registerComponent('grab', {
7470
},
7571

7672
updateDelta: function () {
77-
var currentPosition = this.el.getAttribute('position');
73+
var currentPosition = this.currentPosition;
74+
this.el.object3D.updateMatrixWorld();
75+
currentPosition.setFromMatrixPosition(this.el.object3D.matrixWorld);
7876
if (!this.previousPosition) {
7977
this.previousPosition = new THREE.Vector3();
8078
this.previousPosition.copy(currentPosition);

examples/showcase/tracked-controls/components/ground.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ AFRAME.registerComponent('ground', {
1414
objectLoader.load(MODEL_URL, function (obj) {
1515
obj.children.forEach(function (value) {
1616
value.receiveShadow = true;
17-
value.material.shading = THREE.FlatShading;
17+
value.material.flatShading = THREE.FlatShading;
1818
});
1919
object3D.add(obj);
2020
});

0 commit comments

Comments
 (0)