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
Precision brushes: Steady Stroke for every stroke type, World Size, 0.5 px sizes, precision drag, per-brush pressure curve
islandmed7f05c3d2dd42
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 16064aba..9eb30c34 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -91,6 +91,24 @@ All notable changes to SculptForge are listed here. The format follows- Tablet Mouse mode (Preferences > Tablet): on some Windows tablets the brush stopped following the pen in 0.10.7,because the system cursor reading stayed put while the pen moved. A reading that doesn't move with the pen is nowignored and the pen moves the brush relatively, from where it was, with no jump (#72).+### Added+- Precision work (guide: Sculpting > Precision work). **Steady Stroke** (<kbd>L</kbd>) now works with every stroke+ type (Dots, Drag Stamp, Slide Stamp, Spray), with **Catch up on release** (finish the line to the cursor) and the+ string drawn to the lagging brush; the Lazy Stroke type is Dots with it on. **World Size** (Draw palette) keeps+ Draw Size in model units, so the brush stays the same size on the surface as you zoom; every Draw Size slider+ and the cursor show px and mm. Draw Size goes down to 0.5 px; <kbd>Shift</kbd>+<kbd>[</kbd> /+ <kbd>Shift</kbd>+<kbd>]</kbd> step 1 px, <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+right-drag scrubs the size finely,+ and small brushes space their dabs closer so tiny strokes stay continuous. **Precision drag**: hold+ <kbd>Shift</kbd>+<kbd>Alt</kbd> while drawing and the brush moves at a quarter of the pen's speed, at+ **Precision Intensity**. **A pressure curve per brush**: 2 to 5 points with Soft, Linear, Firm and Fine detail+ presets, in Brush Lab and Preferences > Tablet.++### Fixed+- The brush centre now sits exactly under the cursor at high zoom and on HiDPI screens: the brush's ray is worked+ out from the camera directly, and the view is drawn on whole pixels where the rays are cast (it could be up to+ half a pixel off). The surface point under the brush is lightly filtered, so strokes on dense meshes no longer+ wobble.+## [0.10.7] - 2026-11-01### Changeddiff --git a/CMakeLists.txt b/CMakeLists.txtindex de49b574..4cdce1b0 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -71,6 +71,7 @@ add_library(sculptforge_core STATICsrc/core/Masking.cppsrc/core/BrushAlpha.cppsrc/core/Stroke.cpp+ src/core/Precision.cppsrc/core/PathStroke.cppsrc/core/Sha256.cppsrc/core/BrushGallery.cpp@@ -286,6 +287,7 @@ if(SCULPTFORGE_BUILD_APP)src/app/PanelPerformanceProfile.cppsrc/app/CrashLog.cppsrc/app/App.cpp+ src/app/Precision.cppsrc/app/AsyncStroke.cppsrc/app/Demo.cppsrc/app/UiTest.cppdiff --git a/docs/guide/blender.md b/docs/guide/blender.mdindex 4b82e8ed..47f38658 100644--- a/docs/guide/blender.md+++ b/docs/guide/blender.md@@ -104,7 +104,7 @@ add-on. The preferences list every key while it's on.| <kbd>X</kbd> | Symmetry X || <kbd>Shift</kbd>+<kbd>F</kbd> | Wireframe (the wireframe overlay) || <kbd>F</kbd> / <kbd>P</kbd> | Frame the model / perspective on and off |-| <kbd>L</kbd> | Lazy Stroke (Blender: Stabilize Stroke) |+| <kbd>L</kbd> | Steady Stroke (Blender: Stabilize Stroke) || <kbd>W</kbd> / <kbd>E</kbd> / <kbd>R</kbd> | Move / Scale / Rotate || <kbd>Shift</kbd>+drag | Smooth (Blender already does this) |diff --git a/docs/guide/coming-from-zbrush.md b/docs/guide/coming-from-zbrush.mdindex a5a7f26a..950fff0a 100644--- a/docs/guide/coming-from-zbrush.md+++ b/docs/guide/coming-from-zbrush.md@@ -33,7 +33,7 @@ Features use SculptForge's own names. The ideas are the ones you know; here is w| Sculptris Pro | **Dynamic Topology** | **Dynamic** on the top shelf. See [Dynamic topology](dynamic-topology.md) || QuickSave | **Snapshot** | **File > Save Snapshot**, the Library's **Snapshots** tab. See [Projects](projects.md#snapshots) || Transpose, Gizmo 3D, Transpose All | **Gizmo**, **All Parts** | <kbd>W</kbd> <kbd>E</kbd> <kbd>R</kbd>. See [Gizmo](gizmo.md) |-| LazyMouse | **Lazy Stroke** | Stroke palette, <kbd>L</kbd> |+| LazyMouse | **Steady Stroke** (every stroke type) | Stroke picker, <kbd>L</kbd> || PolyFrame (PolyF) | **Wireframe** (**Wire** on the shelf) | Right shelf, <kbd>Shift</kbd>+<kbd>F</kbd> || QuickMenu | **Quick Menu** | <kbd>Space</kbd> or a right click || DamStandard | **Sharp Crease** brush | <kbd>B</kbd> <kbd>D</kbd> <kbd>S</kbd>. See [Sculpting](sculpting.md) |@@ -98,7 +98,7 @@ either. See [Keyboard and mouse](shortcuts.md#zbrush-style-keys) for the full li<kbd>B</kbd> <kbd>P</kbd> <kbd>I</kbd> Pinch.- **Brush settings.** <kbd>S</kbd> Draw Size, <kbd>U</kbd> Intensity, <kbd>I</kbd> RGB Intensity (ZBrush-stylekeys), <kbd>O</kbd> Falloff, each as a slider under the cursor; <kbd>[</kbd> and <kbd>]</kbd> step the size;- <kbd>Space</kbd> opens the Quick Menu; <kbd>L</kbd> toggles Lazy Stroke. The cursor's outer ring is the Draw+ <kbd>Space</kbd> opens the Quick Menu; <kbd>L</kbd> toggles Steady Stroke. The cursor's outer ring is the DrawSize, the inner ring the Falloff. See [Sculpting and brushes](sculpting.md).- **Masking.** <kbd>Ctrl</kbd> paints a mask and <kbd>Ctrl</kbd>+<kbd>Alt</kbd> erases it; <kbd>Ctrl</kbd>+clickthe model blurs it and <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+click sharpens it; <kbd>Ctrl</kbd>+click the background@@ -169,7 +169,7 @@ The SculptForge column is with the ZBrush-style keys on.| Brush pop-up | <kbd>B</kbd> | <kbd>B</kbd> || Draw Size / Z Intensity / RGB Intensity / Focal Shift | <kbd>S</kbd> / <kbd>U</kbd> / <kbd>I</kbd> / <kbd>O</kbd> | Same keys: Draw Size / Intensity / RGB Intensity / Falloff || QuickMenu | <kbd>Space</kbd> or right-click | Quick Menu: <kbd>Space</kbd> or right-click (a right drag navigates) |-| LazyMouse | <kbd>L</kbd> | Lazy Stroke: <kbd>L</kbd> |+| LazyMouse | <kbd>L</kbd> | Steady Stroke: <kbd>L</kbd> || Pick colour / switch colour | <kbd>C</kbd> / <kbd>V</kbd> | Same || Symmetry | <kbd>X</kbd> | <kbd>X</kbd> || Undo / redo | <kbd>Ctrl</kbd>+<kbd>Z</kbd> / <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Z</kbd> | Same (also <kbd>Ctrl</kbd>+<kbd>Y</kbd>) |diff --git a/docs/guide/glossary.md b/docs/guide/glossary.mdindex cca35d53..cde0fad3 100644--- a/docs/guide/glossary.md+++ b/docs/guide/glossary.md@@ -33,7 +33,7 @@ for what is planned.| Groups By Normals | **Tool > Face Groups > By normals** with an angle (`polygroup_auto_by_normals`) || Bake, Multi Map Exporter (normal / displacement / AO maps) | **Tool > Bake** (`bake`): tangent and object-space normal, displacement, AO, cavity and colour maps from a high-poly Part onto a low-poly's UVs. See [Baking](baking.md) || Layers (sculpt layers) | **Tool > Layers**: sculpt layers with weights, exported as blend shapes. See [Layers](layers.md) |-| LazyMouse | **Lazy Stroke** stroke type (Stroke palette) |+| LazyMouse | **Steady Stroke** (<kbd>L</kbd>, every stroke type) and the **Lazy Stroke** stroke type || LightBox | **Library**, <kbd>,</kbd> (comma) || Live Boolean | Not yet || Local symmetry, radial symmetry | **Transform > Symmetry**: **R** (radial symmetry, Radial Count 2-64 around X, Y or Z, combined with the X / Y / Z mirrors) and **Local** (about the active Part's centre). See [Sculpting](sculpting.md#radial-symmetry) |@@ -62,7 +62,7 @@ for what is planned.| Spotlight | Not yet || Preferences > Performance, Preferences > Mem | **Preferences > Performance**: Antialiasing, Fast Navigation, Multithreading, the last stroke's cost and memory. See [Performance](performance.md) || Store Config | **Store Config**, <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>I</kbd> (**Preferences > Config**) |-| Stroke (Dots, DragRect, DragDot, Spray) | **Stroke** types Dots, Drag Stamp, Slide Stamp, Spray, Lazy Stroke (<kbd>L</kbd> toggles Lazy Stroke) |+| Stroke (Dots, DragRect, DragDot, Spray) | **Stroke** types Dots, Drag Stamp, Slide Stamp, Spray, Lazy Stroke (<kbd>L</kbd> toggles Steady Stroke) || SubTool | **Part**: same idea, <kbd>Alt</kbd>+click to select. See [Parts](parts.md) || Texture Map, New From Polypaint | **Tool > Texture Map**: **New Texture** (1K-8K) and paint straight into it, or **Vertex Paint > Texture**. See [Texture painting](texture-painting.md) || Texture palette | Not yet as a palette of texture images. **Tool > Texture Map > Import Texture** loads an image onto the UVs |diff --git a/docs/guide/interface.md b/docs/guide/interface.mdindex b2d5d8e9..31619d91 100644--- a/docs/guide/interface.md+++ b/docs/guide/interface.md@@ -262,8 +262,8 @@ brushes](brush-lab.md)).### Stroke, Alpha and Material pickers-- **Stroke** (click the Stroke tile): Dots, Drag Stamp, Spray and Lazy Stroke, with Scatter for Spray and Lazy- radius for Lazy Stroke. See [Sculpting and brushes](sculpting.md).+- **Stroke** (click the Stroke tile): Dots, Drag Stamp, Spray and Lazy Stroke, with Scatter for Spray, Steady+ Stroke (and its radius) and Precision Intensity. See [Sculpting and brushes](sculpting.md).- **Alpha** (click the Alpha tile): Round, Square, Noise and the twelve built-in patterns (Pores, Cracks, Scales,Rivets, Stitches, Fabric Weave, Bark, Rock Strata, Wrinkles, Skin Folds, Hair Strands, Dot Grid), the image alpha you loaded, images in yourlibrary's Alphas folder, **Load image...** and **Invert loaded image**.diff --git a/docs/guide/sculpting.md b/docs/guide/sculpting.mdindex 24649f85..c2f6fe1e 100644--- a/docs/guide/sculpting.md+++ b/docs/guide/sculpting.md@@ -317,10 +317,10 @@ shelf, which opens the stroke picker, or from the **Stroke** palette.| **Drag Stamp** | Click and drag one stamp: the drag length sets its size and its direction the rotation. Great with alphas. | None || **Slide Stamp** | Click and drag one stamp of the brush's Draw Size: it slides over the surface under the cursor and lands where you let go. Great for VDMs. | None || **Spray** | Scattered dabs of random size, strength and rotation, for organic texture. | **Scatter** (0 to 2, default 1): how far dabs land from the cursor, as a fraction of the brush size. |-| **Lazy Stroke** | The brush trails the cursor on a string, for smooth, steady lines. | **Lazy radius** (1 to 300 px, default 40): longer is steadier. |+| **Lazy Stroke** | Dots with **Steady Stroke** on: the brush trails the cursor on a string, for smooth, steady lines. | **Steady radius** (1 to 300 px, default 40): longer is steadier. |-The setting slider appears under the stroke tiles when **Spray** or **Lazy Stroke** is selected. With Lazy Stroke,-the viewport draws the string between the cursor and the brush point.+**Scatter** appears under the stroke tiles when **Spray** is selected. **Steady Stroke** works with every stroke+type; see [Precision work](#precision-work).**Continuous**, under the stroke tiles in the stroke picker and in the **Stroke** palette, keeps the brush workingwhile you hold it still on the model (30 dabs a second), with any stroke type.@@ -334,9 +334,56 @@ Notes:- Mask strokes (<kbd>Ctrl</kbd>) always use dots, even when Drag Stamp or Slide Stamp is selected.- Custom brushes set their own dab spacing and can add jitter (see [Brush Lab](brush-lab.md)).-> **ZBrush:** Drag Stamp, Slide Stamp, Spray and Lazy Stroke match ZBrush's DragRect, DragDot, Spray and LazyMouse. Freehand and Dots are the same thing here.+> **ZBrush:** Drag Stamp, Slide Stamp, Spray and Steady Stroke match ZBrush's DragRect, DragDot, Spray and LazyMouse. Freehand and Dots are the same thing here.> Roll and curve strokes are not available yet.+## Precision work++Pores, wrinkles, jewellery and hard-surface trims need a brush that goes exactly where you mean, at exactly the+size you mean. These tools work with every brush and every stroke type.++**Steady Stroke** (<kbd>L</kbd>, or the checkbox in the stroke picker). The brush trails the cursor on a string+and only moves once the string is taut, so hand shake never reaches the surface. It works with Dots, Drag Stamp,+Slide Stamp and Spray. The viewport draws the string and a faint circle of its length. **Steady radius** sets the+length (longer is steadier). **Catch up on release** (on by default) finishes the line to where the cursor is when+you let go; turn it off to end the line a string's length behind.++**World Size** (**Draw** palette). Draw Size is normally in screen pixels, so the brush gets smaller on the model+as you zoom in. With World Size on, the size is kept in model units instead: a 0.4 mm pore brush stays 0.4 mm+whether you are looking at the whole head or one eyelid. Every Draw Size slider shows both numbers, for example+**Draw Size 12 px 0.40 mm**; the mm figure is the brush radius on the surface under the cursor (a model unit is a+metre, as when exporting for 3D printing).++**Finer size control.**++| Do this | Change |+|---|---|+| <kbd>[</kbd> / <kbd>]</kbd> | 10% smaller / larger |+| <kbd>Shift</kbd>+<kbd>[</kbd> / <kbd>Shift</kbd>+<kbd>]</kbd> | 1 px smaller / larger (0.5 px below 2 px) |+| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+right-drag | Scrub the size finely: 100 px to the right is about 1.5 times larger |++Draw Size goes down to 0.5 px. Small brushes space their dabs closer together, so a 1 px stroke is still one+continuous line, and the cursor adds a small cross so you can see where a tiny brush is. The size, in px and mm,+shows next to the cursor for a moment after it changes (all the time with World Size on).++**Precision drag** (<kbd>Shift</kbd>+<kbd>Alt</kbd>, held while drawing). Start the stroke, then hold+<kbd>Shift</kbd>+<kbd>Alt</kbd>: the brush moves at a quarter of the pen's speed, drawn as a blue ring with a line+back to the pen, and works at **Precision Intensity** (stroke picker, default 10). Let go and the brush glides back+under the pen as you keep moving; it never jumps. Hold the keys after the stroke has started: at the press,+<kbd>Shift</kbd>+<kbd>Alt</kbd> still selects and frames a Part (ZBrush and SculptForge styles), and in the Blender+style <kbd>Alt</kbd>+click still navigates. The same works in every input style.++**A pressure curve for each brush.** Every brush keeps its own pen pressure curve, applied after the tablet's+curve. Edit it in **Brush Lab** (under the recipe sliders) or in **Preferences > Tablet** (under the tablet's+curve); both edit the brush you are holding. Drag a point, double-click the curve to add one (up to 5), right-click+a point to remove it. The presets are **Soft**, **Linear**, **Firm** and **Fine detail**: Fine detail keeps light+pressure very light and tops out below full strength, for pores and fine lines. Curves are saved as you change+them.++**Accuracy.** The brush centre sits exactly under the cursor at any zoom and on HiDPI screens (to a fraction of a+pixel), and the surface point under the brush is lightly filtered, so strokes on very dense meshes don't wobble+with every tiny bump. A real step in the surface is followed at once.+## AlphasAn alpha is a grayscale stamp that shapes the brush tip: white is full effect, black is none. It affects everydiff --git a/docs/guide/whats-new.md b/docs/guide/whats-new.mdindex 230aea77..50bc6cfd 100644--- a/docs/guide/whats-new.md+++ b/docs/guide/whats-new.md@@ -91,6 +91,12 @@ highlight: Tablet mouse mode: the brush follows the pen again on some Windows ta- **Tablets in mouse mode work again**: on some Windows tablets with **Mouse mode** on (Preferences > Tablet) thebrush stopped following the pen in 0.10.7. When the system can't say where its cursor is, the pen now moves thebrush by how far it moves, from where it was (#72).+- **Precision work** for pores, wrinkles, jewellery and trims: **Steady Stroke** (<kbd>L</kbd>) with every stroke+ type and a catch-up on release; **World Size**, so the brush keeps its size in mm on the surface as you zoom;+ Draw Size down to 0.5 px with <kbd>Shift</kbd>+<kbd>[</kbd> / <kbd>]</kbd> for 1 px steps; hold+ <kbd>Shift</kbd>+<kbd>Alt</kbd> while drawing to move the brush at a quarter of the pen's speed; and a pressure+ curve for each brush with a **Fine detail** preset. The brush centre now sits exactly under the cursor at any+ zoom. See [Precision work](sculpting.md#precision-work).## Version 0.10.7diff --git a/src/app/App.cpp b/src/app/App.cppindex 276596e7..ceed4837 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -311,6 +311,7 @@ bool App::init(const AppOptions& options) {initProject(); // before opening anything, so it lands in the recent filesinitActions(); // the default shortcuts and every command, for keys, help and the command paletteinitBrushSettings(); // each brush's own size, intensity, stroke and alpha (#78)+ loadBrushCurves(); // each brush's own pressure curve (Precision.cpp)initPhoneActions(); // File > Capture from phone (PanelPhone.cpp)initLightBox();runCommand("new_sphere");@@ -954,7 +955,7 @@ int App::run() {double(sm.view.distance), double(now.distance), double(sm.view.w), double(sm.view.h), double(now.w), double(now.h));else if (verify && !verifyStroke(sm.before, sm.dabs, sm.radii)) return 1;// The test (ui_stroke_path, a light sphere): every dab placed, all of them on the circle.- const float spacing = std::max(1.0f, radiusPx_ * 0.15f);+ const float spacing = dabSpacingPx(radiusPx_, 0.15f);const double expected = 4.0 * 3.14159265358979 * double(sm.r) / double(spacing);if (std::getenv("SF_MEASURE_RESIZE")) return 0; // (the spacing changed with the size: verify checked it)const bool enough = double(sm.dabs.size()) >= 0.9 * expected, onCircle = !off.empty() && off.back() < spacing;@@ -1343,6 +1344,14 @@ void App::onMouseDown(float x, float y, Uint8 button) {return;}}+ if (button == SDL_BUTTON_RIGHT && ctrlDown(SDL_GetModState()) && (SDL_GetModState() & SDL_KMOD_SHIFT) &&+ !(SDL_GetModState() & SDL_KMOD_ALT)) { // in every input style (Ctrl+right-drag still zooms)+ drag_ = Drag::SizeScrub; // Ctrl+Shift+right-drag: Draw Size, finely (Precision.cpp)+ sizeScrubStart_ = radiusPx_;+ sizeScrubDx_ = 0.0f;+ rightClick_.pending = false;+ return;+ }if (blenderStyle() && blenderNavigationDown(button)) return; // middle / Alt+left / right drags navigateif (mayaStyle() && mayaNavigationDown(button)) return; // Alt+left / middle / right: orbit / pan / zoomif (button == SDL_BUTTON_LEFT) {@@ -1514,6 +1523,10 @@ void App::onMouseMove(float x, float y, float dx, float dy, bool fromPen) {case Drag::Capture: captureMouseMove(x, y); break;case Drag::ZSphere: zsphereDragTo(x, y); break;case Drag::AirStroke: airStrokeTo(x, y); break;+ case Drag::SizeScrub:+ sizeScrubDx_ += dx;+ radiusPx_ = drawSizeScrub(sizeScrubStart_, sizeScrubDx_);+ break;case Drag::None: break;}}@@ -1586,6 +1599,8 @@ void App::onMouseUp() {runCommand("insert_primitive", args);}}+ if (drag_ == Drag::Stroke && !maskClickPending_) steadyCatchUp(); // Steady Stroke: on to the pointer (Precision.cpp)+ if (drag_ == Drag::SizeScrub) status_ = drawSizeStatus();if (drag_ == Drag::Stroke && maskClickPending_) maskClickRelease(); // Ctrl+click: blur / sharpen the maskelse if (drag_ == Drag::Stroke && asyncStroke_) {// Predictive strokes: letting go doesn't wait for the dabs still to place; the solver carries on and@@ -1680,11 +1695,20 @@ void App::beginStroke(float x, float y, const RayHit& hit) {straight_ = {};straight_.shiftAtStart = (inputMods() & SDL_KMOD_SHIFT) != 0;strokeAltSmooth_ = false;+ precision_.reset(glm::vec2(x, y)); // (Precision.cpp)+ dabAccuracy_ = {};+ precisionActive_ = false;+ steadyCursor_ = glm::vec2(x, y);+ pickSmoother_.reset();strokeInvert_ = invertToggle_ != (((inputMods() & SDL_KMOD_ALT) != 0) || (erasing() && eraserAction() == PenAction::Invert));// Shift still smooths geometry while the Paint brush is active (ZBrush behaviour).strokePaint_ = strokeBrush_ != BrushType::Smooth && (paintMode_ || paintRgb_);strokeSculpt_ = !(strokePaint_ && paintMode_);const BrushRecipe* recipe = strokeRecipe();+ { // the brush's own pressure curve (Precision.cpp)+ const auto it = brushCurves_.find(pressureCurveKey(strokeBrush_, recipe));+ strokeCurve_ = it == brushCurves_.end() ? PressurePoints() : it->second;+ }haveLastDab_ = false;doc_.sculptor.draftStrokes = draftStrokes() && asyncStrokeAllowed(); // (AsyncStroke.cpp)if (!doc_.sculptor.beginStroke(doc_.mesh,@@ -1781,6 +1805,12 @@ void App::strokeTo(float x, float y) {maskClickPending_ = false;firstDab(maskClickX_, maskClickY_);}+ { // Shift+Alt held: the brush moves at a quarter of the pen's speed (Precision.cpp)+ precisionActive_ = precisionHeld();+ const glm::vec2 p = precision_.follow(glm::vec2(x, y), precisionActive_);+ x = p.x;+ y = p.y;+ }const BrushRecipe* recipe = strokeRecipe();if (strokeBrush_ == BrushType::Move && !recipe && strokeSculpt_ && strokeAlongNormal_) {const glm::vec3 p = alongNormalTarget(x, y);@@ -1808,6 +1838,12 @@ void App::strokeTo(float x, float y) {snakeHookTo(x, y);return;}+ if (steadyOn()) { // Steady Stroke, with every stroke type: the brush trails the pointer on a string+ steadyCursor_ = glm::vec2(x, y);+ const glm::vec2 lazy = lazyMouse_.follow(steadyCursor_);+ x = lazy.x;+ y = lazy.y;+ }if (strokeType_ == StrokeType::DragRect && !strokeMask_) { // mask strokes paint dotsdragRectTo(x, y);return;@@ -1816,11 +1852,6 @@ void App::strokeTo(float x, float y) {dragDotTo(x, y);return;}- if (strokeType_ == StrokeType::LazyMouse) {- const glm::vec2 lazy = lazyMouse_.follow(glm::vec2(x, y));- x = lazy.x;- y = lazy.y;- }{ // Shift pressed after the stroke began: a straight line (ZBrush)const glm::vec2 c = constrainStroke(x, y);x = c.x;@@ -1848,7 +1879,7 @@ void App::strokeTo(float x, float y) {// dab of a long gap before the next look at the pointer made the gaps longer still, until the stroke was one// straight line. The interactive loop works through the queue for a limited time per frame (drainStrokeDabs),// and a gap between samples that is long is drawn as a curve (core/StrokePath.h).- const float spacing = std::max(1.0f, radiusPx_ * (recipe ? recipe->spacing : 0.15f));+ const float spacing = dabSpacingPx(radiusPx_, recipe ? recipe->spacing : 0.15f); // (tiny brushes: closer)const float p0 = lastStrokePressure_, p1 = strokePressure();strokeScratch_.clear();// (a Shift line stays straight: no curve through its corner)@@ -1938,12 +1969,37 @@ void App::dabAt(float x, float y, float pressure) {RayHit hit;if (!(dabView_ ? pickWith(*dabView_, x, y, hit) : pick(x, y, hit))) return;if (pressure < 0.0f) pressure = strokePressure();+ pressure = st.pressureCurve.apply(pressure); // the brush's own curve, after the tablet's++ const float canvasH = dabView_ ? dabView_->canvas.h : canvasHeight();+ const float baseRadius = st.worldRadius > 0.0f ? st.worldRadius : st.radiusPx * cam.worldPerPixel(hit.position, canvasH);+ { // The hit's distance along the ray, filtered: on dense meshes it jitters with every tiny bump (Precision.cpp)+ const glm::vec3 eye = cam.position();+ const glm::vec3 ray = cam.ortho ? cam.forward() : hit.position - eye;+ const float len = glm::length(ray);+ if (len > 1e-9f) {+ const glm::vec3 dir = ray / len;+ const glm::vec3 from = cam.ortho ? hit.position - dir * glm::dot(hit.position - eye, dir) : eye;+ const float t = glm::dot(hit.position - from, dir);+ const float filtered = pickSmoother_.filter(t, baseRadius * 0.5f);+ hit.position = from + dir * filtered;+ if (!dabView_) dabAccuracy_.add(t, filtered, baseRadius);+ }+ }+ if (!dabView_) { // where the dab's centre shows on screen, against where it was asked for (UI tests: sub-pixel)+ const CanvasRect cr = canvasRect();+ const glm::vec4 clip = cam.projection() * cam.view() * glm::vec4(hit.position, 1.0f);+ if (clip.w != 0.0f) {+ const glm::vec2 ndc = glm::vec2(clip) / clip.w;+ const glm::vec2 shown(cr.x + (ndc.x + 1.0f) * 0.5f * cr.w, cr.y + (1.0f - ndc.y) * 0.5f * cr.h);+ dabAccuracy_.maxErrorPx = std::max(dabAccuracy_.maxErrorPx, glm::distance(shown, glm::vec2(x, y)));+ }+ }DabParams p;p.center = hit.position;p.viewDir = cam.forward();- p.radius = st.radiusPx * (st.pressureSize ? std::max(pressure, 0.05f) : 1.0f) *- cam.worldPerPixel(hit.position, dabView_ ? dabView_->canvas.h : canvasHeight()) * dabRadiusScale_;+ p.radius = baseRadius * (st.pressureSize ? std::max(pressure, 0.05f) : 1.0f) * dabRadiusScale_;// Smooth keeps its own Z Intensity (ZBrush), whether picked or held with Shift.p.strength = (st.brush == BrushType::Smooth ? st.smoothStrength : st.strength) * dabStrengthScale_;p.keepVolume = st.brush == BrushType::Smooth && st.smoothKeepVolume;@@ -2315,6 +2371,7 @@ void App::drawUi() {drawTimelineUi(); // the Sculpt Timeline strip, timelapse, proof mode HUD (PanelTimeline.cpp, ProofMode.cpp)pollAlphaFile();syncBrushSettings(); // a brush switch brings back that brush's own settings (#78); before pollVdm's stroke+ syncWorldSize(); // World Size: the brush keeps its size on the surface as you zoom (Precision.cpp)pollVdm();if (previewLod_ >= 0) {const CanvasRect c = canvasRect();@@ -2632,6 +2689,7 @@ void App::drawRecipeEditor(BrushRecipe& recipe) {if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal)) ImGui::SetTooltip("%s", p.help);}ImGui::PopItemWidth();+ drawPressureCurveEditor("lab_brush_curve", ImGui::GetContentRegionAvail().x); // this brush's own (Precision.cpp)const float half = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f;if (ImGui::Button("Save .sfbrush...", ImVec2(half, 0))) saveFileDialog(FileAction::SaveBrush);ImGui::SameLine();@@ -3576,12 +3634,7 @@ void App::drawBrushCursor() {// The inner ring is Focal Shift, as in ZBrush: where the falloff drops to half.dl->AddCircle(c, r * focalRingFraction(focalShift_), IM_COL32(255, 255, 255, 90), 48, 1.0f);}- if (strokeType_ == StrokeType::LazyMouse && drag_ == Drag::Stroke) {- // The string from the cursor to the lagging brush point.- const ImVec2 lp(lazyMouse_.point.x, lazyMouse_.point.y);- dl->AddLine(c, lp, IM_COL32(255, 255, 255, 120), 1.0f);- dl->AddCircleFilled(lp, 3.0f, col);- }+ drawPrecisionCursor(dl, c, r, col); // Steady Stroke's string, the precision drag, the size in mm (Precision.cpp)}} // namespace sfdiff --git a/src/app/App.h b/src/app/App.hindex 0d871b76..e05fcb76 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -33,6 +33,7 @@#include "core/AutoUv.h"#include "core/QRemesh.h"#include "core/RadialMenu.h"+#include "core/Precision.h"#include "core/Stroke.h"#include "core/StrokePath.h"#include "core/SurfaceCursor.h"@@ -142,7 +143,7 @@ public:private:enum class Drag { None, Stroke, Orbit, Pan, Zoom, Roll, MaskCanvas, SubToolClick, Select, Gizmo, Guide, Sculptable, ZSphere, Insert, Capture,- AirStroke, UvTool }; // AirStroke: a stroke begun off the model, waiting to reach it (#62)+ AirStroke, UvTool, SizeScrub }; // AirStroke: a stroke begun off the model, waiting to reach it (#62)void handleEvent(const SDL_Event& e);void onMouseDown(float x, float y, Uint8 button);@@ -291,6 +292,8 @@ private:struct DabSettings {float radiusPx = 60.0f, strength = 0.5f, smoothStrength = 0.5f, focal = 0.0f, maskStrength = 1.0f;float sprayScatter = 1.0f;+ float worldRadius = 0.0f; // World Size: the brush radius in model units (0: Draw Size in pixels)+ PressurePoints pressureCurve; // the brush's own (after the tablet's global curve)bool smoothKeepVolume = false; // Smooth keeps the volume (smoothKeepVolume_, or the alternate smooth)bool pressureSize = false, pressureStrength = true, invert = false, frontFacesOnly = false;bool connectedOnly = false, viewFalloff = false; // the falloff options (Brush palette)@@ -591,6 +594,64 @@ private:bool strokeContinuous_ = false; // Stroke > Continuous (#31): keep dabbing while the pointer restsdouble strokeMovedAt_ = 0.0, continuousDabAt_ = 0.0;LazyMouse lazyMouse_;+ // Precision work (Precision.cpp, core/Precision.h). Steady Stroke (L) puts every stroke type's brush on+ // lazyMouse_'s string, not only the Lazy Stroke type; Catch up finishes the line to the pointer on release.+ bool steadyStroke_ = false;+ bool steadyCatchUp_ = true;+ bool steadyOn() const { return steadyStroke_ || strokeType_ == StrokeType::LazyMouse; }+ glm::vec2 steadyCursor_{0.0f}; // where the pointer is (the string's far end) during a steady stroke+ void steadyCatchUp(); // on release: the brush point runs on to the pointer+ // World Size: Draw Size kept in model units, so the brush stays the same size on the surface as you zoom.+ bool worldSize_ = false;+ float worldRadius_ = 0.0f; // model units (shown in mm)+ float worldSyncedPx_ = 0.0f; // radiusPx_ as worldSize sync last set it (a different value: the user set it)+ float cursorWorldPerPx_ = 0.0f; // at the surface under the pointer (0: not seen yet)+ void syncWorldSize(); // every frame, outside strokes+ std::string drawSizeLabel() const; // "Draw Size %.1f px 0.42 mm" (an ImGui slider format)+ std::string drawSizeStatus() const; // "Draw Size 3.5 px (0.42 mm)"+ void drawPrecisionCursor(ImDrawList* dl, ImVec2 cursor, float radius, ImU32 col);+ void drawPrecisionOptions(); // the Stroke picker: Steady Stroke, its radius and catch-up, Precision Intensity+ glm::vec3 cursorSurface_{0.0f}; // the surface point last under the cursor (World Size measures there)+ bool haveCursorSurface_ = false;+ float sizeReadoutPx_ = 0.0f; // the size readout by the brush shows for a moment after a change+ double sizeReadoutUntil_ = 0.0;+ void drawSizeSlider(const char* id, const char* helpPath, const char* help);+ // Shift+Alt held mid-stroke: the brush moves at a quarter of the pen's speed and dabs at Precision Intensity.+ PrecisionDrag precision_;+ bool precisionActive_ = false;+ float precisionIntensity_ = 0.1f;+ bool precisionHeld() const;+ // Ctrl+Shift+right-drag: scrubs the Draw Size finely (Drag::SizeScrub).+ float sizeScrubStart_ = 0.0f, sizeScrubDx_ = 0.0f;+ // The surface pick under each dab, filtered along its ray so dense meshes don't wobble the stroke.+ PickSmoother pickSmoother_;+ struct DabAccuracy { // this stroke's dabs (UI tests): how far they land from the cursor, how much they wobble+ float maxErrorPx = 0.0f;+ double jitterRaw = 0.0, jitterFiltered = 0.0; // mean |second difference| of the depth, in brush radii+ int count = 0;+ float raw[2] = {0, 0}, filtered[2] = {0, 0};+ void add(float t, float f, float radius) {+ if (count >= 2 && radius > 0.0f) {+ jitterRaw += std::abs(t - 2.0f * raw[1] + raw[0]) / radius;+ jitterFiltered += std::abs(f - 2.0f * filtered[1] + filtered[0]) / radius;+ }+ raw[0] = raw[1], raw[1] = t, filtered[0] = filtered[1], filtered[1] = f;+ ++count;+ }+ } dabAccuracy_;+ // Each brush's own pressure curve (Brush Lab, Preferences > Tablet), keyed as per-brush settings are (#78:+ // "builtin:<brush>", "custom:<recipe>"); <app data>/brush-curves.json keeps them.+ std::map<std::string, PressurePoints> brushCurves_;+ std::string pressureCurveKey() const;+ std::string pressureCurveKey(BrushType type, const BrushRecipe* recipe) const;+ std::string brushCurvesPath() const; // empty in tests and recordings+ PressurePoints strokeCurve_; // the curve of the brush this stroke draws with+ PressurePoints& brushCurve(); // the current brush's (linear until edited)+ const PressurePoints* activeBrushCurve() const;+ void brushCurvesChanged();+ void loadBrushCurves();+ void drawPressureCurveEditor(const char* id, float width);+ int curveDragPoint_ = -1;Spray spray_;float sprayScatter_ = 1.0f; // jitter radius as a fraction of brush sizeglm::vec2 dragAnchor_{0.0f}; // DragRect: where the click landed (window pixels)diff --git a/src/app/AsyncStroke.cpp b/src/app/AsyncStroke.cppindex ecc75e06..0352f735 100644--- a/src/app/AsyncStroke.cpp+++ b/src/app/AsyncStroke.cpp@@ -308,7 +308,9 @@ void App::finishStrokeNow() {App::DabSettings App::dabSettings() const {DabSettings st;st.radiusPx = radiusPx_;- st.strength = strength_;+ st.worldRadius = worldSize_ && worldRadius_ > 0.0f ? worldRadius_ : 0.0f;+ st.pressureCurve = strokeCurve_;+ st.strength = precisionActive_ ? precisionIntensity_ : strength_; // Shift+Alt mid-stroke (Precision.cpp)st.smoothStrength = smoothStrength_;st.smoothKeepVolume = smoothKeepVolume_ != strokeAltSmooth_;st.focal = focalShift_;@@ -397,9 +399,10 @@ void App::buildGhost() {for (const PathDab& d : solver_->batch) pending.push_back({d.x, d.y, d.pressure, 1.0f});for (const PathDab& d : dabQueue_.items()) pending.push_back({d.x, d.y, d.pressure, 1.0f});// The head: from the last dab to where the pen will be when this frame shows (not for strokes that move the- // pointer's path: Lazy Mouse, a Shift line, jitter or spray), in part, as the dabs the pen is about to lay.- const float spacing = std::max(1.0f, radiusPx_ * (strokeRecipe() ? strokeRecipe()->spacing : 0.15f));- if (drag_ == Drag::Stroke && strokeType_ != StrokeType::LazyMouse && strokeType_ != StrokeType::Spray && !straight_.active &&+ // pointer's path: Steady Stroke, the precision drag, a Shift line, jitter or spray), in part, as the dabs the pen is about to lay.+ const float spacing = dabSpacingPx(radiusPx_, strokeRecipe() ? strokeRecipe()->spacing : 0.15f);+ if (drag_ == Drag::Stroke && !steadyOn() && !precisionActive_ && precision_.caughtUp() &&+ strokeType_ != StrokeType::Spray && !straight_.active &&!(strokeRecipe() && strokeRecipe()->jitter > 0.0f)) {const glm::vec2 head = predictedPointer();const glm::vec2 from = !pending.empty() ? glm::vec2(pending.back().x, pending.back().y) : lastDabScreen_;@@ -433,7 +436,8 @@ void App::buildGhost() {camera_.screenRay(sd.x - c.x, sd.y - c.y, c.w, c.h, origin, dir);GhostDab d;if (!ghostSurface(origin, dir, d.center, n)) continue;- d.radius = radiusPx_ * (pressureSize_ ? std::max(sd.pressure, 0.05f) : 1.0f) * camera_.worldPerPixel(d.center, c.h);+ d.radius = (worldSize_ && worldRadius_ > 0.0f ? worldRadius_ : radiusPx_ * camera_.worldPerPixel(d.center, c.h)) *+ (pressureSize_ ? std::max(sd.pressure, 0.05f) : 1.0f);d.normal = n;d.strength = std::clamp((strokeBrush_ == BrushType::Smooth ? smoothStrength_ : strength_), 0.0f, 1.0f) *std::clamp(pressureStrength_ ? sd.pressure : 1.0f, 0.0f, 1.0f);diff --git a/src/app/Config.cpp b/src/app/Config.cppindex c20ea200..ac986961 100644--- a/src/app/Config.cpp+++ b/src/app/Config.cpp@@ -512,10 +512,10 @@ void App::initActions() {[this] { return brushSettings_.shareSizeIntensity; }, nullptr,"On: Draw Size and Z Intensity stay as they are when you pick another brush (as before 0.10.8); Falloff, ""RGB Intensity, the stroke and the alpha still follow each brush. Off (the default): every brush keeps its own.");- add("brush.size_down", "Smaller brush", "Draw", "[", [this] { radiusPx_ = std::max(2.0f, radiusPx_ / 1.1f); }, nullptr,- nullptr, nullptr, nullptr, "Make the brush 10% smaller (hold to repeat).");- add("brush.size_up", "Larger brush", "Draw", "]", [this] { radiusPx_ = std::min(800.0f, radiusPx_ * 1.1f); }, nullptr,- nullptr, nullptr, nullptr, "Make the brush 10% larger (hold to repeat).");+ add("brush.size_down", "Smaller brush", "Draw", "[", [this] { radiusPx_ = drawSizeStep(radiusPx_, -1, false); }, nullptr,+ nullptr, nullptr, nullptr, "Make the brush 10% smaller (hold to repeat; Shift+[ steps one pixel).");+ add("brush.size_up", "Larger brush", "Draw", "]", [this] { radiusPx_ = drawSizeStep(radiusPx_, 1, false); }, nullptr,+ nullptr, nullptr, nullptr, "Make the brush 10% larger (hold to repeat; Shift+] steps one pixel).");add("transform.symmetry_x", "Symmetry X", "Transform", "X", [this] { symmetry_.x = !symmetry_.x; }, ICON_LC_FLIP_HORIZONTAL_2,nullptr, [this] { return symmetry_.x; }, nullptr, "Mirror strokes across the X axis (left / right).");add("view.wireframe", "Wireframe", "Render", "Shift+F", [this] { renderSettings_.wireframe = !renderSettings_.wireframe; },diff --git a/src/app/Input.cpp b/src/app/Input.cppindex 56c72517..b35bb825 100644--- a/src/app/Input.cpp+++ b/src/app/Input.cpp@@ -88,10 +88,38 @@ void App::registerInputActions() {[this] { openQuickMenu(); }, [this] { return quickMenu_.open; });// Stroke and colour.- add("stroke.lazy", "Lazy Stroke", ICON_LC_SPLINE, "Stroke", "L",- "Lazy Stroke on or off: the brush trails the cursor on a string, for steady lines.",- [this] { strokeType_ = strokeType_ == StrokeType::LazyMouse ? StrokeType::Dots : StrokeType::LazyMouse; },- [this] { return strokeType_ == StrokeType::LazyMouse; });+ // (The id stays stroke.lazy so keys people set keep working; the Lazy Stroke type is Dots on the string.)+ add("stroke.lazy", "Steady Stroke", ICON_LC_SPLINE, "Stroke", "L",+ "Steady Stroke on or off, with every stroke type (Dots, Drag Stamp, Slide Stamp, Spray): the brush trails "+ "the cursor on a string and only moves once the string is taut, for steady lines without hand shake.",+ [this] {+ if (strokeType_ == StrokeType::LazyMouse) { // the Lazy Stroke type is on: L turns the string off+ strokeType_ = StrokeType::Dots;+ steadyStroke_ = false;+ } else {+ steadyStroke_ = !steadyStroke_;+ }+ status_ = steadyOn() ? "Steady Stroke on" : "Steady Stroke off";+ },+ [this] { return steadyOn(); });+ add("stroke.steady_catch_up", "Catch up on release", ICON_LC_SPLINE, "Stroke", "",+ "Steady Stroke: when you let go, the line runs on to where the cursor is, instead of stopping a string's "+ "length behind it.",+ [this] { steadyCatchUp_ = !steadyCatchUp_; }, [this] { return steadyCatchUp_; });+ add("brush.world_size", "World Size", ICON_LC_RULER, "Draw", "",+ "Keep the brush size in model units (mm) instead of screen pixels: it stays the same on the surface as you "+ "zoom in and out, for pores, wrinkles and trims of an exact width.",+ [this] {+ worldSize_ = !worldSize_;+ worldSyncedPx_ = -1.0f; // the size as it is now becomes the world size+ status_ = worldSize_ ? "World Size on: the brush keeps its size on the surface" : "World Size off";+ },+ [this] { return worldSize_; });+ add("brush.size_down_fine", "Smaller brush by 1 px", ICON_LC_MINUS, "Draw", "Shift+[",+ "Make the brush one pixel smaller (half a pixel below 2 px), down to 0.5 px.",+ [this] { radiusPx_ = drawSizeStep(radiusPx_, -1, true); });+ add("brush.size_up_fine", "Larger brush by 1 px", ICON_LC_PLUS, "Draw", "Shift+]",+ "Make the brush one pixel larger (half a pixel below 2 px).", [this] { radiusPx_ = drawSizeStep(radiusPx_, 1, true); });add("stroke.continuous", "Continuous", ICON_LC_REPEAT, "Stroke", "","Continuous on or off: while you hold the brush still on the model it keeps adding, 30 dabs a second ""(build up a bump without moving). Not for Move, Tendril or the drag strokes.",@@ -560,7 +588,8 @@ void App::groupMasked() {// ---------------------------------------------------------------------------glm::vec2 App::constrainStroke(float x, float y) {- if (straight_.shiftAtStart || !(inputMods() & SDL_KMOD_SHIFT)) {+ // (Shift+Alt is the precision drag, not a Shift line)+ if (straight_.shiftAtStart || !(inputMods() & SDL_KMOD_SHIFT) || precisionHeld()) {straight_.active = false;return {x, y};}@@ -653,8 +682,7 @@ void App::drawQuickMenu() {ImGui::BeginGroup();const float sw = 150.0f * s;ImGui::SetNextItemWidth(sw);- ui::SliderInside("##qm_drawsize", &radiusPx_, 2.0f, 800.0f, "Draw Size %.0f", ImGuiSliderFlags_Logarithmic);- ui::HelpText("Draw Size", "S", "Brush radius in screen pixels.", "Quick Menu");+ drawSizeSlider("##qm_drawsize", "Quick Menu", "Brush radius in screen pixels (0.5 to 800), and in mm on the surface.");float focal = focalShift_ * 100.0f;ImGui::SetNextItemWidth(sw);if (ui::SliderInside("##qm_focal", &focal, -100.0f, 100.0f, "Falloff %.0f")) focalShift_ = focal / 100.0f;diff --git a/src/app/Palettes.cpp b/src/app/Palettes.cppindex 48473d8e..c774188d 100644--- a/src/app/Palettes.cpp+++ b/src/app/Palettes.cpp@@ -348,8 +348,10 @@ void App::drawPalette_Brush() {void App::drawPalette_Draw() {const tray::Style style; // quiet check marksImGui::SetNextItemWidth(-1);- ui::SliderInside("##drawsize", &radiusPx_, 2.0f, 800.0f, "Draw Size %.0f", ImGuiSliderFlags_Logarithmic);- ui::HelpText("Draw Size", "S", "Brush radius in screen pixels. [ and ] change it by 10%.", "Draw");+ drawSizeSlider("##drawsize", "Draw",+ "Brush radius in screen pixels (0.5 to 800), and in mm on the surface under the cursor. [ and ] change "+ "it by 10%, Shift+[ and Shift+] by 1 px; Ctrl+Shift+right-drag scrubs it finely.");+ ui::ActionButton(*this, "brush.world_size", ImVec2(-1, 0));ImGui::SetNextItemWidth(-1);drawZIntensitySlider("##strength");ImGui::SetNextItemWidth(-1);diff --git a/src/app/PanelMasking.cpp b/src/app/PanelMasking.cppindex 31f79612..446176e0 100644--- a/src/app/PanelMasking.cpp+++ b/src/app/PanelMasking.cpp@@ -73,6 +73,11 @@ void App::beginMaskStroke(float x, float y) {strokePath_.reset(x, y);dabQueue_.clear();lazyMouse_.reset(glm::vec2(x, y));+ steadyCursor_ = glm::vec2(x, y);+ precision_.reset(glm::vec2(x, y));+ precisionActive_ = false;+ pickSmoother_.reset();+ strokeCurve_ = PressurePoints(); // (mask strokes: the tablet's curve only)// ZBrush: a Ctrl+click on the model blurs the mask (Ctrl+Alt+click sharpens it); only a drag paints. The// pen's eraser end set to Erase mask paints straight away.maskClickPending_ = ctrlDown(inputMods()) && !blenderStyle(); // (Blender's Mask brush dabs on a click)diff --git a/src/app/PanelProject.cpp b/src/app/PanelProject.cppindex a1a670cf..dfef11ff 100644--- a/src/app/PanelProject.cpp+++ b/src/app/PanelProject.cpp@@ -448,7 +448,7 @@ void App::applyProjectSettings() {readFloat(b, "smooth_strength", smoothStrength_);readFloat(b, "rgb_intensity", rgbIntensity_);readFloat(b, "focal_shift", focalShift_);- radiusPx_ = std::clamp(radiusPx_, 2.0f, 800.0f);+ radiusPx_ = clampDrawSize(radiusPx_);strength_ = std::clamp(strength_, 0.0f, 1.0f);smoothStrength_ = std::clamp(smoothStrength_, 0.0f, 1.0f);rgbIntensity_ = std::clamp(rgbIntensity_, 0.0f, 1.0f);diff --git a/src/app/Pickers.cpp b/src/app/Pickers.cppindex f98572db..c21ce670 100644--- a/src/app/Pickers.cpp+++ b/src/app/Pickers.cpp@@ -794,12 +794,8 @@ void drawStrokeGrid(App& app, GridMode mode) {ImGui::SliderFloat("##scatter", &app.sprayScatter_, 0.0f, 2.0f, "Scatter %.2f");ui::HelpText("Scatter", nullptr, "How far spray dabs land from the cursor, as a fraction of the brush size.","Stroke");- } else if (app.strokeType_ == StrokeType::LazyMouse) {- ImGui::SetNextItemWidth(-1);- ImGui::SliderFloat("##lazy", &app.lazyMouse_.radius, 1.0f, 300.0f, "Lazy radius %.0f px");- ui::HelpText("Lazy radius", nullptr, "Length of the string the brush trails on: longer = steadier lines.",- "Stroke");}+ app.drawPrecisionOptions(); // Steady Stroke for every stroke type, Precision Intensity (Precision.cpp)}void drawVdmGrid(App& app, GridMode mode) {@@ -1130,7 +1126,7 @@ void drawPickers(App& app) {? Def{"Draw Size", "S","Brush radius in screen pixels. Drag, or type a number and press Enter. [ and ] also ""change it.",- &app.radiusPx_, 2.0f, 800.0f, 1.0f}+ &app.radiusPx_, kMinDrawSizePx, kMaxDrawSizePx, 1.0f}: which == PickerUi::Slider::ZIntensity? Def{s.sliderSmooth ? "Smooth Intensity" : "Intensity", "U",s.sliderSmooth ? "How strongly Smooth works (it keeps its own value, as in ZBrush: hold "@@ -1191,6 +1187,8 @@ void drawPickers(App& app) {char fmt[64];if (!s.sliderTyped.empty())std::snprintf(fmt, sizeof fmt, "%s %s_", d.name, s.sliderTyped.c_str());+ else if (which == PickerUi::Slider::DrawSize)+ std::snprintf(fmt, sizeof fmt, "%s", app.drawSizeLabel().c_str()); // (px and mm, Precision.cpp)elsestd::snprintf(fmt, sizeof fmt, "%s %%.0f", d.name);if (which == PickerUi::Slider::DrawSize) {diff --git a/src/app/Precision.cpp b/src/app/Precision.cppnew file mode 100644index 00000000..8e3ce11c--- /dev/null+++ b/src/app/Precision.cpp@@ -0,0 +1,293 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// Precision work, the app side of core/Precision.h: Steady Stroke with every stroke type (and its catch-up on+// release), World Size (Draw Size kept in model units, shown in mm), the precision drag (Shift+Alt mid-stroke),+// the size readout by the brush, and each brush's own pressure curve (Brush Lab, Preferences > Tablet).+#include "app/App.h"++#include "app/Theme.h"+#include "app/Ui.h"++#include <imgui_internal.h>++#include <algorithm>+#include <cmath>+#include <cstdio>+#include <filesystem>+#include <fstream>+#include <sstream>++namespace sf {++// Shift+Alt, the keyboard's own (not a style's mapping): free mid-stroke in every input style. At the press it+// stays what it was (ZBrush: select and frame a Part; Blender: Alt+left navigates), so it is held once drawing.+bool App::precisionHeld() const {+ const SDL_Keymod keys = SDL_GetModState();+ return (keys & SDL_KMOD_SHIFT) && (keys & SDL_KMOD_ALT) && !(keys & (SDL_KMOD_CTRL | SDL_KMOD_GUI));+}++void App::steadyCatchUp() {+ if (!steadyOn() || !steadyCatchUp_ || drag_ != Drag::Stroke) return;+ if (glm::distance(lazyMouse_.point, steadyCursor_) < 0.5f) return;+ const float keep = lazyMouse_.radius;+ lazyMouse_.radius = 0.0f; // the string goes slack: the brush runs on to the pointer+ strokeTo(mouseX_, mouseY_);+ lazyMouse_.radius = keep;+}++// ---------------------------------------------------------------------------+// World Size and the Draw Size readout+// ---------------------------------------------------------------------------++void App::syncWorldSize() {+ if (drag_ == Drag::Stroke || doc_.sculptor.strokeActive()) return; // a stroke keeps the size it began with+ RayHit hit;+ const CanvasRect c = canvasRect();+ const bool inCanvas = mouseX_ >= c.x && mouseY_ >= c.y && mouseX_ < c.x + c.w && mouseY_ < c.y + c.h;+ if (inCanvas && pick(mouseX_, mouseY_, hit)) {+ cursorSurface_ = hit.position;+ haveCursorSurface_ = true;+ }+ // Off the model: at the surface point last under the cursor (so zooming there keeps the size), else the pivot.+ cursorWorldPerPx_ = camera_.worldPerPixel(haveCursorSurface_ ? cursorSurface_ : camera_.target, canvasHeight());+ const float wpp = cursorWorldPerPx_;+ if (!(wpp > 0.0f)) return;+ if (!worldSize_ || radiusPx_ != worldSyncedPx_ || worldRadius_ <= 0.0f) {+ worldRadius_ = radiusPx_ * wpp; // pixels set the size (a slider, a key, a brush switch)+ } else {+ radiusPx_ = clampDrawSize(worldRadius_ / wpp); // zoomed: the same size on the surface+ }+ worldSyncedPx_ = radiusPx_;+}++namespace {++std::filesystem::path utf8Path(const std::string& s) { return std::filesystem::path(std::u8string(s.begin(), s.end())); }++std::string mmText(float mm) {+ char buf[32];+ std::snprintf(buf, sizeof buf, mm < 1.0f ? "%.2f mm" : mm < 100.0f ? "%.1f mm" : "%.0f mm", double(mm));+ return buf;+}++float shownMm(float radiusPx, float worldRadius, bool worldSize, float wpp) {+ return (worldSize && worldRadius > 0.0f ? worldRadius : radiusPx * wpp) * kMmPerUnit;+}++} // namespace++std::string App::drawSizeLabel() const {+ std::string s = radiusPx_ < 10.0f ? "Draw Size %.1f px" : "Draw Size %.0f px";+ if (cursorWorldPerPx_ > 0.0f) s += " " + mmText(shownMm(radiusPx_, worldRadius_, worldSize_, cursorWorldPerPx_));+ return s;+}++std::string App::drawSizeStatus() const {+ char buf[96];+ std::snprintf(buf, sizeof buf, radiusPx_ < 10.0f ? "Draw Size %.1f px" : "Draw Size %.0f px", double(radiusPx_));+ std::string s = buf;+ if (cursorWorldPerPx_ > 0.0f) s += " (" + mmText(shownMm(radiusPx_, worldRadius_, worldSize_, cursorWorldPerPx_)) + ")";+ return s;+}++void App::drawSizeSlider(const char* id, const char* helpPath, const char* help) {+ ui::SliderInside(id, &radiusPx_, kMinDrawSizePx, kMaxDrawSizePx, drawSizeLabel().c_str(), ImGuiSliderFlags_Logarithmic);+ ui::HelpText("Draw Size", "S", help, helpPath);+}++void App::drawPrecisionCursor(ImDrawList* dl, ImVec2 c, float r, ImU32 col) {+ const float s = uiScale_;+ if (drag_ == Drag::Stroke && steadyOn()) {+ // The string from the pointer to the lagging brush point, which is where the dabs land.+ const ImVec2 lp(lazyMouse_.point.x, lazyMouse_.point.y);+ const ImVec2 cp(steadyCursor_.x, steadyCursor_.y);+ dl->AddLine(cp, lp, IM_COL32(255, 255, 255, 150), 1.0f * s);+ dl->AddCircle(cp, std::max(lazyMouse_.radius, 2.0f), IM_COL32(255, 255, 255, 40), 48, 1.0f);+ dl->AddCircleFilled(lp, 3.0f * s, col);+ }+ if (drag_ == Drag::Stroke && (precisionActive_ || !precision_.caughtUp())) {+ // The precision drag: the brush (at a quarter of the pen's speed) and a line back to the pen.+ const ImVec2 bp(precision_.point.x, precision_.point.y);+ dl->AddLine(c, bp, IM_COL32(120, 220, 255, 140), 1.0f * s);+ dl->AddCircle(bp, std::max(r, 1.5f), IM_COL32(120, 220, 255, 230), 48, 1.5f);+ dl->AddCircleFilled(bp, 1.5f * s, IM_COL32(120, 220, 255, 255));+ }+ // A tiny brush: a cross at its centre (a 1 px ring is hard to see), and the size by the ring.+ if (r < 4.0f) {+ const float arm = 5.0f * s;+ dl->AddLine(ImVec2(c.x - arm, c.y), ImVec2(c.x - r - 1.0f, c.y), col, 1.0f);+ dl->AddLine(ImVec2(c.x + r + 1.0f, c.y), ImVec2(c.x + arm, c.y), col, 1.0f);+ dl->AddLine(ImVec2(c.x, c.y - arm), ImVec2(c.x, c.y - r - 1.0f), col, 1.0f);+ dl->AddLine(ImVec2(c.x, c.y + r + 1.0f), ImVec2(c.x, c.y + arm), col, 1.0f);+ }+ if (radiusPx_ != sizeReadoutPx_) {+ sizeReadoutPx_ = radiusPx_;+ sizeReadoutUntil_ = ImGui::GetTime() + 1.5;+ }+ if (drag_ == Drag::SizeScrub || worldSize_ || ImGui::GetTime() < sizeReadoutUntil_) {+ const std::string text = drawSizeStatus().substr(10); // without "Draw Size "+ const ImVec2 at(c.x + std::max(r, 6.0f * s) + 6.0f * s, c.y - ImGui::GetFontSize() * 0.5f);+ dl->AddText(ImVec2(at.x + 1, at.y + 1), IM_COL32(0, 0, 0, 160), text.c_str());+ dl->AddText(at, IM_COL32(240, 240, 240, 230), text.c_str());+ }+}++void App::drawPrecisionOptions() {+ ImGui::Spacing();+ ui::Checkbox("Steady Stroke##steady", &steadyStroke_);+ ui::HelpAction(*this, "stroke.lazy");+ if (steadyOn()) {+ ImGui::SetNextItemWidth(-1);+ ui::SliderInside("##lazy", &lazyMouse_.radius, 1.0f, 300.0f, "Steady radius %.0f px");+ ui::HelpText("Steady radius", nullptr, "Length of the string the brush trails on: longer = steadier lines.",+ "Stroke");+ ui::Checkbox("Catch up on release##steady_catch_up", &steadyCatchUp_);+ ui::HelpAction(*this, "stroke.steady_catch_up");+ }+ ImGui::SetNextItemWidth(-1);+ float pi = precisionIntensity_ * 100.0f;+ if (ui::SliderInside("##precision_intensity", &pi, 1.0f, 100.0f, "Precision Intensity %.0f"))+ precisionIntensity_ = pi / 100.0f;+ ui::HelpText("Precision Intensity", "Shift+Alt",+ "Hold Shift+Alt while drawing: the brush moves at a quarter of the pen's speed for careful placement, "+ "and dabs at this intensity. Let go and it glides back under the pen.",+ "Stroke");+}++// ---------------------------------------------------------------------------+// Each brush's pressure curve+// ---------------------------------------------------------------------------++std::string App::pressureCurveKey(BrushType type, const BrushRecipe* recipe) const {+ // The same keys as per-brush settings (#78, core/BrushSettings.h), so the curve can join them there.+ return recipe ? "custom:" + recipe->name : std::string("builtin:") + brushName(type);+}++std::string App::pressureCurveKey() const { return pressureCurveKey(brush_, activeRecipe()); }++PressurePoints& App::brushCurve() { return brushCurves_[pressureCurveKey()]; }++const PressurePoints* App::activeBrushCurve() const {+ const auto it = brushCurves_.find(pressureCurveKey());+ return it == brushCurves_.end() ? nullptr : &it->second;+}++std::string App::brushCurvesPath() const {+ return configDir_.empty() || uiConfigDeterministic_ ? std::string() : configDir_ + "brush-curves.json";+}++void App::brushCurvesChanged() {+ const std::string path = brushCurvesPath(); // (none in tests and recordings: they never touch your settings)+ if (path.empty()) return;+ Json j = Json::object();+ for (const auto& [key, curve] : brushCurves_)+ if (!curve.isLinear()) j.set(key, curve.toJson());+ std::ofstream f(utf8Path(path), std::ios::binary | std::ios::trunc);+ f << j.dump(true);+ if (!f) SDL_Log("Could not save %s", path.c_str());+}++void App::loadBrushCurves() {+ const std::string path = brushCurvesPath();+ std::error_code ec;+ if (path.empty() || !std::filesystem::is_regular_file(utf8Path(path), ec)) return;+ std::ifstream f(utf8Path(path), std::ios::binary);+ std::stringstream text;+ text << f.rdbuf();+ Json j;+ std::string err;+ if (!Json::parse(text.str(), j, err) || !j.isObject()) {+ SDL_Log("%s: %s", path.c_str(), err.c_str());+ return;+ }+ for (const auto& [key, value] : j.members()) brushCurves_[key] = PressurePoints::fromJson(value);+}++void App::drawPressureCurveEditor(const char* id, float width) {+ const float s = uiScale_;+ PressurePoints& curve = brushCurve();+ const float h = std::round(width * 0.62f);+ ImGui::PushID(id);+ ImGui::TextDisabled("%s", (std::string("Pressure curve: ") + (activeRecipe() ? activeRecipe()->name : brushName(brush_))).c_str());+ const ImVec2 g0 = ImGui::GetCursorScreenPos(), g1(g0.x + width, g0.y + h);+ ImGui::InvisibleButton("##curve", ImVec2(width, h));+ ui::HelpText("Brush pressure curve", nullptr,+ "How pen pressure (left to right) becomes this brush's pressure (bottom to top), after the tablet's "+ "curve. Each brush keeps its own. Drag a point; double-click the curve to add one (up to 5); "+ "right-click a point to remove it.",+ "Brush");+ const bool hovered = ImGui::IsItemHovered(), active = ImGui::IsItemActive();+ auto toScreen = [&](glm::vec2 p) { return ImVec2(g0.x + p.x * width, g1.y - p.y * h); };+ auto fromScreen = [&](ImVec2 m) {+ return glm::vec2(std::clamp((m.x - g0.x) / width, 0.0f, 1.0f), std::clamp((g1.y - m.y) / h, 0.0f, 1.0f));+ };+ const ImVec2 mouse = ImGui::GetIO().MousePos;+ int near = -1;+ float best = 8.0f * s;+ for (int i = 0; i < curve.count; ++i) {+ const ImVec2 q = toScreen(curve.points[size_t(i)]);+ const float d = std::hypot(q.x - mouse.x, q.y - mouse.y);+ if (d < best) best = d, near = i;+ }+ bool changed = false, done = false;+ if (ImGui::IsItemActivated()) curveDragPoint_ = near;+ if (active && curveDragPoint_ >= 0 && curveDragPoint_ < curve.count) {+ glm::vec2 p = fromScreen(mouse);+ if (curveDragPoint_ == 0) p.x = 0.0f; // the ends keep their x+ if (curveDragPoint_ == curve.count - 1) p.x = 1.0f;+ curve.points[size_t(curveDragPoint_)] = p;+ changed = true;+ }+ if (ImGui::IsItemDeactivated() && curveDragPoint_ >= 0) {+ curveDragPoint_ = -1;+ curve.sort();+ done = true;+ }+ if (hovered && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && near < 0) done = curve.addPoint(fromScreen(mouse).x);+ if (hovered && ImGui::IsMouseClicked(ImGuiMouseButton_Right) && near >= 0) done = curve.removePoint(near);+ if (changed && !active) curve.sort();++ ImDrawList* dl = ImGui::GetWindowDrawList();+ dl->AddRectFilled(g0, g1, IM_COL32(0x18, 0x18, 0x1a, 0xff), 3.0f * s);+ for (int i = 1; i < 4; ++i) {+ const float fx = g0.x + width * float(i) / 4.0f, fy = g0.y + h * float(i) / 4.0f;+ dl->AddLine(ImVec2(fx, g0.y), ImVec2(fx, g1.y), IM_COL32(255, 255, 255, 18));+ dl->AddLine(ImVec2(g0.x, fy), ImVec2(g1.x, fy), IM_COL32(255, 255, 255, 18));+ }+ dl->AddLine(ImVec2(g0.x, g1.y), ImVec2(g1.x, g0.y), IM_COL32(255, 255, 255, 40)); // linear reference+ PressurePoints shown = curve;+ shown.sort(); // (while a point is dragged past its neighbour)+ ImVec2 pts[65];+ for (int i = 0; i <= 64; ++i) {+ const float x = float(i) / 64.0f;+ pts[i] = toScreen({x, shown.apply(x)});+ }+ dl->AddPolyline(pts, 65, ui::color::accent, 0, 2.0f * s);+ for (int i = 0; i < curve.count; ++i)+ dl->AddCircleFilled(toScreen(curve.points[size_t(i)]), (i == near || i == curveDragPoint_ ? 5.0f : 4.0f) * s,+ IM_COL32(255, 255, 255, 230));+ dl->AddRect(g0, g1, ui::color::border, 3.0f * s);++ const auto& presets = PressurePoints::presets();+ const float bw = (width - 3.0f * ImGui::GetStyle().ItemSpacing.x) / 4.0f;+ const char* on = curve.presetName();+ for (size_t i = 0; i < presets.size(); ++i) {+ if (i) ImGui::SameLine();+ const bool sel = on && std::string(on) == presets[i].name;+ if (sel) ImGui::PushStyleColor(ImGuiCol_Button, ImGui::ColorConvertU32ToFloat4(ui::color::accent));+ if (ImGui::Button((std::string(presets[i].name) + "##brushcurve").c_str(), ImVec2(bw, 0))) {+ curve = presets[i].make();+ done = true;+ }+ if (sel) ImGui::PopStyleColor();+ }+ ImGui::PopID();+ if (done) {+ status_ = std::string("Pressure curve for ") + (activeRecipe() ? activeRecipe()->name : brushName(brush_)) + ": " ++ (curve.presetName() ? curve.presetName() : "custom");+ brushCurvesChanged();+ }+}++} // namespace sfdiff --git a/src/app/Shell.cpp b/src/app/Shell.cppindex 3e6a07dc..3b4bb5c7 100644--- a/src/app/Shell.cpp+++ b/src/app/Shell.cpp@@ -744,7 +744,17 @@ CanvasRect App::canvasRect() const {int w = 0, h = 0;SDL_GetWindowSize(window_, &w, &h);if (hideUi_) return {0.0f, 0.0f, float(std::max(w, 1)), float(std::max(h, 1))};- return computeShell(layout_, float(w), float(h), uiScale_, topInset(), shellMetrics()).canvas;+ CanvasRect c = computeShell(layout_, float(w), float(h), uiScale_, topInset(), shellMetrics()).canvas;+ // On whole framebuffer pixels, as canvasViewport draws it: with a fractional rect (HiDPI, UI scales) the view+ // was drawn up to half a pixel from where the rays for the brush were cast.+ int pw = 0, ph = 0;+ if (w > 0 && h > 0 && SDL_GetWindowSizeInPixels(window_, &pw, &ph) && pw > 0 && ph > 0) {+ const float sx = float(pw) / float(w), sy = float(ph) / float(h);+ const float x0 = std::round(c.x * sx) / sx, x1 = std::round((c.x + c.w) * sx) / sx;+ const float y0 = std::round(c.y * sy) / sy, y1 = std::round((c.y + c.h) * sy) / sy;+ c = {x0, y0, std::max(x1 - x0, 1.0f / sx), std::max(y1 - y0, 1.0f / sy)};+ }+ return c;}void App::canvasRay(float x, float y, glm::vec3& origin, glm::vec3& dir) const {@@ -2004,8 +2014,10 @@ void App::drawShelfItem(int shelf, int index, const std::string& item, bool vertImGui::SetNextItemWidth(vertical ? 180.0f * s: std::clamp(item == "widget.draw_size" ? avail * 0.5f : avail, 120.0f * s, 180.0f * s));if (item == "widget.draw_size") {- ui::SliderInside("##drawsize", &radiusPx_, 2.0f, 800.0f, "Draw Size %.0f", ImGuiSliderFlags_Logarithmic);- ui::HelpText("Draw Size", "S", "Brush radius in screen pixels. [ and ] change it by 10%; Ctrl+click to type.", "Draw");+ drawSizeSlider("##drawsize", "Draw",+ "Brush radius in screen pixels (0.5 to 800), and in mm on the surface under the cursor. [ and ] "+ "change it by 10%, Shift+[ and Shift+] by 1 px, Ctrl+Shift+right-drag scrubs it finely; "+ "Ctrl+click to type.");} else {drawZIntensitySlider("##strength");}diff --git a/src/app/Tablet.cpp b/src/app/Tablet.cppindex 673b0ecd..984e7663 100644--- a/src/app/Tablet.cpp+++ b/src/app/Tablet.cpp@@ -562,6 +562,10 @@ void App::drawTabletSection() {path);t.curve.fullAt = std::max(t.curve.fullAt, t.curve.threshold + 0.05f);+ // --- The current brush's own curve (after the one above; Brush Lab shows the same) ---+ ImGui::Spacing();+ drawPressureCurveEditor("prefs_brush_curve", width);+// --- Pressure > Strength / Size: the same toggles as the top shelf ---ImGui::Spacing();const float tw = (width - ImGui::GetStyle().ItemSpacing.x) * 0.5f;diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex 95179ad5..e7d7a1f7 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -42,6 +42,7 @@// expect_shortcut ACTION KEYS the action's effective keys, e.g. expect_shortcut view.front Numpad 1// camera YAW PITCH set the view's angles in degrees (0 0 = the front view), e.g. for guide screenshots// zoom FACTOR / look X Y Z move the camera FACTOR times closer / turn it about (and look at) the point X Y Z+// camera_distance D put the camera D model units from the point it looks at (extreme zoom)// run COMMANDS sculptforge-cli commands, e.g. run new_sphere subdivisions=4 ($SCRIPT_DIR: the script's folder)// drop FILE as if FILE were dropped onto the window (relative to the script's folder)// env NAME VALUE set an environment variable; $SCRIPT_DIR is the script's folder@@ -133,7 +134,15 @@// size_popup_open (the S / U / I / O slider), size_knob_x / size_knob_y (its knob, pixels),// quickmenu_open, right_click_menu, space_camera, space_held, air_strokes, radial_open / radial_menu (-1 none) / radial_held /// radial_hover / radial_ran (radial menus: open, the menu, held by its key or button, the-// slot pointed at, the slot run last), radial_menus, radial_slots_N, lazy_mouse, input_style (0 ZBrush, 1 SculptForge, 2 Blender), turntable,+// slot pointed at, the slot run last), radial_menus, radial_slots_N, lazy_mouse (the Lazy Stroke type),+// steady_stroke (Steady Stroke on, any type), steady_lag (px from the pointer to the brush on+// its string), steady_catch_up, world_size, world_radius_mm, draw_size_exact (px, unrounded),+// precision_active (Shift+Alt mid-stroke), precision_lag (px from the pointer to the brush),+// brush_curve_points / brush_curve_half (the current brush's+// 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 ZBrush, 1 SculptForge, 2 Blender), turntable,// 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@@ -503,6 +512,33 @@ double Demo::query(const std::string& name, bool& known) const {return name == "size_popup_open" ? (open ? 1.0 : 0.0) : name == "size_knob_x" ? knob.x : knob.y;}if (name == "lazy_mouse") return app_.strokeType_ == StrokeType::LazyMouse ? 1.0 : 0.0;+ // Precision work (Precision.cpp)+ if (name == "steady_stroke") return app_.steadyOn() ? 1.0 : 0.0;+ if (name == "steady_lag") return double(glm::distance(app_.lazyMouse_.point, app_.steadyCursor_)); // px+ if (name == "steady_catch_up") return app_.steadyCatchUp_ ? 1.0 : 0.0;+ if (name == "world_size") return app_.worldSize_ ? 1.0 : 0.0;+ if (name == "world_radius_mm") return double(app_.worldRadius_ * kMmPerUnit);+ if (name == "draw_size_exact") return double(app_.radiusPx_);+ if (name == "precision_active") return app_.precisionActive_ ? 1.0 : 0.0;+ if (name == "precision_lag") // px between the brush and the pointer+ return double(glm::distance(app_.precision_.point, glm::vec2(app_.mouseX_, app_.mouseY_)));+ if (name == "brush_curve_points") {+ const PressurePoints* c = app_.activeBrushCurve();+ return c ? double(c->count) : 2.0;+ }+ if (name == "brush_curve_half") { // the current brush's curve at half pressure, x100+ const PressurePoints* c = app_.activeBrushCurve();+ return std::round(double(c ? c->apply(0.5f) : 0.5f) * 100.0);+ }+ if (name == "brush_curves") return double(app_.brushCurves_.size());+ if (name == "dab_error_px") return double(app_.dabAccuracy_.maxErrorPx); // the last stroke's worst dab, px+ if (name == "dab_jitter_raw" || name == "dab_jitter") { // x1000: mean depth wobble per dab, in brush radii+ const auto& a = app_.dabAccuracy_;+ const double n = std::max(1, a.count - 2);+ return 1000.0 * (name == "dab_jitter" ? a.jitterFiltered : a.jitterRaw) / n;+ }+ if (name == "pixel_density") return double(SDL_GetWindowPixelDensity(app_.window_));+ if (name == "dabs") return double(app_.dabAccuracy_.count);if (name == "stroke_type") return double(int(app_.strokeType_)); // 0 Dots, 1 DragRect, 2 DragDot, 3 Spray, 4 LazyMouseif (name == "stroke_continuous") return app_.strokeContinuous_ ? 1.0 : 0.0; // Continuous (#31)if (name == "vdms") return double(app_.doc_.vdms.size());@@ -1327,6 +1363,10 @@ bool Demo::parseStep(int line, const std::vector<std::string>& w, std::string& eif (!need(1)) return false;run([this, f = num(1, 1)] { app_.camera_.distance /= std::max(float(f), 1e-3f); });wait(0.1f);+ } else if (verb == "camera_distance") { // camera_distance D: the camera this far from its target (extreme zoom)+ if (!need(1)) return false;+ run([this, d = num(1, 4)] { app_.camera_.distance = std::max(float(d), 1e-4f); });+ wait(0.1f);} else if (verb == "look") { // look X Y Z: the camera turns about (and looks at) this pointif (!need(3)) return false;run([this, x = num(1, 0), y = num(2, 0), z = num(3, 0)] { app_.camera_.target = glm::vec3(float(x), float(y), float(z)); });diff --git a/src/app/ZBrushNames.h b/src/app/ZBrushNames.hindex ecca46fe..35fb4ee4 100644--- a/src/app/ZBrushNames.h+++ b/src/app/ZBrushNames.h@@ -37,6 +37,7 @@ inline constexpr ZBrushName kZBrushNames[] = {{"Snapshot", "QuickSave", false},{"Gizmo", "Gizmo 3D, Transpose", false},{"Lazy Stroke", "LazyMouse", false},+ {"Steady Stroke", "LazyMouse", false},{"Wire", "PolyF", true},{"Wireframe", "PolyFrame", false},{"Face Group", "Polygroups", false},diff --git a/src/core/BrushSettings.cpp b/src/core/BrushSettings.cppindex ecfef62c..a129f773 100644--- a/src/core/BrushSettings.cpp+++ b/src/core/BrushSettings.cpp@@ -1,6 +1,7 @@// SculptForge - open source digital sculpting// SPDX-License-Identifier: GPL-3.0-or-later#include "core/BrushSettings.h"+#include "core/Precision.h"#include <algorithm>#include <filesystem>@@ -24,7 +25,7 @@ void readFloat(const Json& j, const char* key, float& v) {} // namespacevoid BrushToolSettings::clamp() {- radiusPx = std::clamp(radiusPx, 2.0f, 800.0f);+ radiusPx = clampDrawSize(radiusPx); // (0.5 px and up: core/Precision.h)strength = std::clamp(strength, 0.0f, 1.0f);focal = std::clamp(focal, -1.0f, 1.0f);rgbIntensity = std::clamp(rgbIntensity, 0.0f, 1.0f);diff --git a/src/core/Precision.cpp b/src/core/Precision.cppnew file mode 100644index 00000000..1bbbe2cc--- /dev/null+++ b/src/core/Precision.cpp@@ -0,0 +1,200 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+#include "core/Precision.h"++#include <algorithm>+#include <cmath>++namespace sf {++float clampDrawSize(float px) {+ return std::isfinite(px) ? std::clamp(px, kMinDrawSizePx, kMaxDrawSizePx) : 60.0f;+}++float drawSizeStep(float px, int direction, bool fine) {+ if (!fine) return clampDrawSize(direction < 0 ? px / 1.1f : px * 1.1f);+ // One pixel, half a pixel at the small end; a size between steps lands on the next whole (or half) pixel.+ const float step = (direction < 0 ? px <= 2.0f : px < 2.0f) ? 0.5f : 1.0f;+ const float snapped = direction < 0 ? std::ceil(px / step - 1e-3f) * step : std::floor(px / step + 1e-3f) * step;+ return clampDrawSize(snapped + float(direction < 0 ? -1 : 1) * step);+}++float drawSizeScrub(float px, float dx) { return clampDrawSize(px * std::exp(dx * 0.004f)); }++float dabSpacingPx(float radiusPx, float spacingFraction) {+ const float r = std::max(radiusPx, kMinDrawSizePx);+ return std::max(std::min(1.0f, r * 0.5f), r * spacingFraction);+}++glm::vec2 PrecisionDrag::follow(glm::vec2 cursor, bool slow) {+ const glm::vec2 d = cursor - cursor_;+ cursor_ = cursor;+ if (slow) {+ point += d * speed;+ return point;+ }+ point += d;+ // Let go: close the gap by up to the pen's own motion, so the brush glides back under the pen.+ const glm::vec2 gap = cursor - point;+ const float len = glm::length(gap);+ if (len > 0.0f) point += gap * (std::min(len, glm::length(d)) / len);+ return point;+}++float PickSmoother::filter(float distance, float jump) {+ const float predicted = last_ + velocity_;+ if (!have_ || !(amount > 0.0f) || !(std::abs(distance - predicted) <= jump)) {+ last_ = distance;+ velocity_ = 0.0f;+ have_ = true;+ return distance;+ }+ const float residual = distance - predicted;+ const float alpha = 1.0f - std::clamp(amount, 0.0f, 0.9f);+ last_ = predicted + alpha * residual;+ velocity_ += 0.2f * alpha * residual;+ return last_;+}++// ---------------------------------------------------------------------------+// PressurePoints+// ---------------------------------------------------------------------------++namespace {+float clamp01(float v) { return std::isfinite(v) ? std::clamp(v, 0.0f, 1.0f) : 0.0f; }+constexpr float kMinGap = 0.04f; // between points' x+} // namespace++void PressurePoints::sort() {+ count = std::clamp(count, 2, kMaxPoints);+ for (int i = 0; i < count; ++i) points[size_t(i)] = {clamp01(points[size_t(i)].x), clamp01(points[size_t(i)].y)};+ std::sort(points.begin() + 1, points.begin() + count - 1, [](glm::vec2 a, glm::vec2 b) { return a.x < b.x; });+ points[0].x = 0.0f;+ points[size_t(count - 1)].x = 1.0f;+ for (int i = 1; i < count - 1; ++i) // inner points keep apart from their neighbours+ points[size_t(i)].x = std::clamp(points[size_t(i)].x, points[size_t(i - 1)].x + kMinGap, 1.0f - kMinGap * float(count - 1 - i));+ for (int i = 1; i < count; ++i) // pressing harder never gives less+ points[size_t(i)].y = std::max(points[size_t(i)].y, points[size_t(i - 1)].y);+}++float PressurePoints::apply(float pressure) const {+ const float p = clamp01(pressure);+ const int n = std::clamp(count, 2, kMaxPoints);+ int k = 0;+ while (k < n - 2 && p > points[size_t(k + 1)].x) ++k;+ // Fritsch-Carlson monotone cubic Hermite: tangents from the neighbouring slopes, limited so nothing overshoots.+ auto slope = [&](int i) {+ const glm::vec2 a = points[size_t(i)], b = points[size_t(i + 1)];+ return (b.y - a.y) / std::max(b.x - a.x, 1e-4f);+ };+ auto tangent = [&](int i) {+ if (i == 0) return slope(0);+ if (i == n - 1) return slope(n - 2);+ const float s0 = slope(i - 1), s1 = slope(i);+ if (s0 * s1 <= 0.0f) return 0.0f;+ return 2.0f / (1.0f / s0 + 1.0f / s1); // harmonic mean: monotone+ };+ const glm::vec2 a = points[size_t(k)], b = points[size_t(k + 1)];+ const float h = std::max(b.x - a.x, 1e-4f);+ const float t = std::clamp((p - a.x) / h, 0.0f, 1.0f);+ const float m0 = tangent(k) * h, m1 = tangent(k + 1) * h;+ const float t2 = t * t, t3 = t2 * t;+ const float y = (2 * t3 - 3 * t2 + 1) * a.y + (t3 - 2 * t2 + t) * m0 + (-2 * t3 + 3 * t2) * b.y + (t3 - t2) * m1;+ return std::clamp(y, std::min(a.y, b.y), std::max(a.y, b.y));+}++bool PressurePoints::isLinear() const {+ for (int i = 0; i < count; ++i)+ if (std::abs(points[size_t(i)].y - points[size_t(i)].x) > 1e-3f) return false;+ return true;+}++bool PressurePoints::addPoint(float x) {+ if (count >= kMaxPoints) return false;+ x = clamp01(x);+ for (int i = 0; i < count; ++i)+ if (std::abs(points[size_t(i)].x - x) < kMinGap) return false;+ const float y = apply(x);+ points[size_t(count - 1) + 1] = points[size_t(count - 1)]; // the end moves up one+ points[size_t(count - 1)] = {x, y};+ ++count;+ sort();+ return true;+}++bool PressurePoints::removePoint(int i) {+ if (i <= 0 || i >= count - 1) return false;+ for (int j = i; j < count - 1; ++j) points[size_t(j)] = points[size_t(j + 1)];+ --count;+ return true;+}++bool PressurePoints::operator==(const PressurePoints& o) const {+ if (count != o.count) return false;+ for (int i = 0; i < count; ++i)+ if (glm::length(points[size_t(i)] - o.points[size_t(i)]) > 1e-4f) return false;+ return true;+}++Json PressurePoints::toJson() const {+ Json a = Json::array();+ for (int i = 0; i < count; ++i) {+ Json p = Json::array();+ p.push(double(points[size_t(i)].x));+ p.push(double(points[size_t(i)].y));+ a.push(p);+ }+ return a;+}++PressurePoints PressurePoints::fromJson(const Json& j) {+ PressurePoints c;+ if (!j.isArray() || j.size() < 2 || j.size() > size_t(kMaxPoints)) return c;+ c.count = int(j.size());+ for (size_t i = 0; i < j.size(); ++i) {+ const Json& p = j[i];+ if (!p.isArray() || p.size() != 2) return PressurePoints();+ c.points[i] = {float(p[0].asNumber(double(i) / double(j.size() - 1))), float(p[1].asNumber(0.0))};+ }+ c.sort();+ return c;+}++PressurePoints PressurePoints::linear() { return {}; }++PressurePoints PressurePoints::soft() {+ PressurePoints c;+ c.points = {glm::vec2(0.0f, 0.0f), glm::vec2(0.3f, 0.55f), glm::vec2(1.0f, 1.0f)};+ c.count = 3;+ return c;+}++PressurePoints PressurePoints::firm() {+ PressurePoints c;+ c.points = {glm::vec2(0.0f, 0.0f), glm::vec2(0.6f, 0.3f), glm::vec2(1.0f, 1.0f)};+ c.count = 3;+ return c;+}++PressurePoints PressurePoints::fineDetail() {+ PressurePoints c;+ c.points = {glm::vec2(0.0f, 0.0f), glm::vec2(0.45f, 0.1f), glm::vec2(0.8f, 0.4f), glm::vec2(1.0f, 0.75f)};+ c.count = 4;+ return c;+}++const std::array<PressurePoints::Preset, 4>& PressurePoints::presets() {+ static const std::array<Preset, 4> kPresets{{{"Soft", &PressurePoints::soft},+ {"Linear", &PressurePoints::linear},+ {"Firm", &PressurePoints::firm},+ {"Fine detail", &PressurePoints::fineDetail}}};+ return kPresets;+}++const char* PressurePoints::presetName() const {+ for (const Preset& p : presets())+ if (p.make() == *this) return p.name;+ return nullptr;+}++} // namespace sfdiff --git a/src/core/Precision.h b/src/core/Precision.hnew file mode 100644index 00000000..f71fb709--- /dev/null+++ b/src/core/Precision.h@@ -0,0 +1,97 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// Precision work (pores, wrinkles, jewellery, hard-surface trims): the pieces of the brush that are not tied to a+// window, so they can be tested without one. Steady Stroke itself is LazyMouse in core/Stroke.h (a point on a+// string); here are the precision drag (Shift+Alt mid-stroke: the brush moves at a quarter of the pen's speed),+// fine Draw Size steps, dab spacing for tiny brushes, the filter that keeps the surface pick from wobbling on dense+// meshes, and the point-based pressure curve each brush keeps (Brush Lab and Preferences > Tablet).+#pragma once++#include "core/Json.h"++#include <glm/glm.hpp>++#include <array>+#include <string>++namespace sf {++// Draw Size (the brush radius in screen pixels) limits.+constexpr float kMinDrawSizePx = 0.5f;+constexpr float kMaxDrawSizePx = 800.0f;+// Model units are metres (STL export writes 1000 mm per unit), so World Size shows millimetres.+constexpr float kMmPerUnit = 1000.0f;++float clampDrawSize(float px);+// [ / ]: 10% smaller / larger. Shift+[ / Shift+]: one pixel (half a pixel below 2 px).+float drawSizeStep(float px, int direction, bool fine);+// Ctrl+Shift+right-drag: dx pixels sideways scrub the size finely (about 1.5x per 100 px, never past the limits).+float drawSizeScrub(float px, float dx);++// The distance between dabs, in screen pixels, for a brush of radius `radiusPx` and a recipe's spacing (a fraction+// of the radius). Normally at least a pixel; tiny brushes (below a few px) space by half their radius so a stroke+// with a 0.5 px brush stays one continuous line.+float dabSpacingPx(float radiusPx, float spacingFraction);++// Shift+Alt held mid-stroke: the brush point moves at `speed` times the pen's motion, for careful placement. When+// the keys are let go the point catches up with the pen as it moves on (twice as fast as the pen), never jumping.+struct PrecisionDrag {+ float speed = 0.25f;+ glm::vec2 point{0.0f};++ void reset(glm::vec2 p) {+ point = cursor_ = p;+ }+ glm::vec2 follow(glm::vec2 cursor, bool slow);+ bool caughtUp() const { return glm::length(cursor_ - point) < 0.01f; }++private:+ glm::vec2 cursor_{0.0f};+};++// The surface point under a brush jitters in depth on dense meshes (every tiny bump moves the ray's hit), so the+// dabs wobble. A small filter on the hit's distance along its ray keeps the brush steady. It follows the distance's+// trend (alpha-beta: a slope, as across a curved surface, gives no lag) and smooths only the jitter about it; a jump+// larger than `jump` (a real step, a silhouette) is taken at once.+class PickSmoother {+public:+ float amount = 0.5f; // 0: off; how much of each sample's deviation from the trend is held back+ void reset() { have_ = false; }+ float filter(float distance, float jump);++private:+ float last_ = 0.0f, velocity_ = 0.0f;+ bool have_ = false;+};++// Pen pressure -> brush pressure by 2 to 5 points (0,y0) .. (1,yN) joined by a smooth monotone curve (no overshoot,+// so pressing harder never gives less). Each brush keeps its own (after the tablet's global curve).+struct PressurePoints {+ static constexpr int kMaxPoints = 5;+ std::array<glm::vec2, kMaxPoints> points{glm::vec2(0.0f, 0.0f), glm::vec2(1.0f, 1.0f)};+ int count = 2;++ float apply(float pressure) const;+ bool isLinear() const;+ void sort(); // by x, the ends pinned to x = 0 and x = 1, y clamped to 0..1+ bool addPoint(float x); // a point on the curve at x (false: full, or too close to another)+ bool removePoint(int i); // not an end+ bool operator==(const PressurePoints& o) const;++ Json toJson() const;+ static PressurePoints fromJson(const Json& j); // lenient: a bad value gives the linear curve++ static PressurePoints linear();+ static PressurePoints soft(); // a light touch already gives a lot+ static PressurePoints firm(); // press harder for a strong stroke+ static PressurePoints fineDetail(); // a long, gentle start: light pressure stays light, for pores and fine lines+ struct Preset {+ const char* name;+ PressurePoints (*make)();+ };+ static const std::array<Preset, 4>& presets(); // Soft, Linear, Firm, Fine detail+ const char* presetName() const; // the preset this curve is, or nullptr+};++} // namespace sfdiff --git a/src/render/Camera.cpp b/src/render/Camera.cppindex 5bfb0bfc..f41e2968 100644--- a/src/render/Camera.cpp+++ b/src/render/Camera.cpp@@ -21,8 +21,10 @@ glm::vec3 Camera::position() const { return target + orientation() * glm::vec3(0glm::vec3 Camera::forward() const { return orientation() * glm::vec3(0, 0, -1); }glm::mat4 Camera::view() const {- glm::mat4 world = glm::translate(glm::mat4(1.0f), position()) * glm::mat4_cast(orientation());- return glm::inverse(world);+ // The inverse of translate(position) * rotate(orientation), written out (no general 4x4 inverse and its+ // rounding: at extreme zoom the view and the brush's rays, screenRay, agree to a fraction of a pixel).+ const glm::quat q = glm::normalize(orientation());+ return glm::translate(glm::mat4_cast(glm::conjugate(q)), -position());}glm::mat4 Camera::projection() const {@@ -89,13 +91,20 @@ void Camera::frame(const AABB& box) {}void Camera::screenRay(float x, float y, float width, float height, glm::vec3& origin, glm::vec3& dir) const {- float nx = 2.0f * x / width - 1.0f;- float ny = 1.0f - 2.0f * y / height;- glm::mat4 inv = glm::inverse(projection() * view());- glm::vec4 a = inv * glm::vec4(nx, ny, -1.0f, 1.0f);- glm::vec4 b = inv * glm::vec4(nx, ny, 1.0f, 1.0f);- origin = glm::vec3(a) / a.w;- dir = glm::normalize(glm::vec3(b) / b.w - origin);+ // From the camera's own axes rather than by inverting projection * view: the same ray, without the matrix+ // inverse's rounding, so the brush lands under the cursor to a fraction of a pixel at any zoom.+ const float nx = 2.0f * x / std::max(width, 1e-6f) - 1.0f;+ const float ny = 1.0f - 2.0f * y / std::max(height, 1e-6f);+ const float t = std::tan(fovY * 0.5f);+ const glm::quat q = orientation();+ if (!ortho) {+ origin = position() + q * (glm::vec3(nx * t * aspect, ny * t, -1.0f) * nearPlane()); // on the near plane+ dir = glm::normalize(q * glm::vec3(nx * t * aspect, ny * t, -1.0f));+ return;+ }+ const float h = distance * t; // projection(): the depth range starts behind the eye+ origin = position() + q * glm::vec3(nx * h * aspect, ny * h, farPlane());+ dir = forward();}float Camera::worldPerPixel(const glm::vec3& point, float viewportHeight) const {diff --git a/tests/perf/precision_33m.sfui b/tests/perf/precision_33m.sfuinew file mode 100644index 00000000..19e996c8--- /dev/null+++ b/tests/perf/precision_33m.sfui@@ -0,0 +1,110 @@+# Precision at extreme zoom on 33M triangles (by hand, not in ctest: tools/precision_check.sh). See+# tests/ui/precision_dense.sfui.+run new_bench_sphere millions=33+expect_value pixel_density >= 1+remember pixel_density density+camera 180 0+look 0 0 -0.97+camera_distance 0.06+wait 0.2+mouse_move 0.5 0.5+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+expect_value draw_size_exact == 0.5+key shift+]+expect_value draw_size_exact == 1+# A 1 px brush across the back of the head.+snapshot+view_drag 0.45 0.5 0.55 0.52 1.0+# (A 1 px brush here is 0.03 mm: smaller than this mesh's edges, so it places dabs but moves no vertex; what is+# checked is where the dabs land.)+expect_value dabs > 20+remember dab_error_px err1+expect_value dab_error_px < 0.05+remember dab_jitter_raw jr+remember dab_jitter jf+expect_value dab_jitter <= $jr+key ctrl+z+# World Size at this zoom: a fraction of a millimetre.+mouse_move 0.5 0.5+wait 0.1+remember world_radius_mm mm+expect_value world_radius_mm < 0.5+# 0.5 px, diagonally, with Steady Stroke.+key shift+[+expect_value draw_size_exact == 0.5+key l+view_drag 0.42 0.45 0.58 0.56 1.0+expect_value dabs > 20+remember dab_error_px err2+expect_value dab_error_px < 0.05+key l+shot extreme_zoomdiff --git a/tests/test_precision.cpp b/tests/test_precision.cppnew file mode 100644index 00000000..95e1fc46--- /dev/null+++ b/tests/test_precision.cpp@@ -0,0 +1,224 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// Precision work (core/Precision.h): fine Draw Size steps, dab spacing for tiny brushes, the precision drag, the+// pick filter, Steady Stroke's string and the point-based pressure curve. tests/ui/precision.sfui drives the same+// in the app (every stroke type, World Size across zoom levels, the keys, Shift+Alt, a curve per brush).+#include "TestHarness.h"++#include "core/Precision.h"+#include "core/Stroke.h"+#include "render/Camera.h"++#include <cmath>+#include <vector>++using namespace sf;++namespace {+bool near(float a, float b, float eps = 1e-3f) { return std::abs(a - b) < eps; }+} // namespace++TEST(precision_draw_size_steps) {+ CHECK(near(drawSizeStep(60.0f, 1, true), 61.0f));+ CHECK(near(drawSizeStep(60.0f, -1, true), 59.0f));+ CHECK(near(drawSizeStep(60.4f, 1, true), 61.0f)); // between pixels: the next whole one+ CHECK(near(drawSizeStep(60.4f, -1, true), 60.0f));+ CHECK(near(drawSizeStep(3.0f, -1, true), 2.0f));+ CHECK(near(drawSizeStep(2.0f, -1, true), 1.5f)); // half pixels at the small end+ CHECK(near(drawSizeStep(1.0f, -1, true), 0.5f));+ CHECK(near(drawSizeStep(0.5f, -1, true), kMinDrawSizePx)); // never below 0.5 px+ CHECK(near(drawSizeStep(0.5f, 1, true), 1.0f));+ CHECK(near(drawSizeStep(1.5f, 1, true), 2.0f));+ CHECK(near(drawSizeStep(2.0f, 1, true), 3.0f));+ CHECK(near(drawSizeStep(800.0f, 1, true), kMaxDrawSizePx));+ // [ / ]: 10%, now down to 0.5 px (was 2)+ CHECK(near(drawSizeStep(100.0f, 1, false), 110.0f));+ float r = 10.0f;+ for (int i = 0; i < 60; ++i) r = drawSizeStep(r, -1, false);+ CHECK(near(r, kMinDrawSizePx));+ // Ctrl+Shift+right-drag: fine and symmetric+ CHECK(near(drawSizeScrub(10.0f, 0.0f), 10.0f));+ CHECK(drawSizeScrub(10.0f, 10.0f) > 10.0f && drawSizeScrub(10.0f, 10.0f) < 10.5f); // 10 px of drag: under 5%+ CHECK(near(drawSizeScrub(drawSizeScrub(10.0f, 50.0f), -50.0f), 10.0f));+ CHECK(near(drawSizeScrub(1.0f, -10000.0f), kMinDrawSizePx));+ CHECK(near(clampDrawSize(0.1f), 0.5f) && near(clampDrawSize(NAN), 60.0f));+}++TEST(precision_tiny_brush_spacing_continuous) {+ // The usual spacing (15% of the radius, at least 1 px) for normal brushes...+ CHECK(near(dabSpacingPx(60.0f, 0.15f), 9.0f));+ CHECK(near(dabSpacingPx(4.0f, 0.15f), 1.0f));+ // ... and tiny ones space by half their radius, so dabs overlap and the line has no gaps.+ for (float r : {0.5f, 0.75f, 1.0f, 1.5f, 2.0f, 3.0f}) {+ const float spacing = dabSpacingPx(r, 0.15f);+ CHECK(spacing <= r + 1e-4f); // neighbouring dabs (2r wide) overlap by at least half+ StrokeSpacer sp;+ sp.reset({0.0f, 0.0f});+ std::vector<glm::vec2> dabs;+ for (int i = 1; i <= 40; ++i) sp.moveTo({float(i) * 0.37f, 0.0f}, spacing, dabs); // a slow, short stroke+ CHECK(!dabs.empty());+ float worst = dabs.empty() ? 1e9f : dabs.front().x;+ for (size_t i = 1; i < dabs.size(); ++i) worst = std::max(worst, dabs[i].x - dabs[i - 1].x);+ CHECK(worst < 2.0f * r); // every gap is bridged by the dabs either side+ }+ // A recipe's own wider spacing still wins for big brushes.+ CHECK(near(dabSpacingPx(40.0f, 0.5f), 20.0f));+}++TEST(precision_drag_quarter_speed) {+ PrecisionDrag d;+ d.reset({100.0f, 100.0f});+ CHECK(d.caughtUp());+ // Held: 40 px of pen motion move the brush 10 px.+ glm::vec2 p = d.follow({140.0f, 100.0f}, true);+ CHECK(near(p.x, 110.0f) && near(p.y, 100.0f));+ p = d.follow({140.0f, 140.0f}, true);+ CHECK(near(p.x, 110.0f) && near(p.y, 110.0f));+ CHECK(!d.caughtUp());+ // Let go: the brush moves with the pen and closes the gap as it goes, without a jump.+ const glm::vec2 before = p;+ p = d.follow({141.0f, 140.0f}, false);+ CHECK(glm::distance(p, before) <= 2.0f + 1e-3f); // at most twice the pen's 1 px+ for (int i = 0; i < 200 && !d.caughtUp(); ++i) p = d.follow({141.0f + float(i + 1), 140.0f}, false);+ CHECK(d.caughtUp());+ // Not held from the start: the brush is the pen.+ d.reset({0.0f, 0.0f});+ p = d.follow({25.0f, -5.0f}, false);+ CHECK(near(p.x, 25.0f) && near(p.y, -5.0f));+}++TEST(precision_pick_smoother) {+ PickSmoother f;+ // Jitter about a steady depth is clearly reduced (RMS)...+ double in2 = 0.0, out2 = 0.0;+ f.reset();+ for (int i = 0; i < 400; ++i) {+ const float noise = float((i * 7919) % 11 - 5) * 0.002f; // +-0.01+ const float out = f.filter(10.0f + noise, 0.5f);+ if (i > 10) in2 += double(noise) * noise, out2 += double(out - 10.0f) * (out - 10.0f);+ }+ CHECK(out2 < 0.6 * in2);+ // ... a steady slope (across a curved surface) is followed without lag ...+ f.reset();+ float out = 0.0f;+ for (int i = 0; i < 100; ++i) out = f.filter(5.0f + 0.01f * float(i), 0.5f);+ CHECK(near(out, 5.99f, 2e-3f));+ // ... and a real step (a jump past the brush) is taken at once.+ out = f.filter(9.0f, 0.5f);+ CHECK(near(out, 9.0f));+ // Off: the input.+ f.amount = 0.0f;+ CHECK(near(f.filter(3.0f, 0.5f), 3.0f));+}++TEST(precision_steady_string) {+ // Steady Stroke is the same string for every stroke type: the brush point waits until the string is taut,+ // then follows a radius behind.+ LazyMouse lm;+ lm.radius = 30.0f;+ lm.reset({0.0f, 0.0f});+ CHECK(near(lm.follow({20.0f, 0.0f}).x, 0.0f)); // within the string: no motion (hand shake filtered)+ const glm::vec2 p = lm.follow({100.0f, 0.0f});+ CHECK(near(p.x, 70.0f));+ // Catch up on release: a slack string (radius 0) puts the brush on the pointer.+ lm.radius = 0.0f;+ CHECK(near(lm.follow({100.0f, 0.0f}).x, 100.0f));+}++TEST(precision_world_size_across_zoom) {+ // World Size keeps radius_px * world-per-pixel fixed: zooming in twice as close doubles the pixels.+ Camera cam;+ cam.target = glm::vec3(0.0f);+ cam.distance = 4.0f;+ const glm::vec3 surface(0.0f, 0.0f, 0.0f);+ const float h = 1080.0f;+ const float worldRadius = 0.002f; // 2 mm+ const float px0 = worldRadius / cam.worldPerPixel(surface, h);+ cam.distance = 2.0f;+ const float px1 = worldRadius / cam.worldPerPixel(surface, h);+ CHECK(near(px1 / px0, 2.0f, 0.02f));+ cam.distance = 0.25f;+ const float px2 = worldRadius / cam.worldPerPixel(surface, h);+ CHECK(near(px2 / px0, 16.0f, 0.2f));+ CHECK(near(px2 * cam.worldPerPixel(surface, h) * kMmPerUnit, 2.0f));+}++TEST(precision_pressure_points) {+ const PressurePoints lin = PressurePoints::linear();+ CHECK(lin.isLinear());+ for (float x : {0.0f, 0.25f, 0.5f, 1.0f}) CHECK(near(lin.apply(x), x));+ // Every preset is monotone, starts at 0 and stays within 0..1.+ for (const auto& preset : PressurePoints::presets()) {+ const PressurePoints c = preset.make();+ CHECK(c.count >= 2 && c.count <= PressurePoints::kMaxPoints);+ CHECK(std::string(c.presetName()) == preset.name);+ float last = -1.0f;+ for (int i = 0; i <= 100; ++i) {+ const float y = c.apply(float(i) / 100.0f);+ CHECK(y >= last - 1e-5f && y >= 0.0f && y <= 1.0f);+ last = y;+ }+ for (int i = 0; i < c.count; ++i) CHECK(near(c.apply(c.points[size_t(i)].x), c.points[size_t(i)].y)); // through its points+ }+ CHECK(PressurePoints::soft().apply(0.3f) > 0.5f);+ CHECK(PressurePoints::firm().apply(0.5f) < 0.3f);+ CHECK(PressurePoints::fineDetail().apply(0.3f) < 0.1f); // light stays light+ CHECK(PressurePoints::fineDetail().apply(1.0f) < 0.8f);+ // Editing: add up to 5 points, remove inner ones, the ends stay.+ PressurePoints c;+ CHECK(c.addPoint(0.5f) && c.count == 3 && near(c.apply(0.5f), 0.5f));+ CHECK(!c.addPoint(0.51f)); // too close+ CHECK(c.addPoint(0.25f) && c.addPoint(0.75f) && c.count == 5);+ CHECK(!c.addPoint(0.9f)); // full+ CHECK(!c.removePoint(0) && !c.removePoint(4));+ CHECK(c.removePoint(2) && c.count == 4);+ // A dragged point never makes the curve go down, nor crosses its neighbour.+ c.points[1] = {0.9f, 0.95f};+ c.points[2].y = 0.1f;+ c.sort();+ for (int i = 1; i < c.count; ++i) {+ CHECK(c.points[size_t(i)].x > c.points[size_t(i - 1)].x);+ CHECK(c.points[size_t(i)].y >= c.points[size_t(i - 1)].y);+ }+ // JSON round trip, and lenient reading.+ const PressurePoints f = PressurePoints::fineDetail();+ CHECK(PressurePoints::fromJson(f.toJson()) == f);+ Json bad = Json::array();+ bad.push(Json("x"));+ CHECK(PressurePoints::fromJson(bad).isLinear());+ CHECK(PressurePoints::fromJson(Json()).isLinear());+}++TEST(precision_brush_centre_under_cursor_at_high_zoom) {+ // The ray for a cursor position meets the surface at a point that projects back to that position, to a small+ // fraction of a pixel, even zoomed far in on a model away from the origin (HiDPI: fractional positions).+ for (bool ortho : {false, true}) {+ Camera cam;+ cam.target = glm::vec3(0.31f, 1.27f, -0.43f);+ cam.yaw = 0.7f;+ cam.pitch = -0.35f;+ cam.ortho = ortho;+ const float w = 2560.0f, h = 1440.0f;+ cam.aspect = w / h;+ // Down to a view about 6 mm across on a model a metre from the origin. (Closer still, 0.002 = 1.3 mm across,+ // float world coordinates themselves give ~0.2 px, for the GPU's drawing as for the ray.)+ for (float distance : {4.0f, 0.05f, 0.01f}) {+ cam.distance = distance;+ const glm::mat4 vp = cam.projection() * cam.view();+ float worst = 0.0f;+ for (glm::vec2 px : {glm::vec2(1280.25f, 720.5f), glm::vec2(1333.75f, 701.125f), glm::vec2(1210.5f, 777.375f)}) {+ glm::vec3 o, d;+ cam.screenRay(px.x, px.y, w, h, o, d);+ // a surface through the target, facing the camera+ const glm::vec3 n = -cam.forward();+ const float t = glm::dot(cam.target - o, n) / glm::dot(d, n);+ const glm::vec4 clip = vp * glm::vec4(o + d * t, 1.0f);+ const glm::vec2 ndc = glm::vec2(clip) / clip.w;+ const glm::vec2 back((ndc.x + 1.0f) * 0.5f * w, (1.0f - ndc.y) * 0.5f * h);+ worst = std::max(worst, glm::distance(back, px));+ }+ CHECK(worst < 0.05f);+ }+ }+}diff --git a/tests/ui/precision.sfui b/tests/ui/precision.sfuinew file mode 100644index 00000000..031509c5--- /dev/null+++ b/tests/ui/precision.sfui@@ -0,0 +1,312 @@+# Precision work (Precision.cpp, core/Precision.h): Steady Stroke with every stroke type (L) and its catch-up on+# release, World Size across zoom levels, the fine size keys (Shift+[ / Shift+]) and Ctrl+Shift+right-drag, sizes+# down to 0.5 px, the precision drag (Shift+Alt mid-stroke) in every input style, and a pressure curve per brush.+run ui_look look=classic layout=zbrush # written for the Classic look and the ZBrush-style palette bar and shelves+run new_sphere subdivisions=5+input_style sculptforge++# --- Steady Stroke: L turns it on for every stroke type; the brush trails the pointer on its string. ---+expect_value steady_stroke == 0+key l+expect_value steady_stroke == 1+expect_status Steady Stroke on+expect_value steady_catch_up == 1++# Dots: mid-stroke the brush is a string's length (40 px) behind; on release it catches up to the pointer.+snapshot+drag_path 0.25 0.5 0.45 0.5 0.6 0.5 keep+expect_value stroking == 1+expect_value steady_lag > 35+expect_value steady_lag < 41+release+expect_value moved > 0+expect_value steady_lag < 1+key ctrl+z++# Spray, Drag Stamp and Slide Stamp: the same string.+click "Stroke##palette.stroke"+click "Spray##stroke"+key escape+expect_value stroke_type == 3+drag_path 0.25 0.5 0.45 0.5 0.6 0.5 keep+expect_value steady_lag > 35+release+key ctrl+z+click "Stroke##palette.stroke"+click "Drag Stamp##stroke"+key escape+expect_value stroke_type == 1+drag_path 0.3 0.5 0.5 0.5 0.65 0.5 keep+expect_value steady_lag > 35+release+key ctrl+z+click "Stroke##palette.stroke"+click "Slide Stamp##stroke"+key escape+expect_value stroke_type == 2+drag_path 0.3 0.5 0.5 0.5 0.65 0.5 keep+expect_value steady_lag > 35+release+key ctrl+z++# Catch up off: the line ends a string's length behind the pointer.+click "Stroke##palette.stroke"+click "Dots##stroke"+click "Catch up on release##steady_catch_up"+key escape+expect_value steady_catch_up == 0+drag_path 0.25 0.5 0.45 0.5 0.6 0.5 keep+release+expect_value steady_lag > 35+key ctrl+z+key l+expect_value steady_stroke == 0+expect_status Steady Stroke off++# The Lazy Stroke type is Dots on the string: L turns it off.+click "Stroke##palette.stroke"+click "Lazy Stroke##stroke"+key escape+expect_value steady_stroke == 1+key l+expect_value steady_stroke == 0+expect_value stroke_type == 0++# --- Fine size keys: Shift+[ / Shift+] step one pixel, [ / ] 10%; down to 0.5 px. ---+mouse_move 0.5 0.5+remember draw_size_exact s0+key shift+]+expect_value draw_size_exact == $s0+1+key shift+[+key shift+[+expect_value draw_size_exact == $s0-1+key ]+expect_value draw_size_exact > $s0+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+expect_value draw_size_exact == 0.5+key shift+]+expect_value draw_size_exact == 1+key shift+]+key shift+]+expect_value draw_size_exact == 2+key shift+]+expect_value draw_size_exact == 3+expect_text px++# A 1 px brush still draws one continuous line (dabs at half its radius).+snapshot+stroke 0.3 0.5 0.7 0.5+expect_value moved > 0+key ctrl+z++# Ctrl+Shift+right-drag scrubs the size finely: 100 px to the right is about 1.5x.+key shift+]+key shift+]+key shift+]+key shift+]+key shift+]+key shift+]+key shift+]+expect_value draw_size_exact == 10+hold ctrl+shift+button_drag right 0.5 0.5 0.5521 0.5+hold none+expect_value draw_size_exact > 13+expect_value draw_size_exact < 17+expect_status Draw Size+hold ctrl+shift+button_drag right 0.5 0.5 0.4479 0.5+hold none+expect_value draw_size_exact > 9.5+expect_value draw_size_exact < 10.5+remember camera_distance d0+expect_value camera_distance == $d0++# --- World Size: the brush keeps its size on the surface (mm) as you zoom. ---+key shift+]+key shift+]+key shift+]+key shift+]+key shift+]+key shift+]+key shift+]+key shift+]+key shift+]+key shift+]+mouse_move 0.5 0.5+wait 0.1+remember draw_size_exact px0+expect_value world_radius_mm > 0+click "Draw##palette.draw"+click "World Size##brush.world_size"+expect_value world_size == 1+click "Draw##palette.draw"+mouse_move 0.5 0.5+wait 0.1+remember world_radius_mm mm0+zoom 2+mouse_move 0.5 0.5+wait 0.2+expect_value world_radius_mm == $mm0+expect_value draw_size_exact > $px0*1.7+expect_value draw_size_exact < $px0*3 # (the surface is nearer than the pivot: a bit more than 2x)+zoom 1.5+mouse_move 0.5 0.5+wait 0.2+expect_value world_radius_mm == $mm0+expect_value draw_size_exact > $px0*4+zoom 0.33333333+mouse_move 0.5 0.5+wait 0.2+expect_value world_radius_mm == $mm0+expect_value draw_size_exact > $px0*0.9+expect_value draw_size_exact < $px0*1.1+expect_text mm+# A stroke with World Size on sculpts at that size.+snapshot+stroke 0.3 0.5 0.7 0.5+expect_value moved > 0+key ctrl+z+# Off: pixels again, the size no longer follows the zoom.+click "Draw##palette.draw"+click "World Size##brush.world_size"+expect_value world_size == 0+click "Draw##palette.draw"+remember draw_size_exact px1+zoom 2+mouse_move 0.5 0.5+wait 0.2+expect_value draw_size_exact == $px1+zoom 0.5++# --- Precision drag: Shift+Alt held mid-stroke moves the brush at a quarter of the pen's speed. ---+input_style sculptforge+drag_path 0.25 0.5 0.35 0.5 keep+expect_value precision_active == 0+expect_value precision_lag < 1+hold shift+alt+drag_path 0.35 0.5 0.6 0.5 keep+expect_value precision_active == 1+expect_value precision_lag > 40+expect_value stroking == 1+hold none+drag_path 0.6 0.5 0.7 0.5 0.8 0.5 0.9 0.5 keep+expect_value precision_active == 0+release+key ctrl+z+input_style zbrush+drag_path 0.25 0.5 0.35 0.5 keep+hold shift+alt+drag_path 0.35 0.5 0.6 0.5 keep+expect_value precision_active == 1+expect_value precision_lag > 40+hold none+release+key ctrl+z+input_style blender+drag_path 0.25 0.5 0.35 0.5 keep+hold shift+alt+drag_path 0.35 0.5 0.6 0.5 keep+expect_value precision_active == 1+expect_value precision_lag > 40+hold none+release+key ctrl+z+input_style maya+drag_path 0.25 0.5 0.35 0.5 keep+hold shift+alt+drag_path 0.35 0.5 0.6 0.5 keep+expect_value precision_active == 1+expect_value precision_lag > 40+hold none+release+key ctrl+z+input_style sculptforge++# --- A pressure curve per brush (Preferences > Tablet; Brush Lab shows the same). ---+expect_value brush_curves == 0+expect_value brush_curve_half == 50+click "Preferences##palette.preferences"+click "Tablet##preferences.tablet"+wait 0.3+shot prefs-brush-curve+click "Fine detail##brushcurve"+expect_value brush_curve_points == 4+expect_value brush_curve_half < 20+expect_status Pressure curve for+click "Preferences##palette.preferences"+# Another brush keeps its own (linear) curve; coming back brings Fine detail back.+click "Clay##brush.clay"+expect_value brush_curve_half == 50+expect_value brush_curves == 1+click "Standard##brush.standard"+expect_value brush_curve_half < 20diff --git a/tests/ui/precision_dense.sfui b/tests/ui/precision_dense.sfuinew file mode 100644index 00000000..c50daa1f--- /dev/null+++ b/tests/ui/precision_dense.sfui@@ -0,0 +1,112 @@+# Precision at extreme zoom on a dense mesh (the benchmark sphere, divided like a real sculpt): a tiny brush's dabs+# land exactly under the cursor (projected back to the screen, under 0.05 px, also on HiDPI where the window has 2+# framebuffer pixels per point) and the pick filter steadies their depth. tests/perf/precision_33m.sfui is the same+# on 33M triangles (run by hand: tools/precision_check.sh).+run new_bench_sphere millions=4+expect_value pixel_density >= 1+remember pixel_density density+camera 180 0+look 0 0 -0.97+camera_distance 0.06+wait 0.2+mouse_move 0.5 0.5+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+key [+expect_value draw_size_exact == 0.5+key shift+]+expect_value draw_size_exact == 1+# A 1 px brush across the back of the head.+snapshot+view_drag 0.45 0.5 0.55 0.52 1.0+# (A 1 px brush here is 0.03 mm: smaller than this mesh's edges, so it places dabs but moves no vertex; what is+# checked is where the dabs land.)+expect_value dabs > 20+remember dab_error_px err1+expect_value dab_error_px < 0.05+remember dab_jitter_raw jr+remember dab_jitter jf+expect_value dab_jitter <= $jr+key ctrl+z+# World Size at this zoom: a fraction of a millimetre.+mouse_move 0.5 0.5+wait 0.1+remember world_radius_mm mm+expect_value world_radius_mm < 0.5+# 0.5 px, diagonally, with Steady Stroke.+key shift+[+expect_value draw_size_exact == 0.5+key l+view_drag 0.42 0.45 0.58 0.56 1.0+expect_value dabs > 20+remember dab_error_px err2+expect_value dab_error_px < 0.05+key l+shot extreme_zoomdiff --git a/tools/precision_check.sh b/tools/precision_check.shnew file mode 100755index 00000000..e840ac77--- /dev/null+++ b/tools/precision_check.sh@@ -0,0 +1,13 @@+#!/usr/bin/env bash+# SculptForge - open source digital sculpting+# SPDX-License-Identifier: GPL-3.0-or-later+#+# Precision at extreme zoom on 33M triangles (tests/perf/precision_33m.sfui): too heavy for CI, run by hand before a+# release that touches brushes or the camera. On a HiDPI screen it also checks the 2x framebuffer.+# tools/precision_check.sh [BUILD_DIR]+set -euo pipefail+build=${1:-build}+here=$(cd "$(dirname "$0")/.." && pwd)+out=$(mktemp -d)+trap 'rm -rf "$out"' EXIT+nice -n 19 ionice -c3 "$build/sculptforge" --ui-test "$here/tests/perf/precision_33m.sfui" --ui-out "$out"