From 7e78a2cba6b8a18a133780493ac33837d6b19816 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 2 Nov 2026 06:02:22 +0700 Subject: [PATCH] Material channels: Alt+click keeps one channel Alt+click on a channel of a fill's or the brush's Material section turns that channel on and every other one off (one undo step for a fill). tool.material and layer.fill.set take solo: true for the same. Fixes #74. --- crates/engine/src/layer_cmds.rs | 14 +++++++++++--- crates/engine/src/tool_cmds.rs | 13 ++++++++++++- crates/engine/tests/painter_gaps.rs | 13 +++++++++++++ crates/ui-egui/src/dock.rs | 13 +++++++++---- crates/ui-egui/src/i18n.rs | 1 + crates/ui-egui/src/i18n/ar.rs | 1 + crates/ui-egui/src/i18n/de.rs | 1 + crates/ui-egui/src/i18n/es.rs | 1 + crates/ui-egui/src/i18n/fr.rs | 1 + crates/ui-egui/src/i18n/it.rs | 1 + crates/ui-egui/src/i18n/ja.rs | 1 + crates/ui-egui/src/i18n/ko.rs | 1 + crates/ui-egui/src/i18n/pt_br.rs | 1 + crates/ui-egui/src/i18n/zh_hans.rs | 1 + docs/features.md | 1 + 15 files changed, 56 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/layer_cmds.rs b/crates/engine/src/layer_cmds.rs index e7831f12..e7575baf 100644 --- a/crates/engine/src/layer_cmds.rs +++ b/crates/engine/src/layer_cmds.rs @@ -25,7 +25,7 @@ pub fn specs() -> Vec { "Set fill source", [], None, - "{layer? | effect?: content fill effect id, channel, color?|value?|procedural?: kind, scale?, seed?, contrast?, balance?, invert?, low?, high?|image?|anchor?: anchor effect id, anchorChannel?, enabled?}", + "{layer? | effect?: content fill effect id, channel, color?|value?|procedural?: kind, scale?, seed?, contrast?, balance?, invert?, low?, high?|image?|anchor?: anchor effect id, anchorChannel?, enabled?, solo?: true (this channel on, every other one off)}", has_layer, fill_set ), @@ -303,7 +303,9 @@ fn fill_mut(s: &mut Session, target: FillTarget) -> Result<&mut Fill> { fn fill_set(s: &mut Session, p: &Value) -> Result { let target = fill_target(s, p, "layer.fill.set")?; let ch = channel_param("layer.fill.set", p, "channel")?.ok_or_else(|| bad("layer.fill.set", "`channel` is required"))?; - let enabled = boolp(p, "enabled"); + // `solo`: this channel on, every other one off. + let solo = boolp(p, "solo") == Some(true); + let enabled = if solo { Some(true) } else { boolp(p, "enabled") }; let source = if let Some(kind) = strp(p, "procedural") { let kind = ProceduralKind::parse(kind).ok_or_else(|| bad("layer.fill.set", format!("unknown procedural `{kind}`")))?; let mut pr = Procedural::new(kind); @@ -336,7 +338,7 @@ fn fill_set(s: &mut Session, p: &Value) -> Result { } else if enabled.is_some() { None } else { - return Err(bad("layer.fill.set", "give `color`, `value`, `procedural`, `image`, `anchor` or `enabled`")); + return Err(bad("layer.fill.set", "give `color`, `value`, `procedural`, `image`, `anchor`, `enabled` or `solo`")); }; s.edit("Set fill", |s| { let f = fill_mut(s, target)?; @@ -348,6 +350,9 @@ fn fill_set(s: &mut Session, p: &Value) -> Result { FillTarget::Effect(_) => { let src = source.unwrap_or_else(|| f.source(ch)); f.sources.insert(ch, src); + if solo { + f.sources.retain(|c, _| *c == ch); + } } FillTarget::Layer(id) => { if let Some(src) = source { @@ -359,6 +364,9 @@ fn fill_set(s: &mut Session, p: &Value) -> Result { } else { l.channels.entry(ch).or_default(); } + if solo { + l.channels.retain(|c, _| *c == ch); + } } } Ok(()) diff --git a/crates/engine/src/tool_cmds.rs b/crates/engine/src/tool_cmds.rs index 465726f2..7fa5fdab 100644 --- a/crates/engine/src/tool_cmds.rs +++ b/crates/engine/src/tool_cmds.rs @@ -42,7 +42,15 @@ pub fn specs() -> Vec { "procedural": BrushAlpha::ALL.map(BrushAlpha::label), "library": alphas::library().iter().map(|a| json!({"id": a.id, "label": a.label, "category": a.category})).collect::>(), }))), - cmd!("tool.material", "Tool material", [], None, "{channel, color?|value?, enabled?} or {maskValue?: 0..1}", always, material), + cmd!( + "tool.material", + "Tool material", + [], + None, + "{channel, color?|value?, enabled?, solo?: true (paint this channel only)} or {maskValue?: 0..1}", + always, + material + ), cmd!( "tool.stencil", "Projection stencil", @@ -232,6 +240,9 @@ fn material(s: &mut Session, p: &Value) -> Result { } None => {} } + if boolp(p, "solo") == Some(true) { + s.tool.enabled = std::iter::once(c).collect(); + } } s.revision = s.revision.wrapping_add(1); Ok(json!({ diff --git a/crates/engine/tests/painter_gaps.rs b/crates/engine/tests/painter_gaps.rs index fc82a4e5..48f0b3de 100644 --- a/crates/engine/tests/painter_gaps.rs +++ b/crates/engine/tests/painter_gaps.rs @@ -152,6 +152,19 @@ fn geometry_masks_limit_layers_to_mesh_parts() { assert!(texel(&mut s, 0.1, 0.9) && texel(&mut s, 0.6, 0.4)); } +#[test] +fn solo_keeps_one_material_channel() { + let mut s = session(); + let r = execute(&mut s, "tool.material", &json!({"channel": "roughness", "solo": true})).unwrap(); + assert_eq!(r["enabled"], json!(["roughness"]), "the brush paints roughness only"); + let fill = id(execute(&mut s, "layer.add.fill", &Value::Null).unwrap(), "layer"); + assert!(s.doc.project.layer(fill).unwrap().channels.len() > 1); + execute(&mut s, "layer.fill.set", &json!({"channel": "metallic", "solo": true})).unwrap(); + assert_eq!(s.doc.project.layer(fill).unwrap().channels.keys().copied().collect::>(), [Channel::Metallic]); + execute(&mut s, "edit.undo", &Value::Null).unwrap(); + assert!(s.doc.project.layer(fill).unwrap().channels.len() > 1, "one undo step"); +} + #[test] fn decals_project_an_image_from_a_frame_placed_on_the_surface() { let mut s = session(); diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs index 41332911..cc54ae8c 100644 --- a/crates/ui-egui/src/dock.rs +++ b/crates/ui-egui/src/dock.rs @@ -1222,6 +1222,9 @@ fn text_section(app: &mut TextureCraftApp, ui: &mut Ui) { }); } +/// Tooltip of the material channel chips. +pub(crate) const SOLO_HINT: &str = "Click: turn this channel on or off. Alt+click: this channel only"; + fn material_section(app: &mut TextureCraftApp, ui: &mut Ui) { let tk = Tokens::get(ui.ctx()); ui.label(caption(tr("Material"))); @@ -1229,8 +1232,9 @@ fn material_section(app: &mut TextureCraftApp, ui: &mut Ui) { ui.horizontal_wrapped(|ui| { for c in &chans { let on = app.session.tool.enabled.contains(c); - if chip(ui, tr(c.short()), on).clicked() { - app.run("tool.material", json!({"channel": c.id(), "enabled": !on})); + if chip(ui, tr(c.short()), on).on_hover_text(tr(SOLO_HINT)).clicked() { + let solo = ui.input(|i| i.modifiers.alt); + app.run("tool.material", json!({"channel": c.id(), "enabled": solo || !on, "solo": solo})); } } }); @@ -1328,8 +1332,9 @@ fn fill_editor(app: &mut TextureCraftApp, ui: &mut Ui, fill: &Fill, base: &Value ui.horizontal_wrapped(|ui| { for c in &chans { let enabled = on.contains(c); - if chip(ui, tr(c.short()), enabled).clicked() { - app.run("layer.fill.set", with(base, json!({"channel": c.id(), "enabled": !enabled}))); + if chip(ui, tr(c.short()), enabled).on_hover_text(tr(SOLO_HINT)).clicked() { + let solo = ui.input(|i| i.modifiers.alt); + app.run("layer.fill.set", with(base, json!({"channel": c.id(), "enabled": solo || !enabled, "solo": solo}))); } } }); diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs index f89b7644..04c7a3d9 100644 --- a/crates/ui-egui/src/i18n.rs +++ b/crates/ui-egui/src/i18n.rs @@ -184,6 +184,7 @@ mod tests { "Anchor point", "Layer mask", texturecraft_engine::camera_cmds::DEFAULT_CAMERA, + crate::dock::SOLO_HINT, ]); k.retain(|s| !s.is_empty() && !UNTRANSLATED.contains(s)); k diff --git a/crates/ui-egui/src/i18n/ar.rs b/crates/ui-egui/src/i18n/ar.rs index 976d68cb..2c289b30 100644 --- a/crates/ui-egui/src/i18n/ar.rs +++ b/crates/ui-egui/src/i18n/ar.rs @@ -938,4 +938,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Style", "النمط"), ("Use as brush alpha", "استخدام كألفا للفرشاة"), ("Place as decal", "وضع كملصق"), + ("Click: turn this channel on or off. Alt+click: this channel only", "انقر: تشغيل هذه القناة أو إيقافها. Alt+نقر: هذه القناة فقط"), ]; diff --git a/crates/ui-egui/src/i18n/de.rs b/crates/ui-egui/src/i18n/de.rs index 383fd770..cad4fbe9 100644 --- a/crates/ui-egui/src/i18n/de.rs +++ b/crates/ui-egui/src/i18n/de.rs @@ -993,4 +993,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Style", "Schnitt"), ("Use as brush alpha", "Als Pinsel-Alpha verwenden"), ("Place as decal", "Als Decal platzieren"), + ("Click: turn this channel on or off. Alt+click: this channel only", "Klick: diesen Kanal ein- oder ausschalten. Alt+Klick: nur diesen Kanal"), ]; diff --git a/crates/ui-egui/src/i18n/es.rs b/crates/ui-egui/src/i18n/es.rs index d2bbe0f8..f337d2ca 100644 --- a/crates/ui-egui/src/i18n/es.rs +++ b/crates/ui-egui/src/i18n/es.rs @@ -978,4 +978,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Style", "Estilo"), ("Use as brush alpha", "Usar como alfa del pincel"), ("Place as decal", "Colocar como calcomanía"), + ("Click: turn this channel on or off. Alt+click: this channel only", "Clic: activa o desactiva este canal. Alt+clic: solo este canal"), ]; diff --git a/crates/ui-egui/src/i18n/fr.rs b/crates/ui-egui/src/i18n/fr.rs index 07cf9981..d6db4b27 100644 --- a/crates/ui-egui/src/i18n/fr.rs +++ b/crates/ui-egui/src/i18n/fr.rs @@ -993,4 +993,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Style", "Style"), ("Use as brush alpha", "Utiliser comme alpha du pinceau"), ("Place as decal", "Placer en décalque"), + ("Click: turn this channel on or off. Alt+click: this channel only", "Clic : active ou désactive ce canal. Alt+clic : ce canal uniquement"), ]; diff --git a/crates/ui-egui/src/i18n/it.rs b/crates/ui-egui/src/i18n/it.rs index d4818eca..622b40a4 100644 --- a/crates/ui-egui/src/i18n/it.rs +++ b/crates/ui-egui/src/i18n/it.rs @@ -987,4 +987,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Style", "Stile"), ("Use as brush alpha", "Usa come alpha del pennello"), ("Place as decal", "Posiziona come decal"), + ("Click: turn this channel on or off. Alt+click: this channel only", "Clic: attiva o disattiva questo canale. Alt+clic: solo questo canale"), ]; diff --git a/crates/ui-egui/src/i18n/ja.rs b/crates/ui-egui/src/i18n/ja.rs index 62c1c15d..91e5eabd 100644 --- a/crates/ui-egui/src/i18n/ja.rs +++ b/crates/ui-egui/src/i18n/ja.rs @@ -960,4 +960,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Style", "スタイル"), ("Use as brush alpha", "ブラシのアルファとして使用"), ("Place as decal", "デカールとして配置"), + ("Click: turn this channel on or off. Alt+click: this channel only", "クリック: このチャンネルのオン/オフ。Alt+クリック: このチャンネルのみ"), ]; diff --git a/crates/ui-egui/src/i18n/ko.rs b/crates/ui-egui/src/i18n/ko.rs index ec37113c..26e0c66b 100644 --- a/crates/ui-egui/src/i18n/ko.rs +++ b/crates/ui-egui/src/i18n/ko.rs @@ -945,4 +945,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Style", "스타일"), ("Use as brush alpha", "브러시 알파로 사용"), ("Place as decal", "데칼로 배치"), + ("Click: turn this channel on or off. Alt+click: this channel only", "클릭: 이 채널 켜기/끄기. Alt+클릭: 이 채널만"), ]; diff --git a/crates/ui-egui/src/i18n/pt_br.rs b/crates/ui-egui/src/i18n/pt_br.rs index 5db5da19..001e4f49 100644 --- a/crates/ui-egui/src/i18n/pt_br.rs +++ b/crates/ui-egui/src/i18n/pt_br.rs @@ -975,4 +975,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Style", "Estilo"), ("Use as brush alpha", "Usar como alpha do pincel"), ("Place as decal", "Colocar como decalque"), + ("Click: turn this channel on or off. Alt+click: this channel only", "Clique: liga ou desliga este canal. Alt+clique: só este canal"), ]; diff --git a/crates/ui-egui/src/i18n/zh_hans.rs b/crates/ui-egui/src/i18n/zh_hans.rs index 895dfc20..d6e09df7 100644 --- a/crates/ui-egui/src/i18n/zh_hans.rs +++ b/crates/ui-egui/src/i18n/zh_hans.rs @@ -891,4 +891,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Style", "样式"), ("Use as brush alpha", "用作笔刷 Alpha"), ("Place as decal", "作为贴花放置"), + ("Click: turn this channel on or off. Alt+click: this channel only", "单击:打开或关闭此通道。Alt+单击:仅此通道"), ]; diff --git a/docs/features.md b/docs/features.md index 0b3ab198..a55b2590 100644 --- a/docs/features.md +++ b/docs/features.md @@ -45,6 +45,7 @@ Everything TextureCraft does today, by area. What's still missing is in [`ROADMA - **Fill layers** take uniform values, **22 procedurals** (clouds, cells, grunge, scratches, wood grain, bricks, fabric weave, leather grain, marble veins, Voronoi, paint chips…) or your own **images**, through UV, tri-planar, planar, spherical, cylindrical or decal projection. + Alt+click a material channel (of a fill or the brush) to keep that channel alone. - **54 materials** (metals from measured reflectance, car paint, brushed anisotropic steel, velvet, skin, wax, glass, woods, stone, plastics, fabric, leather, ceramic, rust, cork, paper), **21 smart materials** (rusted iron, worn paint, oxidized copper, bronze statue, weathered wood, mossy