From c0839e873e26ec920b7a8368d3cb8eeea37327bf Mon Sep 17 00:00:00 2001 From: Rebornim <250083243+Rebornim@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:21:07 +0000 Subject: [PATCH] List each set's high poly files in the Baking Log --- crates/engine/src/bake/bake_high_state.rs | 27 +++++ crates/engine/src/bake/bake_log.rs | 50 +++++++++- crates/engine/src/bake/bake_log_high.rs | 11 +++ crates/engine/src/bake/mesh_map_command.rs | 3 +- crates/engine/src/bake/mod.rs | 4 + crates/engine/src/bake_log_cmds.rs | 32 +++--- crates/engine/tests/it/bake_log.rs | 37 ++++++- crates/ui-egui/src/baking_log.rs | 22 +++-- .../ui-egui/src/baking_log/high_poly_list.rs | 98 +++++++++++++++++++ crates/ui-egui/src/lib.rs | 3 +- crates/ui-egui/tests/it/baking_log.rs | 35 ++++++- docs/control-protocol.md | 7 +- 12 files changed, 296 insertions(+), 33 deletions(-) create mode 100644 crates/engine/src/bake/bake_high_state.rs create mode 100644 crates/engine/src/bake/bake_log_high.rs create mode 100644 crates/ui-egui/src/baking_log/high_poly_list.rs diff --git a/crates/engine/src/bake/bake_high_state.rs b/crates/engine/src/bake/bake_high_state.rs new file mode 100644 index 00000000..8ecbd0a5 --- /dev/null +++ b/crates/engine/src/bake/bake_high_state.rs @@ -0,0 +1,27 @@ +use serde::Serialize; + +/// Where one high poly file of a bake stands, as the Baking Log shows it +#[derive(Clone, Debug, PartialEq, Eq, Serialize)] +#[serde(rename_all = "camelCase", tag = "state", content = "reason")] +pub enum BakeHighState { + /// Its texture set has not started baking + Waiting, + Loading, + Loaded, + /// Its texture set's bake failed while getting the high polys ready; the reason is the error + Failed(String), + /// The bake stopped before the file was loaded + Canceled, +} + +impl BakeHighState { + /// Whether the file can still change in this bake + pub fn is_pending(&self) -> bool { + matches!(self, Self::Waiting | Self::Loading) + } + + /// Whether the file counts as an issue in the log + pub fn is_issue(&self) -> bool { + matches!(self, Self::Failed(_) | Self::Canceled) + } +} diff --git a/crates/engine/src/bake/bake_log.rs b/crates/engine/src/bake/bake_log.rs index d8705039..82f63c90 100644 --- a/crates/engine/src/bake/bake_log.rs +++ b/crates/engine/src/bake/bake_log.rs @@ -1,16 +1,18 @@ use texturecraft_core::{BakedMap, Project}; -use super::{BakeLogMap, BakeMapState}; +use super::{BakeHighState, BakeLogHigh, BakeLogMap, BakeMapState, BakeMesh}; /// 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)] 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, } impl BakeLog { - /// Start over for a bake of `sets`: every checked map of each set, waiting, in bake order - pub fn begin(&mut self, project: &Project, sets: &[usize]) { + /// Start over for a bake of `sets`: every checked map of each set and the `high_polys` of each set that bakes from them, waiting, in bake order + pub fn begin(&mut self, project: &Project, high_polys: &[BakeMesh], sets: &[usize]) { self.maps = sets .iter() .filter_map(|index| project.texture_sets.get(*index).map(|set| (*index, set))) @@ -18,13 +20,36 @@ impl BakeLog { set.bake.maps.enabled().map(move |map| BakeLogMap { texture_set: index, set_name: set.name.clone(), map, state: BakeMapState::Waiting }) }) .collect(); + self.highs = sets + .iter() + .filter_map(|index| project.texture_sets.get(*index).map(|set| (*index, set))) + .filter(|(_, set)| !set.bake.high_poly.use_low_as_high) + .flat_map(|(index, set)| { + high_polys.iter().map(move |high| BakeLogHigh { + texture_set: index, + set_name: set.name.clone(), + file: high.name.clone(), + state: BakeHighState::Waiting, + }) + }) + .collect(); } - /// `set` starts baking: its first map is the one in progress + /// `set` starts baking: its high polys load and its first map is the one in progress pub fn set_started(&mut self, set: usize) { + for row in self.highs.iter_mut().filter(|row| row.texture_set == set && row.state == BakeHighState::Waiting) { + row.state = BakeHighState::Loading; + } self.start_next(set); } + /// `set`'s bake has its high polys ready + pub fn high_polys_loaded(&mut self, set: usize) { + for row in self.highs.iter_mut().filter(|row| row.texture_set == set && row.state == BakeHighState::Loading) { + row.state = BakeHighState::Loaded; + } + } + /// `map` of `set` is baked; the set's next map starts pub fn map_baked(&mut self, set: usize, map: BakedMap) { if let Some(row) = self.maps.iter_mut().find(|row| row.texture_set == set && row.map == map) { @@ -45,6 +70,10 @@ impl BakeLog { for row in self.maps.iter_mut().filter(|row| row.texture_set == set) { row.state = BakeMapState::Failed(reason.to_owned()); } + // A file that loaded is not what failed + for row in self.highs.iter_mut().filter(|row| row.texture_set == set && row.state.is_pending()) { + row.state = BakeHighState::Failed(reason.to_owned()); + } } /// The bake stopped: the maps of `current` (the set being baked, not kept) and every map still waiting are canceled @@ -54,6 +83,7 @@ impl BakeLog { row.state = BakeMapState::Canceled; } } + self.cancel_pending_highs(); } /// The whole bake was rolled back: every map that did not fail is canceled @@ -61,6 +91,7 @@ impl BakeLog { for row in self.maps.iter_mut().filter(|row| !matches!(row.state, BakeMapState::Failed(_))) { row.state = BakeMapState::Canceled; } + self.cancel_pending_highs(); } /// Whether a map is still waiting or baking @@ -68,6 +99,17 @@ impl BakeLog { self.maps.iter().any(|row| row.state.is_pending()) } + /// Whether a high poly file is still waiting or loading + pub fn is_loading_high_polys(&self) -> bool { + self.highs.iter().any(|row| row.state.is_pending()) + } + + fn cancel_pending_highs(&mut self) { + for row in self.highs.iter_mut().filter(|row| row.state.is_pending()) { + row.state = BakeHighState::Canceled; + } + } + fn start_next(&mut self, set: usize) { if self.maps.iter().any(|row| row.texture_set == set && row.state == BakeMapState::Baking) { return; diff --git a/crates/engine/src/bake/bake_log_high.rs b/crates/engine/src/bake/bake_log_high.rs new file mode 100644 index 00000000..7c6de83d --- /dev/null +++ b/crates/engine/src/bake/bake_log_high.rs @@ -0,0 +1,11 @@ +use super::BakeHighState; + +/// One row of the Baking Log's high poly list: a high poly file a texture set bakes from in the latest bake +#[derive(Clone, Debug, PartialEq)] +pub struct BakeLogHigh { + pub texture_set: usize, + pub set_name: String, + /// The file's name as the project keeps it (the project carries the file itself, not where it came from) + pub file: String, + pub state: BakeHighState, +} diff --git a/crates/engine/src/bake/mesh_map_command.rs b/crates/engine/src/bake/mesh_map_command.rs index a76561fb..e3f16c22 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, &sets); + session.bake_log.begin(&session.doc.project, &session.bake_meshes.high, &sets); let mut tracers = Vec::with_capacity(sets.len()); for &index in &sets { @@ -871,6 +871,7 @@ fn bake_run(session: &mut Session, params: &Value) -> Result { /// Bake every checked map of texture set `index` at once, store them and mark them baked in the Baking Log fn bake_one_set(session: &mut Session, index: usize, cpu: bool) -> Result { let mut task = session.bake_task(index)?; + session.bake_log.high_polys_loaded(index); if cpu { task.tracer = None; } diff --git a/crates/engine/src/bake/mod.rs b/crates/engine/src/bake/mod.rs index 736b00bb..873c2f35 100644 --- a/crates/engine/src/bake/mod.rs +++ b/crates/engine/src/bake/mod.rs @@ -2,7 +2,9 @@ mod bake_cage_inputs; mod bake_checks; +mod bake_high_state; mod bake_log; +mod bake_log_high; mod bake_log_map; mod bake_map_state; mod bake_mesh; @@ -22,7 +24,9 @@ mod sync_command; mod tile_command; pub use bake_cage_inputs::BakeCageInputs; +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_map_state::BakeMapState; pub use bake_mesh::BakeMesh; diff --git a/crates/engine/src/bake_log_cmds.rs b/crates/engine/src/bake_log_cmds.rs index dc8e243e..edfbd15a 100644 --- a/crates/engine/src/bake_log_cmds.rs +++ b/crates/engine/src/bake_log_cmds.rs @@ -11,26 +11,26 @@ pub fn specs() -> Vec { "Baking log", [], None, - "{} → {running, maps: [{textureSet, setName, map, state: \"waiting\" | \"baking\" | \"baked\" | \"failed\" | \"canceled\", reason?}]}. The latest bake map by map in bake order, as the Baking Log shows it; `reason` says why a map 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?}]}. 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", always, log )] } fn log(session: &mut Session, _: &Value) -> Result { - let maps = session - .bake_log - .maps - .iter() - .map(|row| { - let mut entry = serde_json::to_value(&row.state).map_err(|error| bad("bake.log", error.to_string()))?; - if let Some(fields) = entry.as_object_mut() { - fields.insert("textureSet".into(), json!(row.texture_set)); - fields.insert("setName".into(), json!(row.set_name)); - fields.insert("map".into(), json!(row.map.id())); - } - Ok(entry) - }) - .collect::>>()?; - Ok(json!({ "running": session.bake_log.is_running(), "maps": maps })) + 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 })) +} + +/// One row: its `state` (and `reason`), its texture set, and what it is under `key` +fn entry(state: &impl serde::Serialize, texture_set: usize, set_name: &str, key: &str, what: Value) -> Result { + let mut entry = serde_json::to_value(state).map_err(|error| bad("bake.log", error.to_string()))?; + if let Some(fields) = entry.as_object_mut() { + fields.insert("textureSet".into(), json!(texture_set)); + fields.insert("setName".into(), json!(set_name)); + fields.insert(key.into(), what); + } + Ok(entry) } diff --git a/crates/engine/tests/it/bake_log.rs b/crates/engine/tests/it/bake_log.rs index 955d5561..36ce7772 100644 --- a/crates/engine/tests/it/bake_log.rs +++ b/crates/engine/tests/it/bake_log.rs @@ -3,7 +3,7 @@ use std::collections::BTreeSet; use serde_json::json; -use texturecraft_engine::bake::BakeMapState; +use texturecraft_engine::bake::{BakeHighState, BakeMapState}; use texturecraft_engine::core::BakedMap; use texturecraft_engine::geom::primitives; use texturecraft_engine::{Session, execute, sample_session}; @@ -30,7 +30,7 @@ fn a_canceled_bake_keeps_the_finished_sets_and_cancels_the_rest() { set.bake.maps.select([BakedMap::Normal, BakedMap::Curvature]); } let log = &mut session.bake_log; - log.begin(&session.doc.project, &[0, 1]); + log.begin(&session.doc.project, &session.doc.bake_meshes.high, &[0, 1]); log.set_started(0); log.map_baked(0, BakedMap::Normal); @@ -65,3 +65,36 @@ fn bake_log_reports_each_map_with_its_state_and_a_failures_reason() { let log = execute(&mut session, "bake.log", &json!({})).unwrap(); assert!(log["maps"].as_array().unwrap().iter().all(|row| row["state"] == "failed" && row["reason"] == "The high poly file could not be read."), "{log}"); } + +#[test] +fn a_bake_lists_the_high_polys_each_set_loads_and_skips_a_set_baking_from_its_low_poly() { + let mut session = sample_session(256, 64).unwrap(); + 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(); + session.doc.project.texture_sets[1].bake.high_poly.use_low_as_high = true; + + execute(&mut session, "bake.run", &json!({ "ts": [0, 1], "resolution": 64, "maps": ["opacity"], "dilation": 0 })).unwrap(); + + let highs: Vec<_> = session.bake_log.highs.iter().map(|row| (row.texture_set, row.file.as_str(), row.state.clone())).collect(); + assert_eq!(highs, [(0, "ball_high.obj", BakeHighState::Loaded)]); + let log = execute(&mut session, "bake.log", &json!({})).unwrap(); + assert_eq!(log["highPolys"][0]["state"], "loaded", "{log}"); +} + +#[test] +fn a_set_that_fails_before_its_high_polys_are_ready_marks_them_failed_and_a_cancel_the_rest_canceled() { + let mut session = sample_session(256, 64).unwrap(); + 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]); + + log.set_started(0); + assert_eq!(log.highs[0].state, 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!(!log.is_loading_high_polys()); +} diff --git a/crates/ui-egui/src/baking_log.rs b/crates/ui-egui/src/baking_log.rs index 1688d940..9b2e0257 100644 --- a/crates/ui-egui/src/baking_log.rs +++ b/crates/ui-egui/src/baking_log.rs @@ -3,7 +3,7 @@ use egui::{Align2, CornerRadius, FontId, Id, Rect, Role, Sense, Stroke, StrokeKind, Ui, WidgetInfo, pos2, vec2}; use egui_phosphor::regular as ic; use serde_json::json; -use texturecraft_engine::bake::{BakeLogMap, BakeMapState}; +use texturecraft_engine::bake::{BakeLog, BakeLogMap, BakeMapState}; use texturecraft_engine::core::BakedMap; use crate::TextureCraftApp; @@ -13,6 +13,7 @@ use crate::property_sheet::{SIDE_PADDING_POINTS, TAB_GAP, TAB_ICON_CENTER, TAB_I use crate::theme::{Tokens, semibold}; mod baking_log_tab; +mod high_poly_list; pub use baking_log_tab::BakingLogTab; @@ -69,13 +70,14 @@ pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) { let tokens = Tokens::get(ui.ctx()); let (strip, _) = ui.allocate_exact_size(vec2(ui.available_width(), STRIP_HEIGHT), Sense::hover()); ui.painter().rect_filled(strip, CornerRadius::ZERO, tokens.chrome); - if let Some(tab) = tabs(ui, strip, app.ui.baking_log_tab, app.session.bake_log.is_running()) { + if let Some(tab) = tabs(ui, strip, app.ui.baking_log_tab, &app.session.bake_log) { app.ui.baking_log_tab = tab; } let tab = app.ui.baking_log_tab; let issue_count = match tab { BakingLogTab::BakingProcess => app.session.bake_log.maps.iter().filter(|row| row.state.is_issue()).count(), - _ => 0, + BakingLogTab::HighPolyParameters => app.session.bake_log.highs.iter().filter(|row| row.state.is_issue()).count(), + BakingLogTab::MatchingByName => 0, }; 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; @@ -93,7 +95,11 @@ pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) { ui.add_space(LIST_TOP); match tab { BakingLogTab::BakingProcess => baking_process(ui, &app.session.bake_log.maps, issues_only), - _ => None, + BakingLogTab::HighPolyParameters => { + high_poly_list::high_poly_list(ui, &app.session.bake_log.highs, issues_only); + None + } + BakingLogTab::MatchingByName => None, } }) .inner; @@ -117,7 +123,7 @@ fn open_map_settings(app: &mut TextureCraftApp, texture_set: usize, map: BakedMa } /// The tabs on the `strip` along the panel's top edge, as the Properties section tabs; a tab with work in progress shows dots for its icon -fn tabs(ui: &mut Ui, strip: Rect, shown: BakingLogTab, running: bool) -> Option { +fn tabs(ui: &mut Ui, strip: Rect, shown: BakingLogTab, log: &BakeLog) -> Option { let tokens = Tokens::get(ui.ctx()); let mut picked = None; let mut left = strip.left() + SIDE_PADDING_POINTS - FIRST_TAB_OUTDENT; @@ -137,7 +143,11 @@ fn tabs(ui: &mut Ui, strip: Rect, shown: BakingLogTab, running: bool) -> Option< shown_tab_box(painter, &tokens, rect); } let color = if on || response.hovered() { tokens.text } else { tokens.text_dim }; - let in_progress = running && tab == BakingLogTab::BakingProcess; + let in_progress = match tab { + BakingLogTab::BakingProcess => log.is_running(), + BakingLogTab::HighPolyParameters => log.is_loading_high_polys(), + BakingLogTab::MatchingByName => false, + }; let (icon, icon_color) = if in_progress { (ic::DOTS_THREE, tokens.accent) } else { (tab.icon(), color) }; let center_y = strip.center().y + TAB_TOP / 2.0; painter.text(pos2(left + TAB_ICON_CENTER, center_y), Align2::CENTER_CENTER, icon, FontId::proportional(TAB_ICON_SIZE), icon_color); diff --git a/crates/ui-egui/src/baking_log/high_poly_list.rs b/crates/ui-egui/src/baking_log/high_poly_list.rs new file mode 100644 index 00000000..5f4f5977 --- /dev/null +++ b/crates/ui-egui/src/baking_log/high_poly_list.rs @@ -0,0 +1,98 @@ +//! The Baking Log's High Poly Parameters tab: each texture set of the latest bake and the high poly files it loads + +use egui::{Align2, CornerRadius, FontId, Id, Role, Sense, Ui, WidgetInfo, pos2, vec2}; +use egui_phosphor::regular as ic; +use texturecraft_engine::bake::{BakeHighState, BakeLogHigh}; + +use super::{GLYPH_CENTER, GLYPH_SIZE, HOVER_INSET, NAME_LEFT, NAME_SIZE, ROW_HEIGHT}; +use crate::i18n::{tr, trf}; +use crate::theme::{Tokens, semibold}; + +/// How far a file's row sits right of its texture set's row +const FILE_INDENT: f32 = 22.0; + +/// A row per texture set that loads high polys, folding open onto a row per file (with an issue, if `issues_only`) +pub(super) fn high_poly_list(ui: &mut Ui, highs: &[BakeLogHigh], issues_only: bool) { + let mut start = 0; + while start < highs.len() { + let set = highs[start].texture_set; + let end = highs[start..].iter().position(|row| row.texture_set != set).map_or(highs.len(), |length| start + length); + let files: Vec<&BakeLogHigh> = highs[start..end].iter().filter(|row| !issues_only || row.state.is_issue()).collect(); + start = end; + if files.is_empty() { + continue; + } + + if set_row(ui, set, &files[0].set_name) { + for row in files { + file_row(ui, row); + } + } + } +} + +/// A texture set's row: a caret and its name in SemiBold, named for what it holds; a click folds it. Returns whether it is open +fn set_row(ui: &mut Ui, set: usize, name: &str) -> bool { + let tokens = Tokens::get(ui.ctx()); + let id = Id::unique(("baking_log_high_poly_set", set)); + let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), ROW_HEIGHT), Sense::hover()); + let response = ui.interact(rect, id, Sense::click()); + response.widget_info(|| WidgetInfo::labeled(Role::Button, true, trf("{set}, High poly files", &[("set", &name)]))); + let mut open = ui.data(|data| data.get_temp::(id)).unwrap_or(true); + if response.clicked() { + open = !open; + ui.data_mut(|data| data.insert_temp(id, open)); + } + + 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; + let caret = if open { ic::CARET_DOWN } else { ic::CARET_RIGHT }; + painter.text(pos2(rect.left() + GLYPH_CENTER, center_y), Align2::CENTER_CENTER, caret, FontId::proportional(GLYPH_SIZE), tokens.text_dim); + painter.text(pos2(rect.left() + NAME_LEFT, center_y), Align2::LEFT_CENTER, name, semibold(NAME_SIZE), tokens.text); + if response.has_focus() { + crate::property_sheet::paint_focus_outline(painter, rect, tokens.text_strong); + } + open +} + +/// A high poly file's row under its texture set: glyph and file name; a file not loaded tells why on hover +fn file_row(ui: &mut Ui, row: &BakeLogHigh) { + let tokens = Tokens::get(ui.ctx()); + let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), ROW_HEIGHT), Sense::hover()); + let (glyph, glyph_color, state) = match &row.state { + BakeHighState::Waiting => (ic::CIRCLE_DASHED, tokens.text_dim, tr("Waiting")), + BakeHighState::Loading => (ic::DOTS_THREE, tokens.accent, tr("Loading")), + BakeHighState::Loaded => (ic::CHECK, tokens.text, tr("Loaded")), + BakeHighState::Failed(_) => (ic::X_CIRCLE, tokens.danger, tr("Not loaded")), + BakeHighState::Canceled => (ic::WARNING, tokens.warning, tr("Canceled")), + }; + response.widget_info(|| WidgetInfo::labeled(Role::Label, true, format!("{}, {state}", row.file))); + + 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; + painter.text(pos2(rect.left() + GLYPH_CENTER + FILE_INDENT, center_y), Align2::CENTER_CENTER, glyph, FontId::proportional(GLYPH_SIZE), glyph_color); + let (font, color) = match row.state { + BakeHighState::Loading => (semibold(NAME_SIZE), tokens.text), + BakeHighState::Waiting => (FontId::proportional(NAME_SIZE), tokens.text_dim), + _ => (FontId::proportional(NAME_SIZE), tokens.text), + }; + painter.text(pos2(rect.left() + NAME_LEFT + FILE_INDENT, center_y), Align2::LEFT_CENTER, &row.file, font, color); + + let reason = match &row.state { + BakeHighState::Failed(reason) => Some(reason.as_str()), + BakeHighState::Canceled => Some(tr("The bake was canceled before this file was loaded.")), + _ => None, + }; + if let Some(reason) = reason { + response.on_hover_ui(|ui| { + ui.label(egui::RichText::new(state).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 a786eef7..f825ba7e 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, &sets); + self.session.bake_log.begin(&self.session.doc.project, &self.session.bake_meshes.high, &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 }); } @@ -896,6 +896,7 @@ impl TextureCraftApp { }; match task { Ok(task) => { + self.session.bake_log.high_polys_loaded(set_index); let progress = Arc::new(Progress::new()); let worker_progress = progress.clone(); let maps_total = task.maps().len(); diff --git a/crates/ui-egui/tests/it/baking_log.rs b/crates/ui-egui/tests/it/baking_log.rs index 9f56d585..837e3403 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::{BakeLogMap, BakeMapState}; +use texturecraft_engine::bake::{BakeHighState, BakeLogHigh, BakeLogMap, BakeMapState}; use texturecraft_engine::core::{BakeResolution, BakedMap}; use texturecraft_ui_egui::TextureCraftApp; use texturecraft_ui_egui::docking::Panel; @@ -127,3 +127,36 @@ fn the_issues_filter_says_so_when_nothing_went_wrong() { 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"); } + +#[test] +fn the_high_poly_tab_lists_each_sets_high_poly_files_under_a_row_that_folds() { + let mut harness = harness(); + harness.state_mut().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(); + harness.state_mut().start_bake(vec![0]); + run_to_the_end(&mut harness); + + harness.get_by_label("High Poly Parameters").click(); + harness.run_steps(3); + let set_name = harness.state().session.doc.project.texture_sets[0].name.clone(); + harness.get_by_label("ball_high.obj, Loaded"); + + harness.get_by_label(&format!("{set_name}, High poly files")).click(); + harness.run_steps(3); + assert!(harness.query_by_label("ball_high.obj, Loaded").is_none(), "a folded set hides its files"); +} + +#[test] +fn the_high_poly_tab_counts_and_keeps_its_own_issues() { + let mut harness = harness(); + let set_name = log_a_bake(&mut harness, BakeMapState::Baked); + let row = |file: &str, state| BakeLogHigh { texture_set: 0, set_name: set_name.clone(), file: file.into(), state }; + harness.state_mut().session.bake_log.highs = vec![row("ball_high.obj", BakeHighState::Loaded), row("bolt_high.obj", BakeHighState::Canceled)]; + harness.get_by_label("High Poly Parameters").click(); + harness.run_steps(3); + + harness.get_by_label("1, Show Only Issues").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"); +} diff --git a/docs/control-protocol.md b/docs/control-protocol.md index feb3627f..d97cd2bf 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -306,11 +306,14 @@ 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). -`state` is `waiting`, `baking`, `baked`, `failed` (with the error as `reason`) or `canceled`: +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`: ```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"}]} + {"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"}]} ``` `{"active": false}` when no bake is shown; setting `show` then is an error. Drive a bake with