From 373159ec5ebccb0eefb2078a8dbeed36cdc9cba3 Mon Sep 17 00:00:00 2001 From: Rebornim <250083243+Rebornim@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:38:32 +0000 Subject: [PATCH] List how the bake paired parts by name in the Baking Log --- crates/engine/src/bake/bake_log.rs | 49 +++++++++++- crates/engine/src/bake/bake_log_matching.rs | 18 +++++ crates/engine/src/bake/mesh_map_command.rs | 2 +- crates/engine/src/bake/mod.rs | 3 + crates/engine/src/bake_log_cmds.rs | 8 +- crates/engine/tests/it/bake_log.rs | 39 +++++++-- crates/ui-egui/src/baking_log.rs | 62 +++++++++++---- .../ui-egui/src/baking_log/matching_list.rs | 79 +++++++++++++++++++ crates/ui-egui/src/lib.rs | 2 +- crates/ui-egui/tests/it/baking_log.rs | 51 +++++++++--- docs/control-protocol.md | 8 +- 11 files changed, 286 insertions(+), 35 deletions(-) create mode 100644 crates/engine/src/bake/bake_log_matching.rs create mode 100644 crates/ui-egui/src/baking_log/matching_list.rs diff --git a/crates/engine/src/bake/bake_log.rs b/crates/engine/src/bake/bake_log.rs index 82f63c90..7203b7c1 100644 --- a/crates/engine/src/bake/bake_log.rs +++ b/crates/engine/src/bake/bake_log.rs @@ -1,6 +1,10 @@ +use std::collections::HashSet; + +use texturecraft_bake::NamePair; use texturecraft_core::{BakedMap, Project}; -use super::{BakeHighState, BakeLogHigh, BakeLogMap, BakeMapState, BakeMesh}; +use super::{BakeHighState, BakeLogHigh, BakeLogMap, BakeLogMatching, BakeMapState, BakeMesh}; +use crate::Session; /// The latest bake map by map for the Baking Log, kept from the bake's own state, never from Log lines #[derive(Clone, Debug, Default, PartialEq)] @@ -8,6 +12,8 @@ pub struct BakeLog { pub maps: Vec, /// Each high poly file of each texture set that bakes from the high polys, in bake order pub highs: Vec, + /// How the parts paired by name; `None` when no set of the bake matches "By Mesh Name" + pub matching: Option, } impl BakeLog { @@ -33,6 +39,7 @@ impl BakeLog { }) }) .collect(); + self.matching = None; } /// `set` starts baking: its high polys load and its first map is the one in progress @@ -120,3 +127,43 @@ impl BakeLog { } } } + +impl Session { + /// Start the Baking Log over for a bake of `sets` ([`BakeLog::begin`]), with how their parts pair by name + pub fn begin_bake_log(&mut self, sets: &[usize]) { + let matching = self.bake_log_matching(sets); + self.bake_log.begin(&self.doc.project, &self.doc.bake_meshes.high, sets); + self.bake_log.matching = matching; + } + + /// The name pairs of each of `sets` that matches "By Mesh Name"; a high poly part counts as unpaired only when none of them pairs with it + fn bake_log_matching(&self, sets: &[usize]) -> Option { + let mut matching: Option = None; + let (mut paired_highs, mut unpaired_highs) = (HashSet::new(), Vec::new()); + for &set in sets { + let (Ok(Some(pairs)), Ok(texture_set)) = (self.bake_name_pairs(set), self.doc.project.texture_set(set)) else { continue }; + let settings = &texture_set.bake.high_poly; + let matching = matching.get_or_insert_with(|| BakeLogMatching { + low_suffix: settings.low_suffix.clone(), + high_suffix: settings.high_suffix.clone(), + pairs: Vec::new(), + }); + for pair in pairs { + match (&pair.low, &pair.high) { + (None, Some(high)) if !unpaired_highs.contains(high) => unpaired_highs.push(high.clone()), + (None, _) => {} + (Some(_), high) => { + paired_highs.extend(high.clone()); + matching.pairs.push(pair); + } + } + } + } + + if let Some(matching) = &mut matching { + let unpaired = unpaired_highs.into_iter().filter(|high| !paired_highs.contains(high)); + matching.pairs.extend(unpaired.map(|high| NamePair { low: None, high: Some(high) })); + } + matching + } +} diff --git a/crates/engine/src/bake/bake_log_matching.rs b/crates/engine/src/bake/bake_log_matching.rs new file mode 100644 index 00000000..9e0ef379 --- /dev/null +++ b/crates/engine/src/bake/bake_log_matching.rs @@ -0,0 +1,18 @@ +use texturecraft_bake::NamePair; + +/// The Baking Log's matching list: how the latest bake paired low poly parts with high poly parts by name +#[derive(Clone, Debug, PartialEq)] +pub struct BakeLogMatching { + /// The suffixes the first set matching by name strips, for the column captions + pub low_suffix: String, + pub high_suffix: String, + /// Each low poly part with the high poly part it bakes from, then the high poly parts no set of the bake pairs with + pub pairs: Vec, +} + +impl BakeLogMatching { + /// How many parts found no partner + pub fn issue_count(&self) -> usize { + self.pairs.iter().filter(|pair| pair.unpaired()).count() + } +} diff --git a/crates/engine/src/bake/mesh_map_command.rs b/crates/engine/src/bake/mesh_map_command.rs index e3f16c22..fef806b1 100644 --- a/crates/engine/src/bake/mesh_map_command.rs +++ b/crates/engine/src/bake/mesh_map_command.rs @@ -843,7 +843,7 @@ fn bake_run(session: &mut Session, params: &Value) -> Result { for (index, settings) in next { session.doc.project.texture_set_mut(index)?.bake = settings; } - session.bake_log.begin(&session.doc.project, &session.bake_meshes.high, &sets); + session.begin_bake_log(&sets); let mut tracers = Vec::with_capacity(sets.len()); for &index in &sets { diff --git a/crates/engine/src/bake/mod.rs b/crates/engine/src/bake/mod.rs index 873c2f35..e5edcc07 100644 --- a/crates/engine/src/bake/mod.rs +++ b/crates/engine/src/bake/mod.rs @@ -6,6 +6,7 @@ mod bake_high_state; mod bake_log; mod bake_log_high; mod bake_log_map; +mod bake_log_matching; mod bake_map_state; mod bake_mesh; mod bake_meshes; @@ -28,6 +29,7 @@ pub use bake_high_state::BakeHighState; pub use bake_log::BakeLog; pub use bake_log_high::BakeLogHigh; pub use bake_log_map::BakeLogMap; +pub use bake_log_matching::BakeLogMatching; pub use bake_map_state::BakeMapState; pub use bake_mesh::BakeMesh; pub use bake_meshes::BakeMeshes; @@ -39,6 +41,7 @@ pub use mesh_map_command::{install_gpu_tracer, meshes_json, set_gpu_raytracing, pub use model_patch::settings_patch; pub use streamed_bake::StreamedBake; pub use streamed_map::StreamedMap; +pub use texturecraft_bake::NamePair; pub use texturecraft_bake::*; use crate::CommandSpec; diff --git a/crates/engine/src/bake_log_cmds.rs b/crates/engine/src/bake_log_cmds.rs index edfbd15a..4be8c268 100644 --- a/crates/engine/src/bake_log_cmds.rs +++ b/crates/engine/src/bake_log_cmds.rs @@ -11,7 +11,7 @@ pub fn specs() -> Vec { "Baking log", [], None, - "{} → {running, maps: [{textureSet, setName, map, state: \"waiting\" | \"baking\" | \"baked\" | \"failed\" | \"canceled\", reason?}], highPolys: [{textureSet, setName, file, state: \"waiting\" | \"loading\" | \"loaded\" | \"failed\" | \"canceled\", reason?}]}. The latest bake map by map in bake order, and the high poly files each set bakes from, as the Baking Log shows them; `reason` says why a map or file failed. Empty before the first bake", + "{} → {running, maps: [{textureSet, setName, map, state: \"waiting\" | \"baking\" | \"baked\" | \"failed\" | \"canceled\", reason?}], highPolys: [{textureSet, setName, file, state: \"waiting\" | \"loading\" | \"loaded\" | \"failed\" | \"canceled\", reason?}], matching: null | {lowSuffix, highSuffix, pairs: [{low: name | null, high: name | null}]}}. The latest bake map by map in bake order, the high poly files each set bakes from, and how parts paired by name, as the Baking Log shows them; `reason` says why a map or file failed; a `null` side of a pair is a part with no partner; `matching` is null when no set matched by mesh name. Empty before the first bake", always, log )] @@ -21,7 +21,11 @@ fn log(session: &mut Session, _: &Value) -> Result { let log = &session.bake_log; let maps = log.maps.iter().map(|row| entry(&row.state, row.texture_set, &row.set_name, "map", json!(row.map.id()))).collect::>>()?; let highs = log.highs.iter().map(|row| entry(&row.state, row.texture_set, &row.set_name, "file", json!(row.file))).collect::>>()?; - Ok(json!({ "running": log.is_running() || log.is_loading_high_polys(), "maps": maps, "highPolys": highs })) + let matching = log.matching.as_ref().map(|matching| { + let pairs: Vec = matching.pairs.iter().map(|pair| json!({ "low": pair.low, "high": pair.high })).collect(); + json!({ "lowSuffix": matching.low_suffix, "highSuffix": matching.high_suffix, "pairs": pairs }) + }); + Ok(json!({ "running": log.is_running() || log.is_loading_high_polys(), "maps": maps, "highPolys": highs, "matching": matching })) } /// One row: its `state` (and `reason`), its texture set, and what it is under `key` diff --git a/crates/engine/tests/it/bake_log.rs b/crates/engine/tests/it/bake_log.rs index 36ce7772..419ce6b4 100644 --- a/crates/engine/tests/it/bake_log.rs +++ b/crates/engine/tests/it/bake_log.rs @@ -3,8 +3,8 @@ use std::collections::BTreeSet; use serde_json::json; -use texturecraft_engine::bake::{BakeHighState, BakeMapState}; -use texturecraft_engine::core::BakedMap; +use texturecraft_engine::bake::{BakeHighState, BakeLog, BakeMapState, NamePair}; +use texturecraft_engine::core::{BakedMap, MeshMatchMode}; use texturecraft_engine::geom::primitives; use texturecraft_engine::{Session, execute, sample_session}; @@ -86,15 +86,44 @@ fn a_set_that_fails_before_its_high_polys_are_ready_marks_them_failed_and_a_canc session.add_high_poly_bytes("ball_high.obj", b"o Ball_high\nv 0 0 0\nv 1 0 0\nv 0 1 0\nf 1 2 3\n".to_vec()).unwrap(); let log = &mut session.bake_log; log.begin(&session.doc.project, &session.doc.bake_meshes.high, &[0, 1]); + let state = |log: &BakeLog, set: usize| log.highs.iter().find(|high| high.texture_set == set).map(|high| high.state.clone()); log.set_started(0); - assert_eq!(log.highs[0].state, BakeHighState::Loading); + assert_eq!(state(log, 0), Some(BakeHighState::Loading)); assert!(log.is_loading_high_polys()); log.set_failed(0, "The cage file could not be read."); log.set_started(1); log.cancel(Some(1)); - assert_eq!(log.highs[0].state, BakeHighState::Failed("The cage file could not be read.".into())); - assert_eq!(log.highs[1].state, BakeHighState::Canceled); + assert_eq!(state(log, 0), Some(BakeHighState::Failed("The cage file could not be read.".into()))); + assert_eq!(state(log, 1), Some(BakeHighState::Canceled)); assert!(!log.is_loading_high_polys()); } + +#[test] +fn a_bake_matching_by_name_lists_its_pairs_and_only_the_high_parts_no_set_pairs_with() { + let obj = "o Box_low\nusemtl Body\nv 0 0 0\nv 1 0 0\nv 0 1 0\nvt 0 0\nvt 1 0\nvt 0 1\nf 1/1 2/2 3/3\n\ + o Lid_low\nusemtl Lid\nv 2 0 0\nv 3 0 0\nv 2 1 0\nvt 0 0\nvt 1 0\nvt 0 1\nf 4/4 5/5 6/6\n"; + let mut session = Session::from_mesh_bytes("sets.obj", obj.as_bytes(), 128, "sets").unwrap(); + session + .add_high_poly_bytes("high.obj", b"o Box_high\nv 0 0 0\nv 1 0 0\nv 0 1 0\nf 1 2 3\no Extra_high\nv 2 0 0\nv 3 0 0\nv 2 1 0\nf 4 5 6\n".to_vec()) + .unwrap(); + session.begin_bake_log(&[0, 1]); + assert_eq!(session.bake_log.matching, None, "matching \"Always\" lists no pairs"); + + for set in &mut session.doc.project.texture_sets { + set.bake.high_poly.match_mode = MeshMatchMode::ByMeshName; + } + session.begin_bake_log(&[0, 1]); + + let pair = |low: Option<&str>, high: Option<&str>| NamePair { low: low.map(Into::into), high: high.map(Into::into) }; + let matching = session.bake_log.matching.clone().unwrap(); + assert_eq!( + matching.pairs, + [pair(Some("Box_low"), Some("Box_high")), pair(Some("Lid_low"), None), pair(None, Some("Extra_high"))], + "Box_high is paired by the other set" + ); + assert_eq!(matching.issue_count(), 2); + let log = execute(&mut session, "bake.log", &json!({})).unwrap(); + assert_eq!(log["matching"]["pairs"][1], json!({ "low": "Lid_low", "high": null }), "{log}"); +} diff --git a/crates/ui-egui/src/baking_log.rs b/crates/ui-egui/src/baking_log.rs index 9b2e0257..1ee11974 100644 --- a/crates/ui-egui/src/baking_log.rs +++ b/crates/ui-egui/src/baking_log.rs @@ -14,6 +14,7 @@ use crate::theme::{Tokens, semibold}; mod baking_log_tab; mod high_poly_list; +mod matching_list; pub use baking_log_tab::BakingLogTab; @@ -77,13 +78,19 @@ pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) { let issue_count = match tab { BakingLogTab::BakingProcess => app.session.bake_log.maps.iter().filter(|row| row.state.is_issue()).count(), BakingLogTab::HighPolyParameters => app.session.bake_log.highs.iter().filter(|row| row.state.is_issue()).count(), - BakingLogTab::MatchingByName => 0, + BakingLogTab::MatchingByName => app.session.bake_log.matching.as_ref().map_or(0, |matching| matching.issue_count()), }; if issues_filter(ui, strip, issue_count, app.ui.baking_log_issues_only) { app.ui.baking_log_issues_only = !app.ui.baking_log_issues_only; } let issues_only = app.ui.baking_log_issues_only; + let log = &app.session.bake_log; + let baked = !log.maps.is_empty(); + if tab == BakingLogTab::MatchingByName && baked && log.matching.is_none() { + matching_not_enabled(ui); + return; + } if issues_only && issue_count == 0 { no_issues(ui, tab); return; @@ -92,6 +99,8 @@ pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) { let opened = egui::ScrollArea::vertical() .auto_shrink([false, false]) .show(ui, |ui| { + // Rows sit edge to edge at ROW_HEIGHT, as the matching list's rules need + ui.spacing_mut().item_spacing.y = 0.0; ui.add_space(LIST_TOP); match tab { BakingLogTab::BakingProcess => baking_process(ui, &app.session.bake_log.maps, issues_only), @@ -99,7 +108,12 @@ pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) { high_poly_list::high_poly_list(ui, &app.session.bake_log.highs, issues_only); None } - BakingLogTab::MatchingByName => None, + BakingLogTab::MatchingByName => { + if let Some(matching) = &app.session.bake_log.matching { + matching_list::matching_list(ui, matching, issues_only); + } + None + } } }) .inner; @@ -173,8 +187,8 @@ fn issues_filter(ui: &mut Ui, strip: Rect, issue_count: usize, on: bool) -> bool let rect = Rect::from_min_max(pos2(right - FILTER_BUTTON_WIDTH - count_width, center_y - FILTER_HEIGHT / 2.0), pos2(right, center_y + FILTER_HEIGHT / 2.0)); let name = match &count { - Some(count) => trf("{count}, Show Only Issues", &[("count", count)]), - None => tr("Show Only Issues").to_owned(), + Some(count) => trf("{count}, Show only rows with an issue", &[("count", count)]), + None => tr("Show only rows with an issue").to_owned(), }; let response = ui.interact(rect, ui.scope_id().with("baking_log_issues_filter"), Sense::click()); response.widget_info(|| WidgetInfo::selected(Role::Button, true, on, &name)); @@ -193,22 +207,41 @@ fn issues_filter(ui: &mut Ui, strip: Rect, issue_count: usize, on: bool) -> bool if response.has_focus() { crate::property_sheet::paint_focus_outline(painter, rect, tokens.text_strong); } - response.on_hover_text(tr("Show Only Issues")).clicked() + response.on_hover_text(tr("Show only rows with an issue")).clicked() } -/// What the issues filter leaves when `tab` has no issue: the reference's words for that tab, and how to see every row +/// What the issues filter leaves when `tab` has no issue: one line for that tab, and how to see every row fn no_issues(ui: &mut Ui, tab: BakingLogTab) { let tokens = Tokens::get(ui.ctx()); let message = match tab { - BakingLogTab::BakingProcess => tr("All textures baked successfully so far."), - BakingLogTab::HighPolyParameters => tr("No issues encountered so far."), - BakingLogTab::MatchingByName => tr("No matching issues encountered"), + BakingLogTab::BakingProcess => tr("Every map so far baked without a problem."), + BakingLogTab::HighPolyParameters => tr("Every high poly file so far loaded."), + BakingLogTab::MatchingByName => tr("Every part so far has its partner."), }; let area = ui.available_rect_before_wrap(); let mut child = ui.new_child(egui::UiBuilder::new().max_rect(area).layout(egui::Layout::top_down(egui::Align::Center))); child.add_space((area.height() - EMPTY_TEXT_HEIGHT).max(0.0) / 2.0); child.label(egui::RichText::new(message).font(semibold(NAME_SIZE)).color(tokens.text)); - child.label(egui::RichText::new(tr("Deselect filter to view.")).size(NAME_SIZE).color(tokens.text_dim)); + child.label(egui::RichText::new(tr("Turn off the issues filter to see every row.")).size(NAME_SIZE).color(tokens.text_dim)); + ui.allocate_rect(area, Sense::hover()); +} + +/// What the Matching by Name tab says when no texture set of the latest bake matched by mesh name: the setting's name in SemiBold +fn matching_not_enabled(ui: &mut Ui) { + let tokens = Tokens::get(ui.ctx()); + let mut text = egui::text::LayoutJob::default(); + let format = |font| egui::TextFormat { font_id: font, color: tokens.text, ..Default::default() }; + // One sentence to translate, its setting kept apart to set it in SemiBold + let sentence = tr("{setting} was off for this bake."); + let (before, after) = sentence.split_once("{setting}").unwrap_or(("", sentence)); + text.append(before, 0.0, format(FontId::proportional(NAME_SIZE))); + text.append(tr("Matching by name"), 0.0, format(semibold(NAME_SIZE))); + text.append(after, 0.0, format(FontId::proportional(NAME_SIZE))); + + let area = ui.available_rect_before_wrap(); + let mut child = ui.new_child(egui::UiBuilder::new().max_rect(area).layout(egui::Layout::top_down(egui::Align::Center))); + child.add_space((area.height() - EMPTY_TEXT_HEIGHT / 2.0).max(0.0) / 2.0); + child.label(text); ui.allocate_rect(area, Sense::hover()); } @@ -222,8 +255,9 @@ fn baking_process(ui: &mut Ui, maps: &[BakeLogMap], issues_only: bool) -> Option let mut opened = None; for (index, row) in maps.iter().enumerate().filter(|(_, row)| !issues_only || row.state.is_issue()) { let (rect, open_clicked) = map_row(ui, row); + // Bring the next map into view too, so the list shows what comes after the map being baked if newly_followed && followed == Some(index) { - ui.scroll_to_rect(rect, None); + ui.scroll_to_rect(rect.with_max_y(rect.bottom() + ROW_HEIGHT), None); } if open_clicked { opened = Some((row.texture_set, row.map)); @@ -245,7 +279,7 @@ fn map_row(ui: &mut Ui, row: &BakeLogMap) -> (Rect, bool) { BakeMapState::Canceled => (ic::WARNING, tokens.warning, tr("Canceled")), }; response.widget_info(|| WidgetInfo::labeled(Role::Label, true, format!("{name}, {state}"))); - let open = row.state.is_issue().then(|| open_settings_button(ui, rect, &name)); + let open = row.state.is_issue().then(|| open_settings_button(ui, rect, (row.texture_set, row.map), &name)); let row_hovered = response.hovered() || open.as_ref().is_some_and(|open| open.hovered()); let painter = ui.painter(); @@ -286,11 +320,11 @@ fn map_row(ui: &mut Ui, row: &BakeLogMap) -> (Rect, bool) { } /// The open-settings arrow's square at the right end of `row`; it shows only while the row is hovered or it has focus -fn open_settings_button(ui: &mut Ui, row: Rect, name: &str) -> egui::Response { +fn open_settings_button(ui: &mut Ui, row: Rect, set_map: (usize, BakedMap), name: &str) -> egui::Response { let center = pos2(row.right() - SIDE_PADDING_POINTS - OPEN_BUTTON_SIZE / 2.0, row.center().y); let rect = Rect::from_center_size(center, vec2(OPEN_BUTTON_SIZE, OPEN_BUTTON_SIZE)); let label = trf("Open the {name} settings", &[("name", &name)]); - let response = ui.interact(rect, ui.scope_id().with(("baking_log_open", name)), Sense::click()); + let response = ui.interact(rect, ui.scope_id().with(("baking_log_open", set_map)), Sense::click()); response.widget_info(|| WidgetInfo::labeled(Role::Button, true, &label)); response.on_hover_text(label) } diff --git a/crates/ui-egui/src/baking_log/matching_list.rs b/crates/ui-egui/src/baking_log/matching_list.rs new file mode 100644 index 00000000..22ad6c46 --- /dev/null +++ b/crates/ui-egui/src/baking_log/matching_list.rs @@ -0,0 +1,79 @@ +//! The Baking Log's Matching by Name tab: which low poly part the latest bake paired with which high poly part + +use egui::{Align2, CornerRadius, FontId, Rect, Role, Sense, Stroke, Ui, WidgetInfo, pos2, vec2}; +use egui_phosphor::regular as ic; +use texturecraft_engine::bake::{BakeLogMatching, NamePair}; + +use super::{GLYPH_SIZE, HOVER_INSET, NAME_SIZE, ROW_HEIGHT}; +use crate::i18n::{tr, trf}; +use crate::property_sheet::SIDE_PADDING_POINTS; +use crate::theme::{Tokens, semibold}; + +/// Size of the column captions +const CAPTION_SIZE: f32 = 11.0; + +/// The two columns' captions and a row per pair (only the parts with no partner, if `issues_only`), each ruled off below +pub(super) fn matching_list(ui: &mut Ui, matching: &BakeLogMatching, issues_only: bool) { + let tokens = Tokens::get(ui.ctx()); + let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), ROW_HEIGHT), Sense::hover()); + let captions = [caption(tr("Low poly mesh ({suffix})"), &matching.low_suffix), caption(tr("High poly mesh ({suffix})"), &matching.high_suffix)]; + for (left, caption) in columns(rect).into_iter().zip(captions) { + ui.painter().text(pos2(left, rect.center().y), Align2::LEFT_CENTER, caption, FontId::proportional(CAPTION_SIZE), tokens.text_dim); + } + rule(ui, rect); + + for pair in matching.pairs.iter().filter(|pair| !issues_only || pair.unpaired()) { + pair_row(ui, pair); + } +} + +/// A column caption in capitals, with the set's `suffix` kept as typed +fn caption(template: &str, suffix: &str) -> String { + template.split("{suffix}").map(str::to_uppercase).collect::>().join(suffix) +} + +/// The left edges of the low and high poly columns of `row` +fn columns(row: Rect) -> [f32; 2] { + [row.left() + SIDE_PADDING_POINTS, row.center().x] +} + +/// The hairline under `row`, inside the side padding +fn rule(ui: &Ui, row: Rect) { + let tokens = Tokens::get(ui.ctx()); + let x = row.left() + SIDE_PADDING_POINTS..=row.right() - SIDE_PADDING_POINTS; + ui.painter().hline(x, row.bottom() - 0.5, Stroke::new(1.0, tokens.separator)); +} + +/// A pair's row: the low poly part, then the high poly part; a side with no partner is a warning glyph that tells why on hover +fn pair_row(ui: &mut Ui, pair: &NamePair) { + let tokens = Tokens::get(ui.ctx()); + let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), ROW_HEIGHT), Sense::hover()); + let no_match = tr("No match"); + let name = format!("{}, {}", pair.low.as_deref().unwrap_or(no_match), pair.high.as_deref().unwrap_or(no_match)); + response.widget_info(|| WidgetInfo::labeled(Role::Label, true, &name)); + + let painter = ui.painter(); + if response.hovered() { + painter.rect_filled(rect.shrink2(vec2(HOVER_INSET, 0.0)), CornerRadius::ZERO, tokens.row_hover); + } + let center_y = rect.center().y; + for (left, part) in columns(rect).into_iter().zip([&pair.low, &pair.high]) { + match part { + Some(part) => painter.text(pos2(left, center_y), Align2::LEFT_CENTER, part, FontId::proportional(NAME_SIZE), tokens.text), + None => painter.text(pos2(left, center_y), Align2::LEFT_CENTER, ic::WARNING, FontId::proportional(GLYPH_SIZE), tokens.warning), + }; + } + rule(ui, rect); + + let reason = match (&pair.low, &pair.high) { + (Some(low), None) => Some(trf("No high poly part pairs with {part} by name, so it bakes from none.", &[("part", low)])), + (None, Some(high)) => Some(trf("No low poly part pairs with {part} by name, so no texture set bakes from it.", &[("part", high)])), + _ => None, + }; + if let Some(reason) = reason { + response.on_hover_ui(|ui| { + ui.label(egui::RichText::new(no_match).font(semibold(NAME_SIZE)).color(tokens.text)); + ui.label(egui::RichText::new(reason).size(NAME_SIZE).color(tokens.text_dim)); + }); + } +} diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index f825ba7e..4346c304 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -707,7 +707,7 @@ impl TextureCraftApp { self.session.bake_preview_begin(orders); let total = sets.len(); - self.session.bake_log.begin(&self.session.doc.project, &self.session.bake_meshes.high, &sets); + self.session.begin_bake_log(&sets); self.bake_report = bake_report::BakeReport::started(self.last_time); self.bake = Some(BakeJob { queue: sets, current: None, total, mesh_id: self.session.mesh_id, only }); } diff --git a/crates/ui-egui/tests/it/baking_log.rs b/crates/ui-egui/tests/it/baking_log.rs index 837e3403..3d098b6f 100644 --- a/crates/ui-egui/tests/it/baking_log.rs +++ b/crates/ui-egui/tests/it/baking_log.rs @@ -2,7 +2,7 @@ use egui_kittest::Harness; use egui_kittest::kittest::Queryable; -use texturecraft_engine::bake::{BakeHighState, BakeLogHigh, BakeLogMap, BakeMapState}; +use texturecraft_engine::bake::{BakeHighState, BakeLogHigh, BakeLogMap, BakeLogMatching, BakeMapState, NamePair}; use texturecraft_engine::core::{BakeResolution, BakedMap}; use texturecraft_ui_egui::TextureCraftApp; use texturecraft_ui_egui::docking::Panel; @@ -103,29 +103,29 @@ fn the_issues_filter_keeps_only_the_maps_with_a_problem() { let set_name = log_a_bake(&mut harness, BakeMapState::Failed("The high poly file could not be read.".into())); harness.get_by_label(&format!("{set_name} ID, Baked")); - harness.get_by_label("1, Show Only Issues").click(); + harness.get_by_label("1, Show only rows with an issue").click(); harness.run_steps(3); assert!(harness.query_by_label(&format!("{set_name} ID, Baked")).is_none(), "a baked map is filtered out"); harness.get_by_label(&format!("{set_name} Position, Not baked")); - assert!(harness.query_by_label("Deselect filter to view.").is_none(), "an issue left: no empty text"); + assert!(harness.query_by_label("Turn off the issues filter to see every row.").is_none(), "an issue left: no empty text"); } #[test] fn the_issues_filter_says_so_when_nothing_went_wrong() { let mut harness = harness(); let set_name = log_a_bake(&mut harness, BakeMapState::Baked); - harness.get_by_label("Show Only Issues").click(); + harness.get_by_label("Show only rows with an issue").click(); harness.run_steps(3); assert!(harness.query_by_label(&format!("{set_name} ID, Baked")).is_none()); - harness.get_by_label("All textures baked successfully so far."); - harness.get_by_label("Deselect filter to view."); + harness.get_by_label("Every map so far baked without a problem."); + harness.get_by_label("Turn off the issues filter to see every row."); - harness.get_by_label("Show Only Issues").click(); + harness.get_by_label("Show only rows with an issue").click(); harness.run_steps(3); harness.get_by_label(&format!("{set_name} ID, Baked")); - assert!(harness.query_by_label("All textures baked successfully so far.").is_none(), "off again: every row is back"); + assert!(harness.query_by_label("Every map so far baked without a problem.").is_none(), "off again: every row is back"); } #[test] @@ -154,9 +154,42 @@ fn the_high_poly_tab_counts_and_keeps_its_own_issues() { harness.get_by_label("High Poly Parameters").click(); harness.run_steps(3); - harness.get_by_label("1, Show Only Issues").click(); + harness.get_by_label("1, Show only rows with an issue").click(); harness.run_steps(3); assert!(harness.query_by_label("ball_high.obj, Loaded").is_none(), "a loaded file is filtered out"); harness.get_by_label("bolt_high.obj, Canceled"); } + +#[test] +fn the_matching_tab_lists_the_pairs_and_its_filter_keeps_the_parts_with_no_partner() { + let mut harness = harness(); + log_a_bake(&mut harness, BakeMapState::Baked); + let pair = |low: Option<&str>, high: Option<&str>| NamePair { low: low.map(Into::into), high: high.map(Into::into) }; + harness.state_mut().session.bake_log.matching = Some(BakeLogMatching { + low_suffix: "_low".into(), + high_suffix: "_high".into(), + pairs: vec![pair(Some("Barrel_low"), Some("Barrel_high")), pair(Some("Strap_low"), None)], + }); + harness.get_by_label("Matching by Name").click(); + harness.run_steps(3); + harness.get_by_label("Barrel_low, Barrel_high"); + + harness.get_by_label("1, Show only rows with an issue").click(); + harness.run_steps(3); + + assert!(harness.query_by_label("Barrel_low, Barrel_high").is_none(), "a pair is filtered out"); + harness.get_by_label("Strap_low, No match"); +} + +#[test] +fn the_matching_tab_says_when_no_set_matched_by_name() { + let mut harness = harness(); + harness.get_by_label("Matching by Name").click(); + harness.run_steps(3); + assert!(harness.query_by_label("Matching by name was off for this bake.").is_none(), "nothing baked yet: nothing to say"); + + log_a_bake(&mut harness, BakeMapState::Baked); + + harness.get_by_label("Matching by name was off for this bake."); +} diff --git a/docs/control-protocol.md b/docs/control-protocol.md index d97cd2bf..a682a901 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -308,12 +308,16 @@ also `session.inspect`'s `bakePreview`: `bake.log` `{}` returns the latest bake map by map, as the Baking Log shows it (empty before the first bake). A map's `state` is `waiting`, `baking`, `baked`, `failed` (with the error as `reason`) or `canceled`. `highPolys` lists the high poly files of each set that bakes from them; a file's `state` is `waiting`, -`loading`, `loaded`, `failed` (with the error as `reason`) or `canceled`: +`loading`, `loaded`, `failed` (with the error as `reason`) or `canceled`. `matching` lists each low poly +part with the high poly part it bakes from, then the high poly parts no set paired with; a `null` side is a part +with no partner. It is `null` when no set of the bake matches by mesh name: ```json {"running": false, "maps": [{"textureSet": 0, "setName": "Body", "map": "normal", "state": "baked"}, {"textureSet": 1, "setName": "Head", "map": "normal", "state": "failed", "reason": "no UV tile left to bake"}], - "highPolys": [{"textureSet": 0, "setName": "Body", "file": "body_high.fbx", "state": "loaded"}]} + "highPolys": [{"textureSet": 0, "setName": "Body", "file": "body_high.fbx", "state": "loaded"}], + "matching": {"lowSuffix": "_low", "highSuffix": "_high", + "pairs": [{"low": "Arm_low", "high": "Arm_high"}, {"low": "Strap_low", "high": null}]}} ``` `{"active": false}` when no bake is shown; setting `show` then is an error. Drive a bake with