From c981203ceef93f6f1c9177f83f6aa06ac0d5a38a Mon Sep 17 00:00:00 2001 From: Diego Marcos Segura Date: Wed, 1 Nov 2023 11:26:07 -0700 Subject: [PATCH] Deprecate GearVR and Daydream support. Devices have been discontinued for several years now --- docs/components/cursor.md | 6 +- docs/components/daydream-controls.md | 64 ---- docs/components/gearvr-controls.md | 57 ---- docs/components/laser-controls.md | 6 +- docs/components/tracked-controls.md | 10 +- docs/core/utils.md | 6 +- docs/introduction/index.md | 8 +- .../interactions-and-controllers.md | 37 +-- .../vr-headsets-and-webxr-browsers.md | 10 +- src/components/daydream-controls.js | 206 ------------- src/components/gearvr-controls.js | 205 ------------- src/components/index.js | 3 +- src/components/laser-controls.js | 10 - tests/components/daydream-controls.test.js | 250 ---------------- tests/components/gearvr-controls.test.js | 276 ------------------ tests/components/laser-controls.test.js | 10 +- 16 files changed, 28 insertions(+), 1136 deletions(-) delete mode 100644 docs/components/daydream-controls.md delete mode 100644 docs/components/gearvr-controls.md delete mode 100644 src/components/daydream-controls.js delete mode 100644 src/components/gearvr-controls.js delete mode 100644 tests/components/daydream-controls.test.js delete mode 100644 tests/components/gearvr-controls.test.js diff --git a/docs/components/cursor.md b/docs/components/cursor.md index bcd8230be49..a0f89be330f 100644 --- a/docs/components/cursor.md +++ b/docs/components/cursor.md @@ -89,7 +89,7 @@ AFRAME.registerComponent('cursor-listener', { | fuseTimeout | How long to wait (in milliseconds) before triggering a fuse-based click event. | 1500 | | mouseCursorStylesEnabled | Whether to show pointer cursor in `rayOrigin: mouse` mode when hovering over entity. | true | | rayOrigin | Where the intersection ray is cast from (i.e. xrselect ,entity or mouse). `rayOrigin: mouse` is extremely useful for VR development on a mouse and keyboard. | entity -| upEvents | Array of additional events on the entity to *listen* to for triggering `mouseup` (e.g., `trackpadup` for daydream-controls). | [] | +| upEvents | Array of additional events on the entity to *listen* to for triggering `mouseup`. | [] | To further customize the cursor component, we configure the cursor's dependency component, [the raycaster component][raycaster]. @@ -143,9 +143,9 @@ For example: this.el.addEventListener('click', function (evt) { if (!evt.detail.mouseEvent || evt.detail.mouseEvent.button === 0) { console.log("left button clicked (or touch event / no information)"); - + } else if (evt.detail.mouseEvent.button === 2) { - console.log("right button clicked"); + console.log("right button clicked"); } }); ``` diff --git a/docs/components/daydream-controls.md b/docs/components/daydream-controls.md deleted file mode 100644 index 5f4ea3a46c8..00000000000 --- a/docs/components/daydream-controls.md +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: daydream-controls -type: components -layout: docs -parent_section: components -source_code: src/components/daydream-controls.js -examples: [] ---- - -[trackedcontrols]: ./tracked-controls.md - -The daydream-controls component interfaces with the Google Daydream controllers. -It wraps the [tracked-controls component][trackedcontrols] while adding button -mappings, events, and a Daydream controller model that highlights the touched -and/or pressed buttons (trackpad). - -As a first time set up, to use the Daydream controller on Chrome for Android -enable both `WebVR` and `Gamepad Extensions` experiments in `chrome://flags` -and relaunch the browser. - -Then, open your web app, enter VR mode and place the phone inside the headset. -It can occasionally take a few seconds before the controller can be used. - -## Example - -```html - - -``` - -```html - - - -``` - -## Value - -| Property | Description | Default | -|----------------------|----------------------------------------------------|----------------------| -| armModel | Whether the arm model is used for positional data. | true | -| buttonColor | Button colors when not pressed. | #000000 | -| buttonTouchedColor | Button colors when touched. | #777777 | -| buttonHighlightColor | Button colors when pressed and active. | #FFFFFF | -| hand | Set hand that will be tracked (i.e., right, left). | | -| model | Whether the Daydream controller model is loaded. | true | -| orientationOffset | Offset to apply to model orientation. | x: 0, y: 0, z: 0 | - - -## Events - -| Event Name | Description | -| ---------- | ----------- | -| trackpadchanged | Trackpad changed. | -| trackpaddown | Trackpad pressed. | -| trackpadup | Trackpad released. | -| trackpadtouchstart | Trackpad touched. | -| trackpadtouchend | Trackpad not touched. | - -## Assets - -- [Controller OBJ](https://cdn.aframe.io/controllers/google/vr_controller_daydream.obj) -- [Controller MTL](https://cdn.aframe.io/controllers/google/vr_controller_daydream.mtl) - diff --git a/docs/components/gearvr-controls.md b/docs/components/gearvr-controls.md deleted file mode 100644 index 4cdb9a5aa27..00000000000 --- a/docs/components/gearvr-controls.md +++ /dev/null @@ -1,57 +0,0 @@ ---- -title: gearvr-controls -type: components -layout: docs -parent_section: components -source_code: src/components/gearvr-controls.js -examples: [] ---- - -[trackedcontrols]: ./tracked-controls.md - -The gearvr-controls component interfaces with the Samsung/Oculus Gear VR controllers. -It wraps the [tracked-controls component][trackedcontrols] while adding button -mappings, events, and a Gear VR controller model that highlights the touched -and/or pressed buttons (trackpad, trigger). - -## Example - -```html - - - - - - -``` - -## Value - -| Property | Description | Default | -|----------------------|----------------------------------------------------|----------------------| -| armModel | Whether the arm model is used for positional data. | true | -| buttonColor | Button colors when not pressed. | #000000 | -| buttonTouchedColor | Button colors when touched. | #777777 | -| buttonHighlightColor | Button colors when pressed and active. | #FFFFFF | -| hand | The hand that will be tracked (e.g., right, left). | | -| model | Whether the Gear controller model is loaded. | true | -| orientationOffset | Offset to apply to model orientation. | x: 0, y: 0, z: 0 | - -## Events - -| Event Name | Description | -| ---------- | ----------- | -| trackpadchanged | Trackpad changed. | -| trackpaddown | Trackpad pressed. | -| trackpadup | Trackpad released. | -| trackpadtouchstart | Trackpad touched. | -| trackpadtouchend | Trackpad not touched. | -| triggerchanged | Trigger changed. | -| triggerdown | Trigger pressed. | -| triggerup | Trigger released. | - -## Assets - -- [Controller OBJ](https://cdn.aframe.io/controllers/samsung/gear_vr_controller.obj) -- [Controller MTL](https://cdn.aframe.io/controllers/samsung/gear_vr_controller.mtl) - diff --git a/docs/components/laser-controls.md b/docs/components/laser-controls.md index 6fe57a87fe2..39e7133fe97 100644 --- a/docs/components/laser-controls.md +++ b/docs/components/laser-controls.md @@ -15,12 +15,9 @@ The laser-controls component provides tracked controls with a laser or ray cursor shooting out to be used for input and interactions. *DoF* stands for [degrees of freedom][dof]. Because they only require rotation and some form of input, laser-based interactions scale well across 0 DoF (gaze-based, -Cardboard), 3 DoF (Daydream, GearVR with controllers), and 6 DoF (Vive, Oculus -Touch). If desired, we can get a consistent form of interaction that works +Cardboard), and 6 DoF (Vive, Oculus Touch). If desired, we can get a consistent form of interaction that works across all VR platforms with a single line of HTML. -[daydream-controls]: ./daydream-controls.md -[gearvr-controls]: ./gearvr-controls.md [oculus-touch-controls]: ./oculus-touch-controls.md [tracked-controls]: ./tracked-controls.md [vive-controls]: ./vive-controls.md @@ -32,7 +29,6 @@ the hood, laser-controls sets all of the tracked controller components: - [vive-controls] - [oculus-touch-controls] -- [daydream-controls] - [gearvr-controls] - [windows-motion-controls] diff --git a/docs/components/tracked-controls.md b/docs/components/tracked-controls.md index 5f15b40ce1b..c3a402c00fe 100644 --- a/docs/components/tracked-controls.md +++ b/docs/components/tracked-controls.md @@ -10,18 +10,16 @@ examples: [] [handcontrols]: ./hand-controls.md [oculustouchcontrols]: ./oculus-touch-controls.md [vivecontrols]: ./vive-controls.md -[daydreamcontrols]: ./daydream-controls.md [windowsmotioncontrols]: ./windows-motion-controls.md The tracked-controls component interfaces with tracked controllers. tracked-controls uses the Gamepad API to handle tracked controllers, and is abstracted by the [hand-controls component][handcontrols] as well as the [vive-controls][vivecontrols], [oculus-touch-controls][oculustouchcontrols], -[windows-motion-controls][windowsmotioncontrols], and [daydream-controls][daydreamcontrols] -components. This component elects the appropriate controller, applies pose to -the entity, observes buttons state and emits appropriate events. For non-6DOF controllers -such as [daydream-controls][daydreamcontrols], a primitive arm model is used to emulate -positional data. +[windows-motion-controls][windowsmotioncontrols] components. +This component elects the appropriate controller, applies pose to +the entity, observes buttons state and emits appropriate events. For non-6DOF controllers, +a primitive arm model is used to emulate positional data. tracked-controls sets two components that handles different Web API versions for VR: diff --git a/docs/core/utils.md b/docs/core/utils.md index 27ae0bb6bf6..e88556c980a 100644 --- a/docs/core/utils.md +++ b/docs/core/utils.md @@ -146,10 +146,6 @@ diff({a: 1, b: 2, c: 3}, {b: 2, c: 4}) Checks if a VR headset is connected by looking for orientation data. Returns a `boolean`. -### `AFRAME.utils.device.isGearVR ()` - -Checks if device is Gear VR. Returns a `boolean`. - ### `AFRAME.utils.device.isOculusGo ()` Checks if device is Oculus Go. Returns a `boolean`. @@ -222,7 +218,7 @@ Example use cases: * following a mouse pointer using the mousemove event * integrating with [THREE.TransformControls](https://threejs.org/docs/#examples/en/controls/TransformControls), via the objectChange event. -A context such as `this` can be provided to handle function binding for convenience. +A context such as `this` can be provided to handle function binding for convenience. The same as [lodash's`throttle`][lodash], with `leading` and `trailing` options both set to `true` diff --git a/docs/introduction/index.md b/docs/introduction/index.md index 5f1d387184b..cd3838cc7fd 100644 --- a/docs/introduction/index.md +++ b/docs/introduction/index.md @@ -67,9 +67,9 @@ be an easy yet powerful way to develop VR content. As an [independent open source project][github], A-Frame has grown to be one of the [largest VR communities][community]. -A-Frame supports most VR headsets such as Vive, Rift, Windows Mixed Reality, -Daydream, GearVR, Cardboard, Oculus Go, and can even be used for augmented -reality. Although A-Frame supports the whole spectrum, A-Frame aims to define +A-Frame supports most VR headsets such as Vive, Rift, Windows Mixed Reality, Cardboard, +Oculus Go, and can even be used for augmented reality. +Although A-Frame supports the whole spectrum, A-Frame aims to define fully immersive interactive VR experiences that go beyond basic 360° content, making full use of positional tracking and controllers. @@ -111,7 +111,7 @@ developers have unlimited access to JavaScript, DOM APIs, three.js, WebVR, and WebGL. :globe_with_meridians: **Cross-Platform VR**: Build VR applications for Vive, -Rift, Windows Mixed Reality, Daydream, GearVR, and Cardboard with support for +Rift, Meta Quest, Windows Mixed Reality, and Cardboard with support for all respective controllers. Don't have a headset or controllers? No problem! A-Frame still works on standard desktop and smartphones. diff --git a/docs/introduction/interactions-and-controllers.md b/docs/introduction/interactions-and-controllers.md index b4290d6393e..7f5982e3f75 100644 --- a/docs/introduction/interactions-and-controllers.md +++ b/docs/introduction/interactions-and-controllers.md @@ -75,7 +75,7 @@ clicking directly on the entity using a raycaster. We'll first go over gaze-based interactions. Gaze-based interactions rely on rotating our heads and looking at objects to interact with them. This type of interaction is for headsets without a controller. Even with a rotation-only -controller (Daydream, GearVR, Oculus Go), the interaction is still similar. Since A-Frame +controller (Oculus Go), the interaction is still similar. Since A-Frame provides mouse-drag controls by default, gaze-based can sort of be used on desktop to preview the interaction by dragging the camera rotation. @@ -262,7 +262,7 @@ interact with objects with their hands. A-Frame provides components for controllers across the spectrum as supported by their respective WebVR browsers through the [Gamepad Web API][gamepad]. There -are components for Vive, Oculus Touch, Daydream, GearVR and Oculus Go controllers. +are components for Vive, Oculus Touch, Meta Quest and Oculus Go controllers. To inspect the Gamepad object for poking around or to get the Gamepad ID, we can call `navigator.getGamepads()` in the browser console. This will return a @@ -313,7 +313,7 @@ component by: The controller components following are only activated if they detect the controller is found and seen as connected in the Gamepad API. -### Adding 3DoF Controllers (daydream-controls, gearvr-controls, oculus-go-controls) +### Adding 3DoF Controllers (oculus-go-controls) [dof]: http://www.roadtovr.com/introduction-positional-tracking-degrees-freedom-dof/ @@ -325,29 +325,9 @@ degrees of freedom for VR][dof]. The 3DoF controller components provide rotational tracking, a default model matching the real-life hardware, and events to abstract the button mappings. -The controllers for Google Daydream, Samsung GearVR and Oculus Go have 3DoF, and both +The controllers for Oculus Go have 3DoF, and both support only one controller for one hand. -[daydreamcomponent]: ../components/daydream-controls.md - -To add a controller for Google Daydream, use the [daydream-controls -component][daydreamcomponent]. Then try it out on Chrome for Android on a -Daydream smartphone: - -```html - -``` - -[gearvrcomponent]: ../components/gearvr-controls.md - -To add a controller for Samsung GearVR, use the [gearvr-controls -component][gearvrcomponent]. Then try it out on Oculus Carmel or Samsung -Internet on a smartphone with GearVR: - -```html - -``` - [oculusgocomponent]: ../components/oculus-go-controls.md To add a controller for Oculus Go, use the [oculus-go-controls @@ -431,7 +411,7 @@ To add the hand-controls component: ``` Unfortunately, there is not yet a 3DoF controller component that abstracts well -all the types of 3DoF controllers (i.e., Daydream, GearVR). We could create a +all the types of 3DoF controllers (i.e., Oculus Go). We could create a custom controller that works with both controllers. It would be fairly easy to cover since 3DoF controllers do not offer much potential for interaction (i.e., only rotational tracking with a touchpad). @@ -453,8 +433,7 @@ to understand how to do a custom controller without having to do everything from scratch: - The tracked-controls component will provide pose and events -- The vive-controls, oculus-touch-controls, daydream-controls, or - gearvr-controls components provide button mappings controller-specific events +- The vive-controls, oculus-touch-controls... components provide button mappings and controller-specific events - Our custom controller component will build on all of the above, plus overriding the model, animations, visual feedback, states, etc., @@ -482,8 +461,6 @@ AFRAME.registerComponent('custom-controls', { // Build on top of controller components. el.setAttribute('vive-controls', controlConfiguration); el.setAttribute('oculus-touch-controls', controlConfiguration); - el.setAttribute('daydream-controls', controlConfiguration); - el.setAttribute('gearvr-controls', controlConfiguration); el.setAttribute('windows-motion-controls', controlConfiguration); // Set a model. @@ -508,8 +485,6 @@ touched. To handle buttons, look for the event name in the respective controller component documentation pages at the event tables, then register event handlers how we want: -- [daydream-controls events](../components/daydream-controls.md#events) -- [gearvr-controls events](../components/gearvr-controls.md#events) - [hand-controls events](../components/hand-controls.md#events) - [oculus-touch-controls events](../components/oculus-touch-controls.md#events) - [vive-controls events](../components/vive-controls.md#events) diff --git a/docs/introduction/vr-headsets-and-webxr-browsers.md b/docs/introduction/vr-headsets-and-webxr-browsers.md index b796c3d0244..9b2876c7ce1 100644 --- a/docs/introduction/vr-headsets-and-webxr-browsers.md +++ b/docs/introduction/vr-headsets-and-webxr-browsers.md @@ -44,8 +44,6 @@ are constrained to looking around and wiggling the controller. [HTC Vive]: https://www.vive.com/ [Oculus headsets]: https://www.oculus.com/ -[Google Daydream]: https://vr.google.com/daydream/ -[Samsung GearVR]: http://www.samsung.com/global/galaxy/gear-vr/ [Windows Mixed Reality]: https://developer.microsoft.com/en-us/windows/mixed-reality/ [Vive Focus]: https://enterprise.vive.com/us/vivefocus/ @@ -53,13 +51,12 @@ are constrained to looking around and wiggling the controller. |-------------------------|------------|---------------------|--------------------|--------------------------------| | [HTC Vive] | PC | :white_check_mark: | :white_check_mark: | :white_check_mark: | | [Oculus Rift] | PC | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| [Google Daydream] | Android | :x: | :white_check_mark: | :x: | -| [Samsung GearVR] | Android | :x: | :white_check_mark: | :x: | | [Windows Mixed Reality] | PC | :white_check_mark: | :white_check_mark: | :white_check_mark: | | [Oculus Go] | Standalone | :x: | :white_check_mark: | :x: | | [Vive Focus] | Standalone | :x: | :white_check_mark: | :x: | | [Oculus Quest] | Standalone | :white_check_mark: | :white_check_mark: | :white_check_mark: | | [Oculus Quest 2] | Standalone | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| [Oculus Quest 3] | Standalone | :white_check_mark: | :white_check_mark: | :white_check_mark: | ## What is WebXR? @@ -119,9 +116,10 @@ supports include: - HTC Vive - Oculus Rift - Oculus Quest +- Oculus Quest 2 +- Oculus Quest 3 - Oculus Go -- Google Daydream -- Samsung GearVR +- Valve Index - Vive Focus For general hardware recommendations (not requirements): diff --git a/src/components/daydream-controls.js b/src/components/daydream-controls.js deleted file mode 100644 index 4ca3af09c6a..00000000000 --- a/src/components/daydream-controls.js +++ /dev/null @@ -1,206 +0,0 @@ -var registerComponent = require('../core/component').registerComponent; -var bind = require('../utils/bind'); - -var trackedControlsUtils = require('../utils/tracked-controls'); -var checkControllerPresentAndSetup = trackedControlsUtils.checkControllerPresentAndSetup; -var emitIfAxesChanged = trackedControlsUtils.emitIfAxesChanged; -var onButtonEvent = trackedControlsUtils.onButtonEvent; - -var AFRAME_CDN_ROOT = require('../constants').AFRAME_CDN_ROOT; -var DAYDREAM_CONTROLLER_MODEL_BASE_URL = AFRAME_CDN_ROOT + 'controllers/google/'; -var DAYDREAM_CONTROLLER_MODEL_OBJ_URL = DAYDREAM_CONTROLLER_MODEL_BASE_URL + 'vr_controller_daydream.obj'; -var DAYDREAM_CONTROLLER_MODEL_OBJ_MTL = DAYDREAM_CONTROLLER_MODEL_BASE_URL + 'vr_controller_daydream.mtl'; - -var isWebXRAvailable = require('../utils/').device.isWebXRAvailable; - -var GAMEPAD_ID_WEBXR = 'google-daydream'; -var GAMEPAD_ID_WEBVR = 'Daydream Controller'; - -var GAMEPAD_ID_PREFIX = isWebXRAvailable ? GAMEPAD_ID_WEBXR : GAMEPAD_ID_WEBVR; - -/** - * Button indices: - * 0 - trackpad - * 1 - menu (never dispatched on this layer) - * 2 - system (never dispatched on this layer) - * - * Axis: - * 0 - trackpad x - * 1 - trackpad y - */ -var INPUT_MAPPING_WEBVR = { - axes: {trackpad: [0, 1]}, - buttons: ['trackpad', 'menu', 'system'] -}; - -/** - * Button indices: - * 0 - none - * 1 - none - * 2 - touchpad - * - * Axis: - * 0 - touchpad x - * 1 - touchpad y - * Reference: https://github.com/immersive-web/webxr-input-profiles/blob/master/packages/registry/profiles/google/google-daydream.json - */ -var INPUT_MAPPING_WEBXR = { - axes: {touchpad: [0, 1]}, - buttons: ['none', 'none', 'touchpad', 'menu', 'system'] -}; - -var INPUT_MAPPING = isWebXRAvailable ? INPUT_MAPPING_WEBXR : INPUT_MAPPING_WEBVR; - -/** - * Daydream controls. - * Interface with Daydream controller and map Gamepad events to - * controller buttons: trackpad, menu, system - * Load a controller model and highlight the pressed buttons. - */ -module.exports.Component = registerComponent('daydream-controls', { - schema: { - hand: {default: ''}, // This informs the degenerate arm model. - buttonColor: {type: 'color', default: '#000000'}, - buttonTouchedColor: {type: 'color', default: '#777777'}, - buttonHighlightColor: {type: 'color', default: '#FFFFFF'}, - model: {default: true}, - orientationOffset: {type: 'vec3'}, - armModel: {default: true} - }, - - mapping: INPUT_MAPPING, - - bindMethods: function () { - this.onModelLoaded = bind(this.onModelLoaded, this); - this.onControllersUpdate = bind(this.onControllersUpdate, this); - this.checkIfControllerPresent = bind(this.checkIfControllerPresent, this); - this.removeControllersUpdateListener = bind(this.removeControllersUpdateListener, this); - this.onAxisMoved = bind(this.onAxisMoved, this); - }, - - init: function () { - var self = this; - this.onButtonChanged = bind(this.onButtonChanged, this); - this.onButtonDown = function (evt) { onButtonEvent(evt.detail.id, 'down', self); }; - this.onButtonUp = function (evt) { onButtonEvent(evt.detail.id, 'up', self); }; - this.onButtonTouchStart = function (evt) { onButtonEvent(evt.detail.id, 'touchstart', self); }; - this.onButtonTouchEnd = function (evt) { onButtonEvent(evt.detail.id, 'touchend', self); }; - this.controllerPresent = false; - this.lastControllerCheck = 0; - this.bindMethods(); - }, - - addEventListeners: function () { - var el = this.el; - el.addEventListener('buttonchanged', this.onButtonChanged); - el.addEventListener('buttondown', this.onButtonDown); - el.addEventListener('buttonup', this.onButtonUp); - el.addEventListener('touchstart', this.onButtonTouchStart); - el.addEventListener('touchend', this.onButtonTouchEnd); - el.addEventListener('model-loaded', this.onModelLoaded); - el.addEventListener('axismove', this.onAxisMoved); - this.controllerEventsActive = true; - }, - - removeEventListeners: function () { - var el = this.el; - el.removeEventListener('buttonchanged', this.onButtonChanged); - el.removeEventListener('buttondown', this.onButtonDown); - el.removeEventListener('buttonup', this.onButtonUp); - el.removeEventListener('touchstart', this.onButtonTouchStart); - el.removeEventListener('touchend', this.onButtonTouchEnd); - el.removeEventListener('model-loaded', this.onModelLoaded); - el.removeEventListener('axismove', this.onAxisMoved); - this.controllerEventsActive = false; - }, - - checkIfControllerPresent: function () { - checkControllerPresentAndSetup(this, GAMEPAD_ID_PREFIX, - this.data.hand ? {hand: this.data.hand} : {}); - }, - - play: function () { - this.checkIfControllerPresent(); - this.addControllersUpdateListener(); - }, - - pause: function () { - this.removeEventListeners(); - this.removeControllersUpdateListener(); - }, - - injectTrackedControls: function () { - var el = this.el; - var data = this.data; - el.setAttribute('tracked-controls', { - armModel: data.armModel, - hand: data.hand, - idPrefix: GAMEPAD_ID_PREFIX, - id: GAMEPAD_ID_PREFIX, - orientationOffset: data.orientationOffset - }); - if (!this.data.model) { return; } - this.el.setAttribute('obj-model', { - obj: DAYDREAM_CONTROLLER_MODEL_OBJ_URL, - mtl: DAYDREAM_CONTROLLER_MODEL_OBJ_MTL - }); - }, - - addControllersUpdateListener: function () { - this.el.sceneEl.addEventListener('controllersupdated', this.onControllersUpdate, false); - }, - - removeControllersUpdateListener: function () { - this.el.sceneEl.removeEventListener('controllersupdated', this.onControllersUpdate, false); - }, - - onControllersUpdate: function () { - this.checkIfControllerPresent(); - }, - - onModelLoaded: function (evt) { - var controllerObject3D = evt.detail.model; - var buttonMeshes; - if (!this.data.model) { return; } - buttonMeshes = this.buttonMeshes = {}; - buttonMeshes.menu = controllerObject3D.getObjectByName('AppButton_AppButton_Cylinder.004'); - buttonMeshes.system = controllerObject3D.getObjectByName('HomeButton_HomeButton_Cylinder.005'); - buttonMeshes.trackpad = controllerObject3D.getObjectByName('TouchPad_TouchPad_Cylinder.003'); - buttonMeshes.touchpad = controllerObject3D.getObjectByName('TouchPad_TouchPad_Cylinder.003'); - // Offset pivot point. - controllerObject3D.position.set(0, 0, -0.04); - }, - - onAxisMoved: function (evt) { - emitIfAxesChanged(this, this.mapping.axes, evt); - }, - - onButtonChanged: function (evt) { - var button = this.mapping.buttons[evt.detail.id]; - if (!button) return; - // Pass along changed event with button state, using button mapping for convenience. - this.el.emit(button + 'changed', evt.detail.state); - }, - - updateModel: function (buttonName, evtName) { - if (!this.data.model) { return; } - this.updateButtonModel(buttonName, evtName); - }, - - updateButtonModel: function (buttonName, state) { - var buttonMeshes = this.buttonMeshes; - if (!buttonMeshes || !buttonMeshes[buttonName]) { return; } - var color; - switch (state) { - case 'down': - color = this.data.buttonHighlightColor; - break; - case 'touchstart': - color = this.data.buttonTouchedColor; - break; - default: - color = this.data.buttonColor; - } - buttonMeshes[buttonName].material.color.set(color); - } -}); diff --git a/src/components/gearvr-controls.js b/src/components/gearvr-controls.js deleted file mode 100644 index a16d4d6c725..00000000000 --- a/src/components/gearvr-controls.js +++ /dev/null @@ -1,205 +0,0 @@ -var registerComponent = require('../core/component').registerComponent; -var bind = require('../utils/bind'); - -var trackedControlsUtils = require('../utils/tracked-controls'); -var checkControllerPresentAndSetup = trackedControlsUtils.checkControllerPresentAndSetup; -var emitIfAxesChanged = trackedControlsUtils.emitIfAxesChanged; -var onButtonEvent = trackedControlsUtils.onButtonEvent; -var isWebXRAvailable = require('../utils/').device.isWebXRAvailable; - -var AFRAME_CDN_ROOT = require('../constants').AFRAME_CDN_ROOT; -var GEARVR_CONTROLLER_MODEL_BASE_URL = AFRAME_CDN_ROOT + 'controllers/samsung/'; -var GEARVR_CONTROLLER_MODEL_OBJ_URL = GEARVR_CONTROLLER_MODEL_BASE_URL + 'gear_vr_controller.obj'; -var GEARVR_CONTROLLER_MODEL_OBJ_MTL = GEARVR_CONTROLLER_MODEL_BASE_URL + 'gear_vr_controller.mtl'; - -var GAMEPAD_ID_WEBXR = 'samsung-gearvr'; -var GAMEPAD_ID_WEBVR = 'Gear VR'; - -// Prefix for Gen1 and Gen2 Oculus Touch Controllers. -var GAMEPAD_ID_PREFIX = isWebXRAvailable ? GAMEPAD_ID_WEBXR : GAMEPAD_ID_WEBVR; - -/** - * Button indices: - * 0 - trackpad - * 1 - trigger - * - * Axis: - * 0 - trackpad x - * 1 - trackpad y - */ -var INPUT_MAPPING_WEBVR = { - axes: {trackpad: [0, 1]}, - buttons: ['trackpad', 'trigger'] -}; - -/** - * Button indices: - * 0 - trigger - * 1 - none - * 2 - touchpad - * 3 - menu - * - * Axis: - * 0 - touchpad x - * 1 - touchpad y - * Reference: https://github.com/immersive-web/webxr-input-profiles/blob/master/packages/registry/profiles/samsung/samsung-gearvr.json - */ -var INPUT_MAPPING_WEBXR = { - axes: {touchpad: [0, 1]}, - buttons: ['trigger', 'none', 'touchpad', 'none', 'menu'] -}; - -var INPUT_MAPPING = isWebXRAvailable ? INPUT_MAPPING_WEBXR : INPUT_MAPPING_WEBVR; - -/** - * Gear VR controls. - * Interface with Gear VR controller and map Gamepad events to - * controller buttons: trackpad, trigger - * Load a controller model and highlight the pressed buttons. - */ -module.exports.Component = registerComponent('gearvr-controls', { - schema: { - hand: {default: ''}, // This informs the degenerate arm model. - buttonColor: {type: 'color', default: '#000000'}, - buttonTouchedColor: {type: 'color', default: '#777777'}, - buttonHighlightColor: {type: 'color', default: '#FFFFFF'}, - model: {default: true}, - orientationOffset: {type: 'vec3'}, - armModel: {default: true} - }, - - mapping: INPUT_MAPPING, - - bindMethods: function () { - this.onModelLoaded = bind(this.onModelLoaded, this); - this.onControllersUpdate = bind(this.onControllersUpdate, this); - this.checkIfControllerPresent = bind(this.checkIfControllerPresent, this); - this.removeControllersUpdateListener = bind(this.removeControllersUpdateListener, this); - this.onAxisMoved = bind(this.onAxisMoved, this); - }, - - init: function () { - var self = this; - this.onButtonChanged = bind(this.onButtonChanged, this); - this.onButtonDown = function (evt) { onButtonEvent(evt.detail.id, 'down', self); }; - this.onButtonUp = function (evt) { onButtonEvent(evt.detail.id, 'up', self); }; - this.onButtonTouchStart = function (evt) { onButtonEvent(evt.detail.id, 'touchstart', self); }; - this.onButtonTouchEnd = function (evt) { onButtonEvent(evt.detail.id, 'touchend', self); }; - this.controllerPresent = false; - this.lastControllerCheck = 0; - this.bindMethods(); - }, - - addEventListeners: function () { - var el = this.el; - el.addEventListener('buttonchanged', this.onButtonChanged); - el.addEventListener('buttondown', this.onButtonDown); - el.addEventListener('buttonup', this.onButtonUp); - el.addEventListener('touchstart', this.onButtonTouchStart); - el.addEventListener('touchend', this.onButtonTouchEnd); - el.addEventListener('model-loaded', this.onModelLoaded); - el.addEventListener('axismove', this.onAxisMoved); - this.controllerEventsActive = true; - }, - - removeEventListeners: function () { - var el = this.el; - el.removeEventListener('buttonchanged', this.onButtonChanged); - el.removeEventListener('buttondown', this.onButtonDown); - el.removeEventListener('buttonup', this.onButtonUp); - el.removeEventListener('touchstart', this.onButtonTouchStart); - el.removeEventListener('touchend', this.onButtonTouchEnd); - el.removeEventListener('model-loaded', this.onModelLoaded); - el.removeEventListener('axismove', this.onAxisMoved); - this.controllerEventsActive = false; - }, - - checkIfControllerPresent: function () { - checkControllerPresentAndSetup(this, GAMEPAD_ID_PREFIX, - this.data.hand ? {hand: this.data.hand} : {}); - }, - - play: function () { - this.checkIfControllerPresent(); - this.addControllersUpdateListener(); - }, - - pause: function () { - this.removeEventListeners(); - this.removeControllersUpdateListener(); - }, - - injectTrackedControls: function () { - var el = this.el; - var data = this.data; - el.setAttribute('tracked-controls', { - armModel: data.armModel, - hand: data.hand, - idPrefix: GAMEPAD_ID_PREFIX, - id: GAMEPAD_ID_PREFIX, - orientationOffset: data.orientationOffset - }); - if (!this.data.model) { return; } - this.el.setAttribute('obj-model', { - obj: GEARVR_CONTROLLER_MODEL_OBJ_URL, - mtl: GEARVR_CONTROLLER_MODEL_OBJ_MTL - }); - }, - - addControllersUpdateListener: function () { - this.el.sceneEl.addEventListener('controllersupdated', this.onControllersUpdate, false); - }, - - removeControllersUpdateListener: function () { - this.el.sceneEl.removeEventListener('controllersupdated', this.onControllersUpdate, false); - }, - - onControllersUpdate: function () { - this.checkIfControllerPresent(); - }, - - // No need for onButtonChanged, since Gear VR controller has no analog buttons. - - onModelLoaded: function (evt) { - var controllerObject3D = evt.detail.model; - var buttonMeshes; - if (!this.data.model) { return; } - buttonMeshes = this.buttonMeshes = {}; - buttonMeshes.trigger = controllerObject3D.children[2]; - buttonMeshes.trackpad = controllerObject3D.children[1]; - buttonMeshes.touchpad = controllerObject3D.children[1]; - }, - - onButtonChanged: function (evt) { - var button = this.mapping.buttons[evt.detail.id]; - if (!button) return; - // Pass along changed event with button state, using button mapping for convenience. - this.el.emit(button + 'changed', evt.detail.state); - }, - - onAxisMoved: function (evt) { - emitIfAxesChanged(this, this.mapping.axes, evt); - }, - - updateModel: function (buttonName, evtName) { - if (!this.data.model) { return; } - this.updateButtonModel(buttonName, evtName); - }, - - updateButtonModel: function (buttonName, state) { - var buttonMeshes = this.buttonMeshes; - if (!buttonMeshes || !buttonMeshes[buttonName]) { return; } - var color; - switch (state) { - case 'down': - color = this.data.buttonHighlightColor; - break; - case 'touchstart': - color = this.data.buttonTouchedColor; - break; - default: - color = this.data.buttonColor; - } - buttonMeshes[buttonName].material.color.set(color); - } -}); diff --git a/src/components/index.js b/src/components/index.js index d59003e055a..492a67cf6e4 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -1,8 +1,7 @@ require('./animation'); +require('./anchored'); require('./camera'); require('./cursor'); -require('./daydream-controls'); -require('./gearvr-controls'); require('./geometry'); require('./generic-tracked-controller-controls'); require('./gltf-model'); diff --git a/src/components/laser-controls.js b/src/components/laser-controls.js index 93f3c2613a6..2128ab82a50 100644 --- a/src/components/laser-controls.js +++ b/src/components/laser-controls.js @@ -16,7 +16,6 @@ registerComponent('laser-controls', { var controlsConfiguration = {hand: data.hand, model: data.model}; // Set all controller models. - el.setAttribute('daydream-controls', controlsConfiguration); el.setAttribute('gearvr-controls', controlsConfiguration); el.setAttribute('hp-mixed-reality-controls', controlsConfiguration); el.setAttribute('magicleap-controls', controlsConfiguration); @@ -75,15 +74,6 @@ registerComponent('laser-controls', { }, config: { - 'daydream-controls': { - cursor: {downEvents: ['trackpaddown', 'triggerdown'], upEvents: ['trackpadup', 'triggerup']} - }, - - 'gearvr-controls': { - cursor: {downEvents: ['triggerdown'], upEvents: ['triggerup']}, - raycaster: {origin: {x: 0, y: 0.0010, z: 0}} - }, - 'generic-tracked-controller-controls': { cursor: {downEvents: ['triggerdown'], upEvents: ['triggerup']} }, diff --git a/tests/components/daydream-controls.test.js b/tests/components/daydream-controls.test.js deleted file mode 100644 index 3b141d7f781..00000000000 --- a/tests/components/daydream-controls.test.js +++ /dev/null @@ -1,250 +0,0 @@ -/* global assert, process, setup, suite, test */ -var entityFactory = require('../helpers').entityFactory; - -suite('daydream-controls', function () { - setup(function (done) { - var el = this.el = entityFactory(); - el.setAttribute('daydream-controls', 'hand: right'); // to ensure index = 0 - var callback = function () { - var component = el.components['daydream-controls']; - component.controllersWhenPresent = [{ - id: 'Daydream Controller', - index: 0, - hand: 'right', - axes: [0, 0], - buttons: [{value: 0, pressed: false, touched: false}], - pose: {orientation: [1, 0, 0, 0], position: null} - }]; - el.parentEl.renderer.xr.getStandingMatrix = function () {}; - done(); - }; - if (el.hasLoaded) { callback(); } - el.addEventListener('loaded', callback); - }); - - suite('checkIfControllerPresent', function () { - test('returns not present if no controllers on the first call', function () { - var el = this.el; - var component = el.components['daydream-controls']; - var addEventListenersSpy = this.sinon.spy(component, 'addEventListeners'); - var injectTrackedControlsSpy = this.sinon.spy(component, 'injectTrackedControls'); - - el.sceneEl.systems['tracked-controls-webvr'].controllers = []; - - component.controllerPresent = false; - - component.checkIfControllerPresent(); - - assert.notOk(injectTrackedControlsSpy.called); - assert.notOk(addEventListenersSpy.called); - assert.ok(component.controllerPresent === false); - }); - - test('does not remove event listeners if no controllers', function () { - var el = this.el; - var component = el.components['daydream-controls']; - var addEventListenersSpy = this.sinon.spy(component, 'addEventListeners'); - var injectTrackedControlsSpy = this.sinon.spy(component, 'injectTrackedControls'); - var removeEventListenersSpy = this.sinon.spy(component, 'removeEventListeners'); - - el.sceneEl.systems['tracked-controls-webvr'].controllers = []; - - component.controllerPresent = false; - - component.checkIfControllerPresent(); - - assert.notOk(injectTrackedControlsSpy.called); - assert.notOk(addEventListenersSpy.called); - assert.notOk(removeEventListenersSpy.called); - assert.ok(component.controllerPresent === false); // not undefined - }); - - test('attaches events if controller is newly present', function () { - var el = this.el; - var component = el.components['daydream-controls']; - var addEventListenersSpy = this.sinon.spy(component, 'addEventListeners'); - var injectTrackedControlsSpy = this.sinon.spy(component, 'injectTrackedControls'); - var removeEventListenersSpy = this.sinon.spy(component, 'removeEventListeners'); - - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - - component.controllerPresent = false; - - component.checkIfControllerPresent(); - - assert.ok(injectTrackedControlsSpy.called); - assert.ok(addEventListenersSpy.called); - assert.notOk(removeEventListenersSpy.called); - assert.ok(component.controllerPresent); - }); - - test('does not inject/attach events again if controller already present', function () { - var el = this.el; - var component = el.components['daydream-controls']; - var addEventListenersSpy = this.sinon.spy(component, 'addEventListeners'); - var injectTrackedControlsSpy = this.sinon.spy(component, 'injectTrackedControls'); - var removeEventListenersSpy = this.sinon.spy(component, 'removeEventListeners'); - - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - - component.controllerEventsActive = true; - component.controllerPresent = true; - - component.checkIfControllerPresent(); - - assert.notOk(injectTrackedControlsSpy.called); - assert.notOk(addEventListenersSpy.called); - assert.notOk(removeEventListenersSpy.called); - assert.ok(component.controllerPresent); - }); - - test('removes event listeners if controller disappears', function () { - var el = this.el; - var component = el.components['daydream-controls']; - var addEventListenersSpy = this.sinon.spy(component, 'addEventListeners'); - var injectTrackedControlsSpy = this.sinon.spy(component, 'injectTrackedControls'); - var removeEventListenersSpy = this.sinon.spy(component, 'removeEventListeners'); - - el.sceneEl.systems['tracked-controls-webvr'].controllers = []; - - component.controllerPresent = true; - component.controllerEventsActive = true; - - component.checkIfControllerPresent(); - - assert.notOk(injectTrackedControlsSpy.called); - assert.notOk(addEventListenersSpy.called); - assert.ok(removeEventListenersSpy.called); - assert.notOk(component.controllerPresent); - }); - }); - - suite('axismove', function () { - test('emits trackpadmoved on axismove', function (done) { - var el = this.el; - var component = el.components['daydream-controls']; - - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - component.checkIfControllerPresent(); - - // Install event handler listening for thumbstickmoved. - el.addEventListener('trackpadmoved', function (evt) { - assert.equal(evt.detail.x, 0.1); - assert.equal(evt.detail.y, 0.2); - done(); - }); - - // Emit axismove. - el.emit('axismove', {axis: [0.1, 0.2], changed: [true, false]}); - }); - - test('does not emit trackpadmove on axismove with no changes', function (done) { - var el = this.el; - var component = el.components['daydream-controls']; - - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - - component.checkIfControllerPresent(); - - // Purposely fail. - el.addEventListener('trackpadmoved', function (evt) { - assert.fail('trackpadmoved should not fire if axes have not changed.'); - }); - - // Emit axismove. - el.emit('axismove', {axis: [0.1, 0.2], changed: [false, false]}); - - setTimeout(() => { done(); }); - }); - }); - - suite('buttonchanged', function () { - test('emits trackpadchanged on buttonchanged for button 0', function (done) { - var el = this.el; - var component = el.components['daydream-controls']; - - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - - component.checkIfControllerPresent(); - - const eventState = {value: 0.5, pressed: true, touched: true}; - - // Install event handler listening for triggerchanged. - el.addEventListener('trackpadchanged', function (evt) { - assert.deepEqual(evt.detail, eventState); - done(); - }); - - // Emit buttonchanged for the trackpad button. - el.emit('buttonchanged', {id: 0, state: eventState}); - }); - - test('emits menuchanged on buttonchanged for button 1', function (done) { - var el = this.el; - var component = el.components['daydream-controls']; - - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - - component.checkIfControllerPresent(); - - const eventState = {value: 0.5, pressed: true, touched: true}; - - // Install event handler listening for triggerchanged. - el.addEventListener('menuchanged', function (evt) { - assert.deepEqual(evt.detail, eventState); - done(); - }); - - // Emit buttonchanged for the menu button. - el.emit('buttonchanged', {id: 1, state: eventState}); - }); - - test('emits systemanged on buttonchanged for button 2', function (done) { - var el = this.el; - var component = el.components['daydream-controls']; - - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - - component.checkIfControllerPresent(); - - const eventState = {value: 0.5, pressed: true, touched: true}; - - // Install event handler listening for triggerchanged. - el.addEventListener('systemchanged', function (evt) { - assert.deepEqual(evt.detail, eventState); - done(); - }); - - // Emit buttonchanged for the system button. - el.emit('buttonchanged', {id: 2, state: eventState}); - }); - }); - - suite('armModel', function () { - function makePresent (el) { - var component = el.components['daydream-controls']; - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - component.checkIfControllerPresent(); - } - - test('does not apply if armModel disabled', function () { - var el = this.el; - el.setAttribute('daydream-controls', 'armModel', false); - makePresent(el); - var trackedControls = el.components['tracked-controls-webvr']; - var applyArmModelSpy = this.sinon.spy(trackedControls, 'applyArmModel'); - trackedControls.tick(); - assert.notOk(applyArmModelSpy.called); - }); - - test('applies armModel if armModel enabled', function () { - var el = this.el; - el.setAttribute('daydream-controls', 'armModel', true); - makePresent(el); - var trackedControls = el.components['tracked-controls-webvr']; - var applyArmModelSpy = this.sinon.spy(trackedControls, 'applyArmModel'); - trackedControls.tick(); - assert.ok(applyArmModelSpy.called); - }); - }); -}); diff --git a/tests/components/gearvr-controls.test.js b/tests/components/gearvr-controls.test.js deleted file mode 100644 index f3652f6284f..00000000000 --- a/tests/components/gearvr-controls.test.js +++ /dev/null @@ -1,276 +0,0 @@ -/* global assert, process, setup, sinon, suite, test */ -var entityFactory = require('../helpers').entityFactory; - -suite('gearvr-controls', function () { - setup(function (done) { - var el = this.el = entityFactory(); - el.setAttribute('gearvr-controls', 'hand: right'); // To ensure index is 0. - var callback = function () { - var component = el.components['gearvr-controls']; - component.controllersWhenPresent = [{ - id: 'Gear VR Controller', - index: 0, - hand: 'right', - axes: [0, 0], - buttons: [ - {value: 0, pressed: false, touched: false}, - {value: 0, pressed: false, touched: false} - ], - pose: {orientation: [1, 0, 0, 0], position: null} - }]; - el.parentEl.renderer.xr.getStandingMatrix = function () {}; - done(); - }; - if (el.hasLoaded) { callback(); } - el.addEventListener('loaded', callback); - }); - - suite('checkIfControllerPresent', function () { - test('returns not present if no controllers on first on first call', function () { - var el = this.el; - var component = el.components['gearvr-controls']; - var addEventListenersSpy = sinon.spy(component, 'addEventListeners'); - var injectTrackedControlsSpy = sinon.spy(component, 'injectTrackedControls'); - - el.sceneEl.systems['tracked-controls-webvr'].controllers = []; - - component.controllerPresent = false; - - component.checkIfControllerPresent(); - - sinon.assert.notCalled(injectTrackedControlsSpy); - sinon.assert.notCalled(addEventListenersSpy); - assert.strictEqual(component.controllerPresent, false); - }); - - test('does not remove event listeners if no controllers', function () { - var el = this.el; - var component = el.components['gearvr-controls']; - var addEventListenersSpy = sinon.spy(component, 'addEventListeners'); - var injectTrackedControlsSpy = sinon.spy(component, 'injectTrackedControls'); - var removeEventListenersSpy = sinon.spy(component, 'removeEventListeners'); - - el.sceneEl.systems['tracked-controls-webvr'].controllers = []; - - component.controllerEventsActive = false; - component.controllerPresent = false; - - component.checkIfControllerPresent(); - - sinon.assert.notCalled(injectTrackedControlsSpy); - sinon.assert.notCalled(addEventListenersSpy); - sinon.assert.notCalled(removeEventListenersSpy); - assert.strictEqual(component.controllerPresent, false); - }); - - test('attaches events if controller is newly present', function () { - var el = this.el; - var component = el.components['gearvr-controls']; - var addEventListenersSpy = sinon.spy(component, 'addEventListeners'); - var injectTrackedControlsSpy = sinon.spy(component, 'injectTrackedControls'); - var removeEventListenersSpy = sinon.spy(component, 'removeEventListeners'); - - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - - component.controllerPresent = false; - - component.checkIfControllerPresent(); - - sinon.assert.calledOnce(injectTrackedControlsSpy); - sinon.assert.calledOnce(addEventListenersSpy); - sinon.assert.notCalled(removeEventListenersSpy); - assert.strictEqual(component.controllerPresent, true); - }); - - test('does not inject/attach events again if controller already present', function () { - var el = this.el; - var component = el.components['gearvr-controls']; - var addEventListenersSpy = sinon.spy(component, 'addEventListeners'); - var injectTrackedControlsSpy = sinon.spy(component, 'injectTrackedControls'); - var removeEventListenersSpy = sinon.spy(component, 'removeEventListeners'); - - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - - component.controllerEventsActive = true; - component.controllerPresent = true; - - component.checkIfControllerPresent(); - - sinon.assert.notCalled(injectTrackedControlsSpy); - sinon.assert.notCalled(addEventListenersSpy); - sinon.assert.notCalled(removeEventListenersSpy); - assert.strictEqual(component.controllerPresent, true); - }); - - test('removes event listeners if controller disappears', function () { - var el = this.el; - var component = el.components['gearvr-controls']; - var addEventListenersSpy = sinon.spy(component, 'addEventListeners'); - var injectTrackedControlsSpy = sinon.spy(component, 'injectTrackedControls'); - var removeEventListenersSpy = sinon.spy(component, 'removeEventListeners'); - - el.sceneEl.systems['tracked-controls-webvr'].controllers = []; - - component.controllerEventsActive = true; - component.controllerPresent = true; - - component.checkIfControllerPresent(); - - sinon.assert.notCalled(injectTrackedControlsSpy); - sinon.assert.notCalled(addEventListenersSpy); - sinon.assert.calledOnce(removeEventListenersSpy); - assert.strictEqual(component.controllerPresent, false); - }); - }); - - suite('axismove', function () { - test('emits trackpadmoved on axismove', function (done) { - var el = this.el; - var component = el.components['gearvr-controls']; - - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - - component.checkIfControllerPresent(); - - // Configure the event state for which we'll use the axis state for verification. - const eventState = {axis: [0.1, 0.2], changed: [true, false]}; - - el.addEventListener('trackpadmoved', function (evt) { - assert.equal(evt.detail.x, eventState.axis[0]); - assert.equal(evt.detail.y, eventState.axis[1]); - done(); - }); - - el.emit('axismove', eventState); - }); - - test('does not emit trackpadmoved on axismove with no changes', function (done) { - var el = this.el; - var component = el.components['gearvr-controls']; - - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - - component.checkIfControllerPresent(); - - // Fail purposely. - el.addEventListener('trackpadmoved', function (evt) { - assert.fail('trackpadmoved was called when there was no change.'); - }); - - el.emit('axismove', {axis: [0.1, 0.2], changed: [false, false]}); - setTimeout(() => { done(); }); - }); - }); - - suite('buttonchanged', function () { - [ { button: 'trackpad', id: 0 }, - { button: 'trigger', id: 1 } - ].forEach(function (buttonDescription) { - test('if we get buttonchanged for button ' + buttonDescription.id + ', emit ' + buttonDescription.button + 'changed', function (done) { - var el = this.el; - var component = el.components['gearvr-controls']; - - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - - component.checkIfControllerPresent(); - - // Configure the expected event state and use it to fire the event. - const eventState = {value: 0.5, pressed: true, touched: true}; - - el.addEventListener(buttonDescription.button + 'changed', function (evt) { - assert.deepEqual(evt.detail, eventState); - done(); - }); - - el.emit('buttonchanged', {id: buttonDescription.id, state: eventState}); - }); - - test('if we get buttondown for button ' + buttonDescription.id + ', emit ' + buttonDescription.button + 'down', function (done) { - var el = this.el; - var component = el.components['gearvr-controls']; - - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - - component.checkIfControllerPresent(); - - el.addEventListener(buttonDescription.button + 'down', function (evt) { - done(); - }); - - el.emit('buttondown', {id: buttonDescription.id}); - }); - - test('if we get buttonup for button ' + buttonDescription.id + ', emit ' + buttonDescription.button + 'up', function (done) { - var el = this.el; - var component = el.components['gearvr-controls']; - - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - - component.checkIfControllerPresent(); - - el.addEventListener(buttonDescription.button + 'up', function (evt) { - done(); - }); - - el.emit('buttonup', {id: buttonDescription.id}); - }); - }); - }); - - suite('armModel', function () { - function makePresent (el) { - var component = el.components['gearvr-controls']; - el.sceneEl.systems['tracked-controls-webvr'].controllers = component.controllersWhenPresent; - component.checkIfControllerPresent(); - } - - test('does not apply armModel if armModel disabled', function () { - var el = this.el; - el.setAttribute('gearvr-controls', 'armModel', false); - makePresent(el); - var trackedControls = el.components['tracked-controls-webvr']; - var applyArmModelSpy = sinon.spy(trackedControls, 'applyArmModel'); - trackedControls.tick(); - - // Verify that the function which applies arm model is not called when disabled. - sinon.assert.notCalled(applyArmModelSpy); - - // Additionally verify that no other offets have been applied. - assert.strictEqual(el.object3D.position.x, 0); - assert.strictEqual(el.object3D.position.y, 0); - assert.strictEqual(el.object3D.position.z, 0); - }); - - test('applies armModel if armModel enabled', function () { - var el = this.el; - el.setAttribute('gearvr-controls', 'armModel', true); - makePresent(el); - var trackedControls = el.components['tracked-controls-webvr']; - var applyArmModelSpy = sinon.spy(trackedControls, 'applyArmModel'); - trackedControls.tick(); - - // Verify that the function which applies arm model is called. - sinon.assert.calledOnce(applyArmModelSpy); - }); - - test('verifies armModel position is applied for the right hand', function () { - var el = this.el; - el.setAttribute('gearvr-controls', 'armModel', true); - makePresent(el); - var trackedControls = el.components['tracked-controls-webvr']; - trackedControls.tick(); - assert.ok(el.object3D.position.x > 0); - }); - - test('verifies armModel position is applied for the left hand', function () { - var el = this.el; - el.setAttribute('gearvr-controls', 'armModel', true); - el.setAttribute('gearvr-controls', 'hand', 'left'); - el.components['gearvr-controls'].controllersWhenPresent[0].hand = 'left'; - makePresent(el); - var trackedControls = el.components['tracked-controls-webvr']; - trackedControls.tick(); - assert.ok(el.object3D.position.x < 0); - }); - }); -}); diff --git a/tests/components/laser-controls.test.js b/tests/components/laser-controls.test.js index 99cd3121ef9..e2a68a89521 100644 --- a/tests/components/laser-controls.test.js +++ b/tests/components/laser-controls.test.js @@ -15,8 +15,6 @@ suite('laser-controls', function () { suite('init', function () { test('injects controllers', function () { - assert.ok(el.components['daydream-controls']); - assert.ok(el.components['gearvr-controls']); assert.ok(el.components['oculus-go-controls']); assert.ok(el.components['oculus-touch-controls']); assert.ok(el.components['vive-controls']); @@ -42,17 +40,17 @@ suite('laser-controls', function () { }); test('configures raycaster for oculus-touch-controls', function (done) { - el.emit('controllerconnected', {name: 'gearvr-controls'}); + el.emit('controllerconnected', {name: 'oculus-go-controls'}); setTimeout(() => { var raycaster = el.getAttribute('raycaster'); assert.equal(raycaster.origin.x, 0); - assert.equal(raycaster.origin.y, 0.001); + assert.equal(raycaster.origin.y, 0.0005); done(); }); }); test('creates line', function (done) { - el.emit('controllerconnected', {name: 'daydream-controls'}); + el.emit('controllerconnected', {name: 'oculus-go-controls'}); setTimeout(() => { assert.ok(el.getAttribute('line').color); done(); @@ -62,7 +60,7 @@ suite('laser-controls', function () { test('respects set line color and opacity', function (done) { el.setAttribute('raycaster', 'lineColor', 'red'); el.setAttribute('raycaster', 'lineOpacity', '0.5'); - el.emit('controllerconnected', {name: 'daydream-controls'}); + el.emit('controllerconnected', {name: 'oculus-go-controls'}); setTimeout(() => { assert.equal(el.getAttribute('raycaster').lineColor, 'red'); assert.equal(el.getAttribute('raycaster').lineOpacity, '0.5');