Skip to content

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.

View > Orbit lock: Free / Y (turntable) / X / Z (@foirgairwolf)

islandmedd10b6c1d95a9
diff --git a/changes/feat-orbit-axis-lock.md b/changes/feat-orbit-axis-lock.md
new file mode 100644
index 00000000..f5c85e23
--- /dev/null
+++ b/changes/feat-orbit-axis-lock.md
@@ -0,0 +1,16 @@
+---
+whats_new: **Orbit lock**: **View > Orbit lock** turns the view about one axis only: **Free**, **Y (turntable)**,
+ **X** or **Z** (<kbd>Alt</kbd>+<kbd>Shift</kbd>+<kbd>F</kbd> / <kbd>Y</kbd> / <kbd>X</kbd> / <kbd>Z</kbd>). The axis
+ gizmo shows which axis is locked. Thanks foirgairwolf on Discord for the idea.
+highlight: Orbit lock: turn the view about X, Y or Z only
+added: **Orbit lock** (View > Orbit lock, a request from foirgairwolf on Discord): besides Free and Y (the turntable), rotation
+ drags can turn the view about the world X or Z axis only, with no drift over long drags. A key for each
+ (Alt+Shift+F / Y / X / Z) and the `orbit_lock axis=free|y|x|z` command; the axis gizmo draws the locked axis
+ through its disc with a lock badge. Shift still snaps to side views. Saved with the preferences (also
+ Preferences > Interface / Input > Rotation; older versions read Y as Turntable).
+testers:
+ - Any OS: View > Orbit lock > X; right-drag the background: from the front the model only tips towards you and
+ away, sideways drags do nothing; the gizmo shows X through its disc and a lock badge.
+ - Any OS: Alt+Shift+Z, then drag around the middle of the view: the model turns like a wheel and keeps facing you.
+ - Any OS: restart; the lock is kept. Alt+Shift+F goes back to free rotation.
+---
diff --git a/docs/guide/images/orbit-lock.jpg b/docs/guide/images/orbit-lock.jpg
new file mode 100644
index 00000000..7335e567
Binary files /dev/null and b/docs/guide/images/orbit-lock.jpg differ
diff --git a/docs/guide/navigation.md b/docs/guide/navigation.md
index df9bdcb1..54f8f194 100644
--- a/docs/guide/navigation.md
+++ b/docs/guide/navigation.md
@@ -12,6 +12,25 @@ model about the screen's own axes, so it follows the cursor and can roll right o
in Blender or Maya, set **Edit > Preferences > Interface > Rotation** to **Turntable**: sideways drags then turn the
model around its vertical axis and up-down drags tilt it, stopping just short of looking straight down or up.
+### Orbit lock
+
+**View > Orbit lock** picks how a rotation drag turns the view, one key each:
+
+| Lock | Key | A rotation drag |
+|---|---|---|
+| **Free** | <kbd>Alt</kbd>+<kbd>Shift</kbd>+<kbd>F</kbd> | turns about the screen's axes (the default, as above) |
+| **Y (turntable)** | <kbd>Alt</kbd>+<kbd>Shift</kbd>+<kbd>Y</kbd> | keeps the model upright: the **Turntable** rotation above |
+| **X** | <kbd>Alt</kbd>+<kbd>Shift</kbd>+<kbd>X</kbd> | turns about the world X axis only: from the front, an up or down drag tips the model towards you or away, and sideways drags do nothing |
+| **Z** | <kbd>Alt</kbd>+<kbd>Shift</kbd>+<kbd>Z</kbd> | turns about the world Z axis only: from the front, a drag around the middle of the view turns the model like a wheel; from the side, an up or down drag tips it |
+
+With X or Z locked, only the part of the drag that moves across the axis on screen counts, so the axis itself never
+moves: nothing drifts, however long you drag. <kbd>Shift</kbd> still snaps to the nearest side view. The axis
+gizmo shows the lock: the locked axis runs through its disc in its colour, and a small lock with the axis letter sits
+at the disc's lower right. The lock is the same setting as **Edit > Preferences > Interface > Rotation**, saved
+with your preferences; scripts and the console use `orbit_lock axis=free|y|x|z`.
+
+![View > Orbit lock: the X lock picked in the View menu, the axis gizmo with X through its disc and the lock badge](images/orbit-lock.jpg)
+
Panning moves the target; zooming moves the camera closer to it or further away. The view is a perspective
view with a 35 degree field of view, or orthographic (<kbd>Numpad 5</kbd>): no foreshortening, so sizes don't
shrink with depth. The front, side and top views (<kbd>Numpad 1</kbd>, <kbd>3</kbd>, <kbd>7</kbd>) switch to
diff --git a/docs/guide/shortcuts.md b/docs/guide/shortcuts.md
index 8dcb5f32..c9366530 100644
--- a/docs/guide/shortcuts.md
+++ b/docs/guide/shortcuts.md
@@ -195,7 +195,11 @@ generated from SculptForge's action registry, the same source as the Controls wi
| Action | Keys | What it does |
|---|---|---|
+| Free | <kbd>Alt</kbd>+<kbd>Shift</kbd>+<kbd>F</kbd> | Rotation drags turn the view about the screen's axes and can roll it over the top (the default). Saved with the preferences. |
| Lock camera | <kbd>Shift</kbd>+<kbd>L</kbd> | Lock the camera for left-drags: a drag that starts on the background sculpts once it reaches the model instead of turning the view (Preferences > Input > Start strokes off the model, #62). The status bar shows CAMERA LOCKED while it is on. Right-drag or Alt+drag still move the view. Shift+L turns it on and off. |
+| X | <kbd>Alt</kbd>+<kbd>Shift</kbd>+<kbd>X</kbd> | Rotation drags turn the view about the world X axis only (red): from the front, an up or down drag tips the model towards you or away. Shift still snaps to a side view; the axis gizmo shows the lock. Saved with the preferences. |
+| Y (turntable) | <kbd>Alt</kbd>+<kbd>Shift</kbd>+<kbd>Y</kbd> | Rotation drags turn the view like a turntable: the model stays upright and turns about its vertical (Y) axis. Saved with the preferences. |
+| Z | <kbd>Alt</kbd>+<kbd>Shift</kbd>+<kbd>Z</kbd> | Rotation drags turn the view about the world Z axis only (blue): from the front, a drag around the middle turns the model like a wheel. Shift still snaps to a side view; the axis gizmo shows the lock. Saved with the preferences. |
<!-- END GENERATED: shortcuts -->
diff --git a/src/app/App.cpp b/src/app/App.cpp
index 765f9f38..4ebe51a1 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -1946,7 +1946,7 @@ void App::onMouseMove(float x, float y, float dx, float dy, bool fromPen) {
}
switch (drag_) {
case Drag::Stroke: strokeTo(x, y); break;
- case Drag::Orbit: orbitBy(dx, dy); break;
+ case Drag::Orbit: orbitBy(x, y, dx, dy); break;
case Drag::Roll:
if (rollSideways_) camera_.setOrientation(camera_.orientation() * glm::angleAxis(dx * 0.008f, glm::vec3(0, 0, 1)));
else rollBy(x, y, dx, dy);
@@ -2025,7 +2025,7 @@ void App::resetView() {
status_ = "View reset";
}
-void App::orbitBy(float dx, float dy) {
+void App::orbitBy(float x, float y, float dx, float dy) {
if (autoOrtho_) { // an axis view turned: back to perspective (Blender's Auto Perspective)
camera_.ortho = false;
autoOrtho_ = false;
@@ -2034,7 +2034,10 @@ void App::orbitBy(float dx, float dy) {
orbitRaw_ = camera_;
orbitStarted_ = true;
}
- if (uiPrefs_.turntable || forceTurntable_) orbitRaw_.orbit(dx, dy);
+ const int lock = forceTurntable_ ? 1 : uiPrefs_.orbitLock;
+ if (lock == 1) orbitRaw_.orbit(dx, dy);
+ else if (lock == 2) orbitRaw_.orbitAbout(glm::vec3(1, 0, 0), dx, dy, rollSweep(x, y, dx, dy));
+ else if (lock == 3) orbitRaw_.orbitAbout(glm::vec3(0, 0, 1), dx, dy, rollSweep(x, y, dx, dy));
else orbitRaw_.orbitFree(dx, dy);
// Holding Shift snaps to the nearest view along an axis; letting go continues from where the cursor took it.
if (inputMods(false) & SDL_KMOD_SHIFT) camera_.setOrientation(Camera::snapped(orbitRaw_.orientation()));
@@ -2042,8 +2045,11 @@ void App::orbitBy(float dx, float dy) {
}
void App::rollBy(float x, float y, float dx, float dy) {
- // Turn about the view axis by the angle the cursor sweeps around the canvas centre (a sideways drag far
- // from the centre still turns, by its length).
+ camera_.setOrientation(camera_.orientation() * glm::angleAxis(-rollSweep(x, y, dx, dy), glm::vec3(0, 0, 1)));
+}
+
+float App::rollSweep(float x, float y, float dx, float dy) const {
+ // The angle the cursor sweeps around the canvas centre (near the centre, a sideways drag turns by its length).
const CanvasRect c = canvasRect();
const glm::vec2 centre(c.x + c.w * 0.5f, c.y + c.h * 0.5f);
const glm::vec2 now(x, y), before(x - dx, y - dy);
@@ -2054,7 +2060,7 @@ void App::rollBy(float x, float y, float dx, float dy) {
} else {
angle = dx * 0.008f;
}
- camera_.setOrientation(camera_.orientation() * glm::angleAxis(-angle, glm::vec3(0, 0, 1)));
+ return angle;
}
void App::onMouseUp() {
@@ -4331,7 +4337,8 @@ void App::drawAxisGizmo() {
// negative ends smaller rings (their letter under the pointer). Drawn back to front: the ends pointing away are
// smaller and fainter, the near ones on top. A click on an end snaps to that side (axisGizmoMouseDown), a
// second click to the opposite side; the end under the pointer gets a ring. On an exact side view its name
- // shows under the disc.
+ // shows under the disc. With an orbit lock (View > Orbit lock), the axis the view turns about runs through the
+ // disc, and a lock with its letter sits at the disc's lower right.
ImDrawList* dl = ImGui::GetBackgroundDrawList();
const float unit = axisGizmoUnit();
auto ends = axisGizmoLayout();
@@ -4354,9 +4361,20 @@ void App::drawAxisGizmo() {
dl->AddCircleFilled(centre, discR, withAlpha(tint, onDisc ? 0.17f : light ? 0.08f : 0.07f), 48);
dl->AddCircle(centre, discR, withAlpha(tint, onDisc ? 0.22f : 0.10f), 48, 1.0f * uiScale_);
- std::sort(ends.begin(), ends.end(), [](const AxisGizmoEnd& a, const AxisGizmoEnd& b) { return a.depth < b.depth; });
static constexpr ImU32 colours[3] = {IM_COL32(236, 84, 92, 255), IM_COL32(124, 196, 64, 255), IM_COL32(64, 140, 236, 255)};
static constexpr const char* names[3] = {"X", "Y", "Z"};
+ // The locked axis, end to end through the disc (as long as it looks from here: a dot when it points at you).
+ static constexpr int lockAxes[4] = {-1, 1, 0, 2}; // UiPrefs::orbitLock: free, Y, X, Z
+ const int lockAxis = lockAxes[std::clamp(forceTurntable_ ? 1 : uiPrefs_.orbitLock, 0, 3)];
+ if (lockAxis >= 0)
+ for (const AxisGizmoEnd& e : ends)
+ if (e.axis == lockAxis && !e.negative) {
+ const glm::vec2 d = (e.at - c) * ((discR - 3.0f * unit) / (kAxisGizmoLength * unit));
+ dl->AddLine(ImVec2(c.x - d.x, c.y - d.y), ImVec2(c.x + d.x, c.y + d.y), withAlpha(colours[lockAxis], 0.55f),
+ 1.5f * unit);
+ }
+
+ std::sort(ends.begin(), ends.end(), [](const AxisGizmoEnd& a, const AxisGizmoEnd& b) { return a.depth < b.depth; });
ImFont* font = fontBold_ ? fontBold_ : ImGui::GetFont();
// The letters shrink with the circles (Small) but never grow past the UI font.
const float fontSize = ImGui::GetFontSize() * 0.92f * std::min(1.0f, unit / std::max(uiScale_, 0.01f));
@@ -4399,6 +4417,22 @@ void App::drawAxisGizmo() {
dl->AddText(ImGui::GetFont(), size, ImVec2(at.x + 1.0f, at.y + 1.0f), light ? IM_COL32(255, 255, 255, 110) : IM_COL32(0, 0, 0, 150), text);
dl->AddText(ImGui::GetFont(), size, at, light ? IM_COL32(30, 30, 34, 230) : IM_COL32(232, 232, 236, 220), text);
}
+
+ // The orbit lock's badge: a lock and the axis letter in its colour, on a pill at the disc's lower right.
+ if (lockAxis >= 0) {
+ const float size = ImGui::GetFontSize() * 0.8f;
+ ImFont* f = ImGui::GetFont();
+ const ImVec2 iconSize = f->CalcTextSizeA(size, FLT_MAX, 0.0f, ICON_LC_LOCK);
+ const ImVec2 nameSize = font->CalcTextSizeA(size, FLT_MAX, 0.0f, names[lockAxis]);
+ const float gap = 2.0f * uiScale_, padX = 4.0f * uiScale_, padY = 1.0f * uiScale_;
+ const float w = iconSize.x + gap + nameSize.x + 2.0f * padX, h = std::max(iconSize.y, nameSize.y) + 2.0f * padY;
+ const ImVec2 a(std::round(c.x + discR * 0.62f), std::round(c.y + discR * 0.62f));
+ dl->AddRectFilled(a, ImVec2(a.x + w, a.y + h), light ? IM_COL32(255, 255, 255, 200) : IM_COL32(20, 20, 24, 190), h * 0.5f);
+ dl->AddRect(a, ImVec2(a.x + w, a.y + h), withAlpha(colours[lockAxis], 0.8f), h * 0.5f, 0, 1.0f * uiScale_);
+ dl->AddText(f, size, ImVec2(a.x + padX, a.y + padY), light ? IM_COL32(30, 30, 34, 230) : IM_COL32(232, 232, 236, 230),
+ ICON_LC_LOCK);
+ dl->AddText(font, size, ImVec2(a.x + padX + iconSize.x + gap, a.y + padY), colours[lockAxis], names[lockAxis]);
+ }
}
void App::drawViewFigure() {
diff --git a/src/app/App.h b/src/app/App.h
index b4c35602..064e644b 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -181,7 +181,9 @@ private:
void onMouseMove(float x, float y, float dx, float dy, bool fromPen);
void onMouseUp();
bool blenderNavigationDown(Uint8 button); // Blender style: a press that navigates (Input.cpp's style)
- void orbitBy(float dx, float dy); // a rotation drag: free or turntable (Preferences), Shift snaps
+ // A rotation drag: free, turntable, or about the world X or Z axis (View > Orbit lock); Shift snaps.
+ void orbitBy(float x, float y, float dx, float dy);
+ float rollSweep(float x, float y, float dx, float dy) const; // radians the cursor turns around the canvas centre
void rollBy(float x, float y, float dx, float dy); // Shift+click, release Shift, drag: turn about the view axis
void onKey(SDL_Keycode key, SDL_Keymod mod);
diff --git a/src/app/Config.cpp b/src/app/Config.cpp
index 973f378a..2b70ef50 100644
--- a/src/app/Config.cpp
+++ b/src/app/Config.cpp
@@ -90,7 +90,8 @@ Json toJson(const UiPrefs& p) {
j.set("libraryAtStartup", p.libraryAtStartup);
j.set("libraryFolder", p.libraryFolder);
j.set("cameraNotch", double(p.cameraNotch));
- j.set("turntable", p.turntable);
+ j.set("orbitLock", std::string(orbitLockName(p.orbitLock)));
+ j.set("turntable", p.orbitLock == 1);
j.set("inputStyle", std::string(p.inputStyle == 3 ? "maya" : p.inputStyle == 2 ? "blender" : p.inputStyle == 1 ? "sculptforge" : "classic"));
j.set("emulateNumpad", p.emulateNumpad);
j.set("rightClickQuickMenu", p.rightClickQuickMenu);
@@ -154,6 +155,17 @@ Json toJson(const UiPrefs& p) {
return j;
}
+const char* orbitLockName(int lock) {
+ static constexpr const char* names[4] = {"free", "y", "x", "z"};
+ return names[std::clamp(lock, 0, 3)];
+}
+
+int parseOrbitLock(std::string_view name) {
+ for (int i = 0; i < 4; ++i)
+ if (name == orbitLockName(i)) return i;
+ return name == "turntable" ? 1 : -1;
+}
+
void fromJson(const Json& j, UiPrefs& p) {
if (!j.isObject()) return;
p.popupInfo = j["popupInfo"].asBool(p.popupInfo);
@@ -167,7 +179,8 @@ void fromJson(const Json& j, UiPrefs& p) {
p.libraryAtStartup = j["libraryAtStartup"].asBool(p.libraryAtStartup);
if (j["libraryFolder"].isString()) p.libraryFolder = j["libraryFolder"].asString();
p.cameraNotch = std::clamp(int(j["cameraNotch"].asNumber(p.cameraNotch)), 0, 2);
- p.turntable = j["turntable"].asBool(p.turntable);
+ if (j["turntable"].asBool(false)) p.orbitLock = 1;
+ if (j["orbitLock"].isString()) p.orbitLock = std::max(parseOrbitLock(j["orbitLock"].asString()), 0);
if (j["inputStyle"].isString()) {
p.inputStyleSaved = true;
const std::string style = j["inputStyle"].asString();
@@ -1608,17 +1621,19 @@ void drawInterfaceSection(App& app) {
"Size of text and controls, applied at once. Automatic follows the display the window is on (Windows: "
"Settings > Display > Scale, per monitor).",
"Preferences > Interface");
- static const char* kRotation[] = {"Free", "Turntable"};
+ static const char* kRotation[] = {"Free", "Turntable", "X axis", "Z axis"}; // UiPrefs::orbitLock
+ p.orbitLock = std::clamp(p.orbitLock, 0, 3);
ImGui::SetNextItemWidth(-FLT_MIN);
- if (ImGui::BeginCombo("##rotation", (std::string(tr("Rotation:")) + " " + tr(kRotation[p.turntable ? 1 : 0])).c_str())) {
- for (int i = 0; i < 2; ++i)
- if (ImGui::Selectable(tr(kRotation[i]), (i == 1) == p.turntable)) p.turntable = i == 1;
+ if (ImGui::BeginCombo("##rotation", (std::string(tr("Rotation:")) + " " + tr(kRotation[p.orbitLock])).c_str())) {
+ for (int i = 0; i < 4; ++i)
+ if (ImGui::Selectable(tr(kRotation[i]), i == p.orbitLock)) p.orbitLock = i;
ImGui::EndCombo();
}
ui::HelpText("Rotation", nullptr,
"Free: dragging turns the model about the screen's axes and can roll it over the top; press "
"Shift while rotating to snap to the nearest front, side, top or bottom view. Turntable: the model stays "
- "upright and turns about its vertical axis, as in Blender or Maya.",
+ "upright and turns about its vertical axis, as in Blender or Maya. X axis, Z axis: it turns about that "
+ "world axis only (View > Orbit lock).",
"Preferences > Interface");
static const char* kNotch[] = {"Automatic", "Always reserve", "Off"};
ImGui::SetNextItemWidth(-FLT_MIN);
diff --git a/src/app/Config.h b/src/app/Config.h
index 3e9c1e65..1b53ee2a 100644
--- a/src/app/Config.h
+++ b/src/app/Config.h
@@ -15,6 +15,7 @@
#include <set>
#include <string>
+#include <string_view>
#include <vector>
namespace sf {
@@ -37,7 +38,9 @@ struct UiPrefs {
std::string lengthUnit = "mm", fileUnit = "m";
std::string language = "en"; // Preferences > Interface: the interface language, "en", "es" or "zh-TW" (app/I18n.h)
int cameraNotch = 0; // keep the UI out of a laptop's camera notch: 0 automatic, 1 always, 2 never
- bool turntable = false; // rotation: false = free, about the screen axes; true = turntable (Y up)
+ // View > Orbit lock (rotation): 0 free, about the screen axes; 1 turntable (Y up); 2 about world X only; 3 about
+ // world Z only (Camera::orbitAbout). Saved as "orbitLock", and "turntable" for older versions.
+ int orbitLock = 0;
int inputStyle = 1; // Preferences > Input: 0 classic, 1 SculptForge (the default for new installs:
// 1-0 brushes, I = Falloff...), 2 Blender (middle-drag orbit, numpad views,
// Blender's sculpt keys), 3 Maya (Input.cpp). The first-run welcome asks.
@@ -152,6 +155,9 @@ Json toJson(const UiPrefs& prefs);
void lookToJson(const UiPrefs& prefs, Json& j);
bool lookFromJson(const Json& j, UiPrefs& prefs);
void fromJson(const Json& j, UiPrefs& prefs);
+// UiPrefs::orbitLock as the orbit_lock command and ui.json name it: "free", "y", "x", "z" (-1: not one of them).
+const char* orbitLockName(int lock);
+int parseOrbitLock(std::string_view name);
namespace config {
// Preferences palette sub-palettes (the shell's Preferences palette calls these).
diff --git a/src/app/I18nSimplifiedChinese.cpp b/src/app/I18nSimplifiedChinese.cpp
index eafaf004..702d4eeb 100644
--- a/src/app/I18nSimplifiedChinese.cpp
+++ b/src/app/I18nSimplifiedChinese.cpp
@@ -1111,9 +1111,9 @@ constexpr Entry kSimplifiedChinese[] = {
"文本与控件的大小,立即应用。“自动”会按窗口所在的显示器而定(Windows:设置 > 显示器 > 缩放,按各显示器)。"},
{"Free: dragging turns the model about the screen's axes and can roll it over the top; press Shift while rotating "
"to snap to the nearest front, side, top or bottom view. Turntable: the model stays upright and turns about its "
- "vertical axis, as in Blender or Maya.",
+ "vertical axis, as in Blender or Maya. X axis, Z axis: it turns about that world axis only (View > Orbit lock).",
"自由:拖动会以屏幕的轴旋转模型,并可从上方翻转;旋转时按住 Shift 可贴齐最近的正面、侧面、顶部或底部视图。转盘:"
- "模型保持直立并绕垂直轴旋转,如同 Blender 或 Maya。"},
+ "模型保持直立并绕垂直轴旋转,如同 Blender 或 Maya。X 轴、Z 轴:模型只绕该世界轴旋转(视图 > 轨道锁定)。"},
{"Keeps the interface below the camera notch of MacBooks (and other laptops) when SculptForge fills the screen. "
"Automatic asks the system (macOS) or recognises a notched MacBook display (Linux).",
"SculptForge 全屏时,让界面保持在 MacBook(及其他笔电)相机刘海下方。“自动”会询问系统 (macOS) 或辨识有刘海的"
@@ -1397,9 +1397,27 @@ constexpr Entry kSimplifiedChinese[] = {
"按键对它们没有作用。"},
{"Share size and intensity across brushes", "笔刷之间共用大小与强度"},
{"Free", "自由"},
+ {"Orbit lock",
+ "轨道锁定"},
+ {"Y (turntable)",
+ "Y(转盘)"},
+ {"Rotation drags turn the view about the screen's axes and can roll it over the top (the default). "
+ "Saved with the preferences.",
+ "旋转拖动以屏幕的轴转动视图,并可从上方翻转(默认)。随偏好设置保存。"},
+ {"Rotation drags turn the view like a turntable: the model stays upright and turns about its vertical "
+ "(Y) axis. Saved with the preferences.",
+ "旋转拖动像转盘一样转动视图:模型保持直立并绕其垂直(Y)轴旋转。随偏好设置保存。"},
+ {"Rotation drags turn the view about the world X axis only (red): from the front, an up or down drag "
+ "tips the model towards you or away. Shift still snaps to a side view; the axis gizmo shows the "
+ "lock. Saved with the preferences.",
+ "旋转拖动只绕世界 X 轴(红色)转动视图:从正面看,上下拖动会让模型朝你或远离你倾斜。Shift 仍可贴齐侧视图;轴向小部件会显示锁定。随偏好设置保存。"},
+ {"Rotation drags turn the view about the world Z axis only (blue): from the front, a drag around the "
+ "middle turns the model like a wheel. Shift still snaps to a side view; the axis gizmo shows the "
+ "lock. Saved with the preferences.",
+ "旋转拖动只绕世界 Z 轴(蓝色)转动视图:从正面看,绕中心拖动会让模型在屏幕上原地转动。Shift 仍可贴齐侧视图;轴向小部件会显示锁定。随偏好设置保存。"},
{"Free: the model turns about the screen's axes and can roll over the top. Turntable: it stays upright, as in "
- "Blender or Maya.",
- "自由:模型以屏幕的轴旋转,并可从上方翻转。转盘:模型保持直立,如同 Blender 或 Maya。"},
+ "Blender or Maya. X axis, Z axis: it turns about that world axis only (View > Orbit lock).",
+ "自由:模型以屏幕的轴旋转,并可从上方翻转。转盘:模型保持直立,如同 Blender 或 Maya。X 轴、Z 轴:模型只绕该世界轴旋转(视图 > 轨道锁定)。"},
{"The pointer over the 3D view: a crosshair (the default, as in most sculpting apps; it stays while the view "
"turns) or the arrow. Panels, menus and popups always show the arrow (or their own resize and text cursors). "
"Saved automatically.",
diff --git a/src/app/I18nSpanish.cpp b/src/app/I18nSpanish.cpp
index 8a63ea2a..afe2855b 100644
--- a/src/app/I18nSpanish.cpp
+++ b/src/app/I18nSpanish.cpp
@@ -600,6 +600,30 @@ constexpr Entry kSpanish[] = {
{"Automatic", "Automática"},
{"Rotation", "Rotación"},
{"Free", "Libre"},
+ {"Orbit lock",
+ "Bloqueo de órbita"},
+ {"Y (turntable)",
+ "Y (plataforma giratoria)"},
+ {"Rotation drags turn the view about the screen's axes and can roll it over the top (the default). "
+ "Saved with the preferences.",
+ "Arrastrar para girar mueve la vista sobre los ejes de la pantalla y puede darle la vuelta por "
+ "arriba (lo predeterminado). Se guarda con las preferencias."},
+ {"Rotation drags turn the view like a turntable: the model stays upright and turns about its vertical "
+ "(Y) axis. Saved with the preferences.",
+ "Arrastrar para girar mueve la vista como una plataforma giratoria: el modelo se queda derecho y "
+ "gira sobre su eje vertical (Y). Se guarda con las preferencias."},
+ {"Rotation drags turn the view about the world X axis only (red): from the front, an up or down drag "
+ "tips the model towards you or away. Shift still snaps to a side view; the axis gizmo shows the "
+ "lock. Saved with the preferences.",
+ "Arrastrar para girar mueve la vista solo sobre el eje X del mundo (rojo): desde el frente, "
+ "arrastrar arriba o abajo inclina el modelo hacia ti o hacia atrás. Mayús sigue ajustando a una "
+ "vista lateral; el gizmo de ejes muestra el bloqueo. Se guarda con las preferencias."},
+ {"Rotation drags turn the view about the world Z axis only (blue): from the front, a drag around the "
+ "middle turns the model like a wheel. Shift still snaps to a side view; the axis gizmo shows the "
+ "lock. Saved with the preferences.",
+ "Arrastrar para girar mueve la vista solo sobre el eje Z del mundo (azul): desde el frente, "
+ "arrastrar alrededor del centro gira el modelo como una rueda. Mayús sigue ajustando a una vista "
+ "lateral; el gizmo de ejes muestra el bloqueo. Se guarda con las preferencias."},
{"Turntable", "Plataforma giratoria"},
{"Camera notch", "Muesca de la cámara"},
{"Always reserve", "Reservar siempre"},
@@ -1283,10 +1307,11 @@ constexpr Entry kSpanish[] = {
"ventana (Windows: Configuración > Pantalla > Escala, por monitor)."},
{"Free: dragging turns the model about the screen's axes and can roll it over the top; press Shift while rotating "
"to snap to the nearest front, side, top or bottom view. Turntable: the model stays upright and turns about its "
- "vertical axis, as in Blender or Maya.",
+ "vertical axis, as in Blender or Maya. X axis, Z axis: it turns about that world axis only (View > Orbit lock).",
"Libre: arrastrar gira el modelo sobre los ejes de la pantalla y puede darle la vuelta por arriba; pulsa Mayús "
"mientras giras para ajustar a la vista frontal, lateral, superior o inferior más cercana. Plataforma "
- "giratoria: el modelo se queda derecho y gira sobre su eje vertical, como en Blender o Maya."},
+ "giratoria: el modelo se queda derecho y gira sobre su eje vertical, como en Blender o Maya."
+ " Eje X, eje Z: gira solo sobre ese eje del mundo (Vista > Bloqueo de órbita)."},
{"Keeps the interface below the camera notch of MacBooks (and other laptops) when SculptForge fills the screen. "
"Automatic asks the system (macOS) or recognises a notched MacBook display (Linux).",
"Mantiene la interfaz por debajo de la muesca de la cámara de los MacBook (y otros portátiles) cuando "
@@ -1609,9 +1634,9 @@ constexpr Entry kSpanish[] = {
"pinceles; Nunca: la tecla no hace nada en ellos."},
{"Share size and intensity across brushes", "Compartir tamaño e intensidad entre pinceles"},
{"Free: the model turns about the screen's axes and can roll over the top. Turntable: it stays upright, as in "
- "Blender or Maya.",
+ "Blender or Maya. X axis, Z axis: it turns about that world axis only (View > Orbit lock).",
"Libre: el modelo gira sobre los ejes de la pantalla y puede darse la vuelta por arriba. Plataforma giratoria: "
- "se queda derecho, como en Blender o Maya."},
+ "se queda derecho, como en Blender o Maya. Eje X, eje Z: gira solo sobre ese eje del mundo (Vista > Bloqueo de órbita)."},
{"The pointer over the 3D view: a crosshair (the default, as in most sculpting apps; it stays while the view "
"turns) or the arrow. Panels, menus and popups always show the arrow (or their own resize and text cursors). "
"Saved automatically.",
diff --git a/src/app/I18nTraditionalChinese.cpp b/src/app/I18nTraditionalChinese.cpp
index 6fc3b2fa..696777f1 100644
--- a/src/app/I18nTraditionalChinese.cpp
+++ b/src/app/I18nTraditionalChinese.cpp
@@ -1111,9 +1111,9 @@ constexpr Entry kTraditionalChinese[] = {
"文字與控制項的大小,立即套用。「自動」會依視窗所在的顯示器而定(Windows:設定 > 顯示器 > 縮放,依各顯示器)。"},
{"Free: dragging turns the model about the screen's axes and can roll it over the top; press Shift while rotating "
"to snap to the nearest front, side, top or bottom view. Turntable: the model stays upright and turns about its "
- "vertical axis, as in Blender or Maya.",
+ "vertical axis, as in Blender or Maya. X axis, Z axis: it turns about that world axis only (View > Orbit lock).",
"自由:拖曳會以螢幕的軸旋轉模型,並可從上方翻轉;旋轉時按住 Shift 可貼齊最近的正面、側面、頂部或底部視圖。轉盤:"
- "模型保持直立並繞垂直軸旋轉,如同 Blender 或 Maya。"},
+ "模型保持直立並繞垂直軸旋轉,如同 Blender 或 Maya。X 軸、Z 軸:模型只繞該世界軸旋轉(檢視 > 軌道鎖定)。"},
{"Keeps the interface below the camera notch of MacBooks (and other laptops) when SculptForge fills the screen. "
"Automatic asks the system (macOS) or recognises a notched MacBook display (Linux).",
"SculptForge 全螢幕時,讓界面保持在 MacBook(及其他筆電)相機瀏海下方。「自動」會詢問系統 (macOS) 或辨識有瀏海的"
@@ -1397,9 +1397,27 @@ constexpr Entry kTraditionalChinese[] = {
"按鍵對它們沒有作用。"},
{"Share size and intensity across brushes", "筆刷之間共用大小與強度"},
{"Free", "自由"},
+ {"Orbit lock",
+ "軌道鎖定"},
+ {"Y (turntable)",
+ "Y(轉盤)"},
+ {"Rotation drags turn the view about the screen's axes and can roll it over the top (the default). "
+ "Saved with the preferences.",
+ "旋轉拖曳以螢幕的軸轉動檢視,並可從上方翻轉(預設)。隨偏好設定儲存。"},
+ {"Rotation drags turn the view like a turntable: the model stays upright and turns about its vertical "
+ "(Y) axis. Saved with the preferences.",
+ "旋轉拖曳像轉盤一樣轉動檢視:模型保持直立並繞其垂直(Y)軸旋轉。隨偏好設定儲存。"},
+ {"Rotation drags turn the view about the world X axis only (red): from the front, an up or down drag "
+ "tips the model towards you or away. Shift still snaps to a side view; the axis gizmo shows the "
+ "lock. Saved with the preferences.",
+ "旋轉拖曳只繞世界 X 軸(紅色)轉動檢視:從正面看,上下拖曳會讓模型朝你或遠離你傾斜。Shift 仍可貼齊側視圖;軸向小工具會顯示鎖定。隨偏好設定儲存。"},
+ {"Rotation drags turn the view about the world Z axis only (blue): from the front, a drag around the "
+ "middle turns the model like a wheel. Shift still snaps to a side view; the axis gizmo shows the "
+ "lock. Saved with the preferences.",
+ "旋轉拖曳只繞世界 Z 軸(藍色)轉動檢視:從正面看,繞中心拖曳會讓模型在螢幕上原地轉動。Shift 仍可貼齊側視圖;軸向小工具會顯示鎖定。隨偏好設定儲存。"},
{"Free: the model turns about the screen's axes and can roll over the top. Turntable: it stays upright, as in "
- "Blender or Maya.",
- "自由:模型以螢幕的軸旋轉,並可從上方翻轉。轉盤:模型保持直立,如同 Blender 或 Maya。"},
+ "Blender or Maya. X axis, Z axis: it turns about that world axis only (View > Orbit lock).",
+ "自由:模型以螢幕的軸旋轉,並可從上方翻轉。轉盤:模型保持直立,如同 Blender 或 Maya。X 軸、Z 軸:模型只繞該世界軸旋轉(檢視 > 軌道鎖定)。"},
{"The pointer over the 3D view: a crosshair (the default, as in most sculpting apps; it stays while the view "
"turns) or the arrow. Panels, menus and popups always show the arrow (or their own resize and text cursors). "
"Saved automatically.",
diff --git a/src/app/Input.cpp b/src/app/Input.cpp
index 9537fa2b..46d0ffd7 100644
--- a/src/app/Input.cpp
+++ b/src/app/Input.cpp
@@ -377,7 +377,7 @@ void App::restoreView(int index) {
void App::setInputStyle(int style) {
uiPrefs_.inputStyle = std::clamp(style, 0, 3);
uiPrefs_.wheelZoomToPointer = mayaStyle(); // Maya's wheel zooms toward the pointer; the others to the centre (#134)
- if (blenderStyle()) uiPrefs_.turntable = true; // Blender orbits as a turntable; Preferences > Input changes it
+ if (blenderStyle()) uiPrefs_.orbitLock = 1; // Blender orbits as a turntable; Preferences > Input changes it
maskBrush_.on = false;
applyInputStyle();
if (uiPrefs_.inputStyle == 0) offerQuickTour(); // the Classic sculpting keys: the quick tour, once (QuickTour.cpp)
@@ -616,13 +616,15 @@ void App::drawInputSection() {
drawPackKeymapRows(); // keymaps from installed packs (PanelPacks.cpp)
ImGui::TextDisabled("%s", tr("Rotation"));
ImGui::SameLine();
- int rotation = uiPrefs_.turntable ? 1 : 0;
+ int rotation = std::clamp(uiPrefs_.orbitLock, 0, 3);
ImGui::SetNextItemWidth(-1);
- const std::string rotations = std::string(tr("Free")) + '\0' + tr("Turntable") + '\0';
- if (ImGui::Combo("##rotation_input", &rotation, rotations.c_str())) uiPrefs_.turntable = rotation == 1;
+ const std::string rotations = std::string(tr("Free")) + '\0' + tr("Turntable") + '\0' + tr("X axis") + '\0' +
+ tr("Z axis") + '\0';
+ if (ImGui::Combo("##rotation_input", &rotation, rotations.c_str())) uiPrefs_.orbitLock = rotation;
ui::HelpText("Rotation", nullptr,
"Free: the model turns about the screen's axes and can roll over the top. Turntable: it "
- "stays upright, as in Blender or Maya.",
+ "stays upright, as in Blender or Maya. X axis, Z axis: it turns about that world axis only "
+ "(View > Orbit lock).",
"Preferences > Input");
drawRadialMenusSection(); // RadialMenu.cpp
drawSpaceMouseSection(); // SpaceMouse.cpp
diff --git a/src/app/Palettes.cpp b/src/app/Palettes.cpp
index b8069ba1..86ffbb20 100644
--- a/src/app/Palettes.cpp
+++ b/src/app/Palettes.cpp
@@ -756,6 +756,8 @@ void App::drawPalette_Render() {
bool lockCamera = uiPrefs_.airStrokes; // #62: drags on the background start strokes (Shift+L)
if (ui::Checkbox("Lock camera##view.lock_camera", &lockCamera)) uiPrefs_.airStrokes = lockCamera;
ui::HelpAction(*this, "input.toggle_air_strokes");
+ ImGui::TextDisabled("%s", tr("Orbit lock"));
+ ui::Segmented(*this, {"view.orbit_lock_free", "view.orbit_lock_y", "view.orbit_lock_x", "view.orbit_lock_z"});
drawBackgroundControls("render");
ImGui::TextDisabled("%s", tr("View resolution"));
ui::Segmented(*this, {"perf.res_100", "perf.res_75", "perf.res_50"});
diff --git a/src/app/PanelView.cpp b/src/app/PanelView.cpp
index 816cd658..431a5ec7 100644
--- a/src/app/PanelView.cpp
+++ b/src/app/PanelView.cpp
@@ -130,11 +130,46 @@ void App::registerViewUiCommands() {
return {ok, message};
}});
+ // View > Orbit lock (a request from foirgairwolf on Discord): which way a rotation drag turns the view.
+ commands_.add({"orbit_lock",
+ "Orbit lock (View > Orbit lock): how a rotation drag turns the view. free: about the screen's axes "
+ "(it can roll over the top); y: a turntable, upright, about the vertical axis; x or z: about that "
+ "world axis only. The axis gizmo shows the lock; saved with the preferences.",
+ {{"axis", T::String, "free, x, y or z.", true}},
+ [this](Document&, const Args& a) -> CommandResult {
+ const int lock = parseOrbitLock(argString(a, "axis"));
+ if (lock < 0) return {false, "orbit_lock: axis is free, x, y or z"};
+ uiPrefs_.orbitLock = lock;
+ static constexpr const char* said[4] = {"Orbit lock: free", "Orbit lock: Y (turntable)",
+ "Orbit lock: X axis", "Orbit lock: Z axis"};
+ return {true, said[lock]};
+ }});
+
auto add = [this](std::string id, std::string label, const char* icon, std::string description, std::string palette,
- std::function<void()> run, std::function<bool()> checked) {
- actions_.add({std::move(id), std::move(label), icon, std::move(description), std::move(palette), "", "",
- std::move(run), std::move(checked), nullptr});
+ std::function<void()> run, std::function<bool()> checked, std::string shortcut = "") {
+ actions_.add({std::move(id), std::move(label), icon, std::move(description), std::move(palette),
+ std::move(shortcut), "", std::move(run), std::move(checked), nullptr});
};
+ auto lockRun = [this](int lock) { return [this, lock] { runCommand("orbit_lock", {{"axis", std::string(orbitLockName(lock))}}); }; };
+ auto lockOn = [this](int lock) { return [this, lock] { return uiPrefs_.orbitLock == lock; }; };
+ add("view.orbit_lock_free", "Free", nullptr,
+ "Rotation drags turn the view about the screen's axes and can roll it over the top (the "
+ "default). Saved with the preferences.",
+ "View > Orbit lock", lockRun(0), lockOn(0), "Alt+Shift+F");
+ add("view.orbit_lock_y", "Y (turntable)", nullptr,
+ "Rotation drags turn the view like a turntable: the model stays upright and turns about its "
+ "vertical (Y) axis. Saved with the preferences.",
+ "View > Orbit lock", lockRun(1), lockOn(1), "Alt+Shift+Y");
+ add("view.orbit_lock_x", "X", nullptr,
+ "Rotation drags turn the view about the world X axis only (red): from the front, an up or down drag tips "
+ "the model towards you or away. Shift still snaps to a side view; the axis gizmo shows the lock. Saved with "
+ "the preferences.",
+ "View > Orbit lock", lockRun(2), lockOn(2), "Alt+Shift+X");
+ add("view.orbit_lock_z", "Z", nullptr,
+ "Rotation drags turn the view about the world Z axis only (blue): from the front, a drag around the middle "
+ "turns the model like a wheel. Shift still snaps to a side view; the axis gizmo shows the lock. Saved with "
+ "the preferences.",
+ "View > Orbit lock", lockRun(3), lockOn(3), "Alt+Shift+Z");
add("view.xray", "X-Ray", ICON_LC_SCAN, "See through the other Parts to the active one (again: solid). With only the "
"active Part shown, it is see-through itself (#80, #91).", "Tool > Parts",
[this] { runCommand("xray"); }, [this] { return renderSettings_.xray; });
diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cpp
index 2f7da707..da1c5b8f 100644
--- a/src/app/UiTest.cpp
+++ b/src/app/UiTest.cpp
@@ -180,7 +180,7 @@
// pressure curve: its points, its value at half pressure x100), brush_curves (brushes with
// their own curve), dab_error_px (the last stroke's dab furthest from its cursor
// position, projected back), dab_jitter / dab_jitter_raw (its depth wobble with / without
-// the pick filter, x1000 radii), dabs, pixel_density (2 on a HiDPI screen), input_style (0 classic, 1 SculptForge, 2 Blender), turntable,
+// the pick filter, x1000 radii), dabs, pixel_density (2 on a HiDPI screen), input_style (0 classic, 1 SculptForge, 2 Blender), turntable, orbit_lock (0 free, 1 Y, 2 X, 3 Z),
// camera_ortho, mask_brush (Blender's Mask brush on), shortcut_conflicts (keys two actions
// claim), brush_type (BrushType
// index, -1 for a custom brush or Paint), last_dab_x / last_dab_y (window pixels), paint_r
@@ -801,7 +801,8 @@ double Demo::query(const std::string& name, bool& known) const {
return -1.0; // no such layer
}
if (name == "input_style") return double(app_.uiPrefs_.inputStyle);
- if (name == "turntable") return app_.uiPrefs_.turntable ? 1.0 : 0.0;
+ if (name == "turntable") return app_.uiPrefs_.orbitLock == 1 ? 1.0 : 0.0;
+ if (name == "orbit_lock") return double(app_.uiPrefs_.orbitLock);
if (name == "camera_ortho") return app_.camera_.ortho ? 1.0 : 0.0;
if (name == "mask_brush") return app_.maskBrushActive() ? 1.0 : 0.0;
if (name == "brush_sets") return double(app_.brushSets().size()); // brush sets in the library (#143)
diff --git a/src/render/Camera.cpp b/src/render/Camera.cpp
index f41e2968..682dec61 100644
--- a/src/render/Camera.cpp
+++ b/src/render/Camera.cpp
@@ -52,6 +52,16 @@ void Camera::orbitFree(float dx, float dy) {
glm::angleAxis(-dy * 0.008f, glm::vec3(1, 0, 0)));
}
+void Camera::orbitAbout(const glm::vec3& worldAxis, float dx, float dy, float rollRadians) {
+ // Free orbiting turns the camera by (-dy, -dx, 0) * 0.008 about its own axes: only its part along the locked
+ // axis (in camera space) is kept, and the roll for the part pointing out of the screen.
+ const glm::vec3 axis = glm::normalize(worldAxis);
+ const glm::quat q = glm::normalize(orientation());
+ const glm::vec3 a = glm::conjugate(q) * axis;
+ const float angle = -(dy * a.x + dx * a.y) * 0.008f - rollRadians * a.z;
+ setOrientation(glm::angleAxis(angle, axis) * q);
+}
+
void Camera::setOrientation(const glm::quat& q) {
glm::extractEulerAngleYXZ(glm::mat4_cast(glm::normalize(q)), yaw, pitch, roll);
if (std::abs(roll) < 1e-6f) roll = 0.0f;
diff --git a/src/render/Camera.h b/src/render/Camera.h
index a249a162..21670926 100644
--- a/src/render/Camera.h
+++ b/src/render/Camera.h
@@ -30,6 +30,9 @@ public:
void orbit(float dxPixels, float dyPixels); // turntable
void orbitFree(float dxPixels, float dyPixels); // trackball about the screen axes
+ // Orbit lock X or Z: the view turns about one world axis only. The drag's part across the axis on screen turns
+ // it (as free orbiting would), `rollRadians` (the cursor's sweep around the view's centre) when it points at you.
+ void orbitAbout(const glm::vec3& worldAxis, float dxPixels, float dyPixels, float rollRadians);
void setOrientation(const glm::quat& q); // as yaw / pitch / roll
// The nearest of the 24 views looking along a world axis with another world axis up (the classic
// Shift while rotating).
diff --git a/tests/test_camera.cpp b/tests/test_camera.cpp
index e0e8ce1d..9a6957f5 100644
--- a/tests/test_camera.cpp
+++ b/tests/test_camera.cpp
@@ -106,3 +106,62 @@ TEST(camera_orthographic_matches_perspective_at_the_target) {
const glm::vec4 p = c.projection() * c.view() * glm::vec4(0.0f, 0.0f, 1.0f, 1.0f); // in front of the target...
CHECK(std::abs(p.z / p.w) <= 1.0f); // ...and behind the eye, still drawn
}
+
+TEST(camera_orbit_lock_turns_about_one_world_axis) {
+ // View > Orbit lock X / Z (foirgairwolf on Discord): whatever the drag, the locked axis stays where it is on screen and
+ // nothing turns about the other two.
+ for (int axisIndex : {0, 2}) {
+ glm::vec3 axis(0.0f);
+ axis[axisIndex] = 1.0f;
+ Camera c;
+ c.setOrientation(glm::angleAxis(glm::radians(25.0f), glm::vec3(0, 1, 0)) *
+ glm::angleAxis(glm::radians(-15.0f), glm::vec3(1, 0, 0)));
+ const glm::quat start = c.orientation();
+ const glm::vec3 axisOnScreen = glm::conjugate(start) * axis;
+ c.orbitAbout(axis, 37.0f, -81.0f, 0.2f);
+ c.orbitAbout(axis, -12.0f, 140.0f, -0.05f);
+ const glm::quat q = c.orientation();
+ CHECK(near(glm::conjugate(q) * axis, axisOnScreen, 1e-4f));
+ // The turn from the start is a rotation about the axis alone.
+ const glm::quat turn = q * glm::conjugate(start);
+ const glm::vec3 v(turn.x, turn.y, turn.z);
+ CHECK(glm::length(v - axis * glm::dot(v, axis)) < 1e-4f);
+ CHECK(glm::length(v) > 0.05f); // and it did turn
+ }
+}
+
+TEST(camera_orbit_lock_follows_the_drag) {
+ // From the front: X lock tips the model with an up / down drag and ignores a sideways one (the same way free
+ // orbiting tips it); Z lock turns it like a wheel with the cursor's sweep, as rolling the view does.
+ Camera x;
+ x.orbitAbout(glm::vec3(1, 0, 0), 200.0f, 0.0f, 0.0f);
+ CHECK(near(x.forward(), glm::vec3(0, 0, -1)));
+ Camera free;
+ free.orbitFree(0.0f, 50.0f);
+ x.orbitAbout(glm::vec3(1, 0, 0), 0.0f, 50.0f, 0.0f);
+ CHECK(near(x.forward(), free.forward(), 1e-4f));
+ Camera z;
+ z.orbitAbout(glm::vec3(0, 0, 1), 0.0f, 0.0f, 0.3f);
+ Camera roll;
+ roll.setOrientation(roll.orientation() * glm::angleAxis(-0.3f, glm::vec3(0, 0, 1)));
+ CHECK(near(z.forward(), glm::vec3(0, 0, -1)));
+ CHECK(near(up(z), up(roll), 1e-4f));
+}
+
+TEST(camera_orbit_lock_does_not_drift) {
+ // 1000 small drags (through straight up and down for X, where yaw / pitch / roll is degenerate) end where one
+ // turn by their sum does, and the locked axis has not moved on screen.
+ for (int axisIndex : {0, 2}) {
+ glm::vec3 axis(0.0f);
+ axis[axisIndex] = 1.0f;
+ Camera c;
+ c.setOrientation(glm::angleAxis(glm::radians(10.0f), glm::vec3(0, 1, 0)));
+ const glm::quat start = c.orientation();
+ const glm::vec3 axisOnScreen = glm::conjugate(start) * axis;
+ for (int i = 0; i < 1000; ++i) c.orbitAbout(axis, 0.7f, 1.3f, 0.004f);
+ const float total = -(1.3f * axisOnScreen.x + 0.7f * axisOnScreen.y) * 0.008f * 1000.0f - 0.004f * axisOnScreen.z * 1000.0f;
+ const glm::quat expected = glm::angleAxis(total, axis) * start;
+ CHECK(std::abs(std::abs(glm::dot(glm::normalize(c.orientation()), expected)) - 1.0f) < 1e-4f);
+ CHECK(near(glm::conjugate(c.orientation()) * axis, axisOnScreen, 1e-3f));
+ }
+}
diff --git a/tests/ui/orbit_lock.sfui b/tests/ui/orbit_lock.sfui
new file mode 100644
index 00000000..70acecff
--- /dev/null
+++ b/tests/ui/orbit_lock.sfui
@@ -0,0 +1,69 @@
+# View > Orbit lock (foirgairwolf on Discord, #ideas): Free / Y (turntable) / X / Z, a key and the orbit_lock command
+# each. A rotation drag turns the view about the locked world axis only; the axis gizmo draws that axis through its
+# disc with a lock badge; Shift still snaps; the lock is saved with the preferences.
+run ui_look look=forge layout=sculptforge
+run new_sphere subdivisions=4
+input_style classic
+camera 0 0
+wait 0.2
+expect_value orbit_lock == 0
+expect_shortcut view.orbit_lock_x Alt+Shift+X
+expect_shortcut view.orbit_lock_y Alt+Shift+Y
+expect_shortcut view.orbit_lock_z Alt+Shift+Z
+expect_shortcut view.orbit_lock_free Alt+Shift+F
+expect_value shortcut_conflicts == 0
+run_fails orbit_lock axis=w
+
+# The View menu's row; X picked there.
+click "View##menu.view"
+expect "X##view.orbit_lock_x"
+click "X##view.orbit_lock_x"
+expect_value orbit_lock == 2
+shot view-menu
+key escape
+wait 0.2
+
+# X from the front: a drag tips the model (pitch only), the sideways part does nothing.
+orbit 300 60
+expect_value camera_yaw < 0.01
+expect_value camera_yaw > -0.01
+expect_value camera_roll < 0.01
+expect_value camera_roll > -0.01
+expect_value camera_pitch < -10
+shot x-locked
+
+# Z by key, from the front: the view only rolls (it keeps looking along -Z).
+key shift+alt+z
+expect_value orbit_lock == 3
+camera 0 0
+orbit 200 120
+expect_value camera_yaw < 0.01
+expect_value camera_yaw > -0.01
+expect_value camera_pitch < 0.01
+expect_value camera_pitch > -0.01
+expect_value camera_roll != 0
+shot z-locked
+
+# Shift still snaps to the nearest side view.
+hold shift
+orbit 61 -37
+hold none
+expect_value camera_aligned == 1
+
+# Y is the turntable as before; Free as before.
+run orbit_lock axis=y
+expect_value orbit_lock == 1
+expect_value turntable == 1
+camera 0 0
+orbit 120 -60
+expect_value camera_roll == 0
+key shift+alt+f
+expect_value orbit_lock == 0
+expect_value turntable == 0
+
+# Saved with the preferences.
+run orbit_lock axis=z
+restart
+wait 0.2
+expect_value orbit_lock == 3
+run orbit_lock axis=free