Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for VR headsets that do not provide stageParameters #3000

Merged
merged 4 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/components/look-controls.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -56,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.el.sceneEl.camera.el;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A scene could have multiple cameras. In this case we probably only care about the camera on the entity where this component is setup. I would use the public API this way:

var el = this.el;
var userHeight = el.hasAttribute('camera') && el.getAttribute('camera').userHeight || DEFAULT_CAMERA_HEIGHT;
return userHeight;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work in your case?

Copy link
Member

@dmarcos dmarcos Aug 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried about the coupling of look-controls and the camera components we have now. Moving userHeight to look-controls is something we have discussed in the past but we can do it in a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this works and looks better. Thank you!

var headCamera = headEl.components.camera;
return (headCamera ? headCamera.data.userHeight : 0) || DEFAULT_CAMERA_HEIGHT;
},

play: function () {
this.addEventListeners();
},
Expand Down
24 changes: 24 additions & 0 deletions tests/components/look-controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -52,4 +53,27 @@ suite('look-controls', function () {
window.dispatchEvent(new Event('mouseup'));
});
});

suite('head-height', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tests!

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();
});
});
});