Skip to content

Commit 3d188db

Browse files
authored
Remove VREffect / VRControls in favor of the new WebGLRenderer API (#3152)
1 parent e2c3975 commit 3d188db

File tree

24 files changed

+538
-1265
lines changed

24 files changed

+538
-1265
lines changed

‎docs/components/camera.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ A camera situated at the average height of human eye level (1.6 meters).
2727
| far | Camera frustum far clipping plane. | 10000 |
2828
| fov | Field of view (in degrees). | 80 |
2929
| near | Camera frustum near clipping plane. | 0.005 |
30-
| 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 |
3130
| zoom | Zoom factor of the camera. | 1 |
3231

3332
## Default Camera

‎docs/components/look-controls.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ component](camera.md).
2929
| enabled | Whether look controls are enabled. | true |
3030
| hmdEnabled | Whether to use VR headset pose in VR mode. | true |
3131
| reverseMouseDrag | Whether to reverse mouse drag. | false |
32-
| standing | Whether standing mode is enabled (passed to `THREE.VRControls`). | true |
3332
| touchEnabled | Whether to use touch controls in magic window mode. | true |
33+
| 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 |
3434

3535
## Customizing look-controls
3636

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"present": "0.0.6",
4242
"promise-polyfill": "^3.1.0",
4343
"style-attr": "^1.0.2",
44-
"three": "^0.87.0",
44+
"three": "mrdoob/three.js#aa7557123d",
4545
"three-bmfont-text": "^2.1.0",
4646
"webvr-polyfill": "^0.9.40"
4747
},

‎src/components/camera.js‎

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
var registerComponent = require('../core/component').registerComponent;
22
var THREE = require('../lib/three');
3-
var utils = require('../utils/');
4-
var bind = utils.bind;
5-
6-
var checkHasPositionalTracking = utils.device.checkHasPositionalTracking;
73

84
/**
95
* Camera component.
@@ -15,7 +11,6 @@ module.exports.Component = registerComponent('camera', {
1511
far: {default: 10000},
1612
fov: {default: 80, min: 0},
1713
near: {default: 0.005, min: 0},
18-
userHeight: {default: 0, min: 0},
1914
zoom: {default: 1, min: 0}
2015
},
2116

@@ -26,22 +21,10 @@ module.exports.Component = registerComponent('camera', {
2621
init: function () {
2722
var camera;
2823
var el = this.el;
29-
var sceneEl = el.sceneEl;
30-
31-
this.savedPose = null;
3224

3325
// Create camera.
3426
camera = this.camera = new THREE.PerspectiveCamera();
3527
el.setObject3D('camera', camera);
36-
37-
// Add listeners to save and restore camera pose if headset is present.
38-
this.onEnterVR = bind(this.onEnterVR, this);
39-
this.onExitVR = bind(this.onExitVR, this);
40-
sceneEl.addEventListener('enter-vr', this.onEnterVR);
41-
sceneEl.addEventListener('exit-vr', this.onExitVR);
42-
43-
// Call enter VR handler if the scene has entered VR before the event listeners attached.
44-
if (sceneEl.is('vr-mode')) { this.onEnterVR(); }
4528
},
4629

4730
/**
@@ -53,9 +36,6 @@ module.exports.Component = registerComponent('camera', {
5336
var camera = this.camera;
5437
var system = this.system;
5538

56-
// Update height offset.
57-
this.addHeightOffset(oldData.userHeight);
58-
5939
// Update properties.
6040
camera.aspect = data.aspect || (window.innerWidth / window.innerHeight);
6141
camera.far = data.far;
@@ -81,101 +61,6 @@ module.exports.Component = registerComponent('camera', {
8161
* Remove camera on remove (callback).
8262
*/
8363
remove: function () {
84-
var sceneEl = this.el.sceneEl;
8564
this.el.removeObject3D('camera');
86-
sceneEl.removeEventListener('enter-vr', this.onEnterVR);
87-
sceneEl.removeEventListener('exit-vr', this.onExitVR);
88-
},
89-
90-
/**
91-
* Save pose and remove the offset.
92-
*/
93-
onEnterVR: function () {
94-
this.saveCameraPose();
95-
this.removeHeightOffset();
96-
},
97-
98-
/**
99-
* Restore the pose. Do not need to re-add the offset because it was saved on entering VR.
100-
*/
101-
onExitVR: function () {
102-
this.restoreCameraPose();
103-
},
104-
105-
/**
106-
* Offsets the position of the camera to set a human scale perspective
107-
* This offset is not necessary when using a headset because the SDK
108-
* will return the real user's head height and position.
109-
*/
110-
addHeightOffset: function (oldOffset) {
111-
var el = this.el;
112-
var currentPosition;
113-
var userHeightOffset = this.data.userHeight;
114-
115-
oldOffset = oldOffset || 0;
116-
currentPosition = el.getAttribute('position') || {x: 0, y: 0, z: 0};
117-
el.setAttribute('position', {
118-
x: currentPosition.x,
119-
y: currentPosition.y - oldOffset + userHeightOffset,
120-
z: currentPosition.z
121-
});
122-
},
123-
124-
/**
125-
* Remove the height offset (called when entering VR) since WebVR API gives absolute
126-
* position.
127-
*/
128-
removeHeightOffset: function () {
129-
var currentPosition;
130-
var el = this.el;
131-
var hasPositionalTracking;
132-
var userHeightOffset = this.data.userHeight;
133-
134-
// Remove the offset if there is positional tracking when entering VR.
135-
// Necessary for fullscreen mode with no headset.
136-
// Checking this.hasPositionalTracking to make the value injectable for unit tests.
137-
hasPositionalTracking = this.hasPositionalTracking !== undefined
138-
? this.hasPositionalTracking
139-
: checkHasPositionalTracking();
140-
141-
if (!userHeightOffset || !hasPositionalTracking) { return; }
142-
143-
currentPosition = el.getAttribute('position') || {x: 0, y: 0, z: 0};
144-
el.setAttribute('position', {
145-
x: currentPosition.x,
146-
y: currentPosition.y - userHeightOffset,
147-
z: currentPosition.z
148-
});
149-
},
150-
151-
/**
152-
* Save camera pose before entering VR to restore later if exiting.
153-
*/
154-
saveCameraPose: function () {
155-
var el = this.el;
156-
var hasPositionalTracking = this.hasPositionalTracking !== undefined ? this.hasPositionalTracking : checkHasPositionalTracking();
157-
158-
if (this.savedPose || !hasPositionalTracking) { return; }
159-
160-
this.savedPose = {
161-
position: el.getAttribute('position').clone(),
162-
rotation: el.getAttribute('rotation')
163-
};
164-
},
165-
166-
/**
167-
* Reset camera pose to before entering VR.
168-
*/
169-
restoreCameraPose: function () {
170-
var el = this.el;
171-
var savedPose = this.savedPose;
172-
var hasPositionalTracking = this.hasPositionalTracking !== undefined ? this.hasPositionalTracking : checkHasPositionalTracking();
173-
174-
if (!savedPose || !hasPositionalTracking) { return; }
175-
176-
// Reset camera orientation.
177-
el.setAttribute('position', savedPose.position);
178-
el.setAttribute('rotation', savedPose.rotation);
179-
this.savedPose = null;
18065
}
18166
});

0 commit comments

Comments
 (0)