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 910123ba8bb2f5e54e64037ac478a1ac2e57e577..18416400792ecfbb3242205cbf37f8ba4ef9bf80 100644 --- a/src/components/character-controller.js +++ b/src/components/character-controller.js @@ -119,13 +119,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], @@ -145,7 +145,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/userinput.js b/src/systems/userinput/userinput.js index f6f37a6a9a15f66e33046c3fb6208b6bc15d77cb..7cbbe5331841b554b5720316b84432ef2870fa68 100644 --- a/src/systems/userinput/userinput.js +++ b/src/systems/userinput/userinput.js @@ -55,7 +55,7 @@ function prioritizeBindings(registeredMappings, activeSets) { } AFRAME.registerSystem("userinput", { - readFrameValueAtPath(path) { + get(path) { return this.frame && this.frame[path]; }, diff --git a/src/systems/userinput/userinput.md b/src/systems/userinput/userinput.md index d3701d5c93dd34a4be3828108d29a7a5c094c2a0..2bd9a7eee8aa728d32dcae0ef72fbe9a07dfa237 100644 --- a/src/systems/userinput/userinput.md +++ b/src/systems/userinput/userinput.md @@ -25,7 +25,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 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 `readFrameValueAtPath`. 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. @@ -70,14 +70,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 );