From bb747ff2443d20a9fb1c4f815378ee180a635b98 Mon Sep 17 00:00:00 2001 From: Lewis Weaver Date: Tue, 1 Aug 2017 11:25:13 -0700 Subject: [PATCH 1/3] Fixed head height on VRDisplays that do not provide the optional stageParameters attribute. --- src/components/look-controls.js | 15 ++++++++++++++- tests/components/look-controls.test.js | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/components/look-controls.js b/src/components/look-controls.js index e4d7ba229b3..d80eceed57e 100644 --- a/src/components/look-controls.js +++ b/src/components/look-controls.js @@ -1,5 +1,6 @@ var registerComponent = require('../core/component').registerComponent; var THREE = require('../lib/three'); +var DEFAULT_CAMERA_HEIGHT = require('../constants').DEFAULT_CAMERA_HEIGHT; var bind = require('../utils/bind'); // To avoid recalculation at every mouse movement tick @@ -17,7 +18,9 @@ module.exports.Component = registerComponent('look-controls', { enabled: {default: true}, hmdEnabled: {default: true}, reverseMouseDrag: {default: false}, - standing: {default: true} + standing: {default: true}, + userHeight: {default: 0}, + headElement: {type: 'selector'} }, init: function () { @@ -54,11 +57,21 @@ module.exports.Component = registerComponent('look-controls', { var data = this.data; if (!data.enabled) { return; } this.controls.standing = data.standing; + this.controls.userHeight = this.getUserHeight(); this.controls.update(); this.updateOrientation(); this.updatePosition(); }, + /** + * Return user height to use for standing poses, where a device doesn't provide an offset. + */ + getUserHeight: function () { + var headEl = this.data.headElement || this.el.sceneEl.camera.el; + var headCamera = headEl.components.camera; + return (headCamera ? headCamera.data.userHeight : 0) || DEFAULT_CAMERA_HEIGHT; + }, + play: function () { this.addEventListeners(); }, diff --git a/tests/components/look-controls.test.js b/tests/components/look-controls.test.js index 609a996c025..098bc9ac905 100644 --- a/tests/components/look-controls.test.js +++ b/tests/components/look-controls.test.js @@ -2,6 +2,7 @@ var CANVAS_GRAB_CLASS = 'a-grab-cursor'; var GRABBING_CLASS = 'a-grabbing'; +var DEFAULT_USER_HEIGHT = 1.6; suite('look-controls', function () { setup(function (done) { @@ -52,4 +53,27 @@ suite('look-controls', function () { window.dispatchEvent(new Event('mouseup')); }); }); + + suite('head-height', function () { + test('Return head height from camera device', function (done) { + var el = this.sceneEl; + var cameraEl = el.camera.el; + var cameraHeight = 2.5; + var lookControls = el.camera.el.components['look-controls']; + cameraEl.setAttribute('camera', 'userHeight', cameraHeight); + + assert.shallowDeepEqual(lookControls.getUserHeight(), cameraHeight); + done(); + }); + + test('Return default head height for poses where device does not provide an offset', function (done) { + var el = this.sceneEl; + var lookControls = el.camera.el.components['look-controls']; + var cameraEl = el.camera.el; + cameraEl.components.camera = null; + + assert.shallowDeepEqual(lookControls.getUserHeight(), DEFAULT_USER_HEIGHT); + done(); + }); + }); }); From 20da7d5a0bf6f23f89fc51fb83d1051bbcb540c2 Mon Sep 17 00:00:00 2001 From: Olga Milovanova Date: Fri, 25 Aug 2017 14:09:07 -0700 Subject: [PATCH 2/3] Remove unused public properties --- src/components/look-controls.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/look-controls.js b/src/components/look-controls.js index 1320b7c13bb..8c6bcae3f3f 100644 --- a/src/components/look-controls.js +++ b/src/components/look-controls.js @@ -18,9 +18,7 @@ module.exports.Component = registerComponent('look-controls', { enabled: {default: true}, hmdEnabled: {default: true}, reverseMouseDrag: {default: false}, - standing: {default: true}, - userHeight: {default: 0}, - headElement: {type: 'selector'} + standing: {default: true} }, init: function () { @@ -69,7 +67,7 @@ module.exports.Component = registerComponent('look-controls', { * Return user height to use for standing poses, where a device doesn't provide an offset. */ getUserHeight: function () { - var headEl = this.data.headElement || this.el.sceneEl.camera.el; + var headEl = this.el.sceneEl.camera.el; var headCamera = headEl.components.camera; return (headCamera ? headCamera.data.userHeight : 0) || DEFAULT_CAMERA_HEIGHT; }, From cd29160ac6280f9ec2a18fe361ebfc717bcb429f Mon Sep 17 00:00:00 2001 From: Olga Milovanova Date: Tue, 29 Aug 2017 11:29:22 -0700 Subject: [PATCH 3/3] Decouple look-controls and scene camera --- src/components/look-controls.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/look-controls.js b/src/components/look-controls.js index 8c6bcae3f3f..517e97f3271 100644 --- a/src/components/look-controls.js +++ b/src/components/look-controls.js @@ -67,9 +67,9 @@ module.exports.Component = registerComponent('look-controls', { * Return user height to use for standing poses, where a device doesn't provide an offset. */ getUserHeight: function () { - var headEl = this.el.sceneEl.camera.el; - var headCamera = headEl.components.camera; - return (headCamera ? headCamera.data.userHeight : 0) || DEFAULT_CAMERA_HEIGHT; + var el = this.el; + var userHeight = el.hasAttribute('camera') && el.getAttribute('camera').userHeight || DEFAULT_CAMERA_HEIGHT; + return userHeight; }, play: function () {