Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

Cursor plane fitted to the surface points (steady on steep fine bumps); left-drag scroll only on fixed panels, never a floating window or title bar

islandmed9af74e321e86
diff --git a/src/app/App.cpp b/src/app/App.cpp
index 6bdc2052..a75d1378 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -3253,7 +3253,7 @@ bool App::drawSurfaceCursor(ImDrawList* dl, float radiusPx, ImU32 col, bool ring
// The world radius a dab here gets (App::firstDab / the brushes: Draw Size times world size of a pixel).
const float radius = radiusPx * camera_.worldPerPixel(hit.position, canvasHeight());
if (!(radius > 0.0f) || !std::isfinite(radius)) return false;
- // A steady normal over the brush's area (16 rays), then the ring and the Focal Shift ring as true circles in
+ // A steady normal over the brush's area (32 rays), then the ring and the Focal Shift ring as true circles in
// that plane (#88): no per-point pressing, so bumps can't bend or break the ring. Never a pass over the mesh.
const glm::vec3 n = surfaceCursorNormal(doc_.mesh, doc_.bvh, hit, radius);
surfaceCursorCircle(hit.position, n, radius, 64, cursorRing_);
diff --git a/src/app/Ui.cpp b/src/app/Ui.cpp
index 85f91af3..edadb73d 100644
--- a/src/app/Ui.cpp
+++ b/src/app/Ui.cpp
@@ -440,7 +440,7 @@ void DragScrollPanels() {
}
return;
}
- // A press this frame: left only on empty space (nothing hovered or pressed), middle anywhere on the panel. The
+ // A press this frame: left only on empty space (nothing hovered or pressed) of a fixed panel, middle anywhere. The
// nearest window that scrolls, from the one under the pointer out through its parents (a tray's sections are
// child windows).
for (const ImGuiMouseButton b : {ImGuiMouseButton_Left, ImGuiMouseButton_Middle}) {
@@ -451,6 +451,11 @@ void DragScrollPanels() {
while (w && !(w->ScrollMax.y > 0.0f || w->ScrollMax.x > 0.0f) && (w->Flags & ImGuiWindowFlags_ChildWindow)) w = w->ParentWindow;
if (!w || !(w->ScrollMax.y > 0.0f || w->ScrollMax.x > 0.0f)) continue;
if (w->ScrollbarY && io.MousePos.x >= w->InnerRect.Max.x) continue; // on its scroll bar: ImGui's own
+ // A left-drag on a floating window (or its title bar) moves the window, as ever: only the fixed panels
+ // (trays, palettes, shelves) scroll with it. The middle button never moves windows, so it scrolls any.
+ if (b == ImGuiMouseButton_Left && (!(w->RootWindow->Flags & ImGuiWindowFlags_NoMove) ||
+ w->RootWindow->TitleBarRect().Contains(io.MousePos)))
+ continue;
g_dragScrollWindow = w->ID;
g_dragScrollButton = b;
g_dragScrollMoved = false;
diff --git a/src/core/SurfaceCursor.cpp b/src/core/SurfaceCursor.cpp
index 1bd96bb3..a385357a 100644
--- a/src/core/SurfaceCursor.cpp
+++ b/src/core/SurfaceCursor.cpp
@@ -53,20 +53,31 @@ glm::vec3 interpolatedNormal(const Mesh& mesh, const RayHit& hit) {
glm::vec3 surfaceCursorNormal(const Mesh& mesh, const BVH& bvh, const RayHit& hit, float radius, int samples) {
const glm::vec3 n0 = interpolatedNormal(mesh, hit);
if (!(radius > 0.0f) || samples <= 0) return n0;
- glm::vec3 u, v;
- tangentBasis(n0, u, v);
- glm::vec3 sum = n0 * 2.0f; // the centre counts double: the cursor sits there
- for (const float r : {radius * 0.5f, radius}) {
- for (int i = 0; i < samples; ++i) {
- const float a = 6.28318531f * (float(i) + (r < radius ? 0.0f : 0.5f)) / float(samples); // (staggered rings)
- const glm::vec3 p = hit.position + (u * std::cos(a) + v * std::sin(a)) * r;
- RayHit h;
- if (!pressOnto(mesh, bvh, p, n0, r, h)) continue;
- const glm::vec3 n = interpolatedNormal(mesh, h);
- if (glm::dot(n, n0) > 0.0f) sum += n;
+ // The plane through the surface points around the cursor (two rings, pressed onto the mesh along `axis`): the
+ // area vector of each ring's polygon about the centre (Newell). Its tilt comes from how high the points sit, so
+ // a bump tilts it by about its height over the brush radius, where averaging the points' normals would follow
+ // every steep little slope (#88).
+ auto fit = [&](const glm::vec3& axis) {
+ glm::vec3 u, v;
+ tangentBasis(axis, u, v);
+ glm::vec3 sum(0.0f);
+ glm::vec3 points[64];
+ for (const float r : {radius * 0.5f, radius}) {
+ int count = 0;
+ for (int i = 0; i < samples && count < 64; ++i) {
+ const float a = 6.28318531f * float(i) / float(samples);
+ RayHit h;
+ if (pressOnto(mesh, bvh, hit.position + (u * std::cos(a) + v * std::sin(a)) * r, axis, r, h))
+ points[count++] = h.position - hit.position;
+ }
+ if (count < 3) continue; // (over a hole or off an edge: too little to fit)
+ for (int i = 0; i < count; ++i) sum += glm::cross(points[i], points[(i + 1) % count]);
}
- }
- return safeNormalize(sum, n0);
+ return glm::dot(sum, axis) > 0.0f ? safeNormalize(sum, axis) : axis;
+ };
+ // Twice: the second fit samples the rings in the plane the first one found, square to the form.
+ const glm::vec3 n = fit(fit(n0));
+ return glm::dot(n, n0) > -0.2f ? n : n0;
}
void surfaceCursorCircle(const glm::vec3& center, const glm::vec3& normal, float radius, int count,
diff --git a/src/core/SurfaceCursor.h b/src/core/SurfaceCursor.h
index 96e02f69..e9742208 100644
--- a/src/core/SurfaceCursor.h
+++ b/src/core/SurfaceCursor.h
@@ -6,7 +6,7 @@
// made the ring wobble and break up on bumpy surfaces). The plane's normal is averaged over the brush's area, so
// it turns smoothly with the form and ignores fine detail.
//
-// Cost: under twenty BVH ray casts (each O(log n)) per cursor update, nothing that walks the whole mesh, so it stays
+// Cost: about thirty BVH ray casts (each O(log n)) per cursor update, nothing that walks the whole mesh, so it stays
// cheap at tens of millions of triangles. The app only calls it on frames it draws anyway (pointer moved, stroke,
// view change), so the idle view stays at 0 fps.
#pragma once
@@ -24,10 +24,10 @@ namespace sf {
// triangle's own normal on a coarse mesh); the triangle's normal if the mesh has no usable vertex normals.
glm::vec3 interpolatedNormal(const Mesh& mesh, const RayHit& hit);
-// A steady normal for the cursor at `hit`: the shading normal there averaged with the normals at `samples` points
-// on each of two rings (half the brush radius and the full radius) pressed onto the surface: an area normal, so the
-// ring doesn't wobble from triangle to triangle as the pointer moves over fine detail. Points facing away from the
-// centre's normal (the far side of a thin part) are left out.
+// A steady normal for the cursor at `hit`: the plane fitted through `samples` surface points on each of two rings
+// (half the brush radius and the full radius) around it, fitted twice, so the ring follows the form under the brush
+// and doesn't wobble from bump to bump as the pointer moves over fine detail. The shading normal there when too
+// few points land (over a hole, at an edge).
glm::vec3 surfaceCursorNormal(const Mesh& mesh, const BVH& bvh, const RayHit& hit, float radius, int samples = 8);
// `count` points of the circle of `radius` about `center` in the plane through it with `normal` (a true circle:
diff --git a/tests/test_surface_cursor.cpp b/tests/test_surface_cursor.cpp
index 9245f5b0..ca411722 100644
--- a/tests/test_surface_cursor.cpp
+++ b/tests/test_surface_cursor.cpp
@@ -90,7 +90,7 @@ TEST(surface_cursor_steady_on_bumps) {
}
TEST(surface_cursor_cost_is_rays_not_mesh_passes) {
- // A cursor update is 17 ray casts: on a 5M-triangle sphere it stays well under a millisecond (it walks the
+ // A cursor update is 33 ray casts: on a 5M-triangle sphere it stays well under a millisecond (it walks the
// BVH, never the mesh). Generous bound so slow CI machines and debug builds pass.
Mesh m = makeIcosphere(9, 1.0f);
BVH bvh;