diff --git a/src/components/action-to-event.js b/src/components/action-to-event.js index ee6f397445fea8d556f268ca81ea978f366df6d0..8bcd22e43dcbc30759f7ec3ec17692f0bf75a161 100644 --- a/src/components/action-to-event.js +++ b/src/components/action-to-event.js @@ -8,7 +8,7 @@ AFRAME.registerComponent("action-to-event", { tick() { const userinput = AFRAME.scenes[0].systems.userinput; - if (userinput.readFrameValueAtPath(this.data.path)) { + if (userinput.get(this.data.path)) { this.el.emit(this.data.event); } } diff --git a/src/components/camera-tool.js b/src/components/camera-tool.js index eacfaf8f443a0131cef4cd189f0a05e5c9a58a20..9882eb88f481126ce63b9269f7a3dda44cbbfaab 100644 --- a/src/components/camera-tool.js +++ b/src/components/camera-tool.js @@ -110,7 +110,7 @@ AFRAME.registerComponent("camera-tool", { const grabber = this.el.components.grabbable.grabbers[0]; if (grabber && !!pathsMap[grabber.id]) { const paths = pathsMap[grabber.id]; - if (AFRAME.scenes[0].systems.userinput.readFrameValueAtPath(paths.takeSnapshot)) { + if (AFRAME.scenes[0].systems.userinput.get(paths.takeSnapshot)) { this.takeSnapshotNextTick = true; } } diff --git a/src/components/character-controller.js b/src/components/character-controller.js index 6edc0b2339b200d123ad8f69a5128996ff2c1bdc..083f47e195e7453136c958ecad62762be882c614 100644 --- a/src/components/character-controller.js +++ b/src/components/character-controller.js @@ -117,13 +117,13 @@ AFRAME.registerComponent("character-controller", { root.updateMatrix(); const userinput = AFRAME.scenes[0].systems.userinput; - if (userinput.readFrameValueAtPath(paths.actions.snapRotateLeft)) { + if (userinput.get(paths.actions.snapRotateLeft)) { this.snapRotateLeft(); } - if (userinput.readFrameValueAtPath(paths.actions.snapRotateRight)) { + if (userinput.get(paths.actions.snapRotateRight)) { this.snapRotateRight(); } - const acc = userinput.readFrameValueAtPath(paths.actions.characterAcceleration); + const acc = userinput.get(paths.actions.characterAcceleration); if (acc) { this.accelerationInput.set( this.accelerationInput.x + acc[0], @@ -143,7 +143,7 @@ AFRAME.registerComponent("character-controller", { this.updateVelocity(deltaSeconds); this.accelerationInput.set(0, 0, 0); - const boost = userinput.readFrameValueAtPath(paths.actions.boost) ? 2 : 1; + const boost = userinput.get(paths.actions.boost) ? 2 : 1; move.makeTranslation( this.velocity.x * distance * boost, this.velocity.y * distance * boost, diff --git a/src/components/cursor-controller.js b/src/components/cursor-controller.js index c5113dba822b23944026cff06b41497deecf55f0..1b095fc05948d88e38cbbcebd8b3141046ffb69f 100644 --- a/src/components/cursor-controller.js +++ b/src/components/cursor-controller.js @@ -94,8 +94,8 @@ AFRAME.registerComponent("cursor-controller", { } const userinput = AFRAME.scenes[0].systems.userinput; - const cursorPose = userinput.readFrameValueAtPath(paths.actions.cursor.pose); - const rightHandPose = userinput.readFrameValueAtPath(paths.actions.rightHand.pose); + const cursorPose = userinput.get(paths.actions.cursor.pose); + const rightHandPose = userinput.get(paths.actions.rightHand.pose); this.data.cursor.object3D.visible = this.enabled && !!cursorPose; this.el.setAttribute("line", "visible", this.enabled && !!rightHandPose); @@ -119,7 +119,7 @@ AFRAME.registerComponent("cursor-controller", { const { cursor, near, far, camera, cursorColorHovered, cursorColorUnhovered } = this.data; - const cursorModDelta = userinput.readFrameValueAtPath(paths.actions.cursor.modDelta); + const cursorModDelta = userinput.get(paths.actions.cursor.modDelta); if (isGrabbing && cursorModDelta) { this.distance = THREE.Math.clamp(this.distance - cursorModDelta, near, far); } diff --git a/src/components/hand-controls2.js b/src/components/hand-controls2.js index 534f796c45c304097768d5e486cac12db4d76664..3a97888b172687838581fc720f516e50ceb6b248 100644 --- a/src/components/hand-controls2.js +++ b/src/components/hand-controls2.js @@ -106,10 +106,10 @@ AFRAME.registerComponent("hand-controls2", { const hand = this.data; const userinput = AFRAME.scenes[0].systems.userinput; const subpath = hand === "left" ? paths.actions.leftHand : paths.actions.rightHand; - const hasPose = userinput.readFrameValueAtPath(subpath.pose); - const thumb = userinput.readFrameValueAtPath(subpath.thumb); - const index = userinput.readFrameValueAtPath(subpath.index); - const middleRingPinky = userinput.readFrameValueAtPath(subpath.middleRingPinky); + const hasPose = userinput.get(subpath.pose); + const thumb = userinput.get(subpath.thumb); + const index = userinput.get(subpath.index); + const middleRingPinky = userinput.get(subpath.middleRingPinky); const pose = this.poseForFingers(thumb, index, middleRingPinky); if (pose !== this.pose) { this.el.emit("hand-pose", { previous: this.pose, current: pose }); diff --git a/src/components/pinch-to-move.js b/src/components/pinch-to-move.js index 28dc43cb5d2584532bf549fc3b08aaf01c1ce953..bc5c57a7631e8070c4eaafba13f52c0ceb757bca 100644 --- a/src/components/pinch-to-move.js +++ b/src/components/pinch-to-move.js @@ -9,7 +9,7 @@ AFRAME.registerComponent("pinch-to-move", { }, tick() { const userinput = AFRAME.scenes[0].systems.userinput; - const pinch = userinput.readFrameValueAtPath(paths.device.touchscreen.pinchDelta); + const pinch = userinput.get(paths.device.touchscreen.pinchDelta); if (pinch) { this.axis[1] = pinch * this.data.speed; this.el.emit("move", { axis: this.axis }); diff --git a/src/components/pitch-yaw-rotator.js b/src/components/pitch-yaw-rotator.js index 297bf4f81b5105ca229a5d34bdf527b2389725bb..a2c2ebdead1d580c4480e2578e59c918289941f0 100644 --- a/src/components/pitch-yaw-rotator.js +++ b/src/components/pitch-yaw-rotator.js @@ -36,7 +36,7 @@ AFRAME.registerComponent("pitch-yaw-rotator", { tick() { const userinput = AFRAME.scenes[0].systems.userinput; - const cameraDelta = userinput.readFrameValueAtPath(paths.actions.cameraDelta); + const cameraDelta = userinput.get(paths.actions.cameraDelta); let lookX = this.pendingXRotation; let lookY = 0; if (cameraDelta) { diff --git a/src/components/super-networked-interactable.js b/src/components/super-networked-interactable.js index 4c96f2452f9945c0b9bf29be259c487b8d665c3d..1fbbaa37c6f0786b91f9d8cc109df19e0716829d 100644 --- a/src/components/super-networked-interactable.js +++ b/src/components/super-networked-interactable.js @@ -98,6 +98,6 @@ AFRAME.registerComponent("super-networked-interactable", { if (!(grabber && pathsMap[grabber.id])) return; const userinput = AFRAME.scenes[0].systems.userinput; - this._changeScale(userinput.readFrameValueAtPath(pathsMap[grabber.id].scaleGrabbedGrabbable)); + this._changeScale(userinput.get(pathsMap[grabber.id].scaleGrabbedGrabbable)); } }); diff --git a/src/components/super-spawner.js b/src/components/super-spawner.js index a786639e1b828e34d1daf36bedd10e500d275ed1..7ff4e1189f589d9d026ba63e920dfc5d47a78760 100644 --- a/src/components/super-spawner.js +++ b/src/components/super-spawner.js @@ -116,8 +116,8 @@ AFRAME.registerComponent("super-spawner", { async onSpawnEvent() { const userinput = AFRAME.scenes[0].systems.userinput; - const leftPose = userinput.readFrameValueAtPath(paths.actions.leftHand.pose); - const rightPose = userinput.readFrameValueAtPath(paths.actions.rightHand.pose); + const leftPose = userinput.get(paths.actions.leftHand.pose); + const rightPose = userinput.get(paths.actions.rightHand.pose); const controllerCount = leftPose && rightPose ? 2 : leftPose || rightPose ? 1 : 0; const using6DOF = controllerCount > 1 && this.el.sceneEl.is("vr-mode"); const hand = using6DOF ? this.data.superHand : this.data.cursorSuperHand; diff --git a/src/components/tools/pen.js b/src/components/tools/pen.js index dd52ca4ab14030ddf064a9d5ae9f0ef9a7d4456a..f09e63101f4366440a06ba4d60481999edaba6b8 100644 --- a/src/components/tools/pen.js +++ b/src/components/tools/pen.js @@ -103,20 +103,20 @@ AFRAME.registerComponent("pen", { const userinput = AFRAME.scenes[0].systems.userinput; if (grabber && pathsMap[grabber.id]) { const paths = pathsMap[grabber.id]; - if (userinput.readFrameValueAtPath(paths.startDrawing)) { + if (userinput.get(paths.startDrawing)) { this._startDraw(); } - if (userinput.readFrameValueAtPath(paths.stopDrawing)) { + if (userinput.get(paths.stopDrawing)) { this._endDraw(); } - const penScaleMod = userinput.readFrameValueAtPath(paths.scalePenTip); + const penScaleMod = userinput.get(paths.scalePenTip); if (penScaleMod) { this._changeRadius(penScaleMod); } - if (userinput.readFrameValueAtPath(paths.penNextColor)) { + if (userinput.get(paths.penNextColor)) { this._changeColor(1); } - if (userinput.readFrameValueAtPath(paths.penPrevColor)) { + if (userinput.get(paths.penPrevColor)) { this._changeColor(-1); } } diff --git a/src/systems/userinput/resolve-action-sets.js b/src/systems/userinput/resolve-action-sets.js index d1375f1b02df1c6f3d56463824a13600383fea6b..4341064a1085ba55f3584d4a3a5e00bcd5a8d6d7 100644 --- a/src/systems/userinput/resolve-action-sets.js +++ b/src/systems/userinput/resolve-action-sets.js @@ -136,30 +136,30 @@ export function updateActionSetsBasedOnSuperhands() { !cursorHoveringOnUI; const userinput = AFRAME.scenes[0].systems.userinput; - userinput.toggleActive(sets.leftHandHoveringOnInteractable, leftHandHoveringOnInteractable); - userinput.toggleActive(sets.leftHandHoveringOnPen, leftHandHoveringOnPen); - userinput.toggleActive(sets.leftHandHoveringOnCamera, leftHandHoveringOnCamera); - userinput.toggleActive(sets.leftHandHoveringOnNothing, leftHandHoveringOnNothing); - userinput.toggleActive(sets.leftHandHoldingPen, leftHandHoldingPen); - userinput.toggleActive(sets.leftHandHoldingInteractable, leftHandHoldingInteractable); - userinput.toggleActive(sets.leftHandHoldingCamera, leftHandHoldingCamera); - userinput.toggleActive(sets.leftHandTeleporting, leftHandTeleporting); + userinput.toggleSet(sets.leftHandHoveringOnInteractable, leftHandHoveringOnInteractable); + userinput.toggleSet(sets.leftHandHoveringOnPen, leftHandHoveringOnPen); + userinput.toggleSet(sets.leftHandHoveringOnCamera, leftHandHoveringOnCamera); + userinput.toggleSet(sets.leftHandHoveringOnNothing, leftHandHoveringOnNothing); + userinput.toggleSet(sets.leftHandHoldingPen, leftHandHoldingPen); + userinput.toggleSet(sets.leftHandHoldingInteractable, leftHandHoldingInteractable); + userinput.toggleSet(sets.leftHandHoldingCamera, leftHandHoldingCamera); + userinput.toggleSet(sets.leftHandTeleporting, leftHandTeleporting); - userinput.toggleActive(sets.rightHandHoveringOnInteractable, rightHandHoveringOnInteractable); - userinput.toggleActive(sets.rightHandHoveringOnPen, rightHandHoveringOnPen); - userinput.toggleActive(sets.rightHandHoveringOnNothing, rightHandHoveringOnNothing); - userinput.toggleActive(sets.rightHandHoveringOnCamera, rightHandHoveringOnCamera); - userinput.toggleActive(sets.rightHandHoldingPen, rightHandHoldingPen); - userinput.toggleActive(sets.rightHandHoldingInteractable, rightHandHoldingInteractable); - userinput.toggleActive(sets.rightHandTeleporting, rightHandTeleporting); - userinput.toggleActive(sets.rightHandHoldingCamera, rightHandHoldingCamera); + userinput.toggleSet(sets.rightHandHoveringOnInteractable, rightHandHoveringOnInteractable); + userinput.toggleSet(sets.rightHandHoveringOnPen, rightHandHoveringOnPen); + userinput.toggleSet(sets.rightHandHoveringOnNothing, rightHandHoveringOnNothing); + userinput.toggleSet(sets.rightHandHoveringOnCamera, rightHandHoveringOnCamera); + userinput.toggleSet(sets.rightHandHoldingPen, rightHandHoldingPen); + userinput.toggleSet(sets.rightHandHoldingInteractable, rightHandHoldingInteractable); + userinput.toggleSet(sets.rightHandTeleporting, rightHandTeleporting); + userinput.toggleSet(sets.rightHandHoldingCamera, rightHandHoldingCamera); - userinput.toggleActive(sets.cursorHoveringOnPen, cursorHoveringOnPen); - userinput.toggleActive(sets.cursorHoveringOnCamera, cursorHoveringOnCamera); - userinput.toggleActive(sets.cursorHoveringOnInteractable, cursorHoveringOnInteractable); - userinput.toggleActive(sets.cursorHoveringOnUI, cursorHoveringOnUI); - userinput.toggleActive(sets.cursorHoveringOnNothing, cursorHoveringOnNothing); - userinput.toggleActive(sets.cursorHoldingPen, cursorHoldingPen); - userinput.toggleActive(sets.cursorHoldingCamera, cursorHoldingCamera); - userinput.toggleActive(sets.cursorHoldingInteractable, cursorHoldingInteractable); + userinput.toggleSet(sets.cursorHoveringOnPen, cursorHoveringOnPen); + userinput.toggleSet(sets.cursorHoveringOnCamera, cursorHoveringOnCamera); + userinput.toggleSet(sets.cursorHoveringOnInteractable, cursorHoveringOnInteractable); + userinput.toggleSet(sets.cursorHoveringOnUI, cursorHoveringOnUI); + userinput.toggleSet(sets.cursorHoveringOnNothing, cursorHoveringOnNothing); + userinput.toggleSet(sets.cursorHoldingPen, cursorHoldingPen); + userinput.toggleSet(sets.cursorHoldingCamera, cursorHoldingCamera); + userinput.toggleSet(sets.cursorHoldingInteractable, cursorHoldingInteractable); } diff --git a/src/systems/userinput/userinput.js b/src/systems/userinput/userinput.js index 2ffbdca79db0e2d07d464f32ea320fc8cb31c329..8442cd73a763cf2fa8881e04267fb68d653ac0f1 100644 --- a/src/systems/userinput/userinput.js +++ b/src/systems/userinput/userinput.js @@ -26,29 +26,27 @@ import { updateActionSetsBasedOnSuperhands } from "./resolve-action-sets"; import { GamepadDevice } from "./devices/gamepad"; import { gamepadBindings } from "./bindings/generic-gamepad"; -const prioritizedBindings = new Map(); +const priorityMap = new Map(); function prioritizeBindings(registeredMappings, activeSets) { const activeBindings = new Set(); - prioritizedBindings.clear(); + priorityMap.clear(); for (const mapping of registeredMappings) { for (const setName in mapping) { if (!activeSets.has(setName) || !mapping[setName]) continue; for (const binding of mapping[setName]) { const { root, priority } = binding; + const prevBinding = priorityMap.get(root); if (!root || !priority) { activeBindings.add(binding); - } else if (!prioritizedBindings.has(root)) { + } else if (!prevBinding) { activeBindings.add(binding); - prioritizedBindings.set(root, binding); - } else { - const prevPriority = prioritizedBindings.get(root).priority; - if (priority > prevPriority) { - activeBindings.delete(prioritizedBindings.get(root)); - activeBindings.add(binding); - prioritizedBindings.set(root, binding); - } else if (prevPriority === priority) { - console.error("equal priorities on same root", binding, prioritizedBindings.get(root)); - } + priorityMap.set(root, binding); + } else if (priority > prevBinding.priority) { + activeBindings.delete(priorityMap.get(root)); + activeBindings.add(binding); + priorityMap.set(root, binding); + } else if (prevBinding.priority === priority) { + console.error("equal priorities on same root", binding, priorityMap.get(root)); } } } @@ -57,11 +55,11 @@ function prioritizeBindings(registeredMappings, activeSets) { } AFRAME.registerSystem("userinput", { - readFrameValueAtPath(path) { + get(path) { return this.frame && this.frame[path]; }, - toggleActive(set, value) { + toggleSet(set, value) { this.pendingSetChanges.push({ set, value }); }, diff --git a/src/systems/userinput/userinput.md b/src/systems/userinput/userinput.md index f3d646a6109f1ad1b7feebcdde86d3aacc4066f7..b8ceb54539665f0130863a6018b187bf0562a8aa 100644 --- a/src/systems/userinput/userinput.md +++ b/src/systems/userinput/userinput.md @@ -10,7 +10,7 @@ The userinput system is a module that manages mappings from device state changes ## Overview -The userinput system happens to be an `aframe` `system`; its `tick` is called once per `aframe` `scene` `tick`. The userinput system `tick` creates a map we call the frame object. The keys of the frame are called "paths". The values stored in the frame can be any type, but are usually one of: bool, number, vec2, vec3, vec4, pose. On each tick, each connected `device` writes "raw" input values to known "device paths" within the frame. Configuration units called `bindings` are then applied to transform "raw" input values to app-specific "actions". The userinput system exposes the state of a given `action` in the current frame via `get(path)`. The `bindings` that are applied to transform input to "actions" must be `available`, `active`, and `prioritized`. +The userinput system happens to be an `aframe` `system`; its `tick` is called once a frame within the `aframe` `scene`'s `tick`. When the userinput system `tick` happens, it is responsible for creating a map called the frame. The keys of the frame are called "paths". The values stored in the frame can be any type, but are usually one of: bool, number, vec2, vec3, vec4, pose. On each tick, each connected `device` writes "raw" input values to known "device paths" within the frame. Configuration units called `bindings` are then applied to transform "raw" input values to app-specific "actions". The userinput system exposes the state of a given `action` in the current frame via `get`. The `bindings` that are applied to transform input to "actions" must be `available`, `active`, and `prioritized`. 1. A `binding` is made `available` when the userinput system detects a change to the user's device configuration that matches certain criteria. A touchscreen user only has `availableBindings` related to touchscreen input. A mouse-and-keyboard user only has `availableBindings` related to mouse-and-keyboard input. An oculus/vive user has `bindings` related to mouse, keyboard, and oculus/vive controllers. @@ -55,14 +55,14 @@ A path is used as a key when writing or querying the state a user input frame. P A path used by app code when reading a user input frame. const userinput = AFRAME.scenes[0].systems.userinput; - if (userinput.readFrameValueAtPath("/actions/rightHandGrab")) { + if (userinput.get("/actions/rightHandGrab")) { this.startInteraction(); } The value in the frame can be of any type, but we have tried to keep it to simple types like bool, number, vec2, vec3, and pose. const userinput = AFRAME.scenes[0].systems.userinput; - const acceleration = userinput.readFrameValueAtPath("/actions/characterAcceleration"); + const acceleration = userinput.get("/actions/characterAcceleration"); this.updateVelocity( this.velocity, acceleration || zero ); this.move( this.velocity );