mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-20 06:20:50 +01:00
Merge pull request #137 from storytold/fix/fill-channel-image
Fill layers: put an image on any channel
This commit is contained in:
12 files changed
+92
-27
No files matched your search
+48
-17
@@ -809,7 +809,6 @@ pub(crate) fn texture_set_settings(app: &mut TextureCraftApp, ui: &mut Ui) {
|
||||
}
|
||||
});
|
||||
});
|
||||
let images: Vec<String> = 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,48 @@ 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::<ShelfDrag>().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::<ShelfDrag>(&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<String> {
|
||||
ui.label(caption(tr("Images")));
|
||||
let mut picked = None;
|
||||
// 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();
|
||||
}
|
||||
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<String> {
|
||||
if !resp.dnd_hover_payload::<ShelfDrag>().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::<ShelfDrag>(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 +1537,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 +1558,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 +1573,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 +1635,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})));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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", "تقييد القيم"),
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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", "クランプ"),
|
||||
|
||||
@@ -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", "클램프"),
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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", "钳制"),
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
//! 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));
|
||||
// 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.
|
||||
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 });
|
||||
}
|
||||
+3
-1
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user