From 6d71d2fc3825e7f1062b88ad01b878a0aa4129e3 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 2 Nov 2026 13:43:40 +0700 Subject: [PATCH 1/2] Fill channels take an image from their source menu A fill channel's source menu offered a uniform value, procedurals and anchors, but no image, so a normal or roughness map could not be put on its channel. The menu now lists the image resources and Import..., and an image dropped from the Assets panel onto a channel becomes its source. The mesh map slots share the same menu and drop target. Fixes #127. --- crates/ui-egui/src/dock.rs | 62 ++++++++++++++++------ crates/ui-egui/src/i18n/ar.rs | 2 +- crates/ui-egui/src/i18n/de.rs | 2 +- crates/ui-egui/src/i18n/es.rs | 2 +- crates/ui-egui/src/i18n/fr.rs | 2 +- crates/ui-egui/src/i18n/it.rs | 2 +- crates/ui-egui/src/i18n/ja.rs | 2 +- crates/ui-egui/src/i18n/ko.rs | 2 +- crates/ui-egui/src/i18n/pt_br.rs | 2 +- crates/ui-egui/src/i18n/zh_hans.rs | 2 +- crates/ui-egui/tests/fill_channel_image.rs | 30 +++++++++++ docs/features.md | 4 +- 12 files changed, 87 insertions(+), 27 deletions(-) create mode 100644 crates/ui-egui/tests/fill_channel_image.rs diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs index 659e5895..896079c1 100644 --- a/crates/ui-egui/src/dock.rs +++ b/crates/ui-egui/src/dock.rs @@ -809,7 +809,6 @@ pub(crate) fn texture_set_settings(app: &mut TextureCraftApp, ui: &mut Ui) { } }); }); - let images: Vec = app.session.doc.resources.keys().cloned().collect(); for m in BakedMap::ALL { let present = app.session.doc.baked.get(&ts).is_some_and(|b| b.maps.contains_key(&m)); let row = ui.horizontal(|ui| { @@ -826,16 +825,8 @@ pub(crate) fn texture_set_settings(app: &mut TextureCraftApp, ui: &mut Ui) { // An image resource instead of a bake, or no map. ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { ui.menu_button(RichText::new(ic::DOTS_THREE).size(13.0), |ui| { - ui.label(caption(tr("Images"))); - for name in &images { - if ui.button(name).clicked() { - app.run("textureSet.meshMap.set", json!({"ts": ts, "map": m.id(), "image": name})); - ui.close(); - } - } - if ui.button(tr("Import...")).clicked() { - crate::menus::invoke(app, ui.ctx(), "resource.import"); - ui.close(); + if let Some(name) = image_menu(app, ui) { + app.run("textureSet.meshMap.set", json!({"ts": ts, "map": m.id(), "image": name})); } ui.separator(); if ui.add_enabled(present, egui::Button::new(tr("Clear"))).clicked() { @@ -847,16 +838,45 @@ pub(crate) fn texture_set_settings(app: &mut TextureCraftApp, ui: &mut Ui) { }); // A shelf image dropped on the row becomes this mesh map. let resp = row.response.interact(Sense::hover()).on_hover_text(tr("Drop an image from the Assets panel here to use it as this mesh map")); - if resp.dnd_hover_payload::().is_some_and(|d| matches!(d.asset, Asset::Texture(_))) { - ui.painter().rect_stroke(resp.rect.shrink(1.0), 3.0, Stroke::new(2.0, tk.accent), egui::StrokeKind::Inside); - } - if let Some(Asset::Texture(name)) = dnd_release::(&resp).map(|d| d.asset.clone()) { + if let Some(name) = image_drop(ui, &resp) { app.run("textureSet.meshMap.set", json!({"ts": ts, "map": m.id(), "image": name})); } } }); } +/// Menu items listing the image resources, then Import...: the image picked, if any. +fn image_menu(app: &mut TextureCraftApp, ui: &mut Ui) -> Option { + ui.label(caption(tr("Images"))); + let mut picked = None; + for name in app.session.doc.resources.keys() { + if ui.button(name.as_str()).clicked() { + picked = Some(name.clone()); + } + } + if ui.button(tr("Import...")).clicked() { + crate::menus::invoke(app, ui.ctx(), "resource.import"); + ui.close(); + } + if picked.is_some() { + ui.close(); + } + picked +} + +/// An image from the Assets panel dropped on `resp`, outlined while one hovers it. Other assets +/// are left for the drop targets around it. +fn image_drop(ui: &Ui, resp: &egui::Response) -> Option { + if !resp.dnd_hover_payload::().is_some_and(|d| matches!(d.asset, Asset::Texture(_))) { + return None; + } + ui.painter().rect_stroke(resp.rect.shrink(1.0), 3.0, Stroke::new(2.0, Tokens::get(ui.ctx()).accent), egui::StrokeKind::Inside); + match dnd_release::(resp).map(|d| d.asset.clone()) { + Some(Asset::Texture(name)) => Some(name), + _ => None, + } +} + fn mesh_map_color(m: BakedMap) -> Color32 { match m { BakedMap::Normal => Color32::from_rgb(128, 128, 255), @@ -1514,7 +1534,7 @@ fn fill_channel(app: &mut TextureCraftApp, ui: &mut Ui, fill: &Fill, base: &Valu use texturecraft_engine::core::ChannelKind; { let set = |extra: Value| with(base, with(&json!({"channel": c.id()}), extra)); - ui.group(|ui| { + let group = ui.group(|ui| { ui.horizontal(|ui| { ui.label(RichText::new(tr(c.label())).strong()); ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { @@ -1535,6 +1555,10 @@ fn fill_channel(app: &mut TextureCraftApp, ui: &mut Ui, fill: &Fill, base: &Valu ui.close(); } } + ui.separator(); + if let Some(name) = image_menu(app, ui) { + app.run("layer.fill.set", set(json!({"image": name}))); + } if !anchors.is_empty() { ui.separator(); } @@ -1546,7 +1570,7 @@ fn fill_channel(app: &mut TextureCraftApp, ui: &mut Ui, fill: &Fill, base: &Valu } }) .response - .on_hover_text(tr("Channel source: uniform value, procedural or anchor")); + .on_hover_text(tr("Channel source: uniform value, procedural, image or anchor")); }); }); match fill.source(c) { @@ -1608,6 +1632,10 @@ fn fill_channel(app: &mut TextureCraftApp, ui: &mut Ui, fill: &Fill, base: &Valu } } }); + // A shelf image dropped on the channel becomes its source. + if let Some(name) = image_drop(ui, &group.response.interact(Sense::hover())) { + app.run("layer.fill.set", set(json!({"image": name}))); + } } } diff --git a/crates/ui-egui/src/i18n/ar.rs b/crates/ui-egui/src/i18n/ar.rs index b62b6baf..43f93452 100644 --- a/crates/ui-egui/src/i18n/ar.rs +++ b/crates/ui-egui/src/i18n/ar.rs @@ -148,7 +148,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Cell size (texels at 2K)", "حجم الخلية (تكسل بدقة 2K)"), ("Cells", "خلايا"), ("Channel", "القناة"), - ("Channel source: uniform value, procedural or anchor", "مصدر القناة: قيمة موحدة، إجرائي أو نقطة ارتكاز"), + ("Channel source: uniform value, procedural, image or anchor", "مصدر القناة: قيمة موحدة، إجرائي، صورة أو نقطة ارتكاز"), ("Channels", "القنوات"), ("Checker", "رقعة شطرنج"), ("Clamp", "تقييد القيم"), diff --git a/crates/ui-egui/src/i18n/de.rs b/crates/ui-egui/src/i18n/de.rs index 45ea5c2c..6467f41e 100644 --- a/crates/ui-egui/src/i18n/de.rs +++ b/crates/ui-egui/src/i18n/de.rs @@ -148,7 +148,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Cell size (texels at 2K)", "Zellengröße (Texel bei 2K)"), ("Cells", "Zellen"), ("Channel", "Kanal"), - ("Channel source: uniform value, procedural or anchor", "Kanalquelle: einheitlicher Wert, prozedural oder Anker"), + ("Channel source: uniform value, procedural, image or anchor", "Kanalquelle: einheitlicher Wert, prozedural, Bild oder Anker"), ("Channels", "Kanäle"), ("Checker", "Schachbrett"), ("Clamp", "Begrenzen"), diff --git a/crates/ui-egui/src/i18n/es.rs b/crates/ui-egui/src/i18n/es.rs index f5040e63..af0c3b18 100644 --- a/crates/ui-egui/src/i18n/es.rs +++ b/crates/ui-egui/src/i18n/es.rs @@ -148,7 +148,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Cell size (texels at 2K)", "Tamaño de celda (téxeles a 2K)"), ("Cells", "Celdas"), ("Channel", "Canal"), - ("Channel source: uniform value, procedural or anchor", "Origen del canal: valor uniforme, procedural o anclaje"), + ("Channel source: uniform value, procedural, image or anchor", "Origen del canal: valor uniforme, procedural, imagen o anclaje"), ("Channels", "Canales"), ("Checker", "Damero"), ("Clamp", "Limitar"), diff --git a/crates/ui-egui/src/i18n/fr.rs b/crates/ui-egui/src/i18n/fr.rs index 5a76af66..bcd801ec 100644 --- a/crates/ui-egui/src/i18n/fr.rs +++ b/crates/ui-egui/src/i18n/fr.rs @@ -154,7 +154,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Cell size (texels at 2K)", "Taille des cellules (texels en 2K)"), ("Cells", "Cellules"), ("Channel", "Canal"), - ("Channel source: uniform value, procedural or anchor", "Source du canal : valeur uniforme, procédural ou ancrage"), + ("Channel source: uniform value, procedural, image or anchor", "Source du canal : valeur uniforme, procédural, image ou ancrage"), ("Channels", "Canaux"), ("Checker", "Damier"), ("Clamp", "Limiter"), diff --git a/crates/ui-egui/src/i18n/it.rs b/crates/ui-egui/src/i18n/it.rs index 011fbe11..ff81e64b 100644 --- a/crates/ui-egui/src/i18n/it.rs +++ b/crates/ui-egui/src/i18n/it.rs @@ -151,7 +151,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Cell size (texels at 2K)", "Dimensione celle (texel a 2K)"), ("Cells", "Celle"), ("Channel", "Canale"), - ("Channel source: uniform value, procedural or anchor", "Sorgente del canale: valore uniforme, procedurale o ancoraggio"), + ("Channel source: uniform value, procedural, image or anchor", "Sorgente del canale: valore uniforme, procedurale, immagine o ancoraggio"), ("Channels", "Canali"), ("Checker", "Scacchiera"), ("Clamp", "Limita"), diff --git a/crates/ui-egui/src/i18n/ja.rs b/crates/ui-egui/src/i18n/ja.rs index bf4e8402..cfb6fb73 100644 --- a/crates/ui-egui/src/i18n/ja.rs +++ b/crates/ui-egui/src/i18n/ja.rs @@ -154,7 +154,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Cell size (texels at 2K)", "セルサイズ (2K時のテクセル)"), ("Cells", "セル"), ("Channel", "チャンネル"), - ("Channel source: uniform value, procedural or anchor", "チャンネルのソース: 均一値、プロシージャル、アンカー"), + ("Channel source: uniform value, procedural, image or anchor", "チャンネルのソース: 均一値、プロシージャル、画像、アンカー"), ("Channels", "チャンネル"), ("Checker", "チェッカー"), ("Clamp", "クランプ"), diff --git a/crates/ui-egui/src/i18n/ko.rs b/crates/ui-egui/src/i18n/ko.rs index a9da933b..9b15d2a0 100644 --- a/crates/ui-egui/src/i18n/ko.rs +++ b/crates/ui-egui/src/i18n/ko.rs @@ -148,7 +148,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Cell size (texels at 2K)", "셀 크기 (2K 기준 텍셀)"), ("Cells", "셀"), ("Channel", "채널"), - ("Channel source: uniform value, procedural or anchor", "채널 소스: 균일 값, 프로시저럴 또는 앵커"), + ("Channel source: uniform value, procedural, image or anchor", "채널 소스: 균일 값, 프로시저럴, 이미지 또는 앵커"), ("Channels", "채널"), ("Checker", "체커"), ("Clamp", "클램프"), diff --git a/crates/ui-egui/src/i18n/pt_br.rs b/crates/ui-egui/src/i18n/pt_br.rs index 2da863ef..f27cd03b 100644 --- a/crates/ui-egui/src/i18n/pt_br.rs +++ b/crates/ui-egui/src/i18n/pt_br.rs @@ -151,7 +151,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Cell size (texels at 2K)", "Tamanho da célula (texels em 2K)"), ("Cells", "Células"), ("Channel", "Canal"), - ("Channel source: uniform value, procedural or anchor", "Origem do canal: valor uniforme, procedural ou âncora"), + ("Channel source: uniform value, procedural, image or anchor", "Origem do canal: valor uniforme, procedural, imagem ou âncora"), ("Channels", "Canais"), ("Checker", "Xadrez"), ("Clamp", "Limitar"), diff --git a/crates/ui-egui/src/i18n/zh_hans.rs b/crates/ui-egui/src/i18n/zh_hans.rs index 4727b3e9..0d9ab034 100644 --- a/crates/ui-egui/src/i18n/zh_hans.rs +++ b/crates/ui-egui/src/i18n/zh_hans.rs @@ -130,7 +130,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Cell size (texels at 2K)", "单元大小(2K 下的纹素数)"), ("Cells", "细胞"), ("Channel", "通道"), - ("Channel source: uniform value, procedural or anchor", "通道来源:统一值、程序纹理或锚点"), + ("Channel source: uniform value, procedural, image or anchor", "通道来源:统一值、程序纹理、图像或锚点"), ("Channels", "通道"), ("Checker", "棋盘格"), ("Clamp", "钳制"), diff --git a/crates/ui-egui/tests/fill_channel_image.rs b/crates/ui-egui/tests/fill_channel_image.rs new file mode 100644 index 00000000..37663e6d --- /dev/null +++ b/crates/ui-egui/tests/fill_channel_image.rs @@ -0,0 +1,30 @@ +//! A fill channel takes an image resource from its source menu. + +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; +use serde_json::json; +use texturecraft_engine::core::{Channel, LayerId, LayerKind, Source}; +use texturecraft_ui_egui::TextureCraftApp; + +#[test] +fn a_fill_channel_takes_an_image_from_its_source_menu() { + let mut session = texturecraft_engine::sample_session(256, 64).unwrap(); + let mut png = Vec::new(); + image::RgbaImage::from_pixel(4, 4, image::Rgba([90, 90, 90, 255])).write_to(&mut std::io::Cursor::new(&mut png), image::ImageFormat::Png).unwrap(); + let name = session.import_resource_bytes("rough.png", png).unwrap(); + let out = texturecraft_engine::execute(&mut session, "layer.add.fill", &json!({"roughness": 0.6})).unwrap(); + let layer = LayerId(out["layer"].as_u64().unwrap()); + let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1400.0)).build_eframe(|cc| TextureCraftApp::new(cc, session)); + h.run_steps(4); + + // The source menu button sits in the row of the channel's name. + let row = h.get_all_by_label("Roughness").map(|n| n.rect()).max_by(|a, b| a.right().total_cmp(&b.right())).unwrap().center().y; + let menu = h.get_all_by_label(egui_phosphor::regular::DOTS_THREE).find(|n| (n.rect().center().y - row).abs() < 6.0).unwrap(); + menu.click(); + h.run_steps(2); + h.get_by_label(&name).click(); + h.run_steps(3); + + let LayerKind::Fill(fill) = &h.state().session.doc.project.layers[&layer].kind else { panic!("a fill layer") }; + assert_eq!(fill.source(Channel::Roughness), Source::Image { name }); +} diff --git a/docs/features.md b/docs/features.md index b16a29c1..d909ead3 100644 --- a/docs/features.md +++ b/docs/features.md @@ -49,7 +49,9 @@ Everything TextureCraft does today, by area. What's still missing is in [`ROADMA effect selected, Ctrl+D and Delete duplicate or remove it. - **Fill layers** take uniform values, **23 procedurals** (clouds, cells, grunge, scratches, wood grain, bricks, fabric weave, twill, leather grain, marble veins, Voronoi, paint chips…) or your own - **images**, through UV, tri-planar, planar, spherical, cylindrical or decal projection. + **images**, through UV, tri-planar, planar, spherical, cylindrical or decal projection. Each + channel takes its own image (a normal, roughness or height map, say): pick it in the channel's + source menu, which also imports one, or drop it from the Assets panel onto the channel. Alt+click a material channel (of a fill or the brush) to keep that channel alone. - **63 materials** (metals from measured reflectance, car paint, brushed anisotropic steel, velvet, skin, wax, glass, ice, woods, bark, stone, sand, mud, snow, bone, plastics, fabric, From 699596835e682f1a0c42e213ff5fe4b9f7db9683 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 2 Nov 2026 14:11:23 +0700 Subject: [PATCH 2/2] Image menu: scroll a long list; the test speaks English With many images, the list now scrolls so Import... and the items after it stay on screen. The UI test sets English, as a first run would speak the system's language. --- crates/ui-egui/src/dock.rs | 11 +++++++---- crates/ui-egui/tests/fill_channel_image.rs | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs index 896079c1..0220bae3 100644 --- a/crates/ui-egui/src/dock.rs +++ b/crates/ui-egui/src/dock.rs @@ -849,11 +849,14 @@ pub(crate) fn texture_set_settings(app: &mut TextureCraftApp, ui: &mut Ui) { fn image_menu(app: &mut TextureCraftApp, ui: &mut Ui) -> Option { ui.label(caption(tr("Images"))); let mut picked = None; - for name in app.session.doc.resources.keys() { - if ui.button(name.as_str()).clicked() { - picked = Some(name.clone()); + // Bounded, so Import... and the items after it stay on screen with many images. + egui::ScrollArea::vertical().id_salt("image_menu").max_height(240.0).show(ui, |ui| { + for name in app.session.doc.resources.keys() { + if ui.button(name.as_str()).clicked() { + picked = Some(name.clone()); + } } - } + }); if ui.button(tr("Import...")).clicked() { crate::menus::invoke(app, ui.ctx(), "resource.import"); ui.close(); diff --git a/crates/ui-egui/tests/fill_channel_image.rs b/crates/ui-egui/tests/fill_channel_image.rs index 37663e6d..b87a0052 100644 --- a/crates/ui-egui/tests/fill_channel_image.rs +++ b/crates/ui-egui/tests/fill_channel_image.rs @@ -15,6 +15,8 @@ fn a_fill_channel_takes_an_image_from_its_source_menu() { let out = texturecraft_engine::execute(&mut session, "layer.add.fill", &json!({"roughness": 0.6})).unwrap(); let layer = LayerId(out["layer"].as_u64().unwrap()); let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1400.0)).build_eframe(|cc| TextureCraftApp::new(cc, session)); + // The labels below are English; a first run would speak the system's language. + h.state_mut().ui.prefs.language = "en".into(); h.run_steps(4); // The source menu button sits in the row of the channel's name.