From 1134e37b10e5311c20cb88adbd73618fad9a0512 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 22 Apr 2023 19:21:31 +0200 Subject: [PATCH] toggle edit mode --- bindings/action_manifest.json | 18 +- bindings/index_controller.json | 689 +++++++++++++++++++++++++++++++-- src/app.cpp | 30 +- src/app.h | 4 +- src/controller.cpp | 9 +- 5 files changed, 700 insertions(+), 50 deletions(-) diff --git a/bindings/action_manifest.json b/bindings/action_manifest.json index ddd3886..71d4d74 100644 --- a/bindings/action_manifest.json +++ b/bindings/action_manifest.json @@ -7,17 +7,22 @@ ], "actions": [ { - "name": "/actions/main/in/ToggleAll", + "name": "/actions/main/in/toggle_visibility", "requirement": "mandatory", "type": "boolean" }, { - "name": "/actions/main/in/Grab", + "name": "/actions/main/in/edit_mode", "requirement": "mandatory", "type": "boolean" }, { - "name": "/actions/main/in/Distance", + "name": "/actions/main/in/grab", + "requirement": "mandatory", + "type": "boolean" + }, + { + "name": "/actions/main/in/distance", "requirement": "suggested", "type": "vector2" } @@ -32,9 +37,10 @@ { "language_tag": "en_us", "/actions/main": "Overlay actions", - "/actions/main/in/ToggleAll": "Toggle all", - "/actions/main/in/Grab": "Grab panel", - "/actions/main/in/Distance": "Move away" + "/actions/main/in/toggle_visibility": "Toggle visibility", + "/actions/main/in/edit_mode": "Toggle edit mode", + "/actions/main/in/grab": "grab panel", + "/actions/main/in/distance": "Move away" } ] } \ No newline at end of file diff --git a/bindings/index_controller.json b/bindings/index_controller.json index ebfb3c8..c93ffc0 100644 --- a/bindings/index_controller.json +++ b/bindings/index_controller.json @@ -1,33 +1,658 @@ { - "/actions/main": { - "sources": [ - { - "path": "/user/hand/right/input/b", - "mode": "button", - "inputs": { - "long": { - "output": "/actions/main/in/toggleall" - } - } - }, - { - "path": "/user/hand/right/input/thumbstick", - "mode": "joystick", - "inputs": { - "position": { - "output": "/actions/main/in/distance" - } - } - }, - { - "path": "/user/hand/right/input/trigger", - "mode": "button", - "inputs": { - "click": { - "output": "/actions/main/in/grab" - } - } - } - ] - } -} \ No newline at end of file + "action_manifest_version" : 0, + "alias_info" : { + "/actions/legacy/in/head_proximity" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/left_axis2_press" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/left_axis2_touch" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/left_axis3_press" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/left_axis3_touch" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/left_axis3_value_e0" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/left_axis3_value_e1" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/left_axis4_press" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/left_axis4_touch" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/left_axis4_value_e0" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/left_axis4_value_e1" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/left_system_press" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/left_system_touch" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/right_axis3_press" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/right_axis3_touch" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/right_axis3_value_e0" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/right_axis3_value_e1" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/right_axis4_press" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/right_axis4_touch" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/right_axis4_value_e0" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/right_axis4_value_e1" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/right_system_press" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy/in/right_system_touch" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy_mirrored/in/axis2_press" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy_mirrored/in/axis2_touch" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy_mirrored/in/axis3_press" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy_mirrored/in/axis3_touch" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy_mirrored/in/axis3_value_e0" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy_mirrored/in/axis3_value_e1" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy_mirrored/in/axis4_press" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy_mirrored/in/axis4_touch" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy_mirrored/in/axis4_value_e0" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy_mirrored/in/axis4_value_e1" : { + "alias_name" : "", + "hidden" : true + }, + "/actions/legacy_mirrored/in/system_press" : { + "alias_name" : "", + "hidden" : true + } + }, + "app_key" : "system.generated.overlay", + "bindings" : { + "/actions/legacy" : { + "haptics" : [ + { + "output" : "/actions/legacy/out/left_haptic", + "path" : "/user/hand/left/output/haptic" + }, + { + "output" : "/actions/legacy/out/right_haptic", + "path" : "/user/hand/right/output/haptic" + } + ], + "poses" : [ + { + "output" : "/actions/legacy/in/Left_Pose", + "path" : "/user/hand/left/pose/raw" + }, + { + "output" : "/actions/legacy/in/Right_Pose", + "path" : "/user/hand/right/pose/raw" + } + ], + "sources" : [ + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/left_system_press" + } + }, + "mode" : "button", + "path" : "/user/hand/left/input/system" + }, + { + "inputs" : { + "pull" : { + "output" : "/actions/legacy/in/left_axis1_value" + }, + "touch" : { + "output" : "/actions/legacy/in/left_axis1_touch" + } + }, + "mode" : "trigger", + "path" : "/user/hand/left/input/trigger" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/right_system_press" + } + }, + "mode" : "button", + "path" : "/user/hand/right/input/system" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/right_grip_press" + }, + "touch" : { + "output" : "/actions/legacy/in/right_grip_touch" + } + }, + "mode" : "button", + "path" : "/user/hand/right/input/a" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/left_grip_press" + }, + "touch" : { + "output" : "/actions/legacy/in/left_grip_touch" + } + }, + "mode" : "button", + "path" : "/user/hand/left/input/a" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/left_applicationmenu_press" + }, + "touch" : { + "output" : "/actions/legacy/in/left_applicationmenu_touch" + } + }, + "mode" : "button", + "path" : "/user/hand/left/input/b" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/right_applicationmenu_press" + }, + "touch" : { + "output" : "/actions/legacy/in/right_applicationmenu_touch" + } + }, + "mode" : "button", + "path" : "/user/hand/right/input/b" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/left_axis0_press" + }, + "position" : { + "output" : "/actions/legacy/in/left_axis0_value" + }, + "touch" : { + "output" : "/actions/legacy/in/left_axis0_touch" + } + }, + "mode" : "trackpad", + "path" : "/user/hand/left/input/trackpad" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/right_axis0_press" + }, + "position" : { + "output" : "/actions/legacy/in/right_axis0_value" + }, + "touch" : { + "output" : "/actions/legacy/in/right_axis0_touch" + } + }, + "mode" : "trackpad", + "path" : "/user/hand/right/input/trackpad" + }, + { + "inputs" : { + "pull" : { + "output" : "/actions/legacy/in/right_axis1_value" + }, + "touch" : { + "output" : "/actions/legacy/in/right_axis1_touch" + } + }, + "mode" : "trigger", + "path" : "/user/hand/right/input/trigger" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/left_axis1_press" + }, + "touch" : { + "output" : "/actions/legacy/in/left_axis1_touch" + } + }, + "mode" : "button", + "parameters" : { + "click_activate_threshold" : "0.55", + "click_deactivate_threshold" : "0.5", + "haptic_amplitude" : "0", + "touch_activate_threshold" : "0.1", + "touch_deactivate_threshold" : "0.05" + }, + "path" : "/user/hand/left/input/trigger" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/right_axis1_press" + }, + "touch" : { + "output" : "/actions/legacy/in/right_axis1_touch" + } + }, + "mode" : "button", + "parameters" : { + "click_activate_threshold" : "0.55", + "click_deactivate_threshold" : "0.5", + "haptic_amplitude" : "0", + "touch_activate_threshold" : "0.1", + "touch_deactivate_threshold" : "0.05" + }, + "path" : "/user/hand/right/input/trigger" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/left_axis0_press" + } + }, + "mode" : "button", + "path" : "/user/hand/left/input/trackpad" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/right_axis0_press" + } + }, + "mode" : "button", + "path" : "/user/hand/right/input/trackpad" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/left_axis0_press" + }, + "position" : { + "output" : "/actions/legacy/in/left_axis0_value" + }, + "touch" : { + "output" : "/actions/legacy/in/left_axis0_touch" + } + }, + "mode" : "joystick", + "path" : "/user/hand/left/input/thumbstick" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/right_axis0_press" + }, + "position" : { + "output" : "/actions/legacy/in/right_axis0_value" + }, + "touch" : { + "output" : "/actions/legacy/in/right_axis0_touch" + } + }, + "mode" : "joystick", + "path" : "/user/hand/right/input/thumbstick" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/left_axis0_press" + } + }, + "mode" : "button", + "parameters" : { + "click_activate_threshold" : 0.80000000000000004, + "click_deactivate_threshold" : 0.69999999999999996, + "force_input" : "position", + "haptic_amplitude" : 0 + }, + "path" : "/user/hand/left/input/thumbstick" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/right_axis0_press" + } + }, + "mode" : "button", + "parameters" : { + "click_activate_threshold" : 0.80000000000000004, + "click_deactivate_threshold" : 0.69999999999999996, + "force_input" : "position", + "haptic_amplitude" : 0 + }, + "path" : "/user/hand/right/input/thumbstick" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/left_grip_press" + }, + "touch" : { + "output" : "/actions/legacy/in/left_grip_touch" + } + }, + "mode" : "button", + "parameters" : { + "click_activate_threshold" : "0.8", + "force_input" : "force" + }, + "path" : "/user/hand/left/input/grip" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy/in/right_grip_press" + }, + "touch" : { + "output" : "/actions/legacy/in/right_grip_touch" + } + }, + "mode" : "button", + "parameters" : { + "click_activate_threshold" : "0.8", + "force_input" : "force" + }, + "path" : "/user/hand/right/input/grip" + } + ] + }, + "/actions/legacy_mirrored" : { + "haptics" : [ + { + "output" : "/actions/legacy_mirrored/out/haptic", + "path" : "/user/hand/left/output/haptic" + }, + { + "output" : "/actions/legacy_mirrored/out/haptic", + "path" : "/user/hand/right/output/haptic" + } + ], + "poses" : [ + { + "output" : "/actions/legacy_mirrored/in/pose", + "path" : "/user/hand/left/pose/raw" + }, + { + "output" : "/actions/legacy_mirrored/in/pose", + "path" : "/user/hand/right/pose/raw" + } + ], + "sources" : [ + { + "inputs" : { + "click" : { + "output" : "/actions/legacy_mirrored/in/axis1_press" + }, + "pull" : { + "output" : "/actions/legacy_mirrored/in/axis1_value" + }, + "touch" : { + "output" : "/actions/legacy_mirrored/in/axis1_touch" + } + }, + "mode" : "trigger", + "path" : "/user/hand/left/input/trigger" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy_mirrored/in/axis1_press" + }, + "pull" : { + "output" : "/actions/legacy_mirrored/in/axis1_value" + }, + "touch" : { + "output" : "/actions/legacy_mirrored/in/axis1_touch" + } + }, + "mode" : "trigger", + "path" : "/user/hand/right/input/trigger" + }, + { + "inputs" : { + "position" : { + "output" : "/actions/legacy_mirrored/in/axis0_value" + }, + "touch" : { + "output" : "/actions/legacy_mirrored/in/axis0_touch" + } + }, + "mode" : "trackpad", + "path" : "/user/hand/left/input/trackpad" + }, + { + "inputs" : { + "position" : { + "output" : "/actions/legacy_mirrored/in/axis0_value" + }, + "touch" : { + "output" : "/actions/legacy_mirrored/in/axis0_touch" + } + }, + "mode" : "trackpad", + "path" : "/user/hand/right/input/trackpad" + }, + { + "inputs" : {}, + "mode" : "joystick", + "path" : "/user/hand/left/input/thumbstick" + }, + { + "inputs" : {}, + "mode" : "joystick", + "path" : "/user/hand/right/input/thumbstick" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy_mirrored/in/grip_press" + }, + "touch" : { + "output" : "/actions/legacy_mirrored/in/grip_touch" + } + }, + "mode" : "button", + "path" : "/user/hand/left/input/a" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy_mirrored/in/grip_press" + }, + "touch" : { + "output" : "/actions/legacy_mirrored/in/grip_touch" + } + }, + "mode" : "button", + "path" : "/user/hand/right/input/a" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy_mirrored/in/applicationmenu_press" + }, + "touch" : { + "output" : "/actions/legacy_mirrored/in/applicationmenu_touch" + } + }, + "mode" : "button", + "path" : "/user/hand/left/input/b" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy_mirrored/in/applicationmenu_press" + }, + "touch" : { + "output" : "/actions/legacy_mirrored/in/applicationmenu_touch" + } + }, + "mode" : "button", + "path" : "/user/hand/right/input/b" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy_mirrored/in/axis0_press" + } + }, + "mode" : "button", + "path" : "/user/hand/left/input/trackpad" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/legacy_mirrored/in/axis0_press" + } + }, + "mode" : "button", + "path" : "/user/hand/right/input/trackpad" + } + ] + }, + "/actions/main" : { + "sources" : [ + { + "inputs" : { + "long" : { + "output" : "/actions/main/in/edit_mode" + } + }, + "mode" : "button", + "path" : "/user/hand/right/input/b" + }, + { + "inputs" : { + "position" : { + "output" : "/actions/main/in/distance" + } + }, + "mode" : "joystick", + "path" : "/user/hand/right/input/thumbstick" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/main/in/grab" + } + }, + "mode" : "button", + "path" : "/user/hand/right/input/trigger" + }, + { + "inputs" : { + "click" : { + "output" : "/actions/main/in/grab" + } + }, + "mode" : "button", + "path" : "/user/hand/left/input/trigger" + }, + { + "inputs" : { + "long" : { + "output" : "/actions/main/in/toggle_visibility" + } + }, + "mode" : "button", + "path" : "/user/hand/left/input/b" + }, + { + "inputs" : { + "position" : { + "output" : "/actions/main/in/distance" + } + }, + "mode" : "joystick", + "path" : "/user/hand/left/input/thumbstick" + } + ] + } + }, + "category" : "steamvr_input", + "controller_type" : "knuckles", + "description" : "Default binding values for legacy apps using the Index Controller", + "interaction_profile" : "", + "name" : "Saved overlay configuration for Index Controller", + "options" : { + "mirror_actions" : true, + "simulated_controller_type" : "none" + }, + "simulated_actions" : [] +} diff --git a/src/app.cpp b/src/app.cpp index 5f61799..1b37d25 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -57,11 +57,13 @@ App::App() printf("actions path: %s\n", _actions_path.c_str()); vr_input->SetActionManifestPath(_actions_path.c_str()); - auto action_err = vr_input->GetActionHandle("/actions/main/in/Grab", &_input_handles.grab); + auto action_err = vr_input->GetActionHandle("/actions/main/in/grab", &_input_handles.grab); assert(action_err == 0); - action_err = vr_input->GetActionHandle("/actions/main/in/ToggleAll", &_input_handles.toggle); + action_err = vr_input->GetActionHandle("/actions/main/in/toggle_visibility", &_input_handles.toggle_hidden); assert(action_err == 0); - action_err = vr_input->GetActionHandle("/actions/main/in/Distance", &_input_handles.distance); + action_err = vr_input->GetActionHandle("/actions/main/in/edit_mode", &_input_handles.edit_mode); + assert(action_err == 0); + action_err = vr_input->GetActionHandle("/actions/main/in/distance", &_input_handles.distance); assert(action_err == 0); action_err = vr_input->GetActionSetHandle("/actions/main", &_input_handles.set); assert(action_err == 0); @@ -162,19 +164,29 @@ void App::UpdateInput() vr_sys->GetDeviceToAbsoluteTrackingPose(_tracking_origin, 0, _tracker_poses, MAX_TRACKERS); - if (IsInputJustPressed(_input_handles.toggle)) + if (IsInputJustPressed(_input_handles.toggle_hidden)) { _hidden = !_hidden; - _root_overlay.SetHidden(_hidden); for (auto &panel : _panels) { panel.SetHidden(_hidden); } - _controllers[0]->SetHidden(_hidden); - _controllers[1]->SetHidden(_hidden); + _root_overlay.SetHidden(_hidden || !_edit_mode); + _controllers[0]->SetHidden(_hidden || !_edit_mode); + _controllers[1]->SetHidden(_hidden || !_edit_mode); + } + if (!_hidden && IsInputJustPressed(_input_handles.edit_mode)) + { + _edit_mode = !_edit_mode; + _root_overlay.SetHidden(_hidden || !_edit_mode); + _controllers[0]->SetHidden(_hidden || !_edit_mode); + _controllers[1]->SetHidden(_hidden || !_edit_mode); + } + if (_edit_mode) + { + _controllers[0]->Update(); + _controllers[1]->Update(); } - _controllers[0]->Update(); - _controllers[1]->Update(); } void App::UpdateFramebuffer() diff --git a/src/app.h b/src/app.h index c1508e8..5150f65 100644 --- a/src/app.h +++ b/src/app.h @@ -19,9 +19,10 @@ struct CursorPos struct InputHandles { vr::VRActionSetHandle_t set; - vr::VRActionHandle_t toggle; + vr::VRActionHandle_t toggle_hidden; vr::VRActionHandle_t distance; vr::VRActionHandle_t grab; + vr::VRActionHandle_t edit_mode; }; class App @@ -63,6 +64,7 @@ class App Overlay _root_overlay; std::vector _panels; bool _hidden = false; + bool _edit_mode = false; private: void InitX11(); diff --git a/src/controller.cpp b/src/controller.cpp index 27dc871..d28d8e3 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -25,6 +25,7 @@ Controller::Controller(App *app, ControllerSide side) UpdateStatus(); _laser.SetTextureToColor(255, 200, 255); _laser.SetAlpha(0.2f); + _laser.SetHidden(true); } TrackerID Controller::DeviceIndex() @@ -50,6 +51,7 @@ bool Controller::IsConnected() void Controller::SetHidden(bool state) { _hidden = state; + _laser.SetHidden(_hidden); } void Controller::ReleaseOverlay() @@ -94,7 +96,7 @@ void Controller::UpdateLaser() auto controller_pose = _app->GetTrackerPose(_device_index); auto controller_pos = GetPos(controller_pose); auto forward = -glm::vec3(controller_pose[2]); - auto ray = _app->IntersectRay(controller_pos, forward, 5.0f); + auto ray = _app->IntersectRay(controller_pos, forward, 8.0f); float len = ray.distance; _last_pos = controller_pos; @@ -143,5 +145,8 @@ void Controller::UpdateStatus() _device_index = _app->vr_sys->GetTrackedDeviceIndexForControllerRole(vr::TrackedControllerRole_RightHand); } _is_connected &= _device_index < MAX_TRACKERS; - _laser.SetHidden(!_is_connected || _hidden); + if (!_is_connected) + { + _laser.SetHidden(true); + } }