Radial symmetry for brushes

Strokes can repeat around an axis through the mesh center, 2 to 32 copies, on their own or with
the X/Y/Z mirrors (each mirror is spread too).

- Symmetry gains radial (copies) and axis (X/Y/Z, default Y), serde defaults; sanitized clamps
- symmetry copies are marked and paint where symmetry puts them: the camera visibility and
  back-face tests apply to the stroke itself only, so copies on the far side of the model paint
  (mirror Z included); they still only paint surfaces facing the copy
- tool.brush {symmetryRadial, symmetryAxis}, shown in its result as radialSymmetry; Properties >
  Lazy mouse and symmetry: Radial copies slider and axis; translations in all eight languages
- tests: copies a quarter turn apart, with mirrors, clamping; an engine stroke paints the back of
  a sphere through radial symmetry
This commit is contained in:
bflatastic committed 2026-11-01 15:04:23 +07:00
1 parent 27a695648d
commit afdea4a6dd
17 files changed
+151 -16

No files matched your search

+1 -1
View File
@@ -14,7 +14,7 @@ end to end today (engine + UI + automation + tests), not what is planned.
| Project and files | 8 | 95% | New project from glTF/GLB, FBX (binary and ASCII, 6.x and 7.x), COLLADA, **USD (usda, usdc, usdz)**, **Alembic (Ogawa)**, OBJ, PLY, STL or built-in meshes (auto-unwrap when UVs are missing; a `.gltf`'s buffers and images and a loose USD layer's textures are read from its folder and kept in the project), **project templates** (built-in and saved from a project), `.tcraft` open/save/save as/save a copy, autosave, recent files, drag and drop, reimport mesh **with strokes preserved on the surface**, image resources, remove unused resources, OBJ, textured GLB and **USD** mesh export, browser open/save/download | HDF5 Alembic; Alembic animation (first sample only) |
| Texture sets | 6 | 95% | One set per material, **UDIM / UV tiles** (auto-detected or switched on later with resampling, **a resolution per tile**, one texture per tile at its own size, `$udim` export), list with visibility, sizes 128–8192 with resampling, add/remove channels (19 channel types incl. coat, sheen, anisotropy and scattering), height strength, normal format | Filter radii and height slopes of a tile smaller than its atlas block follow the block |
| Layer stack | 16 | 96% | Paint, fill, folder and **instance** layers; 32 per-channel blend modes and opacities; white/black/painted masks with **mask with height**; generator, fill, levels, invert/threshold, color selection, compare, blur, sharpen and HSL effects on masks and layer content; anchor points; smart masks; mask view (Alt+click); duplicate, group, drag to reorder, rename, color tags, copy/cut/paste (also as instance) across sets, flatten, instantiate across sets, save layers as smart materials; **27 library filters** (adjustments, blur/sharpen/high pass, bevel, glow, edge detect, warps, mosaic, baked lighting, material finishes); **geometry masks** (a layer on chosen mesh parts) | A few niche filters of the reference app's catalog |
| Painting tools | 14 | 88% | Paint, eraser, projection with image stencils, polygon fill, **path** and **lasso fill**, smudge, clone, color picker, quick mask, Shift+click lines with preview, 2D view painting; size, flow, stroke opacity, spacing, hardness, angle, follow path, jitters, alignment, angle fade, backface culling, lazy mouse, X/Y/Z symmetry, pen pressure, procedural and image alphas, **particle brush** | Pen tilt (not exposed by the windowing layer) |
| Painting tools | 14 | 88% | Paint, eraser, projection with image stencils, polygon fill, **path** and **lasso fill**, smudge, clone, color picker, quick mask, Shift+click lines with preview, 2D view painting; size, flow, stroke opacity, spacing, hardness, angle, follow path, jitters, alignment, angle fade, backface culling, lazy mouse, X/Y/Z mirror and **radial symmetry**, pen pressure, procedural and image alphas, **particle brush** | Pen tilt (not exposed by the windowing layer) |
| Materials and assets | 8 | 86% | 48 procedural materials (incl. car paint, velvet, brushed steel, skin, wax), 21 smart materials, 18 smart masks, **67 procedural brush alphas**, 22 procedurals, 6 environments plus imported HDR/EXR panoramas, image resources, a user smart material library, a tabbed shelf with search and **drag and drop** onto layers and the viewport | A smaller bundled library than the reference app's |
| Baking | 10 | 100% | AO, curvature (also from the normal map), thickness, world normal, position, ID, normal, height, **bent normals, opacity, color map and world-space direction**; **high-poly meshes**, cage, frontal/rear distances, average normals, **match by mesh name**; per-texture-set selection, common and per-map parameters, progress and cancel; high-poly base color textures embedded or in files beside a `.gltf`, FBX or USD layer | — |
| Viewport and display | 12 | 95% | PBR with image-based lighting, 6 procedural environments or imported HDR/EXR panoramas with exposure, rotation, blur, opacity, ACES/linear tone mapping, HDR pipeline with bloom, vignette, sharpen and grain, key-light shadows, 4× MSAA plus idle temporal accumulation, channel / mesh-map / mask / UV checker views, 3D and 2D wireframes, brush cursor, axis gizmos, subsurface scattering blur, **depth of field**, saved cameras and cameras from glTF, FBX, COLLADA and USD files, displacement (also in shadows and the path tracers), **path-traced Rendering mode** (F10, on the GPU or the CPU) with environment importance sampling and an edge-aware **denoiser** | Hardware ray tracing |
+13 -1
View File
@@ -25,7 +25,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Brush settings",
[],
None,
"{size?: 0..100, flow?: 0..100, opacity?: 0..100, spacing?: 1..1000, hardness?: 0..100, angle?, followPath?, alignment?: tangent|camera, lazy?, jitterSize?, jitterAngle?, jitterFlow?, jitterPosition?, alpha?: procedural name | {image: resource name} | {library: id (alpha.list)}, backfaceCulling?, symmetryX?, symmetryY?, symmetryZ?, minSize?, smudgeStrength?: 0..100, cloneSource?: composite|layer (what the Clone tool copies), particles?: {enabled?, count?: 1..16, lifetime?: 1..128 steps, gravity?: 0..2}}",
"{size?: 0..100, flow?: 0..100, opacity?: 0..100, spacing?: 1..1000, hardness?: 0..100, angle?, followPath?, alignment?: tangent|camera, lazy?, jitterSize?, jitterAngle?, jitterFlow?, jitterPosition?, alpha?: procedural name | {image: resource name} | {library: id (alpha.list)}, backfaceCulling?, symmetryX?, symmetryY?, symmetryZ?, symmetryRadial?: 0..32 copies around symmetryAxis?: x|y|z (default y), minSize?, smudgeStrength?: 0..100, cloneSource?: composite|layer (what the Clone tool copies), particles?: {enabled?, count?: 1..16, lifetime?: 1..128 steps, gravity?: 0..2}}",
always,
brush
),
@@ -150,6 +150,17 @@ fn brush(s: &mut Session, p: &Value) -> Result<Value> {
*slot = v;
}
}
if let Some(v) = f32p(p, "symmetryRadial") {
b.symmetry.radial = v.clamp(0.0, 32.0) as u8;
}
if let Some(a) = strp(p, "symmetryAxis") {
b.symmetry.axis = match a.to_ascii_lowercase().as_str() {
"x" => 0,
"y" => 1,
"z" => 2,
_ => return Err(bad("tool.brush", format!("unknown symmetry axis `{a}` (x, y or z)"))),
};
}
if let Some(v) = boolp(p, "screenSpace") {
b.screen_space = v;
}
@@ -187,6 +198,7 @@ pub(crate) fn brush_json(s: &Session) -> Value {
(None, None) => json!(b.alpha.label()),
},
"backfaceCulling": b.backface_culling, "symmetry": [b.symmetry.x, b.symmetry.y, b.symmetry.z],
"radialSymmetry": { "copies": b.symmetry.radial, "axis": (["x", "y", "z"].get(b.symmetry.axis as usize)) },
"smudgeStrength": s.tool.smudge_strength * 100.0, "particles": b.particles,
"cloneSource": if s.tool.clone_from == CloneFrom::Layer { "layer" } else { "composite" },
})
+14
View File
@@ -129,3 +129,17 @@ fn particle_brush_paints_below_the_start_and_is_deterministic() {
assert!(highest + 20 > start, "nothing well above the start: {highest}");
assert_eq!(rows, particle_rows());
}
#[test]
fn radial_symmetry_paints_copies_around_the_axis() {
let mut s = session(primitives::sphere(1.0, 48, 24));
assert!(execute(&mut s, "tool.brush", &json!({"symmetryRadial": 2, "symmetryAxis": "w"})).is_err());
let r = execute(&mut s, "tool.brush", &json!({"symmetryRadial": 2, "symmetryAxis": "y"})).unwrap();
assert_eq!(r["radialSymmetry"], json!({"copies": 2, "axis": "y"}));
execute(&mut s, "tool.stroke", &json!({"points": [[200, 200]]})).unwrap();
s.update();
assert!(red_at(&s, 200.0, 200.0));
// Half a turn around Y: the copy faces the other way.
s.camera.yaw = std::f32::consts::PI;
assert!(red_at(&s, 200.0, 200.0), "the radial copy on the back");
}
+20 -3
View File
@@ -126,17 +126,33 @@ pub(crate) fn smoothstep(e0: f32, e1: f32, x: f32) -> f32 {
t * t * (3.0 - 2.0 * t)
}
/// Mirror symmetry through the mesh center.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
/// Mirror and radial symmetry through the mesh center.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Symmetry {
pub x: bool,
pub y: bool,
pub z: bool,
/// Radial symmetry: copies spread evenly around `axis` (0 or 1: off; at most 32).
#[serde(default)]
pub radial: u8,
/// Axis of radial symmetry: 0 = X, 1 = Y, 2 = Z.
#[serde(default = "radial_axis")]
pub axis: u8,
}
fn radial_axis() -> u8 {
1
}
impl Default for Symmetry {
fn default() -> Self {
Symmetry { x: false, y: false, z: false, radial: 0, axis: radial_axis() }
}
}
impl Symmetry {
pub fn any(&self) -> bool {
self.x || self.y || self.z
self.x || self.y || self.z || self.radial > 1
}
}
@@ -254,6 +270,7 @@ impl BrushSettings {
jitter_flow: f(self.jitter_flow, 0.0, 1.0, 0.0),
jitter_position: f(self.jitter_position, 0.0, 4.0, 0.0),
depth: f(self.depth, 0.05, 4.0, 1.0),
symmetry: Symmetry { radial: self.symmetry.radial.min(32), axis: self.symmetry.axis.min(2), ..self.symmetry },
particles: Particles {
enabled: self.particles.enabled,
count: self.particles.count.clamp(1, 16),
+12 -1
View File
@@ -89,7 +89,18 @@ mod tests {
let bvh = Bvh::new(&m);
let cam = OrbitCamera::default();
let ctx = PickCtx { mesh: &m, bvh: &bvh, camera: &cam, viewport: Vec2::new(100.0, 100.0) };
let s = Stamp { center: Vec3::ZERO, normal: Vec3::Z, tangent: Vec3::X, bitangent: Vec3::Y, radius: 0.1, flow: 1.0, hardness: 0.5, depth: 1.0, seed: 3 };
let s = Stamp {
center: Vec3::ZERO,
normal: Vec3::Z,
tangent: Vec3::X,
bitangent: Vec3::Y,
radius: 0.1,
flow: 1.0,
hardness: 0.5,
depth: 1.0,
seed: 3,
copy: false,
};
let p = Particles { enabled: true, count: 4, lifetime: 20, gravity: 1.0 };
let a = emit(&ctx, &p, &s);
assert_eq!(a, emit(&ctx, &p, &s));
+17 -5
View File
@@ -179,18 +179,20 @@ fn scan_triangle(ctx: &RasterCtx, s: &Stamp, t: u32, w: u32, h: u32, fade_lo: f3
let n = (*na * b0 + *nb * b1 + *nc * b2).try_normalize().unwrap_or(s.normal);
let to_eye = (ctx.eye - p).try_normalize().unwrap_or(n);
let facing = n.dot(to_eye);
if ctx.backface_culling && facing <= 0.0 {
// Symmetry copies paint where the camera may not see (the back of the model).
let culled = ctx.backface_culling && !s.copy;
if culled && facing <= 0.0 {
continue;
}
if n.dot(s.normal) <= 0.0 {
continue;
}
if let Some(depth) = ctx.depth
if let Some(depth) = ctx.depth.filter(|_| !s.copy)
&& !depth.visible(p)
{
continue;
}
let fade = if ctx.backface_culling { smoothstep(fade_lo, fade_hi, facing) } else { 1.0 };
let fade = if culled { smoothstep(fade_lo, fade_hi, facing) } else { 1.0 };
let a = shape.sample(lx, ly, s.hardness, s.seed) * s.flow * fade;
if a > 0.0 {
texels.push((x, y, a));
@@ -245,8 +247,18 @@ mod tests {
angle_fade: (70.0, 85.0),
shape: Shape { alpha: crate::BrushAlpha::Round, image: None, library: None, level: 0 },
};
let st =
Stamp { center: Vec3::ZERO, normal: Vec3::Y, tangent: Vec3::X, bitangent: Vec3::Z, radius: 0.25, flow: 1.0, hardness: 0.9, depth: 1.0, seed: 0 };
let st = Stamp {
center: Vec3::ZERO,
normal: Vec3::Y,
tangent: Vec3::X,
bitangent: Vec3::Z,
radius: 0.25,
flow: 1.0,
hardness: 0.9,
depth: 1.0,
seed: 0,
copy: false,
};
rasterize(&mut canvas, &ctx, &[st]);
// Plane is 2 units over 128 texels: radius 0.25 = 16 texels around the center (64, 64).
let at = |x: u32, y: u32| from_u16(canvas.alpha.get(x, y)[0]);
+44 -3
View File
@@ -51,6 +51,8 @@ pub struct Stamp {
pub depth: f32,
/// Varies procedural alphas per stamp.
pub seed: u32,
/// A symmetry copy: it paints where symmetry puts it, whether the camera sees that or not.
pub copy: bool,
}
/// An in-progress stroke.
@@ -190,10 +192,11 @@ impl Stroke {
let r = radius * (1.0 + jitter(2, s.jitter_size)).max(0.05);
let offset = (tangent * jitter(3, 1.0) + bitangent * jitter(4, 1.0)) * s.jitter_position * radius;
let flow = (s.flow * (1.0 - jitter(5, s.jitter_flow).abs())).clamp(0.0, 1.0);
Stamp { center: hit.pos + offset, normal, tangent, bitangent, radius: r, flow, hardness: s.hardness, depth: s.depth, seed: n }
Stamp { center: hit.pos + offset, normal, tangent, bitangent, radius: r, flow, hardness: s.hardness, depth: s.depth, seed: n, copy: false }
}
/// Mirror copies of a stamp for the enabled symmetry axes.
/// Mirror copies of a stamp for the enabled symmetry axes, then radial copies of it and
/// its mirrors.
fn mirrors(&self, s: &Stamp) -> Vec<Stamp> {
let sym = self.settings.symmetry;
if !sym.any() {
@@ -209,7 +212,22 @@ impl Stroke {
let m = |v: Vec3| v * f;
let normal = m(s.normal);
let tangent = m(s.tangent);
out.push(Stamp { center: self.center + m(s.center - self.center), normal, tangent, bitangent: normal.cross(tangent), ..*s });
out.push(Stamp { center: self.center + m(s.center - self.center), normal, tangent, bitangent: normal.cross(tangent), copy: true, ..*s });
}
if sym.radial > 1 {
let axis = [Vec3::X, Vec3::Y, Vec3::Z].get(sym.axis as usize).copied().unwrap_or(Vec3::Y);
let base: Vec<Stamp> = std::iter::once(*s).chain(out.iter().copied()).collect();
for k in 1..sym.radial {
let q = Quat::from_axis_angle(axis, f32::from(k) * std::f32::consts::TAU / f32::from(sym.radial));
out.extend(base.iter().map(|b| Stamp {
center: self.center + q * (b.center - self.center),
normal: q * b.normal,
tangent: q * b.tangent,
bitangent: q * b.bitangent,
copy: true,
..*b
}));
}
}
out
}
@@ -274,4 +292,27 @@ mod tests {
assert_eq!(out.len(), 2);
assert!((out[0].center.x + out[1].center.x).abs() < 1e-4);
}
#[test]
fn radial_symmetry_spreads_copies_around_the_axis() {
let (m, b, c) = ctx_parts();
let ctx = PickCtx { mesh: &m, bvh: &b, camera: &c, viewport: Vec2::new(400.0, 400.0) };
let mut st = BrushSettings::default();
st.symmetry.radial = 4;
let mut s = Stroke::new(&st, &m);
let out = s.add(&ctx, Vec2::new(250.0, 180.0), 1.0);
assert_eq!(out.len(), 4);
// Same height and distance from the Y axis, a quarter turn apart: they sum to the axis.
let sum = out.iter().fold(Vec3::ZERO, |a, x| a + x.center);
assert!(sum.x.abs() < 1e-3 && sum.z.abs() < 1e-3, "{sum}");
assert!(out.iter().all(|x| (x.center.y - out[0].center.y).abs() < 1e-4 && (x.normal.dot(x.tangent)).abs() < 1e-4));
// With mirror X as well: each mirror is spread too.
st.symmetry.x = true;
let mut s = Stroke::new(&st, &m);
assert_eq!(s.add(&ctx, Vec2::new(250.0, 180.0), 1.0).len(), 8);
// Out-of-range settings are clamped.
st.symmetry = crate::brush::Symmetry { radial: 200, axis: 9, ..st.symmetry };
let clean = st.sanitized().symmetry;
assert_eq!((clean.radial, clean.axis), (32, 2));
}
}
+12
View File
@@ -1047,6 +1047,18 @@ fn brush_section(app: &mut TextureCraftApp, ui: &mut Ui) {
ui.checkbox(&mut b.symmetry.y, tr("Mirror Y"));
ui.checkbox(&mut b.symmetry.z, tr("Mirror Z"));
});
let mut copies = f32::from(b.symmetry.radial);
if slider(ui, tr("Radial copies"), &mut copies, 0.0..=32.0, 0).changed() {
b.symmetry.radial = copies as u8;
}
ui.add_enabled_ui(b.symmetry.radial > 1, |ui| {
ui.horizontal(|ui| {
ui.label(tr("Radial axis"));
for (k, name) in ["X", "Y", "Z"].into_iter().enumerate() {
ui.selectable_value(&mut b.symmetry.axis, k as u8, name);
}
});
});
});
*b = b.sanitized();
}
+2
View File
@@ -632,6 +632,8 @@ pub const TABLE: &[(&str, &str)] = &[
("Quarter", "Viertel"),
("Quick mask", "Schnellmaske"),
("Quit", "Beenden"),
("Radial axis", "Radiale Achse"),
("Radial copies", "Radiale Kopien"),
("Radius (texels at 2K)", "Radius (Texel bei 2K)"),
("RENDERING", "RENDERING"),
("Rebind any menu item, tool or command", "Beliebige Menüeinträge, Werkzeuge oder Befehle neu belegen"),
+2
View File
@@ -626,6 +626,8 @@ pub const TABLE: &[(&str, &str)] = &[
("Quarter", "Cuarto"),
("Quick mask", "Máscara rápida"),
("Quit", "Salir"),
("Radial axis", "Eje radial"),
("Radial copies", "Copias radiales"),
("Radius (texels at 2K)", "Radio (téxeles a 2K)"),
("RENDERING", "RENDERIZADO"),
("Rebind any menu item, tool or command", "Reasignar cualquier elemento de menú, herramienta o comando"),
+2
View File
@@ -635,6 +635,8 @@ pub const TABLE: &[(&str, &str)] = &[
("Quarter", "Quart"),
("Quick mask", "Masque rapide"),
("Quit", "Quitter"),
("Radial axis", "Axe radial"),
("Radial copies", "Copies radiales"),
("Radius (texels at 2K)", "Rayon (texels en 2K)"),
("RENDERING", "RENDU"),
("Rebind any menu item, tool or command", "Réattribuer n'importe quel élément de menu, outil ou commande"),
+2
View File
@@ -632,6 +632,8 @@ pub const TABLE: &[(&str, &str)] = &[
("Quarter", "Un quarto"),
("Quick mask", "Maschera rapida"),
("Quit", "Esci"),
("Radial axis", "Asse radiale"),
("Radial copies", "Copie radiali"),
("Radius (texels at 2K)", "Raggio (texel a 2K)"),
("RENDERING", "RENDERING"),
("Rebind any menu item, tool or command", "Riassegna qualsiasi voce di menu, strumento o comando"),
+2
View File
@@ -614,6 +614,8 @@ pub const TABLE: &[(&str, &str)] = &[
("Quarter", "1/4"),
("Quick mask", "クイックマスク"),
("Quit", "終了"),
("Radial axis", "放射軸"),
("Radial copies", "放射状コピー"),
("Radius (texels at 2K)", "半径 (2K時のテクセル)"),
("RENDERING", "レンダリング"),
("Rebind any menu item, tool or command", "メニュー項目、ツール、コマンドのショートカットを再割り当て"),
+2
View File
@@ -608,6 +608,8 @@ pub const TABLE: &[(&str, &str)] = &[
("Quarter", "1/4"),
("Quick mask", "퀵 마스크"),
("Quit", "종료"),
("Radial axis", "방사형 축"),
("Radial copies", "방사형 복사본"),
("Radius (texels at 2K)", "반경 (2K 기준 텍셀)"),
("RENDERING", "렌더링"),
("Rebind any menu item, tool or command", "메뉴 항목, 도구 또는 명령의 단축키를 다시 지정합니다"),
+2
View File
@@ -626,6 +626,8 @@ pub const TABLE: &[(&str, &str)] = &[
("Quarter", "Um quarto"),
("Quick mask", "Máscara rápida"),
("Quit", "Sair"),
("Radial axis", "Eixo radial"),
("Radial copies", "Cópias radiais"),
("Radius (texels at 2K)", "Raio (texels em 2K)"),
("RENDERING", "RENDERIZAÇÃO"),
("Rebind any menu item, tool or command", "Reatribuir qualquer item de menu, ferramenta ou comando"),
+2
View File
@@ -560,6 +560,8 @@ pub const TABLE: &[(&str, &str)] = &[
("Quarter", "1/4"),
("Quick mask", "快速遮罩"),
("Quit", "退出"),
("Radial axis", "径向轴"),
("Radial copies", "径向副本"),
("Radius (texels at 2K)", "半径(2K 下的纹素数)"),
("RENDERING", "渲染"),
("Rebind any menu item, tool or command", "重新绑定任意菜单项、工具或命令"),
+2 -2
View File
@@ -6,8 +6,8 @@ Everything TextureCraft does today, by area. What's still missing is in [`ROADMA
- **Brushes** with size, flow, stroke opacity, spacing, hardness, angle and follow path; size,
angle, flow and position jitter; tangent or camera alignment, angle fade, backface culling, lazy
mouse, X/Y/Z mirror symmetry and pen pressure. **67 procedural brush alphas** in their own shelf
tab, or any imported image as the alpha.
mouse, X/Y/Z mirror and radial symmetry (copies paint the far side too) and pen pressure.
**67 procedural brush alphas** in their own shelf tab, or any imported image as the alpha.
- **Tools:** paint, eraser, **projection** with image stencils (hold S to move, turn and scale the
stencil), polygon fill (triangle, UV island or the whole mesh), **path** and **lasso fill**, a
**particle brush**, **smudge**, **clone** (V + click sets the source), color picker, Shift+click