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.

Radial and local symmetry, timeline at the top of the viewport (#63)

islandmedaff42785cbfd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 53b7bd75..eeb24065 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,14 @@ All notable changes to SculptForge are listed here. The format follows
## [0.10.5] - 2026-11-01
### Added
+- **Radial symmetry** (#63): **R** in Transform > Symmetry and on the top shelf repeats strokes around the X, Y or Z
+ axis (Radial Count 2-64), combined with the X / Y / Z mirrors (mirror + radial = 2N copies), and **Local**
+ symmetry about the active Part's centre. Applies to every brush and stroke, mask and smooth strokes, vertex paint
+ and texture painting, Mask / Select Rectangle and Lasso, Dynamic Topology (new topology on every copy) and Insert;
+ the brush cursor shows on every copy. Saved in projects; `radial`, `radial_axis` and `local` arguments on
+ `stroke`, `vdm_stamp`, `mask_rect`, `mask_lasso`, `hide_rect`, `hide_lasso`, `insert_primitive` and `insert_mesh`.
+- **Preferences > Interface > Timeline position** (#63): the Sculpt Timeline strip at the top of the viewport (the
+ new default, away from the brush shelf) or at the bottom; Store Config keeps it.
- **Preferences > Input > Start strokes off the model** (#62, off by default) and **Toggle strokes off the model**
(<kbd>Shift</kbd>+<kbd>L</kbd>): a left-drag that starts on the background begins a stroke, which touches the model
once the cursor reaches it (Lazy Stroke and the stroke path start there, so nothing jumps). Ctrl (mask) and Shift
diff --git a/docs/guide/glossary.md b/docs/guide/glossary.md
index 24969a5e..9c669f1c 100644
--- a/docs/guide/glossary.md
+++ b/docs/guide/glossary.md
@@ -36,7 +36,7 @@ for what is planned.
| LazyMouse | **Lazy Stroke** stroke type (Stroke palette) |
| LightBox | **Library**, <kbd>,</kbd> (comma) |
| Live Boolean | Not yet |
-| Local symmetry, radial symmetry | Not yet. Symmetry is X, Y and Z across the world axes |
+| 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) |
| Mask by Cavity | **Tool > Masking > By cavity** (`mask_by_cavity`) |
| Masking (Ctrl) | Hold <kbd>Ctrl</kbd> to paint the mask, <kbd>Ctrl</kbd>+<kbd>Alt</kbd> to erase. See [Masking](masking.md) |
| MaskLasso, MaskRect | **Tool > Masking**: pick the shape, then <kbd>Ctrl</kbd>+drag (add <kbd>Alt</kbd> to unmask). See [Masking](masking.md) |
diff --git a/docs/guide/scripting.md b/docs/guide/scripting.md
index 9636c2f9..8d3ee146 100644
--- a/docs/guide/scripting.md
+++ b/docs/guide/scripting.md
@@ -94,7 +94,7 @@ the ones you will use most:
| Geometry | `qremesh` | `target` (default 5000), `adaptive`, `keep_groups`, `detect_edges`, `use_polypaint`, `symmetry`, `keep_original` |
| Parts | `project_all` | `distance` (default 0.02), `mean`, `blur`, `geometry`, `polypaint`, `source` |
| Geometry | `mesh_info` | |
-| Sculpting | `stroke` | `points` (required), `brush`, `radius`, `strength`, `invert`, `symmetry` |
+| Sculpting | `stroke` | `points` (required), `brush`, `radius`, `strength`, `invert`, `symmetry`, `radial`, `radial_axis`, `local` |
| Brushes | `brush_set_alpha` | `name` (round, square, noise) or `path`, `invert` |
| Brushes | `brush_ai` | `prompt` (required), `provider`, `model`, `endpoint` |
| Brushes | `brush_install` | `path`, `code` or `json` |
diff --git a/docs/guide/sculpting.md b/docs/guide/sculpting.md
index 50cf74b4..8231a0f9 100644
--- a/docs/guide/sculpting.md
+++ b/docs/guide/sculpting.md
@@ -499,10 +499,37 @@ X and Z together give four-way symmetry.
Symmetry mirrors across the scene's axes through the origin. Models that are centred on the origin, such as
SculptForge's primitives and most character exports, mirror correctly. If a stroke lands in the wrong place on
-the other side, the model is off-centre.
+the other side, the model is off-centre: turn on **Local** (below).
-> **ZBrush:** this is ZBrush's world symmetry with the >X< axis on. Local symmetry, radial symmetry and
-> topological (poseable) symmetry are not available yet.
+### Radial symmetry
+
+Radial symmetry repeats every stroke around an axis, for wheels, flowers, columns, crowns and other round
+ornaments. Turn it on with **R** on the top shelf or in **Transform > Symmetry**, then set:
+
+- **Radial Count**: how many copies, evenly spaced around the axis (2 to 64; 8 to start with).
+- **X axis**, **Y axis** or **Z axis**: the axis the copies turn around (Y, up, by default).
+
+Radial symmetry works with the mirror axes: with **X** on as well, each copy is also mirrored, so 8 radial copies
+make 16. It applies wherever symmetry does: every brush and stroke type, mask and smooth strokes, vertex paint and
+texture painting, Mask Rectangle / Mask Lasso and Select Rectangle / Select Lasso, Dynamic Topology (new triangles
+appear on every copy) and Insert on the model. The brush cursor shows on every copy, so you can see where each
+one lands.
+
+### Local symmetry
+
+**Local** (next to **R** in **Transform > Symmetry**) puts the mirror planes and the radial axis through the
+middle of the active Part (the centre of its bounding box) instead of the world origin. Use it for a Part that
+isn't centred on the origin, such as a button on a jacket or a wheel on a car. The centre follows the Part: it is
+worked out again when you switch Parts or after an edit.
+
+**R** and **Local** have no default key; you can assign one (see [The interface](interface.md)). Projects save
+the symmetry settings, radial and local included. Scripts and `sculptforge-cli` use the same settings: commands
+that take `symmetry` (`stroke`, `vdm_stamp`, `mask_rect`, `mask_lasso`, `hide_rect`, `hide_lasso`,
+`insert_primitive`, `insert_mesh`) also take `radial` (the count), `radial_axis` (`x`, `y` or `z`) and `local`
+(`true` for the Part's centre), for example `stroke points=... symmetry=x radial=8 radial_axis=y`.
+
+> **ZBrush:** **R** is ZBrush's (R) radial symmetry with Radial Count, and **Local** is its Local Symmetry (about
+> the Part's centre). Topological (poseable) symmetry is not available yet.
## Pen pressure and tablets
diff --git a/docs/guide/timeline.md b/docs/guide/timeline.md
index bfd94562..0acfa8a1 100644
--- a/docs/guide/timeline.md
+++ b/docs/guide/timeline.md
@@ -1,12 +1,12 @@
# Sculpt Timeline and timelapse
-Every stroke and operation you make is a step on the **Sculpt Timeline**, the strip along the bottom of the
-canvas. Drag its scrubber to see the model at any point of the session, click a step to go back there, and keep
+Every stroke and operation you make is a step on the **Sculpt Timeline**, the strip along the top of the
+canvas (or its bottom: **Preferences > Interface > Timeline position**). Drag its scrubber to see the model at any point of the session, click a step to go back there, and keep
sculpting from it: the steps you had made after it are not thrown away as with a plain undo, they stay as a
branch you can switch back to. You can change how strongly a past stroke shows without redoing the strokes
after it, and render the whole history as a turntable timelapse video.
-![The Sculpt Timeline under the canvas: three strokes on the active branch, the scrubber at the last one, and the lane of an earlier continuation above the track](images/timeline-strip.jpg)
+![The Sculpt Timeline strip (here at the bottom of the canvas): three strokes on the active branch, the scrubber at the last one, and the lane of an earlier continuation above the track](images/timeline-strip.jpg)
## The strip
diff --git a/docs/guide/whats-new.md b/docs/guide/whats-new.md
index 7aaca7be..1fbc9d02 100644
--- a/docs/guide/whats-new.md
+++ b/docs/guide/whats-new.md
@@ -33,6 +33,14 @@ chapter opens by itself the first time you start a new version; you can always f
- **Start strokes off the model** (#62): an option in **Preferences > Input**, off by default, and
<kbd>Shift</kbd>+<kbd>L</kbd> to turn it on and off. With it on, a left-drag that starts on the background
sculpts once it reaches the model instead of turning the view. See [Navigation](navigation.md#mouse-and-pen).
+- **Radial and local symmetry** (#63): **R** in **Transform > Symmetry** (and on the top shelf) repeats every
+ stroke around the X, Y or Z axis, 2 to 64 times (**Radial Count**), together with the X / Y / Z mirrors. Every
+ brush, mask, vertex paint and texture stroke, the mask and select shapes, Dynamic Topology and Insert follow it,
+ and the brush cursor shows on every copy. **Local** puts the planes and the axis through the active Part's centre.
+ Saved with the project and scriptable (`radial`, `radial_axis`, `local`). See [Sculpting](sculpting.md#radial-symmetry).
+- **The Sculpt Timeline is at the top of the viewport** (#63), away from the brushes on the bottom shelf. **Preferences >
+ Interface > Timeline position** puts it back at the bottom; Store Config keeps the choice. See
+ [Sculpt Timeline](timeline.md).
## Version 0.10.4
diff --git a/src/app/App.cpp b/src/app/App.cpp
index 735d1566..be37a8dc 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -1385,13 +1385,13 @@ void App::onMouseUp() {
const float px = std::max(insertPx_, 12.0f * uiScale_);
const float dist = glm::length(camera_.position() - insertAt_);
const float worldPerPx = 2.0f * dist * std::tan(camera_.fovY * 0.5f) / std::max(canvasRect().h, 1.0f);
- const std::string symmetry = std::string(symmetry_.x ? "x" : "") + (symmetry_.y ? "y" : "") + (symmetry_.z ? "z" : "");
- Args args{{"symmetry", symmetry}, {"x", double(insertAt_.x)}, {"y", double(insertAt_.y)},
+ Args args{{"x", double(insertAt_.x)}, {"y", double(insertAt_.y)},
{"z", double(insertAt_.z)}, {"nx", double(insertNormal_.x)},
{"ny", double(insertNormal_.y)}, {"nz", double(insertNormal_.z)},
{"size", double(2.0f * px * worldPerPx)},
// the drag's direction on screen turns it about the normal
{"twist", insertPx_ > 4.0f ? double(glm::degrees(std::atan2(mouseY_ - insertY_, mouseX_ - insertX_))) : 0.0}};
+ args = withSymmetryArgs(std::move(args));
if (insertType_ == "mesh") { // your own mesh: a SubTool's copy or a file (insert_mesh)
args[insertMeshKey_] = insertMeshValue_;
runCommand("insert_mesh", args);
@@ -1451,6 +1451,7 @@ void App::onKey(SDL_Keycode key, SDL_Keymod mod) {
// ---------------------------------------------------------------------------
void App::beginStroke(float x, float y, const RayHit& hit) {
+ refreshSymmetryPivot(); // (local symmetry: the active Part's centre as the stroke starts)
strokeBrush_ = activeBrush();
straight_ = {};
straight_.shiftAtStart = (inputMods() & SDL_KMOD_SHIFT) != 0;
@@ -3006,12 +3007,14 @@ bool App::drawSurfaceCursor(ImDrawList* dl, float radiusPx, ImU32 col) {
};
const ImU32 inner = IM_COL32(255, 255, 255, 90);
// Closed polyline through the points facing the camera; a point on the far side of a curve breaks the line.
- auto drawRing = [&](const std::vector<SurfaceRingPoint>& ring, const glm::vec3& m, ImU32 colour, float width) {
+ auto drawRing = [&](const std::vector<SurfaceRingPoint>& ring, const SymCopy& m, ImU32 colour, float width) {
const size_t count = std::min<size_t>(ring.size(), 64);
ImVec2 sp[64];
bool ok[64];
- for (size_t i = 0; i < count; ++i)
- ok[i] = facing(ring[i].position * m, ring[i].normal * m) && gizmoProject(ring[i].position * m, sp[i]);
+ for (size_t i = 0; i < count; ++i) {
+ const glm::vec3 q = m.point(ring[i].position);
+ ok[i] = facing(q, m.dir(ring[i].normal)) && gizmoProject(q, sp[i]);
+ }
for (size_t i = 0; i < count; ++i) {
const size_t j = (i + 1) % count;
if (ok[i] && ok[j]) dl->AddLine(sp[i], sp[j], colour, width);
@@ -3021,14 +3024,18 @@ bool App::drawSurfaceCursor(ImDrawList* dl, float radiusPx, ImU32 col) {
const ImU32 a = ImU32(float((colour >> IM_COL32_A_SHIFT) & 0xFF) * k);
return (colour & ~IM_COL32_A_MASK) | (a << IM_COL32_A_SHIFT);
};
- // The mirrored rings first (fainter), as the brush mirrors its dabs (Sculptor::mirrors; the first is this one).
- const std::vector<glm::vec3> mirrors = Sculptor::mirrors(symmetry_);
+ // The mirrored and radial rings first (fainter), as the brush copies its dabs (Sculptor::copies; the first is
+ // this one): every copy's cursor shows.
+ refreshSymmetryPivot();
+ const std::vector<SymCopy> mirrors = Sculptor::copies(symmetry_);
+ symmetryCopiesDrawn_ = 0;
for (size_t k = mirrors.size(); k-- > 0;) {
- const glm::vec3& m = mirrors[k];
+ const SymCopy& m = mirrors[k];
const bool self = k == 0;
- // A mirror that lands on the cursor's own ring (hovering on the plane) adds nothing.
- if (!self && glm::length(hit.position * m - hit.position) < radius * 0.05f) continue;
- if (!self && !facing(hit.position * m, n * m)) continue;
+ // A copy that lands on the cursor's own ring (hovering on the plane or the axis) adds nothing.
+ if (!self && glm::length(m.point(hit.position) - hit.position) < radius * 0.05f) continue;
+ if (!self && !facing(m.point(hit.position), m.dir(n))) continue;
+ ++symmetryCopiesDrawn_;
drawRing(cursorRing_, m, self ? col : fade(col, 0.45f), self ? 2.0f : 1.25f);
drawRing(cursorInner_, m, self ? inner : fade(inner, 0.6f), 1.0f);
}
@@ -3042,10 +3049,11 @@ bool App::drawSurfaceCursor(ImDrawList* dl, float radiusPx, ImU32 col) {
}
std::array<AxisGizmoEnd, 6> App::axisGizmoLayout() const {
- // Top left of the canvas: the timeline strip is at the bottom.
+ // Top left of the canvas, below the timeline strip when that is at the top (timelineTopInset_).
const CanvasRect canvas = canvasRect();
const float s = 34.0f * uiScale_;
- return axisGizmoEnds(glm::mat3(camera_.view()), glm::vec2(canvas.x + s + 18.0f * uiScale_, canvas.y + s + 18.0f * uiScale_), s);
+ return axisGizmoEnds(glm::mat3(camera_.view()),
+ glm::vec2(canvas.x + s + 18.0f * uiScale_, canvas.y + timelineTopInset_ + s + 18.0f * uiScale_), s);
}
bool App::axisGizmoMouseDown(float x, float y) {
diff --git a/src/app/App.h b/src/app/App.h
index cd7419df..edac01cf 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -229,6 +229,14 @@ private:
float radiusPx_ = 60.0f;
float strength_ = 0.5f;
Symmetry symmetry_;
+ // Local symmetry's centre (symmetry_.pivot) follows the active Part: worked out again, outside strokes, when
+ // the Part, its vertex count or the undo history changed (refreshSymmetryPivot, PanelMasking.cpp).
+ uint64_t symmetryPivotKey_ = ~uint64_t(0);
+ void refreshSymmetryPivot();
+ // The symmetry arguments of the commands that follow the brushes' symmetry (symmetry, radial, radial_axis,
+ // local), added to `args`.
+ Args withSymmetryArgs(Args args);
+ int symmetryCopiesDrawn_ = 0; // brush cursors the last drawSurfaceCursor drew (UI tests: cursor_copies)
bool invertToggle_ = false;
bool frontFacesOnly_ = false;
bool pressureStrength_ = true;
@@ -1112,6 +1120,7 @@ private:
void drawPalette_Stroke();
void drawPalette_Tool();
void drawPalette_Transform();
+ void drawRadialSymmetryControls(); // Transform > Symmetry: radial symmetry's toggle, count and axis (Palettes.cpp)
void drawAlphaSection();
void drawLayersContents();
// Paint Layers sub-palette (PanelPaintLayers.cpp).
@@ -1572,6 +1581,8 @@ private:
std::shared_ptr<struct TimelineUiState> timelineUi_;
std::shared_ptr<struct ProofState> proof_;
void drawTimelineUi(); // once a frame from drawUi: keeps the timeline attached and draws the strip
+ float timelineTopInset_ = 0.0f; // how far down the canvas the strip (or its tab) reaches at the top; 0 at the bottom
+ float timelineStripY_ = -1.0f; // the strip's (or tab's) top edge in window pixels this frame (-1: not shown)
void registerTimelineUiActions(); // view.timeline, timeline.timelapse, help.benchmark
void startTimelapse(const std::string& path, int width, int height, float seconds, int fps);
bool timelapseStep(double budgetSeconds); // renders frames for up to the budget; false when finished
diff --git a/src/app/AsyncStroke.cpp b/src/app/AsyncStroke.cpp
index 93f4f73d..27bbeaf8 100644
--- a/src/app/AsyncStroke.cpp
+++ b/src/app/AsyncStroke.cpp
@@ -420,7 +420,8 @@ void App::buildGhost() {
const CanvasRect c = canvasRect();
const glm::vec3 n0 = glm::normalize(ghostFrame_.normal);
const float depth = glm::dot(ghostFrame_.center - ghostFrame_.areaCenter, n0); // area centre below the surface
- const std::vector<glm::vec3> mirrors = Sculptor::mirrors(symmetry_);
+ std::vector<SymCopy> mirrors = Sculptor::copies(symmetry_);
+ if (mirrors.size() > GhostStroke::kMaxMirrors) mirrors.resize(GhostStroke::kMaxMirrors); // (the shader's groups)
const size_t perMirror = GhostStroke::kMaxDabs / std::max<size_t>(1, mirrors.size());
std::vector<GhostDab> base;
for (const Screen& sd : pending) {
@@ -440,9 +441,9 @@ void App::buildGhost() {
for (uint32_t m = 0; m < mirrors.size(); ++m)
for (const GhostDab& b : base) {
GhostDab d = b;
- d.center *= mirrors[m];
- d.normal *= mirrors[m];
- d.areaCenter *= mirrors[m];
+ d.center = mirrors[m].point(b.center);
+ d.normal = mirrors[m].dir(b.normal);
+ d.areaCenter = mirrors[m].point(b.areaCenter);
d.mirror = m;
g.dabs.push_back(d);
}
diff --git a/src/app/Config.cpp b/src/app/Config.cpp
index 870b21cd..d5b5c651 100644
--- a/src/app/Config.cpp
+++ b/src/app/Config.cpp
@@ -56,6 +56,7 @@ Json toJson(const UiPrefs& p) {
j.set("spaceCamera", p.spaceCamera);
j.set("airStrokes", p.airStrokes);
j.set("cursorFollowsSurface", p.cursorFollowsSurface);
+ j.set("timelinePosition", std::string(p.timelineTop ? "top" : "bottom"));
j.set("showAxes", p.showAxes);
j.set("alphabeticalPalettes", p.alphabeticalPalettes);
j.set("language", p.language);
@@ -98,6 +99,7 @@ void fromJson(const Json& j, UiPrefs& p) {
p.spaceCamera = j["spaceCamera"].asBool(p.spaceCamera);
p.airStrokes = j["airStrokes"].asBool(p.airStrokes);
p.cursorFollowsSurface = j["cursorFollowsSurface"].asBool(p.cursorFollowsSurface);
+ if (j["timelinePosition"].isString()) p.timelineTop = j["timelinePosition"].asString() != "bottom";
p.showAxes = j["showAxes"].asBool(p.showAxes);
p.alphabeticalPalettes = j["alphabeticalPalettes"].asBool(p.alphabeticalPalettes);
if (j["language"].isString()) p.language = languageCode(languageFromCode(j["language"].asString()));
@@ -1088,6 +1090,9 @@ void drawInterfaceSection(App& app) {
ui::HelpText("Shelf tiles", nullptr, "How big the brush tiles on the bottom shelf are. Small leaves the most room for the model.",
"Preferences > Interface");
}
+ // Timeline position (#63): the Sculpt Timeline strip at the top of the viewport (the default) or the bottom.
+ ImGui::TextDisabled("%s", tr("Timeline position"));
+ ui::Segmented(app, {"view.timeline_top", "view.timeline_bottom"});
static const char* kScales[] = {"Automatic", "100%", "125%", "150%", "175%", "200%"};
static const float kScaleValues[] = {0.0f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f};
int current = 0;
diff --git a/src/app/Config.h b/src/app/Config.h
index 352a95bd..8441ce2e 100644
--- a/src/app/Config.h
+++ b/src/app/Config.h
@@ -43,6 +43,9 @@ struct UiPrefs {
// reaches the surface instead of turning the view (off: it turns the view, ZBrush)
bool showAxes = true; // Draw > Camera > Axes: the X / Y / Z gizmo in the canvas corner (#31)
bool cursorFollowsSurface = true; // the brush ring lies on the surface under the pointer, as in SculptGL (#25)
+ // Preferences > Interface > Timeline position (#63): the Sculpt Timeline strip along the top of the viewport
+ // (true, the default: clear of the brush shelf below it) or its bottom.
+ bool timelineTop = true;
TabletSettings tablet; // Preferences > Tablet: pressure curve, eraser, pen buttons
SpaceMouseSettings spaceMouse; // Preferences > Input > SpaceMouse
// Preferences > Performance (PanelPerformance.cpp).
diff --git a/src/app/I18nSpanish.cpp b/src/app/I18nSpanish.cpp
index c045c7f4..01123aa5 100644
--- a/src/app/I18nSpanish.cpp
+++ b/src/app/I18nSpanish.cpp
@@ -192,6 +192,13 @@ constexpr Entry kSpanish[] = {
{"Smooth keeps volume", "Smooth conserva el volumen"},
{"Symmetry", "Simetría"},
{"Symmetry X", "Simetría X"},
+ {"Local", "Local"},
+ {"X axis", "Eje X"},
+ {"Y axis", "Eje Y"},
+ {"Z axis", "Eje Z"},
+ {"Radial Count %d", "Copias radiales %d"},
+ {"Timeline position", "Posición de la línea de tiempo"},
+ {"Top of viewport", "Arriba del visor"},
{"How strongly painting colours the surface (1-100); Ctrl+click to type.",
"Con qué fuerza colorea la pintura la superficie (1-100); Ctrl+clic para escribirlo."},
{"This Part has subdivision levels, so strokes don't remesh it: delete the lower (or higher) levels first.",
diff --git a/src/app/Input.cpp b/src/app/Input.cpp
index 385619cb..3929ea0e 100644
--- a/src/app/Input.cpp
+++ b/src/app/Input.cpp
@@ -679,7 +679,7 @@ void App::drawAirStrokeIndicator() {
const char* text = tr("Strokes start off the model");
const ImVec2 size = ImGui::CalcTextSize(text);
const float pad = 6.0f * uiScale_;
- const ImVec2 at(c.x + (c.w - size.x) * 0.5f, c.y + 10.0f * uiScale_);
+ const ImVec2 at(c.x + (c.w - size.x) * 0.5f, c.y + timelineTopInset_ + 10.0f * uiScale_); // (below a top timeline)
ImDrawList* dl = ImGui::GetForegroundDrawList();
dl->AddRectFilled(ImVec2(at.x - pad, at.y - pad * 0.5f), ImVec2(at.x + size.x + pad, at.y + size.y + pad * 0.5f),
IM_COL32(0, 0, 0, 110), 4.0f * uiScale_);
diff --git a/src/app/Palettes.cpp b/src/app/Palettes.cpp
index d9d9ff3a..9ad74609 100644
--- a/src/app/Palettes.cpp
+++ b/src/app/Palettes.cpp
@@ -694,12 +694,27 @@ void App::drawPalette_Tool() {
}
}
+// Radial symmetry (#63): the toggle with Local, then the count and the axis.
+void App::drawRadialSymmetryControls() {
+ segmented(*this, {"transform.symmetry_radial", "transform.symmetry_local"});
+ ImGui::BeginDisabled(!symmetry_.radialEnabled);
+ ImGui::SetNextItemWidth(-FLT_MIN);
+ tray::SliderInt("##radialcount", &symmetry_.radial, 2, Symmetry::kMaxRadial, tr("Radial Count %d"));
+ ui::HelpText("Radial Count", nullptr,
+ "How many copies radial symmetry makes of every stroke, turned evenly around the axis (2 to 64). With "
+ "X, Y or Z on too, each mirror image gets its copies.",
+ "Transform > Symmetry");
+ segmented(*this, {"transform.radial_axis_x", "transform.radial_axis_y", "transform.radial_axis_z"});
+ ImGui::EndDisabled();
+}
+
void App::drawPalette_Transform() {
const tray::Style style; // quiet check marks
ImGui::TextDisabled("%s", tr("Gizmo"));
drawGizmoContents(false);
ImGui::TextDisabled("%s", tr("Symmetry"));
segmented(*this, {"transform.symmetry_x", "transform.symmetry_y", "transform.symmetry_z"});
+ drawRadialSymmetryControls();
actionRow(*this, {"view.frame", "subtool.solo"});
actionRow(*this, {"view.polyf"});
}
diff --git a/src/app/PanelFace.cpp b/src/app/PanelFace.cpp
index 50ab67c1..a1bcd1db 100644
--- a/src/app/PanelFace.cpp
+++ b/src/app/PanelFace.cpp
@@ -275,7 +275,7 @@ void App::drawFaceOverlay() {
"your left from the front)",
facePlaceIndex_ + 1, faceLandmarkLabel(facePlaceIndex_));
const ImVec2 size = ImGui::CalcTextSize(banner);
- const ImVec2 at(cr.x + (cr.w - size.x) * 0.5f, cr.y + 12.0f * s);
+ const ImVec2 at(cr.x + (cr.w - size.x) * 0.5f, cr.y + timelineTopInset_ + 12.0f * s);
dl->AddRectFilled(ImVec2(at.x - 8 * s, at.y - 4 * s), ImVec2(at.x + size.x + 8 * s, at.y + size.y + 4 * s),
IM_COL32(20, 20, 24, 210), 4.0f * s);
dl->AddText(at, IM_COL32(255, 196, 64, 255), banner);
diff --git a/src/app/PanelMasking.cpp b/src/app/PanelMasking.cpp
index 43b3417d..31f79612 100644
--- a/src/app/PanelMasking.cpp
+++ b/src/app/PanelMasking.cpp
@@ -33,7 +33,29 @@ std::string symmetryAxes(const Symmetry& s) { return std::string(s.x ? "x" : "")
} // namespace
+void App::refreshSymmetryPivot() {
+ if (!symmetry_.local) return;
+ if (doc_.sculptor.strokeActive() || solverBusy()) return; // (the centre holds still during a stroke)
+ const uint64_t key = doc_.undo.revision() * 0x9E3779B97F4A7C15ull ^ (uint64_t(doc_.activeSubtool) << 40) ^
+ uint64_t(doc_.mesh.vertexCount()) ^ (uint64_t(doc_.subtools.size()) << 56);
+ if (key == symmetryPivotKey_) return;
+ symmetryPivotKey_ = key;
+ symmetry_.pivot = symmetryPivot(doc_.mesh);
+}
+
+Args App::withSymmetryArgs(Args args) {
+ refreshSymmetryPivot();
+ args["symmetry"] = symmetryAxes(symmetry_);
+ if (symmetry_.radialOn()) {
+ args["radial"] = double(symmetry_.radial);
+ args["radial_axis"] = std::string(1, char('x' + symmetry_.radialAxis));
+ }
+ if (symmetry_.local) args["local"] = true;
+ return args;
+}
+
void App::beginMaskStroke(float x, float y) {
+ refreshSymmetryPivot();
// Masks are not layered, so the stroke always targets the base (its weight is never 0).
// Ctrl+Alt erases, and so does the pen's eraser end (set to Invert or Erase mask).
strokeInvert_ = (inputMods() & SDL_KMOD_ALT) != 0 ||
@@ -111,8 +133,7 @@ void App::maskSelectMouseUp() {
// Mask the inside, or unmask it with Alt (Mask Strength sets how much), mirrored by the symmetry like a mask
// stroke (#51). A shape that covers none of the model clears the mask instead (ZBrush).
runSelection("mask_rect", "mask_lasso",
- {{"unmask", alt}, {"strength", double(maskStrength_)}, {"symmetry", symmetryAxes(symmetry_)},
- {"clear_outside", !alt}});
+ withSymmetryArgs({{"unmask", alt}, {"strength", double(maskStrength_)}, {"clear_outside", !alt}}));
}
App::HeldBrush App::heldBrush() const {
diff --git a/src/app/PanelPbr.cpp b/src/app/PanelPbr.cpp
index c9358c61..f4a0aed7 100644
--- a/src/app/PanelPbr.cpp
+++ b/src/app/PanelPbr.cpp
@@ -356,7 +356,7 @@ void App::prewarmTexturePaint() {
prewarmCenter_ = hit.position;
prewarmRadius_ = r;
std::vector<glm::vec3> centers;
- for (const glm::vec3& mirror : Sculptor::mirrors(symmetry_)) centers.push_back(hit.position * mirror);
+ for (const SymCopy& mirror : Sculptor::copies(symmetry_)) centers.push_back(mirror.point(hit.position));
prewarmTexturePainting(m, &doc_.bvh, centers, r * 1.25f); // a little wider: the pen moves before it lands
}
diff --git a/src/app/PanelPolygroups.cpp b/src/app/PanelPolygroups.cpp
index 42d552b5..b1f4ce80 100644
--- a/src/app/PanelPolygroups.cpp
+++ b/src/app/PanelPolygroups.cpp
@@ -50,8 +50,7 @@ void App::polygroupMouseUp() {
// Drag: keep the inside of the rectangle or lasso, or with Alt hide it. A shape around nothing (dragged on
// the background) reverses the visibility instead (ZBrush).
// The mirror image of the shape counts too with X / Y / Z symmetry on, as with MaskLasso / MaskRect (#51).
- const std::string symmetry = std::string(symmetry_.x ? "x" : "") + (symmetry_.y ? "y" : "") + (symmetry_.z ? "z" : "");
- if (runSelection("hide_rect", "hide_lasso", {{"inside", alt}, {"symmetry", symmetry}}) && !lastCommandOk_ && !alt &&
+ if (runSelection("hide_rect", "hide_lasso", withSymmetryArgs({{"inside", alt}})) && !lastCommandOk_ && !alt &&
doc_.mesh.hasHidden())
runCommand("invert_visibility");
}
diff --git a/src/app/PanelProject.cpp b/src/app/PanelProject.cpp
index 85773314..0a89b486 100644
--- a/src/app/PanelProject.cpp
+++ b/src/app/PanelProject.cpp
@@ -300,6 +300,10 @@ void App::storeProjectSettings() {
sym.set("x", symmetry_.x);
sym.set("y", symmetry_.y);
sym.set("z", symmetry_.z);
+ sym.set("radial", symmetry_.radialEnabled); // radial symmetry (#63): on, its count and axis
+ sym.set("radial_count", double(symmetry_.radial));
+ sym.set("radial_axis", double(symmetry_.radialAxis));
+ sym.set("local", symmetry_.local); // around the active Part's centre
s.set("symmetry", std::move(sym));
Json gizmo = Json::object(); // Gizmo 3D (Gizmo.cpp): where the pivot is and the options
@@ -395,6 +399,16 @@ void App::applyProjectSettings() {
readBool(sym, "x", symmetry_.x);
readBool(sym, "y", symmetry_.y);
readBool(sym, "z", symmetry_.z);
+ symmetry_.radialEnabled = false; // (older projects have none)
+ symmetry_.local = false;
+ readBool(sym, "radial", symmetry_.radialEnabled);
+ readBool(sym, "local", symmetry_.local);
+ float count = float(symmetry_.radial), axis = float(symmetry_.radialAxis);
+ readFloat(sym, "radial_count", count);
+ readFloat(sym, "radial_axis", axis);
+ symmetry_.radial = std::clamp(int(std::lround(count)), 2, Symmetry::kMaxRadial);
+ symmetry_.radialAxis = std::clamp(int(std::lround(axis)), 0, 2);
+ symmetryPivotKey_ = ~uint64_t(0);
}
if (const Json& g = s["gizmo"]; g.isObject()) {
gizmo_.centreKey = ~uint64_t(0);
@@ -623,7 +637,8 @@ void App::drawUpdateBanner() {
if (!updateAvailable_) return;
const UpdateInfo& u = *updateAvailable_;
const CanvasRect c = canvasRect(); // top centre of the 3D view, clear of the shelves
- ImGui::SetNextWindowPos(ImVec2(c.x + c.w * 0.5f, c.y + 12.0f * uiScale_), ImGuiCond_Always, ImVec2(0.5f, 0.0f));
+ ImGui::SetNextWindowPos(ImVec2(c.x + c.w * 0.5f, c.y + timelineTopInset_ + 12.0f * uiScale_), ImGuiCond_Always,
+ ImVec2(0.5f, 0.0f)); // (below the timeline strip when it is at the top)
ImGui::SetNextWindowBgAlpha(0.96f);
const ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing |
diff --git a/src/app/PanelTimeline.cpp b/src/app/PanelTimeline.cpp
index 2fe7c5d9..71a174af 100644
--- a/src/app/PanelTimeline.cpp
+++ b/src/app/PanelTimeline.cpp
@@ -1,8 +1,8 @@
// SculptForge - open source digital sculpting
// SPDX-License-Identifier: GPL-3.0-or-later
//
-// The Sculpt Timeline strip (docs/guide/timeline.md): every step of the history as a tick along the bottom of the
-// canvas. Drag the scrubber to see the model at any point, click a tick to go there; sculpting from an earlier
+// The Sculpt Timeline strip (docs/guide/timeline.md): every step of the history as a tick along the top (the
+// default) or the bottom of the canvas. Drag the scrubber to see the model at any point, click a tick to go there; sculpting from an earlier
// point starts a branch and the old continuation stays as a lane above the track (click it to switch back).
// Right-click a stroke to re-tune its strength. Timelapse renders the history as a turntable video. The data
// side is core/Timeline.h; Help > Benchmark (proof mode) is in ProofMode.cpp.
@@ -157,7 +157,8 @@ void App::registerTimelineUiActions() {
Timeline::saveWithProject = ui().saveHistory;
}
add("view.timeline", "Sculpt Timeline", ICON_LC_HISTORY, "Edit",
- "Show or hide the history strip along the bottom of the canvas: every stroke and operation as a tick. Drag "
+ "Show or hide the history strip along the top or bottom of the canvas (Preferences > Interface > Timeline "
+ "position): every stroke and operation as a tick. Drag "
"to see the model at any point, click to go there; sculpting from an earlier point keeps the old "
"continuation as a branch. Right-click a stroke to change its strength.",
[this, ui] {
@@ -165,6 +166,14 @@ void App::registerTimelineUiActions() {
savePrefs(ui(), configDir_, uiConfigDeterministic_);
},
[ui] { return ui().visible; });
+ add("view.timeline_top", "Top of viewport", nullptr, "Preferences > Interface",
+ "Timeline position: the Sculpt Timeline strip runs along the top of the viewport, below the top shelf and away "
+ "from the brushes on the bottom shelf (the default). Store Config keeps it.",
+ [this] { uiPrefs_.timelineTop = true; }, [this] { return uiPrefs_.timelineTop; });
+ add("view.timeline_bottom", "Bottom", nullptr, "Preferences > Interface",
+ "Timeline position: the Sculpt Timeline strip runs along the bottom of the viewport, above the brush shelf. "
+ "Store Config keeps it.",
+ [this] { uiPrefs_.timelineTop = false; }, [this] { return !uiPrefs_.timelineTop; });
add("timeline.timelapse", "Export timelapse...", ICON_LC_FILM, "Edit",
"Render the history of the active Part as a turntable timelapse video (1080p or 4K MP4, no captions).",
[ui] { ui().timelapseDialog = true; });
@@ -364,13 +373,19 @@ void App::drawTimelineUi() {
ImGui::EndPopup();
}
- // The strip: along the bottom of the canvas.
+ // The strip: along the bottom of the canvas, or its top (Preferences > Interface > Timeline position, #63:
+ // away from the brush shelf). At the top it sits below the top shelf (the canvas starts there) and what else
+ // the canvas shows at its top (the axis gizmo, the update banner) moves down below it (timelineTopInset_).
const CanvasRect c = canvasRect();
const float sc = uiScale_;
+ const bool top = uiPrefs_.timelineTop;
+ timelineTopInset_ = 0.0f;
+ timelineStripY_ = -1.0f;
if (c.w < 200 || c.h < 150 || hideUi_) return;
const float margin = 10 * sc;
if (!s.visible) {
- ImGui::SetNextWindowPos(ImVec2(c.x + c.w * 0.5f, c.y + c.h - 4 * sc), ImGuiCond_Always, ImVec2(0.5f, 1.0f));
+ if (top) ImGui::SetNextWindowPos(ImVec2(c.x + c.w * 0.5f, c.y + 4 * sc), ImGuiCond_Always, ImVec2(0.5f, 0.0f));
+ else ImGui::SetNextWindowPos(ImVec2(c.x + c.w * 0.5f, c.y + c.h - 4 * sc), ImGuiCond_Always, ImVec2(0.5f, 1.0f));
ImGui::SetNextWindowBgAlpha(0.85f);
if (ImGui::Begin("##timeline_tab", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing |
@@ -382,6 +397,8 @@ void App::drawTimelineUi() {
savePrefs(s, configDir_, uiConfigDeterministic_);
}
ui::HelpText("Sculpt Timeline", nullptr, "Open the history strip.", "Edit");
+ timelineStripY_ = ImGui::GetWindowPos().y;
+ if (top) timelineTopInset_ = ImGui::GetWindowPos().y + ImGui::GetWindowSize().y - c.y;
}
ImGui::End();
return;
@@ -390,7 +407,10 @@ void App::drawTimelineUi() {
const int lanes = std::min<int>(3, int(branches.size()));
const float laneH = 7 * sc, trackH = 26 * sc;
const float height = 30 * sc + trackH + float(lanes) * (laneH + 3 * sc);
- ImGui::SetNextWindowPos(ImVec2(c.x + margin, c.y + c.h - margin - height), ImGuiCond_Always);
+ const float stripY = top ? c.y + margin : c.y + c.h - margin - height;
+ ImGui::SetNextWindowPos(ImVec2(c.x + margin, stripY), ImGuiCond_Always);
+ timelineStripY_ = stripY;
+ if (top) timelineTopInset_ = margin + height;
ImGui::SetNextWindowSize(ImVec2(c.w - 2 * margin, height), ImGuiCond_Always);
ImGui::SetNextWindowBgAlpha(0.88f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8 * sc, 5 * sc));
@@ -435,7 +455,7 @@ void App::drawTimelineUi() {
if (ImGui::SmallButton(ICON_LC_FILM)) s.timelapseDialog = true;
ui::HelpText("Export timelapse", nullptr, "Render this history as a turntable timelapse video.", "Edit > Sculpt Timeline");
ImGui::SameLine();
- if (ImGui::SmallButton(ICON_LC_CHEVRON_DOWN)) {
+ if (ImGui::SmallButton(top ? ICON_LC_CHEVRON_UP : ICON_LC_CHEVRON_DOWN)) {
s.visible = false;
savePrefs(s, configDir_, uiConfigDeterministic_);
}
diff --git a/src/app/Shell.cpp b/src/app/Shell.cpp
index 71443799..72b7eef0 100644
--- a/src/app/Shell.cpp
+++ b/src/app/Shell.cpp
@@ -396,6 +396,21 @@ void App::registerShellActions() {
flag("transform.symmetry_x", "X", nullptr, "Transform", "X", &symmetry_.x, "Mirror strokes across X (left and right).");
flag("transform.symmetry_y", "Y", nullptr, "Transform", "", &symmetry_.y, "Mirror strokes across Y (top and bottom).");
flag("transform.symmetry_z", "Z", nullptr, "Transform", "", &symmetry_.z, "Mirror strokes across Z (front and back).");
+ flag("transform.symmetry_radial", "R", nullptr, "Transform", "", &symmetry_.radialEnabled,
+ "Radial symmetry: repeat strokes around an axis (Radial Count copies, Transform palette).");
+ flag("transform.symmetry_local", "Local", nullptr, "Transform", "", &symmetry_.local,
+ "Local symmetry: mirror and turn strokes about the active Part's centre instead of the world origin.");
+ for (int axis = 0; axis < 3; ++axis) { // the axis radial copies turn around
+ Action a;
+ a.id = std::string("transform.radial_axis_") + char('x' + axis);
+ a.label = std::string(1, char('X' + axis)) + " axis";
+ a.palette = "Transform";
+ a.description = std::string("Radial symmetry turns its copies around the ") + char('X' + axis) +
+ (axis == 1 ? " axis (up, the default)." : " axis.");
+ a.run = [this, axis] { symmetry_.radialAxis = axis; };
+ a.checked = [this, axis] { return symmetry_.radialAxis == axis; };
+ actions_.add(std::move(a));
+ }
flag("ui.brush_lab", "AI Brush", ICON_LC_SPARKLES, "Brush", "", &showBrushLab_,
"Brush Lab: describe a brush in words and AI builds it; tweak the recipe with sliders.");
flag("ui.generate3d", "Generate 3D", ICON_LC_WAND_SPARKLES, "Generate", "", &showImageTo3D_,
diff --git a/src/app/UiLayout.cpp b/src/app/UiLayout.cpp
index 003865a5..6cda092e 100644
--- a/src/app/UiLayout.cpp
+++ b/src/app/UiLayout.cpp
@@ -33,7 +33,7 @@ UiLayout standardLayout() {
"draw.zadd", "draw.zsub", "draw.rgb", "draw.paint_vertex", "draw.paint_texture", "draw.new_texture", "sep", "widget.draw_size",
"widget.strength", "row", "ui.brush_lab", "draw.front_faces", "sep",
"draw.dynamic", "widget.dyntopo_detail", "sep",
- "transform.symmetry_x", "transform.symmetry_y", "transform.symmetry_z", "sep", "draw.pressure_strength",
+ "transform.symmetry_x", "transform.symmetry_y", "transform.symmetry_z", "transform.symmetry_radial", "sep", "draw.pressure_strength",
"draw.pressure_size", "widget.points"};
l.leftShelf = {"widget.tile.brush", "widget.tile.stroke", "widget.tile.alpha", "widget.tile.material", "widget.color"};
l.rightShelf = {"edit.undo", "edit.redo", "sep",
diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cpp
index 79d720fd..7699f5f9 100644
--- a/src/app/UiTest.cpp
+++ b/src/app/UiTest.cpp
@@ -81,6 +81,10 @@
// moved (vertices moved since `snapshot`), moved_max / moved_sum (distance),
// moved_masked (masked vertices that moved), mask_soft (vertices partly masked),
// selection_shown (1 while a rectangle / lasso selection is drawn), symmetry_x,
+// symmetry_radial (the radial count, 0 off), radial_axis (0 X, 1 Y, 2 Z), symmetry_local,
+// symmetry_copies (copies every stroke makes), cursor_copies (brush cursors drawn),
+// symmetry_pivot_x (local symmetry's centre), timeline_top (1: the strip at the top),
+// timeline_y / axis_gizmo_y (their tops / centre, fractions of the canvas from its top),
// tablet_mouse_mode (Preferences > Tablet > Mouse mode),
// smooth_keep_volume (Brush > Smooth keeps volume), stroke_keep_volume (1 when Smooth
// dabs keep the volume now: the option, flipped by letting go of Shift mid-stroke),
@@ -611,6 +615,26 @@ double Demo::query(const std::string& name, bool& known) const {
}
if (name == "selection_shown") return app_.drag_ == App::Drag::Select && app_.selectMoved_ ? 1.0 : 0.0;
if (name == "symmetry_x") return app_.symmetry_.x ? 1.0 : 0.0;
+ // Radial and local symmetry (#63): the count while radial is on (0 off), its axis (0 X, 1 Y, 2 Z), local (1 on),
+ // the copies every stroke makes, the brush cursors drawn last frame, the local centre.
+ if (name == "symmetry_radial") return app_.symmetry_.radialOn() ? double(app_.symmetry_.radial) : 0.0;
+ if (name == "radial_axis") return double(app_.symmetry_.radialAxis);
+ if (name == "symmetry_local") return app_.symmetry_.local ? 1.0 : 0.0;
+ if (name == "symmetry_copies") return double(Sculptor::copies(app_.symmetry_).size());
+ if (name == "cursor_copies") return double(app_.symmetryCopiesDrawn_);
+ if (name == "symmetry_pivot_x") return double(app_.symmetry_.pivot.x);
+ // Timeline position (#63): 1 at the top of the viewport; the strip's top edge and the axis gizmo's centre as
+ // fractions of the canvas height from its top (-1: the strip isn't shown).
+ if (name == "timeline_top") return app_.uiPrefs_.timelineTop ? 1.0 : 0.0;
+ if (name == "timeline_y" || name == "axis_gizmo_y") {
+ const auto c = app_.canvasRect();
+ if (name == "timeline_y")
+ return app_.timelineStripY_ < 0.0f ? -1.0 : double((app_.timelineStripY_ - c.y) / std::max(c.h, 1.0f));
+ const auto ends = app_.axisGizmoLayout();
+ float y = 0.0f;
+ for (const auto& e : ends) y += e.at.y;
+ return double((y / float(ends.size()) - c.y) / std::max(c.h, 1.0f));
+ }
if (name == "hidden") {
size_t n = 0;
for (uint8_t h : m.hidden) n += h != 0;
diff --git a/src/core/Commands.cpp b/src/core/Commands.cpp
index 4fd002b9..84b608df 100644
--- a/src/core/Commands.cpp
+++ b/src/core/Commands.cpp
@@ -651,13 +651,7 @@ CommandRegistry::CommandRegistry() {
st.curve = argBool(a, "curve", true);
st.spacing = float(argNumber(a, "spacing", -1.0));
st.seed = uint32_t(std::max(argNumber(a, "seed", 1.0), 0.0));
- for (char c : argString(a, "symmetry")) {
- const char l = char(std::tolower(static_cast<unsigned char>(c)));
- if (l == 'x') st.symmetry.x = true;
- else if (l == 'y') st.symmetry.y = true;
- else if (l == 'z') st.symmetry.z = true;
- else return {false, "symmetry takes the axes x, y and z"};
- }
+ if (!symmetryArg(a, doc.mesh, st.symmetry, err)) return {false, err};
// Resolve the brush: a library recipe (exact name, then any case), then a built-in type.
const std::string name = argString(a, "brush");
@@ -818,7 +812,15 @@ CommandRegistry::CommandRegistry() {
registerProjectCommands(*this); // keep last (core/Project.cpp)
}
-void CommandRegistry::add(Command cmd) { commands_.push_back(std::move(cmd)); }
+void CommandRegistry::add(Command cmd) {
+ // The commands that follow the brushes' symmetry take radial and local symmetry too (#63).
+ static const char* const kSymmetric[] = {"stroke", "vdm_stamp", "mask_rect", "mask_lasso", "hide_rect",
+ "hide_lasso", "insert_primitive", "insert_mesh"};
+ for (const char* name : kSymmetric)
+ if (cmd.name == name)
+ for (ParamSpec& p : radialSymmetryParams()) cmd.params.push_back(std::move(p));
+ commands_.push_back(std::move(cmd));
+}
const Command* CommandRegistry::find(const std::string& name) const {
for (const auto& c : commands_)
diff --git a/src/core/Dyntopo.cpp b/src/core/Dyntopo.cpp
index fccd8030..5e9baab6 100644
--- a/src/core/Dyntopo.cpp
+++ b/src/core/Dyntopo.cpp
@@ -213,7 +213,8 @@ void DynamicTopology::killVertex(uint32_t v) {
for (size_t k = 0; k < mirrorMaps_.size(); ++k) {
const uint32_t w = mirrorOf(k, v);
if (w == kNone) continue;
- if (mirrorOf(k, w) == v) mirrorMaps_[k].stamp[w] = 0;
+ const size_t back = k < mirrorInverse_.size() ? mirrorInverse_[k] : k;
+ if (mirrorOf(back, w) == v) mirrorMaps_[back].stamp[w] = 0;
mirrorMaps_[k].stamp[v] = 0;
}
}
@@ -446,8 +447,8 @@ bool DynamicTopology::inside(uint32_t a, uint32_t b, bool mirrored) const {
};
if (within(center_)) return true;
if (!mirrored) return false;
- for (const glm::vec3& s : mirrorSigns_)
- if (within(center_ * s)) return true;
+ for (const SymCopy& s : mirrorSigns_)
+ if (within(s.point(center_))) return true;
return false;
}
@@ -478,8 +479,8 @@ void DynamicTopology::queryRegion() {
};
addSlivers(regionTris_);
std::vector<uint32_t> more;
- for (const glm::vec3& s : mirrorSigns_) {
- bvh_->queryTriangles(*mesh_, center_ * s, radius_, more);
+ for (const SymCopy& s : mirrorSigns_) {
+ bvh_->queryTriangles(*mesh_, s.point(center_), radius_, more);
addSlivers(more);
mirrorTris_.insert(mirrorTris_.end(), more.begin(), more.end());
}
@@ -600,8 +601,14 @@ void DynamicTopology::setMirror(size_t k, uint32_t v, uint32_t w) {
}
map.to[v] = w;
map.stamp[v] = mirrorStamp_;
- map.to[w] = v;
- map.stamp[w] = mirrorStamp_;
+ // The inverse copy maps w back to v (the same map for a mirror).
+ MirrorMap& back = mirrorMaps_[k < mirrorInverse_.size() ? mirrorInverse_[k] : k];
+ if (back.to.size() < need) {
+ back.to.resize(need + need / 4, kNone);
+ back.stamp.resize(need + need / 4, 0);
+ }
+ back.to[w] = v;
+ back.stamp[w] = mirrorStamp_;
}
// Pairs each vertex with the vertex at its mirror image (within eps_), for every mirror; only pairs that
@@ -658,11 +665,11 @@ void DynamicTopology::matchMirrors(const std::vector<uint32_t>& verts) {
return best;
};
for (size_t k = 0; k < mirrorSigns_.size(); ++k) {
- const glm::vec3 s = mirrorSigns_[k];
+ const SymCopy& s = mirrorSigns_[k];
for (uint32_t v : verts) {
if (mirrorOf(k, v) != kNone) continue; // (its partner found it first)
- const uint32_t w = nearest(m.positions[v] * s);
- if (w == kNone || nearest(m.positions[w] * s) != v) continue;
+ const uint32_t w = nearest(s.point(m.positions[v]));
+ if (w == kNone || nearest(s.inversePoint(m.positions[w])) != v) continue;
setMirror(k, v, w);
}
}
@@ -1205,8 +1212,8 @@ void DynamicTopology::relaxPass() {
for (uint32_t v : changedV_) {
if (deadV_[v] || locked(v)) continue;
bool in = glm::dot(m.positions[v] - center_, m.positions[v] - center_) <= r2;
- for (const glm::vec3& s : mirrorSigns_) {
- const glm::vec3 d0 = m.positions[v] - center_ * s;
+ for (const SymCopy& s : mirrorSigns_) {
+ const glm::vec3 d0 = m.positions[v] - s.point(center_);
in = in || glm::dot(d0, d0) <= r2;
}
if (!in) continue;
@@ -1269,8 +1276,8 @@ void DynamicTopology::gatherRegion() {
const float reach = radius_ * 1.25f + target_ * 2.0f;
bvh_->queryTriangles(*mesh_, center_, reach, tris);
addCorners(tris);
- for (const glm::vec3& s : mirrorSigns_) {
- bvh_->queryTriangles(*mesh_, center_ * s, reach, tris);
+ for (const SymCopy& s : mirrorSigns_) {
+ bvh_->queryTriangles(*mesh_, s.point(center_), reach, tris);
addCorners(tris);
}
// Matched within a third of the edge length (the target, or the mesh's own where it is finer, so the
@@ -1291,7 +1298,7 @@ void DynamicTopology::gatherRegion() {
}
bool DynamicTopology::remesh(Mesh& mesh, BVH& bvh, const glm::vec3& center, float radius, float edgeLength,
- std::span<const glm::vec3> mirrors) {
+ std::span<const SymCopy> mirrors) {
const auto clock = std::chrono::steady_clock::now();
moved_.clear();
recordedNow_.clear();
@@ -1323,6 +1330,12 @@ bool DynamicTopology::remesh(Mesh& mesh, BVH& bvh, const glm::vec3& center, floa
splitLen2_ = (edgeLength * 4.0f / 3.0f) * (edgeLength * 4.0f / 3.0f);
collapseLen2_ = (edgeLength * 0.6f) * (edgeLength * 0.6f);
mirrorSigns_.assign(mirrors.size() > 1 ? mirrors.begin() + 1 : mirrors.end(), mirrors.end());
+ // Each copy's inverse (a mirror is its own; a radial turn's is the opposite turn), without the identity.
+ mirrorInverse_.clear();
+ if (!mirrorSigns_.empty()) {
+ const std::vector<size_t> inv = symmetryInverses(mirrors);
+ for (size_t k = 1; k < inv.size(); ++k) mirrorInverse_.push_back(inv[k] > 0 ? inv[k] - 1 : k - 1);
+ }
mirrorMaps_.resize(mirrorSigns_.size());
if (++mirrorStamp_ == 0) { // (wrapped: forget every old entry)
for (MirrorMap& map : mirrorMaps_) std::fill(map.stamp.begin(), map.stamp.end(), 0);
diff --git a/src/core/Dyntopo.h b/src/core/Dyntopo.h
index b58e2d98..da677eea 100644
--- a/src/core/Dyntopo.h
+++ b/src/core/Dyntopo.h
@@ -23,6 +23,7 @@
#include "core/BVH.h"
#include "core/Mesh.h"
+#include "core/Symmetry.h"
#include <glm/glm.hpp>
@@ -95,10 +96,11 @@ struct DyntopoStats {
// starts recording, finish() ends the stroke.
class DynamicTopology {
public:
- // Remeshes within `radius` of `center` and of its mirror images (`mirrors` as Sculptor::mirrors makes them,
- // the identity first) towards edges of `edgeLength`. Returns false when nothing changed.
+ // Remeshes within `radius` of `center` and of its symmetric copies (`mirrors` as Sculptor::copies makes them:
+ // mirror images and radial turns, the identity first) towards edges of `edgeLength`. Returns false when
+ // nothing changed.
bool remesh(Mesh& mesh, BVH& bvh, const glm::vec3& center, float radius, float edgeLength,
- std::span<const glm::vec3> mirrors);
+ std::span<const SymCopy> mirrors);
// The vertices the last remesh renumbered (old slot, new slot), for per-vertex stroke state.
std::span<const std::pair<uint32_t, uint32_t>> movedVertices() const { return moved_; }
// The vertex slots the last remesh added to the stroke's undo record (their stroke-start state is there).
@@ -192,7 +194,8 @@ private:
// The current remesh.
glm::vec3 center_{0.0f};
float radius_ = 0.0f, target_ = 0.0f, splitLen2_ = 0.0f, collapseLen2_ = 0.0f, eps_ = 0.0f;
- std::vector<glm::vec3> mirrorSigns_; // without the identity
+ std::vector<SymCopy> mirrorSigns_; // the symmetric copies, without the identity
+ std::vector<size_t> mirrorInverse_; // per copy, the index (in mirrorSigns_) of its inverse
// Per mirror: each vertex's image (valid where stamp == mirrorStamp_, so a new remesh forgets them all).
struct MirrorMap {
std::vector<uint32_t> to, stamp;
diff --git a/src/core/Kelvinlet.cpp b/src/core/Kelvinlet.cpp
index 52a33b62..40442daa 100644
--- a/src/core/Kelvinlet.cpp
+++ b/src/core/Kelvinlet.cpp
@@ -669,14 +669,14 @@ void Sculptor::kelvinletStep(Mesh& mesh, BVH& bvh, BrushType type, const Kelvinl
kelvinOverBudget_ = false;
dabVerts_.clear();
dabLeaves_.clear();
- for (const glm::vec3& m : mirrors(sym)) {
+ for (const SymCopy& m : copies(sym)) {
KelvinletStep ms = step;
- ms.center *= m;
- ms.delta *= m;
- ms.travel *= m;
- ms.viewDir *= m;
+ ms.center = m.point(step.center);
+ ms.delta = m.dir(step.delta);
+ ms.travel = m.dir(step.travel);
+ ms.viewDir = m.dir(step.viewDir);
// The rotation axis is a pseudovector: a mirror flips it once more (det = -1 for an odd mirror count).
- ms.axis = step.axis * m * (m.x * m.y * m.z);
+ ms.axis = m.dir(step.axis) * m.handedness();
kelvinletSingle(mesh, bvh, k, ms);
}
if (kelvinletFarPending()) { // one group of the far field's vertices catches up (see KelvinFarField)
@@ -739,13 +739,8 @@ void Sculptor::dabKelvinlet(Mesh& mesh, BVH& bvh, BrushType type, const DabParam
void Sculptor::cloneStamp(Mesh& mesh, BVH& bvh, const DabParams& p, Symmetry sym) {
dabVerts_.clear();
dabLeaves_.clear();
- for (const glm::vec3& m : mirrors(sym)) {
- DabParams mp = p;
- mp.center *= m;
- mp.viewDir *= m;
- mp.strokeDelta *= m;
- mp.alphaUp *= m;
- dabVdmSingle(mesh, bvh, mp, m.x * m.y * m.z);
+ for (const SymCopy& m : copies(sym)) {
+ dabVdmSingle(mesh, bvh, transformed(p, m), m.handedness());
}
updateDabNormals(mesh, bvh);
}
diff --git a/src/core/Masking.cpp b/src/core/Masking.cpp
index ed5c3454..1a042e8c 100644
--- a/src/core/Masking.cpp
+++ b/src/core/Masking.cpp
@@ -68,9 +68,8 @@ float smoothstep01(float e0, float e1, float x) {
} // namespace
-// The "symmetry" argument ("x", "xz" ...) as mirror sign vectors (Sculptor::mirrors); none without it.
-bool symmetryMirrorsArg(const Args& a, std::vector<glm::vec3>& mirrors, std::string& error) {
- Symmetry sym{false, false, false};
+bool symmetryArg(const Args& a, const Mesh& mesh, Symmetry& sym, std::string& error) {
+ sym = Symmetry{false, false, false};
for (char c : argString(a, "symmetry")) {
const char l = char(std::tolower(static_cast<unsigned char>(c)));
if (l == 'x') sym.x = true;
@@ -81,10 +80,45 @@ bool symmetryMirrorsArg(const Args& a, std::vector<glm::vec3>& mirrors, std::str
return false;
}
}
- mirrors = Sculptor::mirrors(sym);
+ const double radial = argNumber(a, "radial", 1.0);
+ if (!(radial >= 1.0 && radial <= double(Symmetry::kMaxRadial)) || radial != std::floor(radial)) {
+ error = "radial takes a whole number of copies, 1 (off) to " + std::to_string(Symmetry::kMaxRadial);
+ return false;
+ }
+ sym.radial = int(radial);
+ sym.radialEnabled = sym.radial > 1;
+ std::string axis = argString(a, "radial_axis");
+ if (axis.empty()) axis = "y";
+ for (char& c : axis) c = char(std::tolower(static_cast<unsigned char>(c)));
+ if (axis != "x" && axis != "y" && axis != "z") {
+ error = "radial_axis takes x, y or z";
+ return false;
+ }
+ sym.radialAxis = axis[0] - 'x';
+ sym.local = argBool(a, "local", false);
+ if (sym.local) sym.pivot = symmetryPivot(mesh);
return true;
}
+bool symmetryCopiesArg(const Args& a, const Mesh& mesh, std::vector<SymCopy>& copies, std::string& error) {
+ Symmetry sym;
+ if (!symmetryArg(a, mesh, sym, error)) return false;
+ copies = Sculptor::copies(sym);
+ return true;
+}
+
+std::vector<ParamSpec> radialSymmetryParams() {
+ return {{"radial", ParamSpec::Type::Number,
+ "Radial symmetry: this many copies turned evenly around radial_axis (2-64; default 1, off). With "
+ "mirror axes too, each mirror image gets its copies.",
+ false},
+ {"radial_axis", ParamSpec::Type::String, "The axis radial copies turn around: x, y or z (default y).", false},
+ {"local", ParamSpec::Type::Bool,
+ "Local symmetry: mirror planes and the radial axis go through the Part's centre instead of the world "
+ "origin (default false).",
+ false}};
+}
+
bool maskClear(Mesh& mesh) {
if (!mesh.hasMask()) return false;
const bool changed = std::any_of(mesh.mask.begin(), mesh.mask.end(), [](float m) { return m != 0.0f; });
@@ -256,18 +290,18 @@ namespace {
// Vertex v, or one of its mirror images, projects inside the shape.
bool inShape(const Mesh& mesh, const glm::mat4& viewProj, const ScreenPolygon& shape,
- const std::vector<glm::vec3>& mirrors, uint32_t v) {
+ const std::vector<SymCopy>& mirrors, uint32_t v) {
glm::vec2 ndc;
if (projectToNdc(viewProj, mesh.positions[v], ndc) && shape.contains(ndc)) return true;
- for (const glm::vec3& m : mirrors)
- if (m != glm::vec3(1.0f) && projectToNdc(viewProj, mesh.positions[v] * m, ndc) && shape.contains(ndc)) return true;
+ for (const SymCopy& m : mirrors)
+ if (!m.identity() && projectToNdc(viewProj, m.point(mesh.positions[v]), ndc) && shape.contains(ndc)) return true;
return false;
}
} // namespace
bool maskInShape(Mesh& mesh, const glm::mat4& viewProj, const ScreenPolygon& shape, float strength, bool unmask,
- const std::vector<glm::vec3>& mirrors) {
+ const std::vector<SymCopy>& mirrors) {
if (mesh.vertexCount() == 0 || !shape.valid()) return false;
const float s = std::clamp(strength, 0.0f, 1.0f);
return maskPass(mesh, [&](const std::vector<float>& m, uint32_t v) {
@@ -277,7 +311,7 @@ bool maskInShape(Mesh& mesh, const glm::mat4& viewProj, const ScreenPolygon& sha
}
bool shapeCoversMesh(const Mesh& mesh, const glm::mat4& viewProj, const ScreenPolygon& shape,
- const std::vector<glm::vec3>& mirrors) {
+ const std::vector<SymCopy>& mirrors) {
if (!shape.valid()) return false;
const bool anyHidden = mesh.hasHidden();
for (uint32_t v = 0; v < uint32_t(mesh.vertexCount()); ++v)
@@ -291,17 +325,17 @@ void Sculptor::dabMask(Mesh& mesh, const BVH& bvh, const DabParams& p, Symmetry
if (s <= 0.0f) return;
if (microReady(mesh)) { // the micro level's own mask, per grid point (core/MicroSculpt.cpp)
const double k0 = micro_.findMs + micro_.kernelMs + micro_.stitchMs;
- for (const glm::vec3& mirror : mirrors(sym))
- micro_.dab(mesh, bvh, BrushType::Standard, p.center * mirror, p.viewDir * mirror, p.radius, 1.0f, p.invert, p.focal,
- p.alphaUp * mirror, true, s);
+ for (const SymCopy& mirror : copies(sym))
+ micro_.dab(mesh, bvh, BrushType::Standard, mirror.point(p.center), mirror.dir(p.viewDir), p.radius, 1.0f, p.invert,
+ p.focal, mirror.dir(p.alphaUp), true, s);
timings.kernelMs += micro_.findMs + micro_.kernelMs + micro_.stitchMs - k0;
++timings.dabs;
return;
}
auto clock = std::chrono::steady_clock::now();
std::vector<float>& mask = mesh.ensureMask();
- for (const glm::vec3& mirror : mirrors(sym)) {
- const glm::vec3 center = p.center * mirror, viewDir = p.viewDir * mirror;
+ for (const SymCopy& mirror : copies(sym)) {
+ const glm::vec3 center = mirror.point(p.center), viewDir = mirror.dir(p.viewDir);
brushVertices(mesh, bvh, center, p.radius, verts_);
// New values in parallel; recording and writing them in order.
weights_.resize(verts_.size());
@@ -434,8 +468,8 @@ void registerMaskingCommands(CommandRegistry& registry) {
std::vector<glm::vec2> points;
std::string error;
if (!viewProjArg(doc.mesh, a, vp, error) || !shape(a, points, error)) return {false, error};
- std::vector<glm::vec3> mirrors;
- if (!symmetryMirrorsArg(a, mirrors, error)) return {false, error};
+ std::vector<SymCopy> mirrors;
+ if (!symmetryCopiesArg(a, doc.mesh, mirrors, error)) return {false, error};
const ScreenPolygon polygon(points);
const bool unmask = argBool(a, "unmask", false);
if (argBool(a, "clear_outside", false) && !shapeCoversMesh(doc.mesh, vp, polygon, mirrors)) {
diff --git a/src/core/Masking.h b/src/core/Masking.h
index 959fe3da..afe125dc 100644
--- a/src/core/Masking.h
+++ b/src/core/Masking.h
@@ -10,6 +10,7 @@
#include "core/Commands.h"
#include "core/Mesh.h"
+#include "core/Symmetry.h"
#include <glm/glm.hpp>
@@ -57,19 +58,24 @@ bool maskBorder(Mesh& mesh, int rings, bool polygroups, bool soft, float strengt
// project inside `shape` (NDC under `viewProj`, see ScreenSelect.h) gain
// `strength` (0-1) of mask, or lose it with `unmask`. Vertices behind the
// camera count as outside; the far side of the model is selected too.
-// `mirrors` (Sculptor::mirrors of the symmetry) also selects each vertex whose
-// mirror image projects inside, as the brushes mirror (#51); empty = none.
+// `mirrors` (Sculptor::copies of the symmetry) also selects each vertex whose
+// mirror image or radial copy projects inside, as the brushes mirror (#51, #63); empty = none.
bool maskInShape(Mesh& mesh, const glm::mat4& viewProj, const ScreenPolygon& shape, float strength, bool unmask,
- const std::vector<glm::vec3>& mirrors = {});
+ const std::vector<SymCopy>& mirrors = {});
// Whether any visible vertex (or, with `mirrors`, its mirror image) projects
// inside `shape`: a selection that covers none of the model clears the mask
// instead (ZBrush: Ctrl+drag on the background).
bool shapeCoversMesh(const Mesh& mesh, const glm::mat4& viewProj, const ScreenPolygon& shape,
- const std::vector<glm::vec3>& mirrors = {});
+ const std::vector<SymCopy>& mirrors = {});
-// The "symmetry" argument of a command ("x", "xz" ...) as mirror sign vectors (Sculptor::mirrors, the first one
-// the identity); just the identity without it. False, saying why, for anything but the axes x, y and z.
-bool symmetryMirrorsArg(const Args& a, std::vector<glm::vec3>& mirrors, std::string& error);
+// A command's symmetry arguments: "symmetry" (mirror axes, "x", "xz" ...), "radial" (copies around an axis,
+// 2-64; default 1, off), "radial_axis" (x, y or z; default y) and "local" (around `mesh`'s centre instead of
+// the world origin). Without them, no symmetry. False, saying why, for a bad value.
+bool symmetryArg(const Args& a, const Mesh& mesh, Symmetry& sym, std::string& error);
+// The same as the list of copies (Sculptor::copies, the first one the identity).
+bool symmetryCopiesArg(const Args& a, const Mesh& mesh, std::vector<SymCopy>& copies, std::string& error);
+// The parameter specs of "radial", "radial_axis" and "local" (commands that take "symmetry" add them).
+std::vector<ParamSpec> radialSymmetryParams();
// Registers mask_clear, mask_all, mask_invert, mask_blur, mask_sharpen,
// mask_grow, mask_shrink, mask_by_cavity, mask_by_polygroup, mask_border,
diff --git a/src/core/Micro.h b/src/core/Micro.h
index 41c4ed5f..710a6777 100644
--- a/src/core/Micro.h
+++ b/src/core/Micro.h
@@ -247,7 +247,7 @@ public:
void dab(Mesh& m, const BVH& bvh, BrushType type, const glm::vec3& center, const glm::vec3& viewDir, float radius,
float strength, bool invert, float focal, const glm::vec3& alphaUp, bool maskBrush, float maskStrength);
// Move: captures the points within the dab (with each mirror's signs), then moves them along their normals.
- void beginGrab(Mesh& m, const BVH& bvh, const glm::vec3& center, float radius, float focal, const glm::vec3& mirror);
+ void beginGrab(Mesh& m, const BVH& bvh, const glm::vec3& center, float radius, float focal, const glm::mat3& mirror);
void grab(Mesh& m, const glm::vec3& delta);
// Puts every grid point the stroke changed back (the stroke stays open).
void restore(Mesh& m);
@@ -283,7 +283,7 @@ private:
float baseEdge_ = 0.0f; // the base's average edge length
// Move: per mirror its triangles and, per triangle, weight and direction of its coarse grid points.
struct GrabMirror {
- glm::vec3 mirror{1.0f};
+ glm::mat3 mirror{1.0f};
uint32_t stride = 1, firstTri = 0, tris = 0;
};
std::vector<GrabMirror> grabMirrors_;
diff --git a/src/core/MicroSculpt.cpp b/src/core/MicroSculpt.cpp
index 6601fcf6..8f918bc2 100644
--- a/src/core/MicroSculpt.cpp
+++ b/src/core/MicroSculpt.cpp
@@ -527,7 +527,7 @@ void MicroStroke::widen(MicroMesh& mm, float need) {
strokeStep_ = mm.step;
}
-void MicroStroke::beginGrab(Mesh& m, const BVH& bvh, const glm::vec3& center, float radius, float focal, const glm::vec3& mirror) {
+void MicroStroke::beginGrab(Mesh& m, const BVH& bvh, const glm::vec3& center, float radius, float focal, const glm::mat3& mirror) {
if (!active_ || !m.micro) return;
MicroMesh& mm = *m.micro;
const uint32_t n = mm.n;
@@ -590,7 +590,7 @@ void MicroStroke::grab(Mesh& m, const glm::vec3& delta) {
size_t weightBase = 0;
for (const GrabMirror& gm : grabMirrors_) {
const uint32_t cm = n / gm.stride, cs = (cm + 1) * (cm + 2) / 2;
- const glm::vec3 dm = delta * gm.mirror;
+ const glm::vec3 dm = gm.mirror * delta;
poolFor(gm.tris, [&](size_t b, size_t e) {
thread_local std::vector<float> coarse;
coarse.resize(cs);
diff --git a/src/core/Polygroups.cpp b/src/core/Polygroups.cpp
index 299fbdc1..cfcc3b3b 100644
--- a/src/core/Polygroups.cpp
+++ b/src/core/Polygroups.cpp
@@ -148,7 +148,7 @@ bool groupExists(const Mesh& m, uint32_t group) {
// Hides or keeps the visible triangles by whether their centre projects inside a screen shape.
template <class Inside>
std::vector<uint8_t> hiddenByShape(const Mesh& mesh, const glm::mat4& viewProj, Inside inside, bool hideInside,
- const std::vector<glm::vec3>& mirrors) {
+ const std::vector<SymCopy>& mirrors) {
std::vector<uint8_t> hidden = currentHidden(mesh);
for (uint32_t t = 0; t < mesh.triangleCount(); ++t) {
if (hidden[t]) continue;
@@ -157,7 +157,7 @@ std::vector<uint8_t> hiddenByShape(const Mesh& mesh, const glm::mat4& viewProj,
glm::vec2 ndc;
bool in = projectToNdc(viewProj, c, ndc) && inside(ndc);
for (size_t k = 0; k < mirrors.size() && !in; ++k) // or its mirror image, with symmetry (#51)
- in = mirrors[k] != glm::vec3(1.0f) && projectToNdc(viewProj, c * mirrors[k], ndc) && inside(ndc);
+ in = !mirrors[k].identity() && projectToNdc(viewProj, mirrors[k].point(c), ndc) && inside(ndc);
if (in == hideInside) hidden[t] = 1;
}
return unlessAllHidden(std::move(hidden));
@@ -262,7 +262,7 @@ std::vector<uint8_t> hiddenInverted(const Mesh& mesh) {
}
std::vector<uint8_t> hiddenByRect(const Mesh& mesh, const glm::mat4& viewProj, glm::vec2 rectMin, glm::vec2 rectMax,
- bool hideInside, const std::vector<glm::vec3>& mirrors) {
+ bool hideInside, const std::vector<SymCopy>& mirrors) {
const glm::vec2 lo = glm::min(rectMin, rectMax), hi = glm::max(rectMin, rectMax);
return hiddenByShape(
mesh, viewProj, [&](glm::vec2 p) { return p.x >= lo.x && p.x <= hi.x && p.y >= lo.y && p.y <= hi.y; },
@@ -270,7 +270,7 @@ std::vector<uint8_t> hiddenByRect(const Mesh& mesh, const glm::mat4& viewProj, g
}
std::vector<uint8_t> hiddenByLasso(const Mesh& mesh, const glm::mat4& viewProj, const std::vector<glm::vec2>& lasso,
- bool hideInside, const std::vector<glm::vec3>& mirrors) {
+ bool hideInside, const std::vector<SymCopy>& mirrors) {
const ScreenPolygon polygon(lasso);
return hiddenByShape(mesh, viewProj, [&](glm::vec2 p) { return polygon.contains(p); }, hideInside, mirrors);
}
@@ -454,8 +454,8 @@ void registerPolygroupCommands(CommandRegistry& reg) {
if (doc.mesh.triangleCount() == 0) return {false, "The mesh is empty"};
glm::mat4 vp;
std::string error;
- std::vector<glm::vec3> mirrors;
- if (!viewProjArg(doc.mesh, a, vp, error) || !symmetryMirrorsArg(a, mirrors, error)) return {false, error};
+ std::vector<SymCopy> mirrors;
+ if (!viewProjArg(doc.mesh, a, vp, error) || !symmetryCopiesArg(a, doc.mesh, mirrors, error)) return {false, error};
const glm::vec2 lo(float(argNumber(a, "x0", -1)), float(argNumber(a, "y0", -1)));
const glm::vec2 hi(float(argNumber(a, "x1", 1)), float(argNumber(a, "y1", 1)));
const bool inside = argBool(a, "inside", false);
@@ -479,9 +479,9 @@ void registerPolygroupCommands(CommandRegistry& reg) {
glm::mat4 vp;
std::vector<glm::vec2> lasso;
std::string error;
- std::vector<glm::vec3> mirrors;
+ std::vector<SymCopy> mirrors;
if (!viewProjArg(doc.mesh, a, vp, error) || !lassoArg(a, lasso, error) ||
- !symmetryMirrorsArg(a, mirrors, error))
+ !symmetryCopiesArg(a, doc.mesh, mirrors, error))
return {false, error};
const bool inside = argBool(a, "inside", false);
std::vector<uint8_t> hidden = hiddenByLasso(doc.mesh, vp, lasso, inside, mirrors);
diff --git a/src/core/Polygroups.h b/src/core/Polygroups.h
index 0f035796..064ee9c4 100644
--- a/src/core/Polygroups.h
+++ b/src/core/Polygroups.h
@@ -9,6 +9,7 @@
#pragma once
#include "core/Mesh.h"
+#include "core/Symmetry.h"
#include <glm/glm.hpp>
@@ -50,13 +51,13 @@ std::vector<uint8_t> hiddenInverted(const Mesh& mesh);
// Rectangle selection in normalised device coordinates (-1..1, y up) under
// `viewProj`: triangles whose centre projects inside stay visible and the rest
// are hidden, or with `hideInside` the inside is hidden instead. Triangles
-// behind the camera count as outside. `mirrors` (Sculptor::mirrors of the symmetry): a triangle whose mirror
-// image's centre projects inside counts as inside too (#51); empty = none.
+// behind the camera count as outside. `mirrors` (Sculptor::copies of the symmetry): a triangle whose mirror
+// image's or radial copy's centre projects inside counts as inside too (#51, #63); empty = none.
std::vector<uint8_t> hiddenByRect(const Mesh& mesh, const glm::mat4& viewProj, glm::vec2 rectMin, glm::vec2 rectMax,
- bool hideInside, const std::vector<glm::vec3>& mirrors = {});
+ bool hideInside, const std::vector<SymCopy>& mirrors = {});
// The same with a lasso: a closed polygon of NDC points (even-odd inside test).
std::vector<uint8_t> hiddenByLasso(const Mesh& mesh, const glm::mat4& viewProj, const std::vector<glm::vec2>& lasso,
- bool hideInside, const std::vector<glm::vec3>& mirrors = {});
+ bool hideInside, const std::vector<SymCopy>& mirrors = {});
// True when every triangle of `group` is visible and no other is.
bool polygroupIsolated(const Mesh& mesh, uint32_t group);
diff --git a/src/core/Polypaint.cpp b/src/core/Polypaint.cpp
index 6e14b75c..5ddf3db3 100644
--- a/src/core/Polypaint.cpp
+++ b/src/core/Polypaint.cpp
@@ -119,8 +119,8 @@ size_t paintDab(Sculptor& sculptor, Mesh& mesh, const BVH& bvh, const DabParams&
static thread_local std::vector<uint32_t> verts;
auto clock = std::chrono::steady_clock::now();
size_t changed = 0;
- for (const glm::vec3& m : Sculptor::mirrors(sym)) {
- const glm::vec3 center = p.center * m, viewDir = p.viewDir * m;
+ for (const SymCopy& m : Sculptor::copies(sym)) {
+ const glm::vec3 center = m.point(p.center), viewDir = m.dir(p.viewDir);
brushVertices(mesh, bvh, center, p.radius, verts);
for (uint32_t v : verts) {
if (p.frontFacesOnly && v < mesh.normals.size() && glm::dot(mesh.normals[v], viewDir) > 0.0f) continue;
diff --git a/src/core/Sculpt.cpp b/src/core/Sculpt.cpp
index 508e9dab..d6d3cb04 100644
--- a/src/core/Sculpt.cpp
+++ b/src/core/Sculpt.cpp
@@ -207,6 +207,77 @@ std::vector<glm::vec3> Sculptor::mirrors(Symmetry sym) {
return out;
}
+std::vector<SymCopy> symmetryCopies(const Symmetry& sym) {
+ const glm::vec3 pivot = sym.local ? sym.pivot : glm::vec3(0.0f);
+ const int n = sym.radialOn() ? std::clamp(sym.radial, 1, Symmetry::kMaxRadial) : 1;
+ const int axis = std::clamp(sym.radialAxis, 0, 2);
+ std::vector<SymCopy> out;
+ for (const glm::vec3& s : Sculptor::mirrors(sym))
+ for (int k = 0; k < n; ++k) {
+ // A turn of k/n about the axis (exact for the quarter and half turns, so duplicates compare equal).
+ glm::mat3 r(1.0f);
+ if (k > 0) {
+ const double a = 2.0 * 3.14159265358979323846 * double(k) / double(n);
+ float c = float(std::cos(a)), si = float(std::sin(a));
+ if (4 * k % n == 0) { // a multiple of a quarter turn
+ c = std::round(c);
+ si = std::round(si);
+ }
+ const int u = (axis + 1) % 3, v = (axis + 2) % 3; // r turns u towards v
+ r[u][u] = c;
+ r[u][v] = si;
+ r[v][u] = -si;
+ r[v][v] = c;
+ }
+ SymCopy copy;
+ copy.m = glm::mat3(glm::vec3(s.x, 0, 0), glm::vec3(0, s.y, 0), glm::vec3(0, 0, s.z)) * r;
+ copy.pivot = pivot;
+ bool repeated = false;
+ for (const SymCopy& o : out) {
+ float d = 0.0f;
+ for (int i = 0; i < 3; ++i) d += glm::dot(o.m[i] - copy.m[i], o.m[i] - copy.m[i]);
+ repeated = repeated || d < 1e-8f;
+ }
+ if (!repeated) out.push_back(copy);
+ }
+ return out;
+}
+
+glm::vec3 symmetryPivot(const Mesh& mesh) {
+ const size_t n = mesh.positions.size();
+ if (n == 0) return glm::vec3(0.0f);
+ constexpr size_t kBlock = 1 << 16;
+ std::vector<AABB> boxes((n + kBlock - 1) / kBlock);
+ poolFor(n, [&](size_t b, size_t e) {
+ AABB box;
+ for (size_t i = b; i < e; ++i) box.expand(mesh.positions[i]);
+ boxes[b / kBlock] = box;
+ }, kBlock);
+ AABB all;
+ for (const AABB& b : boxes) {
+ all.expand(b.min);
+ all.expand(b.max);
+ }
+ return all.center();
+}
+
+std::vector<size_t> symmetryInverses(std::span<const SymCopy> copies) {
+ std::vector<size_t> out(copies.size(), 0);
+ for (size_t i = 0; i < copies.size(); ++i) {
+ const glm::mat3 t = glm::transpose(copies[i].m); // (orthogonal: the inverse)
+ float best = 1e30f;
+ for (size_t j = 0; j < copies.size(); ++j) {
+ float d = 0.0f;
+ for (int c = 0; c < 3; ++c) d += glm::dot(copies[j].m[c] - t[c], copies[j].m[c] - t[c]);
+ if (d < best) {
+ best = d;
+ out[i] = j;
+ }
+ }
+ }
+ return out;
+}
+
namespace {
// Sets bit `v` (atomically: neighbouring blocks of a parallel pass may share a word); true if it was clear.
@@ -273,7 +344,7 @@ void Sculptor::remeshDab(Mesh& mesh, BVH& bvh, const DabParams& p, Symmetry sym,
auto clock = std::chrono::steady_clock::now();
if (dyntopo.constantDetail && strokeDiagonal_ <= 0.0f) strokeDiagonal_ = glm::length(mesh.bounds().extent());
const float edge = dyntopoEdgeLength(dyntopo, p.radius, strokeDiagonal_) * scale;
- const std::vector<glm::vec3> ms = mirrors(sym);
+ const std::vector<SymCopy> ms = copies(sym);
// Over everything the brush can reach (square tips and alphas reach into their corners).
dynTopo_.remesh(mesh, bvh, p.center, p.radius * reach, edge, ms);
lastRemesh_ = true;
@@ -530,9 +601,9 @@ void Sculptor::dab(Mesh& mesh, BVH& bvh, BrushType type, const DabParams& p, Sym
if (microReady(mesh)) { // a micro level: the grid takes the dab (core/MicroSculpt.cpp)
const double k0 = micro_.findMs + micro_.kernelMs, s0 = micro_.stitchMs;
const uint64_t pts = micro_.points;
- for (const glm::vec3& m : mirrors(sym))
- micro_.dab(mesh, bvh, type, p.center * m, p.viewDir * m, p.radius, p.strength * std::clamp(p.pressure, 0.0f, 1.0f),
- p.invert, p.focal, p.alphaUp * m, false, 0.0f);
+ for (const SymCopy& m : copies(sym))
+ micro_.dab(mesh, bvh, type, m.point(p.center), m.dir(p.viewDir), p.radius, p.strength * std::clamp(p.pressure, 0.0f, 1.0f),
+ p.invert, p.focal, m.dir(p.alphaUp), false, 0.0f);
timings.kernelMs += micro_.findMs + micro_.kernelMs - k0;
timings.normalsMs += micro_.stitchMs - s0;
timings.vertices += micro_.points - pts;
@@ -546,14 +617,10 @@ void Sculptor::dab(Mesh& mesh, BVH& bvh, BrushType type, const DabParams& p, Sym
}
dabVerts_.clear();
dabLeaves_.clear();
- for (const glm::vec3& m : mirrors(sym)) {
- frameWanted_ = m == glm::vec3(1.0f); // (the unmirrored pass records lastFrame)
- DabParams mp = p;
- mp.center *= m;
- mp.viewDir *= m;
- mp.strokeDelta *= m;
- mp.alphaUp *= m;
- if (type == BrushType::Vdm) dabVdmSingle(mesh, bvh, mp, m.x * m.y * m.z);
+ for (const SymCopy& m : copies(sym)) {
+ frameWanted_ = m.identity(); // (the unmirrored pass records lastFrame)
+ const DabParams mp = m.identity() ? p : transformed(p, m);
+ if (type == BrushType::Vdm) dabVdmSingle(mesh, bvh, mp, m.handedness());
else dabSingle(mesh, bvh, type, mp);
}
updateDabNormals(mesh, bvh);
@@ -855,13 +922,9 @@ void Sculptor::dabRecipe(Mesh& mesh, BVH& bvh, const BrushRecipe& recipe, const
base.frontFacesOnly = p.frontFacesOnly || recipe.frontFacesOnly;
dabVerts_.clear();
dabLeaves_.clear();
- for (const glm::vec3& m : mirrors(sym)) {
- frameWanted_ = m == glm::vec3(1.0f); // (the unmirrored pass records lastFrame)
- DabParams mp = base;
- mp.center *= m;
- mp.viewDir *= m;
- mp.strokeDelta *= m;
- mp.alphaUp *= m;
+ for (const SymCopy& m : copies(sym)) {
+ frameWanted_ = m.identity(); // (the unmirrored pass records lastFrame)
+ const DabParams mp = m.identity() ? base : transformed(base, m);
dabRecipeSingle(mesh, bvh, recipe, mp);
}
updateDabNormals(mesh, bvh);
@@ -1011,11 +1074,11 @@ void Sculptor::beginGrab(Mesh& mesh, BVH& bvh, const DabParams& p, Symmetry sym)
// A micro level (core/Micro.h): Move deforms the base cage below it (dual scale: the detail is relative to the
// base, so it rides along in its local frame), unless asked to move the micro surface along its normals.
if (microMoveAlongNormals && microReady(mesh)) {
- for (const glm::vec3& m : mirrors(sym)) micro_.beginGrab(mesh, bvh, p.center * m, p.radius, p.focal, m);
+ for (const SymCopy& m : copies(sym)) micro_.beginGrab(mesh, bvh, m.point(p.center), p.radius, p.focal, m.m);
return;
}
- for (const glm::vec3& m : mirrors(sym)) {
- glm::vec3 c = p.center * m;
+ for (const SymCopy& m : copies(sym)) {
+ glm::vec3 c = m.point(p.center);
brushVertices(mesh, bvh, c, p.radius, verts_);
for (uint32_t v : verts_) {
float w = brushFalloff(glm::distance(mesh.positions[v], c), p.radius, p.focal) *
@@ -1024,7 +1087,7 @@ void Sculptor::beginGrab(Mesh& mesh, BVH& bvh, const DabParams& p, Symmetry sym)
grabVerts_.push_back(v);
grabWeights_.push_back(w);
}
- grabMirrors_.push_back({grabVerts_.size(), m});
+ grabMirrors_.push_back({grabVerts_.size(), m.m});
const std::span<const uint32_t> leaves = bvh.queriedLeaves();
grabLeaves_.insert(grabLeaves_.end(), leaves.begin(), leaves.end());
}
@@ -1054,7 +1117,7 @@ void Sculptor::grab(Mesh& mesh, BVH& bvh, const glm::vec3& delta) {
// One mirror after another (a vertex may be in two), each in parallel.
size_t begin = 0;
for (const auto& [end, m] : grabMirrors_) {
- const glm::vec3 dm = delta * m;
+ const glm::vec3 dm = m * delta;
scratch_.resize(end - begin);
poolFor(end - begin, [&](size_t b, size_t e) {
for (size_t i = b; i < e; ++i) scratch_[i] = dm * grabWeights_[begin + i];
diff --git a/src/core/Sculpt.h b/src/core/Sculpt.h
index 968a917d..b65a074f 100644
--- a/src/core/Sculpt.h
+++ b/src/core/Sculpt.h
@@ -7,11 +7,13 @@
#include "core/Dyntopo.h"
#include "core/Kelvinlet.h"
#include "core/Mesh.h"
+#include "core/Symmetry.h"
#include "core/Undo.h"
#include <chrono>
#include <functional>
#include <memory>
+#include <span>
#include <string>
#include <string_view>
#include <vector>
@@ -72,9 +74,17 @@ struct DabParams {
bool keepVolume = false;
};
-struct Symmetry {
- bool x = true, y = false, z = false;
-};
+// Local symmetry's centre for a Part: the middle of its bounding box (in parallel).
+glm::vec3 symmetryPivot(const Mesh& mesh);
+// A dab's parameters for one copy: its centre, view direction, stroke delta and alpha orientation moved by it.
+inline DabParams transformed(const DabParams& p, const SymCopy& c) {
+ DabParams o = p;
+ o.center = c.point(p.center);
+ o.viewDir = c.dir(p.viewDir);
+ o.strokeDelta = c.dir(p.strokeDelta);
+ o.alphaUp = c.dir(p.alphaUp);
+ return o;
+}
// --- Shared brush helpers (every brush, including future paint/mask brushes, goes through these) ---
@@ -193,8 +203,10 @@ public:
// micro displacement along its normals instead.
bool microMoveAlongNormals = false;
MicroStroke& microStroke() { return micro_; }
- // Mirror sign vectors for the enabled symmetry axes (always starts with (1,1,1)).
+ // Mirror sign vectors for the enabled symmetry axes (always starts with (1,1,1)); ignores radial and local.
static std::vector<glm::vec3> mirrors(Symmetry sym);
+ // Every copy of a stroke (core/Symmetry.h, symmetryCopies), the identity first.
+ static std::vector<SymCopy> copies(Symmetry sym) { return symmetryCopies(sym); }
// Puts every vertex the current stroke moved (or painted) back the way it
// started (the stroke stays open). DragRect re-stamps from scratch while dragging.
@@ -260,7 +272,7 @@ private:
bool topologyHeld_ = false;
glm::vec3 lastCenter_{0.0f};
float lastRadius_ = 0.0f, lastEdge_ = 0.0f;
- std::vector<glm::vec3> lastMirrors_;
+ std::vector<SymCopy> lastMirrors_;
bool active_ = false;
bool frameWanted_ = false; // the next dabSingle records lastFrame
@@ -287,10 +299,10 @@ private:
std::vector<uint8_t> firstTouch_;
std::vector<uint32_t> blockFirst_;
// Move brush: each mirror's vertices and weights (grabMirrors_: where each mirror's run ends, and its
- // signs), every vertex once (sorted), and the BVH leaves holding them.
+ // matrix), every vertex once (sorted), and the BVH leaves holding them.
std::vector<uint32_t> grabVerts_;
std::vector<float> grabWeights_;
- std::vector<std::pair<size_t, glm::vec3>> grabMirrors_;
+ std::vector<std::pair<size_t, glm::mat3>> grabMirrors_;
std::vector<uint32_t> grabAll_, grabLeaves_;
// Layer brush: per-stroke height already applied to each vertex.
diff --git a/src/core/SubTools.cpp b/src/core/SubTools.cpp
index 126ac9ad..bfc6f5dd 100644
--- a/src/core/SubTools.cpp
+++ b/src/core/SubTools.cpp
@@ -247,9 +247,9 @@ bool normalizedPiece(const Mesh& source, float size, Mesh& out) {
// point, +Y along the normal, turned by twist, with mirrored copies for symmetry; merged into the active
// SubTool as one new polygroup, one undo step.
CommandResult insertPiece(Document& doc, Mesh prim, const Args& a, const std::string& label) {
- std::vector<glm::vec3> mirrors;
+ std::vector<SymCopy> mirrors;
std::string error;
- if (!symmetryMirrorsArg(a, mirrors, error)) return {false, error};
+ if (!symmetryCopiesArg(a, doc.mesh, mirrors, error)) return {false, error};
const float size = float(std::max(argNumber(a, "size", 0.2), 1e-4));
glm::vec3 n(float(argNumber(a, "nx", 0.0)), float(argNumber(a, "ny", 1.0)), float(argNumber(a, "nz", 0.0)));
n = glm::length(n) > 1e-8f ? glm::normalize(n) : glm::vec3(0, 1, 0);
@@ -274,30 +274,34 @@ CommandResult insertPiece(Document& doc, Mesh prim, const Args& a, const std::st
for (uint32_t g : doc.mesh.polygroups) group = std::max(group, g);
prim.polygroups.assign(prim.triangles.size(), group + 1);
prim.recomputeAllNormals();
- // Symmetry: a mirrored copy across each enabled plane (through the centre, as the brushes mirror),
- // in the same polygroup and the same undo step. A copy that would land on one already there
- // (inserted on a plane itself) is left out.
+ // Symmetry: a copy for each mirror image and radial turn (about the same centre as the brushes'), in the
+ // same polygroup and the same undo step. A copy that would land on one already there (inserted on a plane
+ // or the radial axis itself) is left out.
std::vector<Mesh> copies;
std::vector<glm::vec3> placed{at};
- for (const glm::vec3& m : mirrors) {
- const glm::vec3 centre = at * m;
+ for (const SymCopy& m : mirrors) {
+ const glm::vec3 centre = m.point(at);
if (std::any_of(placed.begin(), placed.end(),
[&](const glm::vec3& p) { return glm::length(centre - p) < size * 0.25f; }))
continue;
placed.push_back(centre);
Mesh copy = prim;
- for (auto& p : copy.positions) p *= m;
- if (m.x * m.y * m.z < 0.0f) // a reflection turns the triangles inside out: wind them back
+ for (auto& p : copy.positions) p = m.point(p);
+ if (m.handedness() < 0.0f) // a reflection turns the triangles inside out: wind them back
for (auto& t : copy.triangles) std::swap(t.y, t.z);
copy.recomputeAllNormals();
copies.push_back(std::move(copy));
}
+ bool radial = false; // (a copy turned other than by a half turn: not just mirrored)
+ for (const SymCopy& m : mirrors)
+ for (int i = 0; i < 3; ++i)
+ for (int j = 0; j < 3; ++j) radial = radial || (i != j && m.m[i][j] != 0.0f);
std::vector<const Mesh*> parts{&doc.mesh, &prim};
for (const Mesh& c2 : copies) parts.push_back(&c2);
Mesh merged = mergeMeshes(parts);
const size_t tris = prim.triangleCount() * (1 + copies.size());
doc.replaceMeshUndoable(std::move(merged), "Insert " + label);
- return {true, "Inserted " + (copies.empty() ? "a " + label : std::to_string(copies.size() + 1) + " " + label + "s (mirrored)") +
+ return {true, "Inserted " + (copies.empty() ? "a " + label : std::to_string(copies.size() + 1) + " " + label + (radial ? "s (radial)" : "s (mirrored)")) +
" (" + std::to_string(tris) + " triangles, face group " + std::to_string(group + 1) + ")"};
}
diff --git a/src/core/Symmetry.h b/src/core/Symmetry.h
new file mode 100644
index 00000000..0bfe91c6
--- /dev/null
+++ b/src/core/Symmetry.h
@@ -0,0 +1,55 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+#pragma once
+
+// Stroke symmetry: X / Y / Z mirrors, radial copies around an axis, about the world origin or a local pivot.
+// Sculptor::copies (core/Sculpt.h) turns the settings into the list of copies every brush applies.
+
+#include <glm/glm.hpp>
+
+#include <cstddef>
+#include <span>
+#include <vector>
+
+namespace sf {
+
+struct Symmetry {
+ bool x = true, y = false, z = false;
+ // Radial symmetry (#63): while `radialEnabled`, `radial` copies of every stroke turned evenly around
+ // `radialAxis` (0 X, 1 Y, 2 Z); 2 to kMaxRadial (1 is none). With mirror axes on too, each mirror image gets
+ // its copies (mirror + radial = 2N copies with one axis). The count stays while radial is toggled off.
+ bool radialEnabled = false;
+ int radial = 8;
+ int radialAxis = 1;
+ // Local symmetry: mirror planes and the radial axis go through `pivot` (the app sets it to the active Part's
+ // centre) instead of the world origin.
+ bool local = false;
+ glm::vec3 pivot{0.0f};
+ static constexpr int kMaxRadial = 64;
+ bool radialOn() const { return radialEnabled && radial > 1; }
+ // Only the X / Y / Z mirrors through the origin (what Sculptor::mirrors can express).
+ bool mirrorOnly() const { return !radialOn() && (!local || pivot == glm::vec3(0.0f)); }
+};
+
+// One copy of a symmetric stroke: a rotation (and reflection) `m` about `pivot`. Points move as
+// pivot + m (p - pivot), directions as m d; the first copy Sculptor::copies makes is the identity.
+struct SymCopy {
+ glm::mat3 m{1.0f};
+ glm::vec3 pivot{0.0f};
+ glm::vec3 point(const glm::vec3& p) const { return pivot + m * (p - pivot); }
+ glm::vec3 dir(const glm::vec3& d) const { return m * d; }
+ glm::vec3 inversePoint(const glm::vec3& p) const { return pivot + glm::transpose(m) * (p - pivot); }
+ glm::vec3 inverseDir(const glm::vec3& d) const { return glm::transpose(m) * d; }
+ // -1 when the copy is mirrored an odd number of times (det m < 0): stamps flip, pseudovectors flip once more.
+ float handedness() const { return glm::determinant(m) < 0.0f ? -1.0f : 1.0f; }
+ bool identity() const { return m == glm::mat3(1.0f); }
+};
+
+// Every copy of a stroke the symmetry makes: each mirror image (in Sculptor::mirrors' order) times each radial
+// turn, duplicates dropped (X and Z mirrors with an even radial count repeat a half turn), the identity first.
+// Defined in Sculpt.cpp.
+std::vector<SymCopy> symmetryCopies(const Symmetry& sym);
+// For each copy, the index of its inverse in the same list (a mirror is its own; a turn's is the opposite turn).
+std::vector<size_t> symmetryInverses(std::span<const SymCopy> copies);
+
+} // namespace sf
diff --git a/src/core/Texture.cpp b/src/core/Texture.cpp
index 1f1ce28c..04e4019b 100644
--- a/src/core/Texture.cpp
+++ b/src/core/Texture.cpp
@@ -1382,12 +1382,12 @@ size_t TexturePainter::dab(Mesh& mesh, const BVH& bvh, const DabParams& p, const
using Mirror = DabMirror;
std::vector<Mirror> mirrors;
- for (const glm::vec3& m : Sculptor::mirrors(sym)) {
+ for (const SymCopy& m : Sculptor::copies(sym)) {
Mirror mi;
- mi.center = p.center * m;
- mi.viewDir = p.viewDir * m;
+ mi.center = m.point(p.center);
+ mi.viewDir = m.dir(p.viewDir);
// The alpha's frame on the view plane (as recipe brushes orient it).
- glm::vec3 aUp = p.alphaUp * m;
+ glm::vec3 aUp = m.dir(p.alphaUp);
aUp -= mi.viewDir * glm::dot(aUp, mi.viewDir);
mi.aUp = glm::length(aUp) > 1e-6f ? glm::normalize(aUp) : glm::vec3(0, 1, 0);
mi.aRight = glm::cross(mi.aUp, -mi.viewDir);
diff --git a/src/core/Vdm.cpp b/src/core/Vdm.cpp
index 29c3ef1b..8a6d995f 100644
--- a/src/core/Vdm.cpp
+++ b/src/core/Vdm.cpp
@@ -1,6 +1,7 @@
// SculptForge - open source digital sculpting
// SPDX-License-Identifier: GPL-3.0-or-later
#include "core/Vdm.h"
+#include "core/Masking.h"
#include "core/BrushLibrary.h"
#include "core/Commands.h"
@@ -925,10 +926,8 @@ void registerVdmCommands(CommandRegistry& registry) {
p.alphaUp = up * std::cos(angle) - right * std::sin(angle);
p.vdm = doc.brushVdm.get();
Symmetry sym{false, false, false};
- const std::string axes = lower(argString(a, "symmetry"));
- sym.x = axes.find('x') != std::string::npos;
- sym.y = axes.find('y') != std::string::npos;
- sym.z = axes.find('z') != std::string::npos;
+ std::string symError;
+ if (!symmetryArg(a, doc.mesh, sym, symError)) return {false, symError};
if (!doc.sculptor.beginStroke(doc.mesh, "VDM", doc.activeLayer))
return {false, "Active layer weight is 0 - raise it to sculpt into the layer"};
doc.sculptor.dab(doc.mesh, doc.bvh, BrushType::Vdm, p, sym);
diff --git a/tests/test_radial_symmetry.cpp b/tests/test_radial_symmetry.cpp
new file mode 100644
index 00000000..bef67be0
--- /dev/null
+++ b/tests/test_radial_symmetry.cpp
@@ -0,0 +1,432 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// Radial and local symmetry (#63, core/Symmetry.h): the copies Sculptor::copies makes (turns, mirror + radial,
+// a local pivot), their inverses, and that brushes, masks, vertex paint, visibility, insert and dynamic topology
+// follow every copy, from C++ and through the commands.
+#include "TestHarness.h"
+
+#include "core/Commands.h"
+#include "core/Masking.h"
+#include "core/Polypaint.h"
+#include "core/Primitives.h"
+
+#include <algorithm>
+#include <chrono>
+#include <cmath>
+#include <cstdlib>
+
+using namespace sf;
+
+namespace {
+
+const CommandRegistry& registry() {
+ static CommandRegistry r;
+ return r;
+}
+
+bool near(const glm::vec3& a, const glm::vec3& b, float eps = 1e-4f) { return glm::length(a - b) < eps; }
+
+bool orthonormal(const glm::mat3& m) {
+ const glm::mat3 t = glm::transpose(m) * m;
+ for (int i = 0; i < 3; ++i)
+ for (int j = 0; j < 3; ++j)
+ if (std::abs(t[i][j] - (i == j ? 1.0f : 0.0f)) > 1e-5f) return false;
+ return true;
+}
+
+Symmetry radial(int n, int axis, bool x = false) {
+ Symmetry s{x, false, false};
+ s.radialEnabled = true;
+ s.radial = n;
+ s.radialAxis = axis;
+ return s;
+}
+
+// The images of `p` under every copy, each distinct one once.
+std::vector<glm::vec3> images(const Symmetry& s, const glm::vec3& p) {
+ std::vector<glm::vec3> out;
+ for (const SymCopy& c : Sculptor::copies(s)) {
+ const glm::vec3 q = c.point(p);
+ if (std::none_of(out.begin(), out.end(), [&](const glm::vec3& o) { return near(o, q); })) out.push_back(q);
+ }
+ return out;
+}
+
+float maxMoved(const Mesh& before, const Mesh& after, const glm::vec3& around, float radius) {
+ float best = 0.0f;
+ for (size_t v = 0; v < before.vertexCount(); ++v)
+ if (glm::distance(before.positions[v], around) < radius)
+ best = std::max(best, glm::distance(before.positions[v], after.positions[v]));
+ return best;
+}
+
+} // namespace
+
+TEST(radial_copies_count_and_order) {
+ // Mirror-only symmetry is unchanged: the same copies, in the same order, as the mirror signs.
+ const Symmetry xz{true, false, true};
+ const std::vector<SymCopy> m = Sculptor::copies(xz);
+ const std::vector<glm::vec3> signs = Sculptor::mirrors(xz);
+ CHECK(m.size() == signs.size());
+ for (size_t i = 0; i < m.size() && i < signs.size(); ++i)
+ CHECK(near(m[i].point(glm::vec3(1, 2, 3)), glm::vec3(1, 2, 3) * signs[i]));
+ // Radial off (or a count of 1): just the identity.
+ Symmetry off{false, false, false};
+ off.radial = 8;
+ CHECK(Sculptor::copies(off).size() == 1);
+ CHECK(Sculptor::copies(radial(1, 1)).size() == 1);
+ // N copies; mirror + radial = 2N; the identity first; every copy a rotation or reflection.
+ for (int n : {2, 3, 5, 8, 16, 64}) {
+ const std::vector<SymCopy> r = Sculptor::copies(radial(n, 1));
+ CHECK(int(r.size()) == n);
+ CHECK(r[0].identity());
+ for (const SymCopy& c : r) CHECK(orthonormal(c.m) && c.handedness() > 0.0f);
+ const std::vector<SymCopy> mr = Sculptor::copies(radial(n, 1, true));
+ CHECK(int(mr.size()) == 2 * n);
+ int mirrored = 0;
+ for (const SymCopy& c : mr) mirrored += c.handedness() < 0.0f;
+ CHECK(mirrored == n);
+ }
+ // X and Z mirrors make a half turn about Y, which an even radial count already has: no duplicates.
+ Symmetry xzr = radial(8, 1);
+ xzr.x = xzr.z = true;
+ CHECK(Sculptor::copies(xzr).size() == 16);
+ Symmetry xzr3 = radial(3, 1);
+ xzr3.x = xzr3.z = true;
+ CHECK(Sculptor::copies(xzr3).size() == 12);
+}
+
+TEST(radial_transform_maths) {
+ // N turns about each axis: the images of a point off the axis are N points evenly round it, at the same
+ // height and distance, a turn of 2 pi / N apart; a point on the axis stays put.
+ for (int axis = 0; axis < 3; ++axis)
+ for (int n : {3, 4, 7, 12}) {
+ glm::vec3 p(0.0f), up(0.0f);
+ p[(axis + 1) % 3] = 1.0f;
+ p[axis] = 0.25f;
+ up[axis] = 1.0f;
+ const std::vector<SymCopy> r = Sculptor::copies(radial(n, axis));
+ std::vector<glm::vec3> q;
+ for (const SymCopy& c : r) q.push_back(c.point(p));
+ CHECK(int(images(radial(n, axis), p).size()) == n);
+ for (const glm::vec3& v : q) {
+ CHECK(std::abs(v[axis] - 0.25f) < 1e-5f);
+ CHECK(std::abs(glm::length(v - up * 0.25f) - 1.0f) < 1e-5f);
+ }
+ // Copy k turns by k steps: the angle between copy 1's image and the original is one step.
+ const float step = 2.0f * 3.14159265f / float(n);
+ const glm::vec3 a = glm::normalize(p - up * 0.25f), b = glm::normalize(q[1] - up * 0.25f);
+ CHECK(std::abs(std::acos(std::clamp(glm::dot(a, b), -1.0f, 1.0f)) - step) < 1e-4f);
+ CHECK(near(r[1].point(up * 0.7f), up * 0.7f));
+ // Directions turn with points; the inverse undoes a copy.
+ for (const SymCopy& c : r) {
+ CHECK(near(c.inversePoint(c.point(p)), p));
+ CHECK(near(c.point(p) - c.point(glm::vec3(0.0f)), c.dir(p)));
+ }
+ }
+ // Quarter turns are exact (duplicates compare equal; a 90 degree copy of X is exactly Z or -Z).
+ const std::vector<SymCopy> four = Sculptor::copies(radial(4, 1));
+ for (const SymCopy& c : four)
+ for (int i = 0; i < 3; ++i)
+ for (int j = 0; j < 3; ++j) CHECK(c.m[i][j] == std::round(c.m[i][j]));
+ // Inverses: copy i then its inverse is the identity; a mirror is its own, a turn's is the opposite turn.
+ Symmetry mr = radial(6, 2, true);
+ const std::vector<SymCopy> all = Sculptor::copies(mr);
+ const std::vector<size_t> inv = symmetryInverses(all);
+ for (size_t i = 0; i < all.size(); ++i) {
+ const glm::mat3 id = all[inv[i]].m * all[i].m;
+ CHECK(near(id[0], glm::vec3(1, 0, 0)) && near(id[1], glm::vec3(0, 1, 0)) && near(id[2], glm::vec3(0, 0, 1)));
+ if (all[i].handedness() < 0.0f) CHECK(inv[i] == i);
+ }
+ CHECK(inv[0] == 0);
+ CHECK(inv[1] == 5); // a sixth of a turn undone by five sixths
+}
+
+TEST(radial_mirror_plus_radial) {
+ // X mirror + 4 turns about Y: 8 images of a general point, all at its height and distance from the axis,
+ // half of them mirror images (the point with x negated, turned).
+ const glm::vec3 p(0.8f, 0.3f, 0.2f);
+ const std::vector<glm::vec3> q = images(radial(4, 1, true), p);
+ CHECK(q.size() == 8);
+ const float r = std::hypot(p.x, p.z);
+ for (const glm::vec3& v : q) CHECK(std::abs(v.y - p.y) < 1e-5f && std::abs(std::hypot(v.x, v.z) - r) < 1e-5f);
+ CHECK(std::any_of(q.begin(), q.end(), [&](const glm::vec3& v) { return near(v, glm::vec3(-p.x, p.y, p.z)); }));
+ // A point on the mirror plane: its mirror image is itself, so 4 distinct images.
+ CHECK(images(radial(4, 1, true), glm::vec3(0.0f, 0.3f, 1.0f)).size() == 4);
+ // Mirror and radial about the same axis: X mirror with turns about X.
+ CHECK(images(radial(5, 0, true), glm::vec3(0.5f, 0.2f, 0.7f)).size() == 10);
+}
+
+TEST(radial_local_pivot) {
+ // Local symmetry: the mirror plane and the radial axis go through the pivot, not the origin.
+ Symmetry s{true, false, false};
+ s.local = true;
+ s.pivot = glm::vec3(5.0f, 1.0f, -2.0f);
+ std::vector<SymCopy> c = Sculptor::copies(s);
+ CHECK(c.size() == 2);
+ CHECK(near(c[1].point(glm::vec3(6.0f, 3.0f, 4.0f)), glm::vec3(4.0f, 3.0f, 4.0f)));
+ CHECK(near(c[1].dir(glm::vec3(1.0f, 0.0f, 0.0f)), glm::vec3(-1.0f, 0.0f, 0.0f)));
+ // Without `local` the pivot is ignored.
+ s.local = false;
+ CHECK(near(Sculptor::copies(s)[1].point(glm::vec3(6.0f, 3.0f, 4.0f)), glm::vec3(-6.0f, 3.0f, 4.0f)));
+ // Radial about the pivot: images circle it; the pivot itself stays.
+ Symmetry r = radial(6, 1);
+ r.local = true;
+ r.pivot = glm::vec3(5.0f, 1.0f, -2.0f);
+ for (const SymCopy& k : Sculptor::copies(r)) {
+ CHECK(near(k.point(r.pivot), r.pivot));
+ CHECK(std::abs(glm::distance(k.point(r.pivot + glm::vec3(2.0f, 0.5f, 0.0f)), r.pivot) -
+ glm::length(glm::vec3(2.0f, 0.5f, 0.0f))) < 1e-4f);
+ }
+ CHECK(!r.mirrorOnly());
+ // The Part's centre: the middle of its bounding box.
+ Mesh m = makeIcosphere(2, 1.0f);
+ for (auto& p : m.positions) p += glm::vec3(3.0f, -1.0f, 0.5f);
+ CHECK(near(symmetryPivot(m), glm::vec3(3.0f, -1.0f, 0.5f), 1e-3f));
+}
+
+TEST(radial_stroke_moves_every_copy) {
+ // A Standard dab with 6 copies about Y moves the surface at each copy's centre, about equally; nothing
+ // between them.
+ Document d = makeDoc(makeIcosphere(5, 1.0f));
+ const Mesh before = d.mesh;
+ const Symmetry s = radial(6, 1);
+ DabParams p;
+ p.center = glm::normalize(glm::vec3(1.0f, 0.2f, 0.0f));
+ p.viewDir = -p.center;
+ p.radius = 0.2f;
+ p.strength = 0.5f;
+ CHECK(d.sculptor.beginStroke(d.mesh, "Standard"));
+ d.sculptor.dab(d.mesh, d.bvh, BrushType::Standard, p, s);
+ d.undo.push(d.sculptor.endStroke());
+ float lo = 1e30f, hi = 0.0f;
+ for (const SymCopy& c : Sculptor::copies(s)) {
+ const float moved = maxMoved(before, d.mesh, c.point(p.center), p.radius);
+ lo = std::min(lo, moved);
+ hi = std::max(hi, moved);
+ // Halfway to the next copy: untouched.
+ const glm::vec3 between = Sculptor::copies(radial(12, 1))[1].point(c.point(p.center));
+ CHECK(maxMoved(before, d.mesh, between, 0.05f) == 0.0f);
+ }
+ CHECK(lo > 0.0f);
+ CHECK(hi < lo * 1.5f);
+ // Undo gives back the stroke-start mesh.
+ CHECK(d.undo.undo(d.mesh, d.bvh));
+ float diff = 0.0f;
+ for (size_t v = 0; v < before.vertexCount(); ++v) diff = std::max(diff, glm::distance(before.positions[v], d.mesh.positions[v]));
+ CHECK(diff == 0.0f);
+}
+
+TEST(radial_mask_paint_and_grab) {
+ // The mask brush, vertex paint and Move follow every copy too.
+ Document d = makeDoc(makeIcosphere(4, 1.0f));
+ const Symmetry s = radial(4, 1);
+ DabParams p;
+ p.center = glm::vec3(1.0f, 0.0f, 0.0f);
+ p.viewDir = glm::vec3(-1.0f, 0.0f, 0.0f);
+ p.radius = 0.25f;
+ p.strength = 1.0f;
+ CHECK(d.sculptor.beginStroke(d.mesh, "Mask"));
+ d.sculptor.dabMask(d.mesh, d.bvh, p, s);
+ d.undo.push(d.sculptor.endStroke());
+ for (const SymCopy& c : Sculptor::copies(s)) {
+ float m = 0.0f;
+ for (size_t v = 0; v < d.mesh.vertexCount(); ++v)
+ if (glm::distance(d.mesh.positions[v], c.point(p.center)) < 0.05f) m = std::max(m, d.mesh.maskAt(uint32_t(v)));
+ CHECK(m > 0.5f);
+ }
+ d.mesh.clearMask();
+ CHECK(d.sculptor.beginStroke(d.mesh, "Paint"));
+ CHECK(paintDab(d.sculptor, d.mesh, d.bvh, p, glm::vec3(1.0f, 0.0f, 0.0f), s) > 0);
+ d.undo.push(d.sculptor.endStroke());
+ for (const SymCopy& c : Sculptor::copies(s)) {
+ float red = 0.0f;
+ for (size_t v = 0; v < d.mesh.vertexCount(); ++v)
+ if (glm::distance(d.mesh.positions[v], c.point(p.center)) < 0.05f)
+ red = std::max(red, d.mesh.colorAt(uint32_t(v)).x - d.mesh.colorAt(uint32_t(v)).y);
+ CHECK(red > 0.5f);
+ }
+ // Move: each copy's region goes its own way (the drag turned with it).
+ const Mesh before = d.mesh;
+ CHECK(d.sculptor.beginStroke(d.mesh, "Move"));
+ d.sculptor.beginGrab(d.mesh, d.bvh, p, s);
+ d.sculptor.grab(d.mesh, d.bvh, glm::vec3(0.1f, 0.0f, 0.0f));
+ d.undo.push(d.sculptor.endStroke());
+ for (const SymCopy& c : Sculptor::copies(s)) {
+ glm::vec3 moved(0.0f);
+ for (size_t v = 0; v < d.mesh.vertexCount(); ++v)
+ if (glm::distance(before.positions[v], c.point(p.center)) < 0.05f) moved += d.mesh.positions[v] - before.positions[v];
+ CHECK(glm::dot(glm::normalize(moved), c.dir(glm::vec3(1.0f, 0.0f, 0.0f))) > 0.99f);
+ }
+}
+
+TEST(radial_dynamic_topology_adds_detail_on_every_copy) {
+ Document d = makeDoc(makeIcosphere(3, 1.0f));
+ d.sculptor.dyntopo.enabled = true;
+ d.sculptor.dyntopo.detail = 0.75f;
+ const Symmetry s = radial(5, 1);
+ const size_t before = d.mesh.triangleCount();
+ auto trianglesNear = [&](const glm::vec3& c) {
+ size_t n = 0;
+ for (const glm::uvec3& t : d.mesh.triangles)
+ n += glm::distance((d.mesh.positions[t.x] + d.mesh.positions[t.y] + d.mesh.positions[t.z]) / 3.0f, c) < 0.2f;
+ return n;
+ };
+ const glm::vec3 at = glm::normalize(glm::vec3(1.0f, 0.3f, 0.2f));
+ std::vector<size_t> start;
+ for (const SymCopy& c : Sculptor::copies(s)) start.push_back(trianglesNear(c.point(at)));
+ CHECK(d.sculptor.beginStroke(d.mesh, "Standard"));
+ for (int i = 0; i < 6; ++i) {
+ DabParams p;
+ p.center = at;
+ p.viewDir = -at;
+ p.radius = 0.25f;
+ p.strength = 0.3f;
+ d.sculptor.dab(d.mesh, d.bvh, BrushType::Standard, p, s);
+ }
+ d.undo.push(d.sculptor.endStroke());
+ CHECK(d.mesh.triangleCount() > before);
+ size_t k = 0;
+ for (const SymCopy& c : Sculptor::copies(s)) CHECK(trianglesNear(c.point(at)) > start[k++] * 2);
+ // A rotationally symmetric mesh gets matching topology: a 16-sided cylinder (each side the same quads) with
+ // 4 turns about its axis: every vertex's quarter-turn image is a vertex after the remesh, and every operation
+ // found its images (the turns are not their own inverses, unlike mirrors).
+ Document r = makeDoc(makeCylinder(16, 2.0f));
+ r.sculptor.dyntopo.enabled = true;
+ r.sculptor.dyntopo.detail = 0.8f;
+ const Symmetry s4 = radial(4, 1);
+ CHECK(r.sculptor.beginStroke(r.mesh, "Standard"));
+ DabParams q;
+ q.center = glm::vec3(1.0f, 0.1f, 0.15f);
+ q.viewDir = glm::vec3(-1.0f, 0.0f, 0.0f);
+ q.radius = 0.35f;
+ q.strength = 0.3f;
+ RayHit hit;
+ if (r.bvh.raycast(r.mesh, glm::vec3(3.0f, 0.1f, 0.3f), glm::vec3(-1.0f, 0.0f, 0.0f), hit)) q.center = hit.position;
+ const size_t cylBefore = r.mesh.triangleCount();
+ for (int i = 0; i < 3; ++i) r.sculptor.dab(r.mesh, r.bvh, BrushType::Standard, q, s4);
+ r.undo.push(r.sculptor.endStroke());
+ CHECK(r.mesh.triangleCount() > cylBefore);
+ size_t unmatched = 0;
+ const SymCopy quarter = Sculptor::copies(s4)[1];
+ for (const glm::vec3& v : r.mesh.positions) {
+ const glm::vec3 w = quarter.point(v);
+ bool found = false;
+ for (const glm::vec3& u : r.mesh.positions) found = found || glm::distance(u, w) < 1e-3f;
+ unmatched += !found;
+ }
+ CHECK(unmatched == 0);
+ CHECK(r.sculptor.dynamicTopology().stats.unpaired == 0);
+}
+
+TEST(radial_commands) {
+ // Python / CLI parity: stroke, mask_rect, hide_rect and insert_primitive take radial, radial_axis and local.
+ for (const char* name : {"stroke", "vdm_stamp", "mask_rect", "mask_lasso", "hide_rect", "hide_lasso", "insert_primitive", "insert_mesh"}) {
+ const Command* c = registry().find(name);
+ CHECK(c != nullptr);
+ if (!c) continue;
+ int found = 0;
+ for (const ParamSpec& p : c->params) found += p.name == "radial" || p.name == "radial_axis" || p.name == "local";
+ CHECK(found == 3);
+ }
+ Document d;
+ CHECK(registry().execute(d, "new_sphere", {{"subdivisions", 4.0}}).ok);
+ const Mesh start = d.mesh;
+ CHECK(registry().execute(d, "stroke", {{"points", std::string("0.9,0.2,0.3 0.9,0.25,0.3")}, {"view", std::string("-1,0,0")},
+ {"radius", 0.15}, {"radial", 6.0}, {"radial_axis", std::string("y")}}).ok);
+ // The stroke landed on the +X side and was copied round Y: something moved on the -X side too.
+ float movedFar = 0.0f;
+ for (size_t v = 0; v < start.vertexCount(); ++v)
+ if (start.positions[v].x < -0.5f) movedFar = std::max(movedFar, glm::distance(start.positions[v], d.mesh.positions[v]));
+ CHECK(movedFar > 0.0f);
+ // Bad values are errors.
+ CHECK(!registry().execute(d, "mask_rect", {{"radial", 1.5}}).ok);
+ CHECK(!registry().execute(d, "mask_rect", {{"radial", 65.0}}).ok);
+ CHECK(!registry().execute(d, "mask_rect", {{"radial", 4.0}, {"radial_axis", std::string("w")}}).ok);
+ // mask_rect: a small rectangle at the right side of the front view masks 4 regions round Y.
+ const Args rect = {{"x0", 0.55}, {"y0", -0.1}, {"x1", 0.75}, {"y1", 0.1}};
+ CHECK(registry().execute(d, "mask_rect", rect).ok);
+ size_t one = 0;
+ for (size_t v = 0; v < d.mesh.vertexCount(); ++v) one += d.mesh.maskAt(uint32_t(v)) > 0.5f;
+ CHECK(registry().execute(d, "mask_clear").ok);
+ Args rr = rect;
+ rr["radial"] = 4.0;
+ CHECK(registry().execute(d, "mask_rect", rr).ok);
+ size_t four = 0;
+ for (size_t v = 0; v < d.mesh.vertexCount(); ++v) four += d.mesh.maskAt(uint32_t(v)) > 0.5f;
+ CHECK(one > 0 && four > one * 2);
+ CHECK(registry().execute(d, "mask_clear").ok);
+ // hide_rect keeps the rectangle and its copies.
+ Args hr = rect;
+ hr["radial"] = 3.0;
+ CHECK(registry().execute(d, "hide_rect", hr).ok);
+ CHECK(d.mesh.hasHidden());
+ CHECK(registry().execute(d, "show_all").ok);
+ // insert_primitive: one cone per copy, one undo step.
+ const size_t tris = d.mesh.triangleCount();
+ const Args cone = {{"type", std::string("cone")}, {"x", 1.0}, {"y", 0.0}, {"z", 0.0}, {"nx", 1.0}, {"ny", 0.0}, {"nz", 0.0},
+ {"size", 0.2}, {"radial", 5.0}};
+ const CommandResult r = registry().execute(d, "insert_primitive", cone);
+ CHECK(r.ok);
+ CHECK(r.message.find("5 cones (radial)") != std::string::npos);
+ const size_t five = d.mesh.triangleCount() - tris;
+ CHECK(registry().execute(d, "undo").ok);
+ Args single = cone;
+ single.erase("radial");
+ CHECK(registry().execute(d, "insert_primitive", single).ok);
+ CHECK(five == (d.mesh.triangleCount() - tris) * 5);
+ CHECK(registry().execute(d, "undo").ok);
+ // local: about the Part's own centre. Move the sphere off the origin; a local X mirror lands on the sphere.
+ CHECK(registry().execute(d, "transform", {{"translate", std::string("3,0,0")}, {"all", true}}).ok);
+ const Mesh moved = d.mesh;
+ CHECK(registry().execute(d, "stroke", {{"points", std::string("3.9,0.2,0.3 3.9,0.25,0.3")}, {"view", std::string("-1,0,0")},
+ {"radius", 0.15}, {"symmetry", std::string("x")}, {"local", true}}).ok);
+ float movedMirror = 0.0f;
+ for (size_t v = 0; v < moved.vertexCount(); ++v)
+ if (moved.positions[v].x < 2.5f) movedMirror = std::max(movedMirror, glm::distance(moved.positions[v], d.mesh.positions[v]));
+ CHECK(movedMirror > 0.0f);
+}
+
+TEST(radial_sixteen_copies_on_a_dense_mesh_stays_interactive) {
+ // N = 16 copies on a dense sphere: the time per dab (all 16 copies) stays interactive. CI uses a 1.3M-triangle
+ // sphere; SF_RADIAL_BENCH=1 measures the 20M one (and X only, 16 turns, 16 turns + X) for the record.
+ const bool full = std::getenv("SF_RADIAL_BENCH") != nullptr;
+ Document d;
+ CHECK(registry().execute(d, "new_sphere", {{"triangles", full ? 20000000.0 : 1300000.0}}).ok);
+ auto measure = [&](const Symmetry& s, float radius) {
+ CHECK(d.sculptor.beginStroke(d.mesh, "Standard"));
+ const int dabs = 30;
+ double total = 0.0;
+ for (int i = 0; i < dabs; ++i) {
+ DabParams p;
+ p.center = glm::normalize(glm::vec3(1.0f, 0.02f * float(i), 0.1f));
+ p.viewDir = -p.center;
+ p.radius = radius;
+ p.strength = 0.4f;
+ const auto t0 = std::chrono::steady_clock::now();
+ d.sculptor.dab(d.mesh, d.bvh, BrushType::Standard, p, s);
+ if (i > 0) total += std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t0).count();
+ }
+ d.undo.push(d.sculptor.endStroke());
+ if (full) {
+ const SculptTimings& t = d.sculptor.timings;
+ std::printf(" (totals: kernel %.0f ms, normals %.0f ms, bvh %.0f ms, %llu vertices)\n", t.kernelMs, t.normalsMs,
+ t.bvhMs, (unsigned long long)t.vertices);
+ d.sculptor.timings = SculptTimings{};
+ }
+ return total / (dabs - 1);
+ };
+ const double ms = measure(radial(16, 1), 0.08f);
+ std::printf(" radial 16 on %zu triangles, radius 0.08: %.2f ms per dab (all copies)\n", d.mesh.triangleCount(), ms);
+ CHECK(ms < 250.0); // (a loaded CI machine; typically a few ms)
+ if (full) {
+ for (float radius : {0.08f, 0.2f}) {
+ const double x = measure(Symmetry{true, false, false}, radius);
+ const double r16 = measure(radial(16, 1), radius);
+ const double rx = measure(radial(16, 1, true), radius);
+ std::printf(" radius %.2f: X only %.2f ms, radial 16 %.2f ms, radial 16 + X (32 copies) %.2f ms per dab\n",
+ double(radius), x, r16, rx);
+ }
+ }
+}
diff --git a/tests/ui/air_strokes.sfui b/tests/ui/air_strokes.sfui
index db6302de..76cd705b 100644
--- a/tests/ui/air_strokes.sfui
+++ b/tests/ui/air_strokes.sfui
@@ -48,7 +48,7 @@ expect_value masked > 0
expect_value camera_yaw == $yaw1
remember masked m0
hold ctrl
-drag_path -0.3 -0.3 -0.3 -0.3
+drag_path -0.3 -0.05 -0.3 -0.05
hold none
expect_value masked > $m0
key ctrl+shift+a
diff --git a/tests/ui/ctrl_brushes.sfui b/tests/ui/ctrl_brushes.sfui
index a4d64906..1d929f5a 100644
--- a/tests/ui/ctrl_brushes.sfui
+++ b/tests/ui/ctrl_brushes.sfui
@@ -38,7 +38,7 @@ expect_value mask_shape == 2
# The picked MaskRect masks with Ctrl+drag (starting on the background) and Tool > Masking agrees.
hold ctrl
-drag_path -0.2 -0.2 0.5 1.2
+drag_path -0.2 -0.05 0.5 1.2
hold none
expect_value masked > 1000
key ctrl+z
@@ -73,7 +73,7 @@ hold none
expect_value hidden > 1000
remember hidden kept
hold ctrl+shift+alt
-drag_path -0.2 -0.2 0.45 -0.2 0.45 1.2 -0.2 1.2
+drag_path -0.2 -0.05 0.45 -0.05 0.45 1.2 -0.2 1.2
hold none
expect_value hidden > $kept
click "Visibility"
@@ -89,7 +89,7 @@ expect_value hide_shape == 2
# SelectRect from the background, then with Alt from the model. (X symmetry is on: the mirror image of the
# rectangle is kept too, so it stops short of the middle to leave something to hide.)
hold ctrl+shift
-drag_path -0.2 -0.2 0.3 1.2
+drag_path -0.2 -0.05 0.3 1.2
hold none
expect_value hidden > 1000
remember hidden kept
diff --git a/tests/ui/mask_lasso.sfui b/tests/ui/mask_lasso.sfui
index 5753d5cb..b26d2fd5 100644
--- a/tests/ui/mask_lasso.sfui
+++ b/tests/ui/mask_lasso.sfui
@@ -19,7 +19,7 @@ hold none
# Ctrl+drag a lasso that starts on the background around the left half: it masks inside, front and back.
hold ctrl
-drag_path -0.2 -0.2 0.45 -0.2 0.55 0.5 0.45 1.2 -0.2 1.2 keep
+drag_path -0.2 -0.05 0.45 -0.05 0.55 0.5 0.45 1.2 -0.2 1.2 keep
shot lasso_drawing
release
hold none
@@ -42,7 +42,7 @@ shot rect_unmasked
# Ctrl+drag a rectangle over the top masks it; undo takes back just that selection.
hold ctrl
-drag_path 0.6 -0.3 1.3 0.3
+drag_path 0.6 -0.05 1.3 0.3
hold none
expect_value masked > $unmasked
key ctrl+z
@@ -50,7 +50,7 @@ expect_value masked == $unmasked
# A Ctrl+drag selection that covers none of the model clears the mask (ZBrush); undo brings it back.
hold ctrl
-drag_path 1.3 -0.3 1.6 0.0
+drag_path 1.3 -0.05 1.6 0.0
hold none
expect_value masked == 0
key ctrl+z
@@ -70,7 +70,7 @@ click "Clear##mask"
key x
expect_value symmetry_x == 1
hold ctrl
-drag_path -0.2 -0.2 0.45 -0.2 0.55 0.5 0.45 1.2 -0.2 1.2
+drag_path -0.2 -0.05 0.45 -0.05 0.55 0.5 0.45 1.2 -0.2 1.2
hold none
expect_value masked > $lasso*1.6
remember masked lasso_mirrored
@@ -108,7 +108,7 @@ click "Clear##mask"
# MaskPen, Ctrl+drag starting on the background (#48): a mask rectangle is drawn while dragging and masks what it
# covers (the left half); one that covers none of the model clears the mask, as before.
hold ctrl
-drag_path -0.3 -0.3 0.45 1.3 keep
+drag_path -0.3 -0.05 0.45 1.3 keep
expect_value selection_shown == 1
shot pen_rect_drawing
release
@@ -118,7 +118,7 @@ expect_value masked > 2000
expect_value masked < 7000
remember masked pen_rect
hold ctrl
-drag_path 1.3 -0.3 1.6 0.0 keep
+drag_path 1.3 -0.05 1.6 0.0 keep
expect_value selection_shown == 1
release
hold none
@@ -138,7 +138,7 @@ click "Visibility"
click "Select Lasso##select.lasso"
expect_value hidden == 0
hold ctrl+shift
-drag_path -0.2 -0.2 0.7 -0.2 0.7 1.2 -0.2 1.2 keep
+drag_path -0.2 -0.05 0.7 -0.05 0.7 1.2 -0.2 1.2 keep
shot hide_lasso_drawing
release
hold none
diff --git a/tests/ui/radial_symmetry.sfui b/tests/ui/radial_symmetry.sfui
new file mode 100644
index 00000000..60a252ab
--- /dev/null
+++ b/tests/ui/radial_symmetry.sfui
@@ -0,0 +1,77 @@
+# Radial and local symmetry (#63): the R toggle on the top shelf and in Transform > Symmetry, Radial Count and the
+# axis, every copy's brush cursor, strokes that land on every copy, mask rectangles that follow them, projects
+# that keep the settings, and Local about the Part's own centre.
+run new_sphere subdivisions=5
+key f
+expect_value symmetry_radial == 0
+expect_value symmetry_copies == 2
+
+# Ctrl+hover explains it; a click turns it on with 8 copies about Y (16 with X on).
+hold ctrl
+hover "R##transform.symmetry_radial"
+expect_help "Radial symmetry"
+hold none
+click "R##transform.symmetry_radial"
+expect_value symmetry_radial == 8
+expect_value radial_axis == 1
+expect_value symmetry_copies == 16
+
+# The Transform palette: Radial Count and the axis.
+click "Transform##palette.transform"
+expect "##radialcount"
+expect_text "Radial Count 8"
+expect "Y axis##transform.radial_axis_y"
+shot transform-palette
+key escape
+
+# Seen from above: the brush cursor shows on every copy (8 turns, each mirrored: the mirror images of a cursor
+# off the plane land on other turns' places only when the count is even, so all 16 show).
+camera 0 89
+key f
+hover_model 0.8 0.5
+expect_value surface_cursor == 1
+expect_value cursor_copies >= 8
+shot cursors-from-above
+
+# X off: a stroke near the rim lands 8 times, once per copy.
+key x
+expect_value symmetry_copies == 8
+snapshot
+stroke 0.82 0.45 0.86 0.55
+expect_value moved > 0
+remember moved one_stroke
+shot radial-stroke
+key ctrl+z
+
+# 4 copies through the command (the same as the slider): the stroke moves about half as many vertices.
+run stroke points=0.9,0.3,0.2 view=-1,0,0 radius=0.15 radial=4
+key ctrl+z
+
+# A mask rectangle follows the copies too (#51 for mirrors, now for turns).
+remember masked unmasked
+hold ctrl
+drag_path 0.75 0.4 0.95 0.4 0.95 0.6 0.75 0.6
+hold none
+expect_value masked > $unmasked
+remember masked radial_mask
+shot radial-mask
+run mask_clear
+
+# Projects keep radial symmetry.
+run save_project path=sf_ui_radial.sfproj
+click "R##transform.symmetry_radial"
+expect_value symmetry_radial == 0
+run open path=sf_ui_radial.sfproj
+expect_value symmetry_radial == 8
+expect_value radial_axis == 1
+
+# Local: about the Part's own centre. Move the sphere off the origin; the centre follows it.
+click "Transform##palette.transform"
+click "Local##transform.symmetry_local"
+expect_value symmetry_local == 1
+key escape
+run transform translate=2,0,0 all=true
+hover_model 0.5 0.5
+expect_value symmetry_pivot_x > 1.9
+expect_value symmetry_pivot_x < 2.1
+shot local
diff --git a/tests/ui/timeline.sfui b/tests/ui/timeline.sfui
index 359c5d2a..8a13363b 100644
--- a/tests/ui/timeline.sfui
+++ b/tests/ui/timeline.sfui
@@ -1,5 +1,6 @@
# Sculpt Timeline (PanelTimeline.cpp, core/Timeline.h): the strip records every stroke, the scrubber travels in the
# history, sculpting from an earlier point keeps the old continuation as a branch.
+# The strip is at the top of the viewport by default (#63; Preferences > Interface > Timeline position).
run new_sphere subdivisions=5
expect_value timeline_steps == 0
stroke 0.35 0.40 0.60 0.45
@@ -11,9 +12,9 @@ expect_value timeline_cursor == 4
shot strokes
# Drag the scrubber to the start of the track, then back to the middle.
-view_drag 0.60 0.887 0.075 0.887
+view_drag 0.60 0.177 0.075 0.177
expect_value timeline_cursor == 0
-view_drag 0.09 0.887 0.40 0.887
+view_drag 0.09 0.177 0.40 0.177
expect_value timeline_cursor < 4
expect_value timeline_cursor > 0
shot scrubbed
diff --git a/tests/ui/timeline_position.sfui b/tests/ui/timeline_position.sfui
new file mode 100644
index 00000000..332c1838
--- /dev/null
+++ b/tests/ui/timeline_position.sfui
@@ -0,0 +1,40 @@
+# Timeline position (#63): the Sculpt Timeline strip runs along the top of the viewport by default, away from the
+# brush shelf, below the top shelf, with the axis gizmo below it; Preferences > Interface puts it back at the
+# bottom, and Store Config keeps the choice.
+run new_sphere subdivisions=4
+stroke 0.35 0.40 0.60 0.45
+expect_value timeline_top == 1
+expect_value timeline_y >= 0
+expect_value timeline_y < 0.05
+expect_value axis_gizmo_y > 0.1
+shot top
+
+# Scrubbing works at the top: drag to the start of the track.
+view_drag 0.60 0.177 0.075 0.177
+expect_value timeline_cursor == 0
+
+# Preferences > Interface > Timeline position: Bottom.
+click "Preferences##palette.preferences"
+click "Interface##preferences.interface"
+expect_text "Timeline position"
+expect "Top of viewport##view.timeline_top"
+click "Bottom##view.timeline_bottom"
+expect_value timeline_top == 0
+shot preferences-interface
+key escape
+expect_value timeline_y > 0.8
+expect_value axis_gizmo_y < 0.1
+shot bottom
+
+# Store Config keeps it; Restore Custom UI reads it back.
+key ctrl+shift+i
+expect_status "UI configuration stored"
+click "Preferences##palette.preferences"
+click "Top of viewport##view.timeline_top"
+key escape
+expect_value timeline_top == 1
+key f3
+type "##Command palette" "restore custom"
+key enter
+expect_status "Custom UI restored"
+expect_value timeline_top == 0
diff --git a/tests/ui/zbrush_feel.sfui b/tests/ui/zbrush_feel.sfui
index ca6348c8..dd871aba 100644
--- a/tests/ui/zbrush_feel.sfui
+++ b/tests/ui/zbrush_feel.sfui
@@ -160,7 +160,7 @@ expect_value camera_distance == $d0
# --- Visibility: Ctrl+Shift+click on a partly hidden mesh hides the group clicked ---
# Hide the top with Ctrl+Shift+Alt+drag, then Ctrl+Shift+click the equator band (the new group).
hold ctrl+shift+alt
-drag_path -0.2 -0.2 1.2 0.2
+drag_path -0.2 -0.05 1.2 0.2
hold none
expect_value hidden > 0
remember hidden h1