Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
Touch and trackpad navigation, SpaceMouse holds during strokes, stroke-wait log (phoenix, Discord)
islandmedbf6e61cbef99
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 9e3e3d17..99a6384d 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -149,6 +149,7 @@ add_library(sculptforge_core STATICsrc/core/RadialMenu.cppsrc/core/StrokePopup.cppsrc/core/SpaceMouse.cpp+ src/core/TouchGesture.cppsrc/io/ObjIO.cppsrc/io/FbxIO.cppthird_party/ufbx/ufbx.c@@ -418,6 +419,7 @@ if(SCULPTFORGE_BUILD_APP)src/app/Tablet.cppsrc/app/Wintab.cppsrc/app/SpaceMouse.cpp+ src/app/Touch.cppsrc/app/Input.cppsrc/app/RadialMenu.cppsrc/app/StrokePopup.cppdiff --git a/changes/fix-phoenix-input.md b/changes/fix-phoenix-input.mdnew file mode 100644index 00000000..29a0289e--- /dev/null+++ b/changes/fix-phoenix-input.md@@ -0,0 +1,21 @@+---+whats_new: **Touch and trackpad navigation**: two fingers pinch to zoom and twist to roll the view; the SpaceMouse holds still while you sculpt.+added: **Touch screens and trackpads**: two fingers over the model pinch to zoom and twist to roll the view, and on a+ touch screen slide to pan; they never sculpt. One finger on a touch screen still sculpts. Thanks to phoenix+ (Discord) for the report.+added: **Hold during strokes** (Preferences > Input > SpaceMouse, on by default): while you sculpt, paint or mask, the+ SpaceMouse leaves the view alone and its buttons do nothing, so a hand on the cap never moves the model under the+ pen or mouse. Pointer events from a SpaceMouse that the system also lists as a mouse are ignored. Thanks to phoenix+ (Discord).+fixed: Pinch and two-finger rotate did nothing on macOS trackpads and touch screens. Thanks to phoenix (Discord).+testers:+ - macOS with a trackpad: pinch over the model (zooms), twist two fingers (the view rolls once you turn past a+ little), two-finger scroll (zooms as before). Nothing gets sculpted.+ - Windows touch screen or touch laptop: one finger sculpts; two fingers pan, pinch-zoom and twist; landing the+ second finger mid-stroke ends the stroke and moves the view.+ - Any OS with a SpaceMouse and a tablet: rest a hand on the cap while you sculpt with the pen; the view must not+ move or jitter during the stroke, and moves again once you lift the pen.+---+phoenix (AL3D), Discord #bug-reports 11-05: mirror freeze, no multi-touch on macOS, SpaceMouse conflicts. Touch:+core/TouchGesture + app/Touch.cpp (finger events; SDL 3.4 pinch events when built against it). SpaceMouse: hold during+strokes, 6-DoF pointer filter. Freeze: no hang found in the symmetry path; the stroke thread wait now logs every 2 s.diff --git a/docs/guide/navigation.md b/docs/guide/navigation.mdindex 298fda68..69596a84 100644--- a/docs/guide/navigation.md+++ b/docs/guide/navigation.md@@ -85,6 +85,21 @@ model fills the view, zoom out a little or use the right-shelf buttons.On macOS, <kbd>Cmd</kbd> works wherever this guide says <kbd>Ctrl</kbd> for these gestures, except<kbd>Ctrl</kbd>+middle-drag, which needs <kbd>Ctrl</kbd> itself.+## Touch screens and trackpads++Two fingers on the model navigate; they never sculpt.++| Gesture | Touch screen | Trackpad |+|---|---|---|+| Spread or pinch two fingers | Zoom in or out | Zoom in or out |+| Twist two fingers | Roll the view with them | Roll the view with them |+| Slide two fingers | Pan | Zoom (as the scroll wheel) |+| One finger | Sculpt, as with the mouse | Moves the pointer |++A twist starts rolling once the fingers have turned about 10 degrees, so a pinch doesn't tilt the view by accident.+On a touch screen a single finger waits a moment for a second one before it sculpts; if the second finger lands+after a stroke has started, the stroke ends there and the fingers take over the view (one undo removes the stroke).+## The right-shelf navigation buttonsThe right shelf has three buttons you **drag on** rather than click. They are handy with a pen,@@ -136,6 +151,9 @@ pen while they turn the view, and that works best, but you don't have to.doesn't drift the view. The live bars turn orange once an axis is past it.- **Lock rotation to turntable**: the model stays upright; twisting turns it about the world's up axis androlling the cap does nothing.+- **Hold during strokes** (on by default): while you sculpt, paint or mask, the SpaceMouse leaves the view alone and+ its buttons do nothing, so a hand resting on the cap never moves the model under the pen. Turn it off to turn+ the view mid-stroke.- **Dominant axis**: only the direction you push the most moves the view, so a twist doesn't also pan a little.- **Invert**: reverse any of the six moves (Pan X, Zoom, Pan Y, Tilt, Roll, Spin). If a direction feels wrong onyour model of SpaceMouse, flip it here.diff --git a/src/app/App.cpp b/src/app/App.cppindex bdb2a10b..1bfbb39c 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -428,6 +428,7 @@ int App::runUiTest(int w, int h, int fps) {pollSculptable();updateCameraAspect();updateSpaceMouse(dt);+ touchTick(); // a finger's press that waited for a second finger long enough goes throughhardwareProfileFrameBegin(); // (only with SF_HW_PROFILE_IN_TESTS=1: tests use fixed settings)Demo::beginFrame();@@ -1046,6 +1047,7 @@ int App::run() {// The SpaceMouse moves the view by its held axes every frame (frame-rate independent); while it does,// spaceMouseMoving() is true and a loop that waits for events when idle must keep drawing.updateSpaceMouse(dt);+ touchTick(); // a finger's press that waited for a second finger long enough goes throughhardwareProfileFrameBegin(); // the frame governor's CPU and GPU timingif (uiScaleDirty_) applyUiScale(); // (Preferences, a display-scale change: #87)@@ -1314,6 +1316,7 @@ void App::handleEvent(const SDL_Event& event) {void App::dispatchEvent(const SDL_Event& event) {if (strayMouseMotion(event)) return; // neither the canvas nor the UI follows a driver's stray mouse events+ if (sixDofPointerEvent(event)) return; // nor a SpaceMouse that also says it is a mouse (SpaceMouse.cpp)if ((event.type >= SDL_EVENT_KEY_DOWN && event.type < SDL_EVENT_JOYSTICK_AXIS_MOTION &&event.type != SDL_EVENT_KEYMAP_CHANGED && event.type != SDL_EVENT_KEYBOARD_ADDED &&event.type != SDL_EVENT_KEYBOARD_REMOVED && event.type != SDL_EVENT_MOUSE_ADDED &&@@ -1329,6 +1332,7 @@ void App::dispatchEvent(const SDL_Event& event) {if (strokePopupMouseEvent(e)) return; // clicks on the open stroke popup (StrokePopup.cpp)ImGui_ImplSDL3_ProcessEvent(&e);const ImGuiIO& io = ImGui::GetIO();+ if (touchMouseEvent(e)) return; // a finger's press waits for a second finger; a gesture's stay off (Touch.cpp)switch (e.type) {case SDL_EVENT_QUIT:@@ -1366,8 +1370,20 @@ void App::dispatchEvent(const SDL_Event& event) {case SDL_EVENT_PEN_BUTTON_UP:handlePenEvent(e);break;+ case SDL_EVENT_FINGER_DOWN:+ case SDL_EVENT_FINGER_UP:+ case SDL_EVENT_FINGER_MOTION:+ case SDL_EVENT_FINGER_CANCELED:+#if SDL_VERSION_ATLEAST(3, 4, 0)+ case SDL_EVENT_PINCH_BEGIN:+ case SDL_EVENT_PINCH_UPDATE:+ case SDL_EVENT_PINCH_END:+#endif+ touchEvent(e); // two fingers navigate (Touch.cpp)+ break;case SDL_EVENT_MOUSE_ADDED:case SDL_EVENT_MOUSE_REMOVED:+ sixDofMice_.erase(e.mdevice.which);tabletDeviceEvent(e); // a tablet plugged in or out (Tablet.cpp)break;case SDL_EVENT_MOUSE_BUTTON_DOWN:@@ -1389,7 +1405,9 @@ void App::dispatchEvent(const SDL_Event& event) {onMouseMove(e.motion.x, e.motion.y, e.motion.xrel, e.motion.yrel, e.motion.which == SDL_PEN_MOUSEID);break;case SDL_EVENT_MOUSE_WHEEL:- if (!io.WantCaptureMouse && canvasRect().contains(e.wheel.mouse_x, e.wheel.mouse_y)) camera_.zoom(e.wheel.y);+ // (Not the scroll a trackpad sends during a pinch or twist: Touch.cpp zooms for that.)+ if (!io.WantCaptureMouse && !touchPinching_ && canvasRect().contains(e.wheel.mouse_x, e.wheel.mouse_y))+ camera_.zoom(e.wheel.y);break;case SDL_EVENT_KEY_DOWN:if (e.key.key == SDLK_SPACE && !e.key.repeat && // hold Space and drag: the camera (#43; not while typing)diff --git a/src/app/App.h b/src/app/App.hindex d65088b4..7eee2a7f 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -41,6 +41,7 @@#include "core/StrokePath.h"#include "core/SurfaceCursor.h"#include "core/SpaceMouse.h"+#include "core/TouchGesture.h"#include "core/Tablet.h"#include "core/SelfUpdate.h"#include "core/UpdateCheck.h"@@ -2161,7 +2162,8 @@ private:// ---- end Tablet ----// ---- SpaceMouse (SpaceMouse.cpp, core/SpaceMouse.h, docs/guide/navigation.md) ----// A 3Dconnexion SpaceMouse read through SDL's joystick API (no 3Dconnexion SDK): its six axes move the camera- // every frame, independently of the mouse and pen (a stroke held by the pen keeps going), its buttons run actions.+ // every frame, independently of the mouse and pen (held while a stroke runs, unless Hold during strokes is off),+ // its buttons run actions.void spaceMouseEvent(const SDL_Event& e); // hot-plug and buttonsvoid spaceMouseScan(); // take the first SpaceMouse SDL knows about, if none is openvoid spaceMouseClose();@@ -2180,7 +2182,40 @@ private:// Every joystick SDL listed at the last scan and why it was or wasn't taken, for Preferences and the device// report a user can paste into an issue (#104).std::vector<std::string> joysticksSeen_;+ // A pointer device that is really a 6-DoF controller (a SpaceMouse the system also lists as a mouse): its+ // pointer events never reach the canvas or the UI (phoenix, Discord 11-05). Names cached per mouse id.+ bool sixDofPointerEvent(const SDL_Event& e);+ std::unordered_map<SDL_MouseID, bool> sixDofMice_;+ // The view held still and the buttons ignored while a stroke runs (SpaceMouseSettings::holdWhileStroking).+ bool spaceMouseHeldByStroke() const;// ---- end SpaceMouse ----+ // ---- Touch (Touch.cpp, core/TouchGesture.h, docs/guide/navigation.md) ----+ // Two fingers on a touch screen pan, pinch-zoom and twist the view; on a trackpad they pinch-zoom and twist+ // (their scroll stays the wheel). One finger on a touch screen still sculpts: its mouse press waits kTouchHold+ // for a second finger before it reaches the canvas. SDL 3.4's pinch events zoom too (macOS trackpads).+ static constexpr double kTouchHold = 0.08; // seconds+ // UI tests' devices (Demo touch_pinch): any other unknown id counts as a touch screen, as SDL can't say.+ static constexpr SDL_TouchID kUiTestTouchScreen = 0x5F70, kUiTestTrackpad = 0x5F71;+ void touchEvent(const SDL_Event& e); // finger and pinch events+ bool touchMouseEvent(const SDL_Event& e); // SDL's mouse events made from a finger: true when held or dropped+ void touchTick(); // once a frame: a held press that waited long enough goes through+ void touchFlushPress();+ void touchApply(const TwoFingerStep& step);+ TouchGesture touch_;+ bool touchNavigates_ = false; // this touch began over the 3D view+ bool touchDirect_ = true; // a touch screen (false: a trackpad)+ bool touchSwallowMouse_ = false; // a gesture ran: the finger's mouse events stay off the canvas until it lifts+ bool touchNativePinch_ = false; // SDL sends pinch events: a trackpad's finger spread doesn't zoom again+ bool touchTwisting_ = false; // the twist passed kTouchTwistStart: it rolls the view from now on+ bool touchPinching_ = false; // a trackpad pinch or twist is under way: its stray scroll doesn't zoom+ float touchTwistSum_ = 0.0f, touchZoomSum_ = 0.0f;+ struct TouchPress {+ bool held = false;+ float x = 0.0f, y = 0.0f;+ int clicks = 1;+ double at = 0.0;+ } touchPress_;+ // ---- end Touch ----// ---- Sculpt Timeline (PanelTimeline.cpp, core/Timeline.h) and proof mode (ProofMode.cpp) ----// The history strip along the bottom of the canvas, the timelapse export, and Help > Benchmark: a scripted// stroke through the input handlers on 5M..100M+ meshes with a live HUD, an MP4 and a JSON result.diff --git a/src/app/AsyncStroke.cpp b/src/app/AsyncStroke.cppindex 334bf4be..be8cef13 100644--- a/src/app/AsyncStroke.cpp+++ b/src/app/AsyncStroke.cpp@@ -55,8 +55,13 @@ void App::StrokeSolver::start() {}void App::StrokeSolver::wait() {+ // The main thread waits here for the stroke thread (it must: the mesh is the stroke's until it is done). A+ // wait of seconds is a frozen window (phoenix, Discord 11-05): say so in the log. (`batch` is only read there.)std::unique_lock<std::mutex> lock(mutex_);- idle_.wait(lock, [this] { return !busy_.load(std::memory_order_acquire); });+ const auto start = std::chrono::steady_clock::now();+ while (!idle_.wait_for(lock, std::chrono::seconds(2), [this] { return !busy_.load(std::memory_order_acquire); }))+ SDL_Log("stroke: the main thread has waited %.0f s for the stroke thread (a batch of %zu dabs)",+ std::chrono::duration<double>(std::chrono::steady_clock::now() - start).count(), batch.size());}bool App::StrokeSolver::waitFor(double seconds) {diff --git a/src/app/SpaceMouse.cpp b/src/app/SpaceMouse.cppindex 0f62302f..81d7c687 100644--- a/src/app/SpaceMouse.cpp+++ b/src/app/SpaceMouse.cpp@@ -131,7 +131,7 @@ void App::spaceMouseEvent(const SDL_Event& e) {if (!spaceMouse_ || e.jbutton.which != spaceMouseId_) break;spaceMouseLastButton_ = e.jbutton.button;const SpaceMouseSettings& s = uiPrefs_.spaceMouse;- if (!s.enabled || e.jbutton.button >= s.buttons.size()) break;+ if (!s.enabled || e.jbutton.button >= s.buttons.size() || spaceMouseHeldByStroke()) break;const std::string& id = s.buttons[e.jbutton.button];if (id.empty()) break;const Action* a = actions_.find(id);@@ -153,6 +153,7 @@ void App::updateSpaceMouse(float dt) {spaceMouseAxes_[size_t(i)] = std::clamp(float(SDL_GetJoystickAxis(spaceMouse_, i)) / 32767.0f, -1.0f, 1.0f);for (float v : spaceMouseAxes_) spaceMouseReported_ = spaceMouseReported_ || v != 0.0f;const SpaceMouseSettings& s = uiPrefs_.spaceMouse;+ if (spaceMouseHeldByStroke()) return; // (the axes above still show in Preferences)const SpaceMouseMotion m = spaceMouseMotion(spaceMouseAxes_, dt, s);if (!m.any()) return;spaceMouseMoving_ = true;@@ -173,8 +174,31 @@ void App::updateSpaceMouse(float dt) {const float h = canvasHeight();if (m.panX != 0.0f || m.panY != 0.0f) camera_.pan(m.panX * h, m.panY * h, h);if (m.zoom != 0.0f) camera_.zoom(m.zoom);- // A stroke held by the pen carries on: its dabs follow the pen on screen, so the next sample sculpts where the- // pen now points on the turned model; nothing else about the stroke changes.+ // With Hold during strokes off, a stroke held by the pen carries on: its dabs follow the pen on screen, so the+ // next sample sculpts where the pen now points on the turned model; nothing else about the stroke changes.+}++bool App::spaceMouseHeldByStroke() const {+ return uiPrefs_.spaceMouse.holdWhileStroking &&+ (drag_ == Drag::Stroke || drag_ == Drag::MaskCanvas || drag_ == Drag::AirStroke || strokeFinishing_);+}++bool App::sixDofPointerEvent(const SDL_Event& e) {+ SDL_MouseID which = 0;+ if (e.type == SDL_EVENT_MOUSE_MOTION) which = e.motion.which;+ else if (e.type == SDL_EVENT_MOUSE_BUTTON_DOWN || e.type == SDL_EVENT_MOUSE_BUTTON_UP) which = e.button.which;+ else if (e.type == SDL_EVENT_MOUSE_WHEEL) which = e.wheel.which;+ else return false;+ if (which == 0 || which == SDL_PEN_MOUSEID || which == SDL_TOUCH_MOUSEID) return false; // (0: the system's pointer)+ auto it = sixDofMice_.find(which);+ if (it == sixDofMice_.end()) {+ const char* name = SDL_GetMouseNameForID(which);+ // By name only (a mouse has no USB ids in SDL): "3Dconnexion ...", "SpaceMouse ...", never a CadMouse.+ const bool sixDof = name && isSpaceMouseDevice(0, 0, name);+ if (sixDof) SDL_Log("SpaceMouse: pointer events from \"%s\" ignored (a 6-DoF device, not a mouse)", name);+ it = sixDofMice_.emplace(which, sixDof).first;+ }+ return it->second;}// ---------------------------------------------------------------------------@@ -259,6 +283,11 @@ void App::drawSpaceMouseSection() {"The model stays upright: twisting turns it about the world's up axis, tilting looks over or under it, ""and rolling the cap does nothing.",path);+ ui::Checkbox("Hold during strokes##spacemouse.hold", &s.holdWhileStroking);+ ui::HelpText("Hold during strokes", nullptr,+ "While you sculpt, paint or mask, the SpaceMouse leaves the view alone and its buttons do nothing, so "+ "a hand resting on the cap never moves the model under the pen. Off: the view turns mid-stroke.",+ path);ui::Checkbox("Dominant axis##spacemouse.dominant", &s.dominant);ui::HelpText("Dominant axis", nullptr,"Only the direction you push the most moves the view: a twist doesn't also pan a little.", path);@@ -326,8 +355,8 @@ void App::drawSpaceMouseSection() {ImGui::TextColored(col(ui::color::textDim), "Last button pressed: %d", spaceMouseLastButton_ + 1);if (ImGui::SmallButton(ICON_LC_ROTATE_CCW " SpaceMouse defaults##spacemouse.defaults")) s = SpaceMouseSettings();ui::HelpText("SpaceMouse defaults", nullptr,- "On, speed 1, dead zone 8%, nothing inverted, free rotation, all axes at once; left button Frame, right "- "button Front view.",+ "On, speed 1, dead zone 8%, nothing inverted, free rotation, held during strokes, all axes at once; left "+ "button Frame, right button Front view.",path);}diff --git a/src/app/Touch.cpp b/src/app/Touch.cppnew file mode 100644index 00000000..c5415209--- /dev/null+++ b/src/app/Touch.cpp@@ -0,0 +1,170 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// Touch screens and trackpads (phoenix, Discord 11-05: pinch and two-finger rotate did nothing on macOS). SDL sends+// a finger event for each finger on a touch screen, and on macOS and Windows for each finger on a trackpad too; SDL+// 3.4 adds pinch events (a macOS trackpad's pinch). Two fingers that land over the 3D view navigate it:+// touch screen: the point between them pans, spreading them zooms, twisting them rolls the view;+// trackpad: spreading zooms and twisting rolls (two-finger scrolling stays the wheel, as before).+// One finger on a touch screen still sculpts through the mouse events SDL makes from it; its press waits kTouchHold+// (or until the finger moves) for a second finger, so starting a pinch never drops a dab. The pairing math is in+// core/TouchGesture.h. User guide: docs/guide/navigation.md.+#include "app/App.h"++#include <glm/gtc/quaternion.hpp>++#include <algorithm>+#include <cmath>++namespace sf {++namespace {++constexpr float kTouchTwistStart = 0.17f; // radians (10 degrees) of twist before it rolls: a pinch alone doesn't+constexpr float kTouchPinchStart = 0.05f; // log scale a trackpad pinch must reach before its scroll is dropped+constexpr float kTrackpadAspect = 1.5f; // a trackpad's width over its height (its coordinates are 0..1 each way;+ // Demo touch_pinch assumes the same)++double now() { return double(SDL_GetTicksNS()) * 1e-9; }++} // namespace++void App::touchEvent(const SDL_Event& e) {+#if SDL_VERSION_ATLEAST(3, 4, 0)+ if (e.type == SDL_EVENT_PINCH_BEGIN || e.type == SDL_EVENT_PINCH_UPDATE || e.type == SDL_EVENT_PINCH_END) {+ touchNativePinch_ = true;+ if (e.type == SDL_EVENT_PINCH_UPDATE && !ImGui::GetIO().WantCaptureMouse &&+ canvasRect().contains(mouseX_, mouseY_)) {+ camera_.zoom(pinchZoomSteps(e.pinch.scale));+ touchPinching_ = true;+ }+ if (e.type == SDL_EVENT_PINCH_END) touchPinching_ = false;+ return;+ }+#endif+ const SDL_TouchFingerEvent& f = e.tfinger;+ if (f.touchID == SDL_MOUSE_TOUCHID) return; // SDL's touches made from the mouse+ if (e.type == SDL_EVENT_FINGER_UP || e.type == SDL_EVENT_FINGER_CANCELED) {+ touch_.up(f.fingerID);+ if (touch_.fingers() == 0) {+ touchTwisting_ = touchPinching_ = false;+ touchTwistSum_ = touchZoomSum_ = 0.0f;+ touchSwallowMouse_ = false; // (its mouse release came first; this one is for a release SDL never sent)+ }+ return;+ }+ glm::vec2 p;+ if (e.type == SDL_EVENT_FINGER_DOWN && touch_.fingers() == 0) {+ const SDL_TouchDeviceType t = f.touchID == kUiTestTrackpad ? SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE+ : SDL_GetTouchDeviceType(f.touchID);+ touchDirect_ = t != SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE && t != SDL_TOUCH_DEVICE_INDIRECT_RELATIVE;+ }+ if (touchDirect_) { // window coordinates, as the mouse's+ int w = 0, h = 0;+ SDL_GetWindowSize(window_, &w, &h);+ p = glm::vec2(f.x * float(w), f.y * float(h));+ } else {+ p = glm::vec2(f.x * kTrackpadAspect, f.y);+ }+ if (e.type == SDL_EVENT_FINGER_DOWN) {+ if (touch_.fingers() == 0) { // the first finger decides whether this touch is the view's+ const glm::vec2 at = touchDirect_ ? p : glm::vec2(mouseX_, mouseY_);+ touchNavigates_ = !ImGui::GetIO().WantCaptureMouse && canvasRect().contains(at.x, at.y);+ }+ const bool wasGesture = touch_.gesture();+ touch_.down(f.fingerID, p);+ if (touch_.gesture() && !wasGesture && touchNavigates_) {+ SDL_Log("touch: two-finger %s gesture", touchDirect_ ? "touch screen" : "trackpad");+ if (touchDirect_) {+ // The first finger's press never reaches the canvas; a stroke it already began ends here.+ touchPress_.held = false;+ touchSwallowMouse_ = true;+ if (drag_ != Drag::None) onMouseUp();+ }+ }+ return;+ }+ if (e.type == SDL_EVENT_FINGER_MOTION) {+ TwoFingerStep step;+ if (touch_.move(f.fingerID, p, step) && touchNavigates_) touchApply(step);+ }+}++void App::touchApply(const TwoFingerStep& step) {+ if (touchDirect_ && (step.pan.x != 0.0f || step.pan.y != 0.0f)) {+ const float h = canvasHeight();+ camera_.pan(step.pan.x, step.pan.y, h);+ }+ if (step.scale != 1.0f && (touchDirect_ || !touchNativePinch_)) {+ camera_.zoom(pinchZoomSteps(step.scale));+ touchZoomSum_ += std::log(step.scale);+ }+ // A twist rolls the view once it is clearly meant (a pinch's fingers turn a little on their own): then the+ // whole twist so far, so the view stays under the fingers.+ touchTwistSum_ += step.angle;+ float roll = 0.0f;+ if (touchTwisting_) roll = step.angle;+ else if (std::abs(touchTwistSum_) > kTouchTwistStart) {+ touchTwisting_ = true;+ roll = touchTwistSum_;+ }+ if (roll != 0.0f) {+ if (autoOrtho_) { // an axis view turned: back to perspective, as when orbiting with the mouse+ camera_.ortho = false;+ autoOrtho_ = false;+ }+ // Clockwise on screen (y down) turns the model clockwise, as the SpaceMouse's roll does.+ camera_.setOrientation(camera_.orientation() * glm::angleAxis(-roll, glm::vec3(0, 0, 1)));+ orbitStarted_ = false;+ }+ if (!touchDirect_ && (touchTwisting_ || std::abs(touchZoomSum_) > kTouchPinchStart)) touchPinching_ = true;+}++bool App::touchMouseEvent(const SDL_Event& e) {+ switch (e.type) {+ case SDL_EVENT_MOUSE_BUTTON_DOWN:+ if (e.button.which != SDL_TOUCH_MOUSEID || e.button.button != SDL_BUTTON_LEFT) return false;+ if (touchSwallowMouse_ || touch_.gesture()) return true;+ if (ImGui::GetIO().WantCaptureMouse || !canvasRect().contains(e.button.x, e.button.y)) return false;+ touchPress_ = {true, e.button.x, e.button.y, e.button.clicks, now()};+ mouseX_ = e.button.x;+ mouseY_ = e.button.y;+ redrawIn(kTouchHold); // (the loop wakes to let it through: touchTick)+ return true;+ case SDL_EVENT_MOUSE_MOTION:+ if (e.motion.which != SDL_TOUCH_MOUSEID) return false;+ if (touchSwallowMouse_ || touch_.gesture()) return true;+ if (touchPress_.held) {+ const float slop = 10.0f * uiScale_;+ if (std::hypot(e.motion.x - touchPress_.x, e.motion.y - touchPress_.y) < slop) return true;+ touchFlushPress(); // moving: a stroke, the motion follows+ }+ return false;+ case SDL_EVENT_MOUSE_BUTTON_UP:+ if (e.button.which != SDL_TOUCH_MOUSEID || e.button.button != SDL_BUTTON_LEFT) return false;+ if (touchSwallowMouse_) {+ touchSwallowMouse_ = false;+ if (drag_ != Drag::None) onMouseUp();+ return true;+ }+ if (touchPress_.held) touchFlushPress(); // a tap: one dab+ return false;+ default:+ return false;+ }+}++void App::touchFlushPress() {+ if (!touchPress_.held) return;+ touchPress_.held = false;+ lastInputPen_ = false;+ mouseClicks_ = touchPress_.clicks;+ onMouseDown(touchPress_.x, touchPress_.y, SDL_BUTTON_LEFT);+ mouseClicks_ = 1;+}++void App::touchTick() {+ if (touchPress_.held && now() - touchPress_.at >= kTouchHold) touchFlushPress();+}++} // namespace sfdiff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex 9febcd45..69dfbaba 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -228,6 +228,14 @@// mouse_move U V a plain mouse (not the pen) moves to a point on the model, e.g. the stray mouse// events Windows Ink sends beside the pen's//+// Touch (Touch.cpp): fingers as SDL sends them, each step a frame.+// touch_pinch U V SCALE TWIST DX DY [trackpad] [late] two fingers about a point on the model, 120 px apart, over+// 0.4 s: their span grows SCALE times, they turn TWIST degrees (clockwise > 0) and their+// midpoint moves DX DY pixels. Touch screen (SDL's mouse events for the first finger too)+// or trackpad; late: the first finger lands alone and drags 40 px first (a stroke starts)+// touch_stroke U0 V0 U1 V1 one finger on the touch screen from one point on the model to another (sculpts)+// expect_value touch_fingers (fingers down now)+//// Simulated 3Dconnexion SpaceMouse: an SDL virtual joystick with a SpaceMouse Compact's USB ids (256F:C635), six// axes and two buttons, found and opened by the app as a real one would be (SpaceMouse.cpp, hot-plug included).// spacemouse TX TY TZ RX RY RZ [S] plug it in if needed, hold the cap at these axis values (-1..1, the device's@@ -907,6 +915,7 @@ double Demo::query(const std::string& name, bool& known) const {const glm::vec3 f = glm::abs(app_.camera_.forward());return std::max({f.x, f.y, f.z}) > 0.99999f ? 1.0 : 0.0;}+ if (name == "touch_fingers") return double(app_.touch_.fingers());if (name == "spacemouse_connected") return app_.spaceMouse_ ? 1.0 : 0.0;if (name == "spacemouse_moving") return app_.spaceMouseMoving() ? 1.0 : 0.0;if (name == "camera_distance") return app_.camera_.distance;@@ -2147,6 +2156,92 @@ bool Demo::parseStep(int line, const std::vector<std::string>& w, std::string& emouseMotion(p.x, p.y);});wait(0.05f);+ } else if (verb == "touch_pinch" || verb == "touch_stroke") {+ // Fingers as SDL sends them, on a touch screen with the mouse events SDL makes from the first finger (before+ // that finger's own event), or on a trackpad (no mouse events; the pointer rests over the model).+ if (!need(verb == "touch_pinch" ? 6 : 4)) return false;+ struct Touch {+ ImVec2 centre, end;+ float scale = 1.0f, twist = 0.0f, dx = 0.0f, dy = 0.0f;+ bool pad = false, late = false, stroke = false;+ };+ auto tc = std::make_shared<Touch>();+ tc->stroke = verb == "touch_stroke";+ const float u0 = num(1, 0.5f), v0 = num(2, 0.5f);+ float u1 = 0.0f, v1 = 0.0f;+ if (tc->stroke) {+ u1 = num(3, 0.5f);+ v1 = num(4, 0.5f);+ } else {+ tc->scale = num(3, 1.0f);+ tc->twist = glm::radians(num(4, 0.0f));+ tc->dx = num(5, 0.0f);+ tc->dy = num(6, 0.0f);+ for (size_t i = 7; i < w.size(); ++i) {+ if (w[i] == "trackpad") tc->pad = true;+ else if (w[i] == "late") tc->late = true;+ }+ }+ run([this, tc, u0, v0, u1, v1] {+ tc->centre = onModel(u0, v0);+ tc->end = tc->stroke ? onModel(u1, v1) : tc->centre;+ });+ steps_.push_back([this, tc](float t) {+ int ww = 0, wh = 0;+ SDL_GetWindowSize(app_.window_, &ww, &wh);+ const SDL_TouchID device = tc->pad ? App::kUiTestTrackpad : App::kUiTestTouchScreen;+ auto finger = [&](SDL_EventType type, SDL_FingerID id, ImVec2 p) {+ SDL_Event e{};+ e.type = type;+ e.tfinger.touchID = device;+ e.tfinger.fingerID = id;+ // (a trackpad's own 0..1 square, as wide as App::kTrackpadAspect: the twist keeps its angle)+ e.tfinger.x = tc->pad ? p.x / float(wh) / 1.5f : p.x / float(ww);+ e.tfinger.y = p.y / float(wh);+ e.tfinger.pressure = type == SDL_EVENT_FINGER_UP ? 0.0f : 1.0f;+ e.tfinger.windowID = SDL_GetWindowID(app_.window_);+ app_.handleEvent(e);+ };+ auto first = [&](SDL_EventType type, ImVec2 p) { // the first finger, with SDL's mouse events for it+ if (!tc->pad) {+ mouseMotion(p.x, p.y, SDL_TOUCH_MOUSEID);+ if (type == SDL_EVENT_FINGER_DOWN) mouseButton(true, SDL_BUTTON_LEFT, SDL_TOUCH_MOUSEID);+ if (type == SDL_EVENT_FINGER_UP) mouseButton(false, SDL_BUTTON_LEFT, SDL_TOUCH_MOUSEID);+ }+ finger(type, 1, p);+ };+ constexpr float kSeconds = 0.4f, kLate = 0.25f, kSpan = 120.0f;+ if (tc->stroke) {+ const float k = std::min(t / kSeconds, 1.0f);+ const ImVec2 p(tc->centre.x + (tc->end.x - tc->centre.x) * k, tc->centre.y + (tc->end.y - tc->centre.y) * k);+ first(t == 0.0f ? SDL_EVENT_FINGER_DOWN : SDL_EVENT_FINGER_MOTION, p);+ if (t >= kSeconds) first(SDL_EVENT_FINGER_UP, p);+ return t >= kSeconds;+ }+ // late: the first finger lands alone and drags (a stroke begins), the second lands kLate later.+ const float start = tc->late ? kLate : 0.0f;+ const float k = std::clamp((t - start) / kSeconds, 0.0f, 1.0f);+ const float span = kSpan * std::pow(tc->scale, k), a = tc->twist * k;+ const ImVec2 c(tc->centre.x + tc->dx * k, tc->centre.y + tc->dy * k);+ const ImVec2 off(std::cos(a) * span * 0.5f, std::sin(a) * span * 0.5f);+ ImVec2 pa(c.x - off.x, c.y - off.y);+ const ImVec2 pb(c.x + off.x, c.y + off.y);+ if (tc->late && t < start) pa = ImVec2(pa.x, pa.y - 40.0f * (1.0f - t / start)); // dragging down to pa+ if (t == 0.0f) {+ if (tc->pad) mouseMotion(c.x, c.y); // the pointer over the model+ first(SDL_EVENT_FINGER_DOWN, tc->late ? ImVec2(pa.x, pa.y - 40.0f) : pa);+ if (!tc->late) finger(SDL_EVENT_FINGER_DOWN, 2, pb);+ return false;+ }+ first(SDL_EVENT_FINGER_MOTION, pa);+ if (tc->late && t >= start && !app_.touch_.gesture()) finger(SDL_EVENT_FINGER_DOWN, 2, pb);+ if (t >= start) finger(SDL_EVENT_FINGER_MOTION, 2, pb);+ if (t < start + kSeconds) return false;+ first(SDL_EVENT_FINGER_UP, pa);+ finger(SDL_EVENT_FINGER_UP, 2, pb);+ return true;+ });+ wait(0.15f);} else if (verb == "spacemouse" || verb == "spacemouse_hold") {if (!need(6)) return false;std::array<float, 6> v{};diff --git a/src/core/SpaceMouse.cpp b/src/core/SpaceMouse.cppindex 8938a366..246f0dda 100644--- a/src/core/SpaceMouse.cpp+++ b/src/core/SpaceMouse.cpp@@ -77,6 +77,7 @@ Json toJson(const SpaceMouseSettings& s) {j.set("invert", invert);j.set("turntable", s.turntable);j.set("dominant", s.dominant);+ j.set("holdWhileStroking", s.holdWhileStroking);Json buttons = Json::array();for (const std::string& b : s.buttons) buttons.push(b);j.set("buttons", buttons);@@ -94,6 +95,7 @@ void fromJson(const Json& j, SpaceMouseSettings& s) {for (size_t i = 0; i < s.invert.size() && i < inv.size(); ++i) s.invert[i] = inv[i].asBool(s.invert[i]);s.turntable = j["turntable"].asBool(s.turntable);s.dominant = j["dominant"].asBool(s.dominant);+ s.holdWhileStroking = j["holdWhileStroking"].asBool(s.holdWhileStroking);if (const Json& b = j["buttons"]; b.isArray())for (size_t i = 0; i < s.buttons.size() && i < b.size(); ++i)if (b[i].isString()) s.buttons[i] = b[i].asString();diff --git a/src/core/SpaceMouse.h b/src/core/SpaceMouse.hindex 044890a7..3e282eff 100644--- a/src/core/SpaceMouse.h+++ b/src/core/SpaceMouse.h@@ -41,6 +41,9 @@ struct SpaceMouseSettings {std::array<bool, kSmAxes> invert{};bool turntable = false; // lock rotation to a turntable: no roll, the world's up stays upbool dominant = false; // only the axis pushed furthest moves the view (no accidental diagonal moves)+ // While a pen or mouse stroke runs the view holds still and the buttons do nothing, so a hand on the cap (or a+ // noisy cap) never moves the model under the pen (phoenix, Discord 11-05). Off: the view turns mid-stroke.+ bool holdWhileStroking = true;// The action each button runs ("" = nothing): the two side buttons default to Frame and Front view.std::array<std::string, kSpaceMouseButtonSlots> buttons{"view.frame", "view.front"};};diff --git a/src/core/TouchGesture.cpp b/src/core/TouchGesture.cppnew file mode 100644index 00000000..3884e820--- /dev/null+++ b/src/core/TouchGesture.cpp@@ -0,0 +1,70 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+#include "core/TouchGesture.h"++#include <algorithm>+#include <cmath>++namespace sf {++namespace {+bool finite(glm::vec2 p) { return std::isfinite(p.x) && std::isfinite(p.y); }+} // namespace++void TouchGesture::down(uint64_t id, glm::vec2 p) {+ if (!finite(p)) return;+ for (Finger& f : fingers_)+ if (f.id == id) {+ f.p = p;+ return;+ }+ if (fingers_.size() >= kMaxFingers) return;+ fingers_.push_back({id, p});+ gesture_ = gesture_ || fingers_.size() >= 2;+}++bool TouchGesture::move(uint64_t id, glm::vec2 p, TwoFingerStep& step) {+ if (!finite(p)) return false;+ const auto it = std::find_if(fingers_.begin(), fingers_.end(), [id](const Finger& f) { return f.id == id; });+ if (it == fingers_.end()) return false;+ const size_t index = size_t(it - fingers_.begin());+ if (fingers_.size() < 2 || index > 1) { // (a third finger resting doesn't steer)+ it->p = p;+ return false;+ }+ const glm::vec2 a0 = fingers_[0].p, b0 = fingers_[1].p;+ it->p = p;+ const glm::vec2 a1 = fingers_[0].p, b1 = fingers_[1].p;+ step = TwoFingerStep();+ step.pan = (a1 + b1) * 0.5f - (a0 + b0) * 0.5f;+ const glm::vec2 d0 = b0 - a0, d1 = b1 - a1;+ const float l0 = glm::length(d0), l1 = glm::length(d1);+ constexpr float kMinSpan = 1e-4f; // two fingers on the same spot: no pinch or twist to measure+ if (l0 > kMinSpan && l1 > kMinSpan) {+ step.scale = l1 / l0;+ float a = std::atan2(d1.y, d1.x) - std::atan2(d0.y, d0.x);+ constexpr float kPi = 3.14159265358979f;+ if (a > kPi) a -= 2.0f * kPi;+ if (a < -kPi) a += 2.0f * kPi;+ step.angle = a;+ }+ return true;+}++void TouchGesture::up(uint64_t id) {+ fingers_.erase(std::remove_if(fingers_.begin(), fingers_.end(), [id](const Finger& f) { return f.id == id; }),+ fingers_.end());+ if (fingers_.empty()) gesture_ = false;+}++void TouchGesture::clear() {+ fingers_.clear();+ gesture_ = false;+}++float pinchZoomSteps(float scale) {+ if (!std::isfinite(scale) || !(scale > 0.0f)) return 0.0f;+ return std::log(scale) / -std::log(0.88f); // Camera::zoom: distance * 0.88^steps = distance / scale+}++} // namespace sfdiff --git a/src/core/TouchGesture.h b/src/core/TouchGesture.hnew file mode 100644index 00000000..ceb70195--- /dev/null+++ b/src/core/TouchGesture.h@@ -0,0 +1,52 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// Two-finger navigation on a touch screen or a trackpad (phoenix, Discord 11-05): which fingers are down and how+// a pair of them moved since the last event, as a pan, a pinch and a twist. Independent of SDL so it can be unit+// tested; the app side (finger and pinch events to the camera, one finger still sculpting) is src/app/Touch.cpp.+#pragma once++#include <glm/glm.hpp>++#include <cstdint>+#include <vector>++namespace sf {++// One move of a pair of fingers, in the coordinates the fingers were given in.+struct TwoFingerStep {+ glm::vec2 pan{0.0f}; // how far the point between the two fingers moved+ float scale = 1.0f; // new distance between them / old distance (> 1: spread apart, zoom in)+ float angle = 0.0f; // radians the line between them turned, -pi .. pi (> 0: clockwise with y down)+};++class TouchGesture {+public:+ static constexpr size_t kMaxFingers = 10;++ // A finger landed (an id already down moves there instead).+ void down(uint64_t id, glm::vec2 p);+ // A finger moved. True when two or more are down and the first two (in landing order) moved as a pair: `step`+ // says how. Unknown ids and non-finite positions are ignored.+ bool move(uint64_t id, glm::vec2 p, TwoFingerStep& step);+ void up(uint64_t id);+ void clear();+ int fingers() const { return int(fingers_.size()); }+ // Two or more fingers have been down at once since the first one landed (until all are lifted): the touch is a+ // gesture, not a stroke.+ bool gesture() const { return gesture_; }++private:+ struct Finger {+ uint64_t id;+ glm::vec2 p;+ };+ std::vector<Finger> fingers_;+ bool gesture_ = false;+};++// Camera::zoom steps (x0.88 of the distance each) for a pinch that spread the fingers by `scale`: the model grows+// on screen by about the same factor. 0 for a scale that isn't finite and positive.+float pinchZoomSteps(float scale);++} // namespace sfdiff --git a/tests/test_spacemouse.cpp b/tests/test_spacemouse.cppindex 50088d92..db198539 100644--- a/tests/test_spacemouse.cpp+++ b/tests/test_spacemouse.cpp@@ -155,8 +155,9 @@ TEST(spacemouse_frame_rate_independent) {TEST(spacemouse_settings_json) {SpaceMouseSettings s;- CHECK(s.enabled && s.buttons[0] == "view.frame" && s.buttons[1] == "view.front");+ CHECK(s.enabled && s.holdWhileStroking && s.buttons[0] == "view.frame" && s.buttons[1] == "view.front");s.enabled = false;+ s.holdWhileStroking = false;s.speed = 2.25f;s.deadZone = 0.2f;s.invert[2] = s.invert[5] = true;@@ -170,7 +171,7 @@ TEST(spacemouse_settings_json) {std::string err;CHECK(Json::parse(toJson(s).dump(), parsed, err));fromJson(parsed, r);- CHECK(!r.enabled && near(r.speed, 2.25f) && near(r.deadZone, 0.2f) && r.turntable && r.dominant);+ CHECK(!r.enabled && !r.holdWhileStroking && near(r.speed, 2.25f) && near(r.deadZone, 0.2f) && r.turntable && r.dominant);for (int i = 0; i < kSmAxes; ++i) CHECK(r.invert[size_t(i)] == (i == 2 || i == 5));CHECK(r.buttons[0] == "view.top" && r.buttons[1].empty() && r.buttons[3] == "edit.undo");@@ -180,7 +181,7 @@ TEST(spacemouse_settings_json) {j.set("deadZone", -1.0);SpaceMouseSettings d;fromJson(j, d);- CHECK(near(d.speed, 4.0f) && near(d.deadZone, 0.0f) && d.enabled && d.buttons[0] == "view.frame");+ CHECK(near(d.speed, 4.0f) && near(d.deadZone, 0.0f) && d.enabled && d.holdWhileStroking && d.buttons[0] == "view.frame");fromJson(Json(), d); // not an object: untouchedCHECK(near(d.speed, 4.0f));}diff --git a/tests/test_touch.cpp b/tests/test_touch.cppnew file mode 100644index 00000000..f1981993--- /dev/null+++ b/tests/test_touch.cpp@@ -0,0 +1,90 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// Two-finger navigation (phoenix, Discord 11-05): the pairing of fingers into a pan, a pinch and a twist, and the+// pinch's zoom steps (core/TouchGesture.h).+#include "TestHarness.h"++#include "core/TouchGesture.h"+#include "render/Camera.h"++#include <cmath>+#include <limits>++using namespace sf;++namespace {+bool near(float a, float b, float eps = 1e-4f) { return std::abs(a - b) < eps; }+} // namespace++TEST(touch_one_finger_is_not_a_gesture) {+ TouchGesture g;+ TwoFingerStep s;+ g.down(1, {100, 100});+ CHECK(g.fingers() == 1 && !g.gesture());+ CHECK(!g.move(1, {150, 120}, s)); // one finger: a stroke, not navigation+ CHECK(!g.move(7, {0, 0}, s)); // an id that never landed+ g.up(1);+ CHECK(g.fingers() == 0 && !g.gesture());+}++TEST(touch_pinch_pan_twist) {+ TouchGesture g;+ TwoFingerStep s;+ g.down(1, {100, 100});+ g.down(2, {200, 100});+ CHECK(g.gesture());+ // Spread: the second finger moves right by 100, the span doubles; the midpoint moves 50 right.+ CHECK(g.move(2, {300, 100}, s));+ CHECK(near(s.scale, 2.0f) && near(s.angle, 0.0f) && near(s.pan.x, 50.0f) && near(s.pan.y, 0.0f));+ // Both fingers slide down by 40 (two events): each half of a 40 px pan, no pinch or twist.+ CHECK(g.move(1, {100, 140}, s));+ CHECK(near(s.pan.y, 20.0f));+ CHECK(g.move(2, {300, 140}, s));+ CHECK(near(s.pan.y, 20.0f) && near(s.pan.x, 0.0f));+ // Twist clockwise (y down) by 90 degrees about the first finger.+ CHECK(g.move(2, {100, 340}, s));+ CHECK(near(s.angle, 3.14159265f / 2.0f) && near(s.scale, 1.0f));+ // Across -pi / pi: wraps to the short way round.+ TouchGesture w;+ w.down(1, {0, 0});+ w.down(2, {-100, 1});+ CHECK(w.move(2, {-100, -1}, s));+ CHECK(std::abs(s.angle) < 0.05f);+}++TEST(touch_third_finger_and_lifting) {+ TouchGesture g;+ TwoFingerStep s;+ g.down(1, {0, 0});+ g.down(2, {100, 0});+ g.down(3, {50, 50});+ CHECK(g.fingers() == 3);+ CHECK(!g.move(3, {60, 60}, s)); // the third finger doesn't steer+ g.up(1); // the pair is now 2 and 3+ CHECK(g.gesture()); // still a gesture until every finger lifts+ CHECK(g.move(3, {60, 0}, s));+ g.up(2);+ g.up(3);+ CHECK(!g.gesture() && g.fingers() == 0);+ // Two fingers on one spot, NaN positions: no pinch or twist from nothing.+ g.down(4, {10, 10});+ g.down(5, {10, 10});+ CHECK(g.move(5, {20, 10}, s));+ CHECK(near(s.scale, 1.0f) && near(s.angle, 0.0f));+ CHECK(!g.move(5, {std::numeric_limits<float>::quiet_NaN(), 0.0f}, s));+ g.clear();+ CHECK(g.fingers() == 0 && !g.gesture());+}++TEST(touch_pinch_zoom_steps) {+ CHECK(near(pinchZoomSteps(1.0f), 0.0f));+ CHECK(pinchZoomSteps(2.0f) > 0.0f && pinchZoomSteps(0.5f) < 0.0f);+ CHECK(near(pinchZoomSteps(0.0f), 0.0f) && near(pinchZoomSteps(-1.0f), 0.0f));+ CHECK(near(pinchZoomSteps(std::numeric_limits<float>::infinity()), 0.0f));+ // Spreading the fingers to twice their span halves the camera's distance (the model looks twice as big).+ Camera c;+ c.distance = 10.0f;+ c.zoom(pinchZoomSteps(2.0f));+ CHECK(near(c.distance, 5.0f, 1e-3f));+}diff --git a/tests/ui/spacemouse.sfui b/tests/ui/spacemouse.sfuiindex d3390759..1c4f93f7 100644--- a/tests/ui/spacemouse.sfui+++ b/tests/ui/spacemouse.sfui@@ -1,8 +1,9 @@# SpaceMouse navigation (#6), with a virtual joystick that has a SpaceMouse Compact's USB ids (the app finds and# opens it as it would the real device): twisting, tilting, pushing and pulling the cap turn, pan and zoom the view;# a resting cap inside the dead zone does nothing; Preferences > Input > SpaceMouse inverts axes, locks the-# rotation to a turntable and turns it off; the side buttons frame and show the front; a pen stroke held while the-# view turns stays one stroke; unplugging and plugging back in works; every input style.+# rotation to a turntable and turns it off; the side buttons frame and show the front; a stroke holds the view still+# (Hold during strokes) or, with that off, stays one stroke while the view turns; unplugging and plugging back in+# works; every input style.run ui_look look=classic layout=classic # written for the Classic look and the classic palette bar and shelvesrun new_sphere subdivisions=4snapshot@@ -105,7 +106,30 @@ click "Use SpaceMouse##spacemouse.enabled"click "SpaceMouse defaults##spacemouse.defaults"key escape-# A pen stroke held while the cap turns the view stays one stroke, and one undo takes it back.+# Hold during strokes (on by default, phoenix 11-05): while a stroke runs the cap neither turns the view nor runs+# its buttons; the view moves again once the stroke ends.+key f+camera 30 0+snapshot+drag_path 0.3 0.45 0.7 0.55 keep+expect_value stroking == 1+spacemouse 0 0 0 0 0 0.8 0.3+expect_value camera_yaw > 29.9+expect_value camera_yaw < 30.1+expect_value spacemouse_moving == 0+spacemouse_button 2+expect_value camera_aligned == 0+release+expect_value stroking == 0+key ctrl+z+expect_value moved == 0+spacemouse 0 0 0 0 0 0.8 0.3+expect_value camera_yaw > 40++# Hold during strokes off: a pen stroke held while the cap turns the view stays one stroke, and one undo takes it back.+click "Preferences##palette.preferences"+click "Hold during strokes##spacemouse.hold"+key escapekey fcamera 0 0snapshot@@ -121,6 +145,9 @@ expect_value moved == 0pen_stroke 0.3 0.45 0.7 0.55 0.6 0.6expect_value moved_out > 0key ctrl+z+click "Preferences##palette.preferences"+click "Hold during strokes##spacemouse.hold"+key escape# Unplugged and plugged back in (hot-plug).spacemouse_unplugdiff --git a/tests/ui/touch.sfui b/tests/ui/touch.sfuinew file mode 100644index 00000000..ab76c902--- /dev/null+++ b/tests/ui/touch.sfui@@ -0,0 +1,72 @@+# Touch screens and trackpads (phoenix, Discord 11-05: pinch and two-finger rotate did nothing on macOS). Two+# fingers over the model pan, pinch-zoom and twist the view and never sculpt; a second finger landing on a stroke+# ends it and navigates; one finger still sculpts; a trackpad's two fingers pinch-zoom and twist.+run ui_look look=classic layout=classic+run new_sphere subdivisions=4+snapshot++# Touch screen: spread two fingers to twice their span, the model doubles on screen (half the distance).+key f+camera 0 0+remember camera_distance d0+touch_pinch 0.5 0.5 2 0 0 0+expect_value camera_distance < $d0*0.55+expect_value camera_distance > $d0*0.45+expect_value moved == 0+expect_value stroking == 0+expect_value touch_fingers == 0+# Pinch them together: further away.+remember camera_distance d1+touch_pinch 0.5 0.5 0.5 0 0 0+expect_value camera_distance > $d1*1.8++# Twist clockwise by 45 degrees: the model turns clockwise with the fingers (the camera rolls the other way).+key f+camera 0 0+touch_pinch 0.5 0.5 1 45 0 0+expect_value camera_roll < -35+expect_value camera_roll > -55+# A pinch whose fingers turn a little (5 degrees) doesn't roll the view.+camera 0 0+touch_pinch 0.5 0.5 1.5 5 0 0+expect_value camera_roll == 0++# Slide both fingers: the view pans.+key f+camera 0 0+remember camera_pan p0+touch_pinch 0.5 0.5 1 0 120 0+expect_value camera_pan > $p0+expect_value moved == 0++# The first finger drags alone (a stroke starts), then the second lands: the stroke ends, the fingers zoom.+key f+camera 0 0+remember camera_distance d2+touch_pinch 0.5 0.5 2 0 0 0 late+expect_value stroking == 0+expect_value camera_distance < $d2*0.7+key ctrl+z+expect_value moved == 0++# One finger sculpts, as before.+key f+camera 0 0+touch_stroke 0.3 0.45 0.7 0.55+expect_value stroking == 0+expect_value moved_out > 0+key ctrl+z+expect_value moved == 0++# Trackpad: pinch zooms, twist rolls, nothing is sculpted.+key f+camera 0 0+remember camera_distance d3+touch_pinch 0.5 0.5 2 0 0 0 trackpad+expect_value camera_distance < $d3*0.55+camera 0 0+touch_pinch 0.5 0.5 1 -45 0 0 trackpad+expect_value camera_roll > 35+expect_value moved == 0+expect_value touch_fingers == 0+shot touch_after