mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-24 16:30:46 +01:00
Merge pull request #96 from storytold/ui/alt-click-solo-channel
Material channels: Alt+click keeps one channel
This commit is contained in:
15 files changed
+56
-8
No files matched your search
@@ -25,7 +25,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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<Value> {
|
||||
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<Value> {
|
||||
} 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<Value> {
|
||||
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<Value> {
|
||||
} else {
|
||||
l.channels.entry(ch).or_default();
|
||||
}
|
||||
if solo {
|
||||
l.channels.retain(|c, _| *c == ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -42,7 +42,15 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"procedural": BrushAlpha::ALL.map(BrushAlpha::label),
|
||||
"library": alphas::library().iter().map(|a| json!({"id": a.id, "label": a.label, "category": a.category})).collect::<Vec<_>>(),
|
||||
}))),
|
||||
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<Value> {
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
if boolp(p, "solo") == Some(true) {
|
||||
s.tool.enabled = std::iter::once(c).collect();
|
||||
}
|
||||
}
|
||||
s.revision = s.revision.wrapping_add(1);
|
||||
Ok(json!({
|
||||
|
||||
@@ -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::<Vec<_>>(), [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();
|
||||
|
||||
@@ -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})));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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+نقر: هذه القناة فقط"),
|
||||
];
|
||||
@@ -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"),
|
||||
];
|
||||
@@ -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"),
|
||||
];
|
||||
@@ -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"),
|
||||
];
|
||||
@@ -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"),
|
||||
];
|
||||
@@ -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+クリック: このチャンネルのみ"),
|
||||
];
|
||||
@@ -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+클릭: 이 채널만"),
|
||||
];
|
||||
@@ -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"),
|
||||
];
|
||||
@@ -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+单击:仅此通道"),
|
||||
];
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user