Skip to content

Commit

Permalink
Remove VREffect / VRControls in favor of the new WebGLRenderer API
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarcos committed Dec 12, 2017
1 parent cfb2d2b commit b72d93c
Show file tree
Hide file tree
Showing 24 changed files with 538 additions and 1,265 deletions.
1 change: 0 additions & 1 deletion docs/components/camera.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ A camera situated at the average height of human eye level (1.6 meters).
| far | Camera frustum far clipping plane. | 10000 |
| fov | Field of view (in degrees). | 80 |
| near | Camera frustum near clipping plane. | 0.005 |
| 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 |
| zoom | Zoom factor of the camera. | 1 |

## Default Camera
Expand Down
2 changes: 1 addition & 1 deletion docs/components/look-controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ component](camera.md).
| enabled | Whether look controls are enabled. | true |
| hmdEnabled | Whether to use VR headset pose in VR mode. | true |
| reverseMouseDrag | Whether to reverse mouse drag. | false |
| standing | Whether standing mode is enabled (passed to `THREE.VRControls`). | true |
| touchEnabled | Whether to use touch controls in magic window mode. | true |
| 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 |

## Customizing look-controls

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"present": "0.0.6",
"promise-polyfill": "^3.1.0",
"style-attr": "^1.0.2",
"three": "^0.87.0",
"three": "mrdoob/three.js#aa7557123d",
"three-bmfont-text": "^2.1.0",
"webvr-polyfill": "^0.9.40"
},
Expand Down
115 changes: 0 additions & 115 deletions src/components/camera.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
var registerComponent = require('../core/component').registerComponent;
var THREE = require('../lib/three');
var utils = require('../utils/');
var bind = utils.bind;

var checkHasPositionalTracking = utils.device.checkHasPositionalTracking;

/**
* Camera component.
Expand All @@ -15,7 +11,6 @@ module.exports.Component = registerComponent('camera', {
far: {default: 10000},
fov: {default: 80, min: 0},
near: {default: 0.005, min: 0},
userHeight: {default: 0, min: 0},
zoom: {default: 1, min: 0}
},

Expand All @@ -26,22 +21,10 @@ module.exports.Component = registerComponent('camera', {
init: function () {
var camera;
var el = this.el;
var sceneEl = el.sceneEl;

this.savedPose = null;

// Create camera.
camera = this.camera = new THREE.PerspectiveCamera();
el.setObject3D('camera', camera);

// Add listeners to save and restore camera pose if headset is present.
this.onEnterVR = bind(this.onEnterVR, this);
this.onExitVR = bind(this.onExitVR, this);
sceneEl.addEventListener('enter-vr', this.onEnterVR);
sceneEl.addEventListener('exit-vr', this.onExitVR);

// Call enter VR handler if the scene has entered VR before the event listeners attached.
if (sceneEl.is('vr-mode')) { this.onEnterVR(); }
},

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

// Update height offset.
this.addHeightOffset(oldData.userHeight);

// Update properties.
camera.aspect = data.aspect || (window.innerWidth / window.innerHeight);
camera.far = data.far;
Expand All @@ -81,101 +61,6 @@ module.exports.Component = registerComponent('camera', {
* Remove camera on remove (callback).
*/
remove: function () {
var sceneEl = this.el.sceneEl;
this.el.removeObject3D('camera');
sceneEl.removeEventListener('enter-vr', this.onEnterVR);
sceneEl.removeEventListener('exit-vr', this.onExitVR);
},

/**
* Save pose and remove the offset.
*/
onEnterVR: function () {
this.saveCameraPose();
this.removeHeightOffset();
},

/**
* Restore the pose. Do not need to re-add the offset because it was saved on entering VR.
*/
onExitVR: function () {
this.restoreCameraPose();
},

/**
* Offsets the position of the camera to set a human scale perspective
* This offset is not necessary when using a headset because the SDK
* will return the real user's head height and position.
*/
addHeightOffset: function (oldOffset) {
var el = this.el;
var currentPosition;
var userHeightOffset = this.data.userHeight;

oldOffset = oldOffset || 0;
currentPosition = el.getAttribute('position') || {x: 0, y: 0, z: 0};
el.setAttribute('position', {
x: currentPosition.x,
y: currentPosition.y - oldOffset + userHeightOffset,
z: currentPosition.z
});
},

/**
* Remove the height offset (called when entering VR) since WebVR API gives absolute
* position.
*/
removeHeightOffset: function () {
var currentPosition;
var el = this.el;
var hasPositionalTracking;
var userHeightOffset = this.data.userHeight;

// Remove the offset if there is positional tracking when entering VR.
// Necessary for fullscreen mode with no headset.
// Checking this.hasPositionalTracking to make the value injectable for unit tests.
hasPositionalTracking = this.hasPositionalTracking !== undefined
? this.hasPositionalTracking
: checkHasPositionalTracking();

if (!userHeightOffset || !hasPositionalTracking) { return; }

currentPosition = el.getAttribute('position') || {x: 0, y: 0, z: 0};
el.setAttribute('position', {
x: currentPosition.x,
y: currentPosition.y - userHeightOffset,
z: currentPosition.z
});
},

/**
* Save camera pose before entering VR to restore later if exiting.
*/
saveCameraPose: function () {
var el = this.el;
var hasPositionalTracking = this.hasPositionalTracking !== undefined ? this.hasPositionalTracking : checkHasPositionalTracking();

if (this.savedPose || !hasPositionalTracking) { return; }

this.savedPose = {
position: el.getAttribute('position').clone(),
rotation: el.getAttribute('rotation')
};
},

/**
* Reset camera pose to before entering VR.
*/
restoreCameraPose: function () {
var el = this.el;
var savedPose = this.savedPose;
var hasPositionalTracking = this.hasPositionalTracking !== undefined ? this.hasPositionalTracking : checkHasPositionalTracking();

if (!savedPose || !hasPositionalTracking) { return; }

// Reset camera orientation.
el.setAttribute('position', savedPose.position);
el.setAttribute('rotation', savedPose.rotation);
this.savedPose = null;
}
});
Loading

0 comments on commit b72d93c

Please sign in to comment.