From dfafec43c14e0738ca12c28cb094df48a6b5aa66 Mon Sep 17 00:00:00 2001 From: Rebornim <250083243+Rebornim@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:09:06 +0000 Subject: [PATCH] Report the Baking Log's rows through bake.log Automation gets the latest bake map by map with each map's state and the error of a failed one, the same rows the Baking Log shows. --- crates/engine/src/bake/bake_log.rs | 3 +-- crates/engine/src/bake/bake_log_map.rs | 5 +--- crates/engine/src/bake_log_cmds.rs | 36 ++++++++++++++++++++++++++ crates/engine/src/commands.rs | 1 + crates/engine/src/lib.rs | 1 + crates/engine/tests/it/bake_log.rs | 17 ++++++++++++ docs/control-protocol.md | 8 ++++++ 7 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 crates/engine/src/bake_log_cmds.rs diff --git a/crates/engine/src/bake/bake_log.rs b/crates/engine/src/bake/bake_log.rs index 2f263cf2..d8705039 100644 --- a/crates/engine/src/bake/bake_log.rs +++ b/crates/engine/src/bake/bake_log.rs @@ -1,10 +1,9 @@ -use serde::Serialize; use texturecraft_core::{BakedMap, Project}; use super::{BakeLogMap, BakeMapState}; /// 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, Serialize)] +#[derive(Clone, Debug, Default, PartialEq)] pub struct BakeLog { pub maps: Vec, } diff --git a/crates/engine/src/bake/bake_log_map.rs b/crates/engine/src/bake/bake_log_map.rs index 4a04bd7d..6f5d714a 100644 --- a/crates/engine/src/bake/bake_log_map.rs +++ b/crates/engine/src/bake/bake_log_map.rs @@ -1,15 +1,12 @@ -use serde::Serialize; use texturecraft_core::BakedMap; use super::BakeMapState; /// One row of the Baking Log's process list: a map of a texture set in the latest bake -#[derive(Clone, Debug, PartialEq, Serialize)] -#[serde(rename_all = "camelCase")] +#[derive(Clone, Debug, PartialEq)] pub struct BakeLogMap { pub texture_set: usize, pub set_name: String, pub map: BakedMap, - #[serde(flatten)] pub state: BakeMapState, } diff --git a/crates/engine/src/bake_log_cmds.rs b/crates/engine/src/bake_log_cmds.rs new file mode 100644 index 00000000..dc8e243e --- /dev/null +++ b/crates/engine/src/bake_log_cmds.rs @@ -0,0 +1,36 @@ +//! The `bake.log` query: the Baking Log's rows for automation + +use serde_json::{Value, json}; + +use crate::commands::{CommandSpec, always, bad}; +use crate::{Result, Session, cmd}; + +pub fn specs() -> Vec { + vec![cmd!( + "bake.log", + "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", + 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 })) +} diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs index 49cead62..41e7d619 100644 --- a/crates/engine/src/commands.rs +++ b/crates/engine/src/commands.rs @@ -139,6 +139,7 @@ pub fn command_specs() -> &'static [CommandSpec] { v.extend(crate::project_cmds::specs()); v.extend(crate::bake::specs()); v.extend(crate::bake_preview::specs()); + v.extend(crate::bake_log_cmds::specs()); v.extend(crate::materialx_cmds::specs()); v.extend(crate::pbr_cmds::specs()); v.extend(crate::file_cmds::specs()); diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 148af463..ab6319f7 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -11,6 +11,7 @@ pub mod add_mask_cmds; mod anchored_micro_edit; pub mod bake; +pub mod bake_log_cmds; pub mod bake_preview; pub mod brush_preset_cmds; pub mod camera_cmds; diff --git a/crates/engine/tests/it/bake_log.rs b/crates/engine/tests/it/bake_log.rs index 965295e1..955d5561 100644 --- a/crates/engine/tests/it/bake_log.rs +++ b/crates/engine/tests/it/bake_log.rs @@ -48,3 +48,20 @@ fn a_canceled_bake_keeps_the_finished_sets_and_cancels_the_rest() { assert!(state_of(1).iter().all(|state| *state == BakeMapState::Canceled), "maps of the set not kept are canceled: {:?}", log.maps); assert!(!log.is_running()); } + +#[test] +fn bake_log_reports_each_map_with_its_state_and_a_failures_reason() { + let mesh = primitives::builtin("plane").unwrap(); + let mut session = Session::new_project("t", mesh, "builtin:plane", None, 256).unwrap(); + execute(&mut session, "bake.run", &json!({ "resolution": 64, "maps": ["opacity", "position"], "dilation": 0 })).unwrap(); + + let log = execute(&mut session, "bake.log", &json!({})).unwrap(); + assert_eq!(log["running"], false); + let maps: BTreeSet<&str> = log["maps"].as_array().unwrap().iter().map(|row| row["map"].as_str().unwrap()).collect(); + assert_eq!(maps, BTreeSet::from(["opacity", "position"])); + assert!(log["maps"].as_array().unwrap().iter().all(|row| row["state"] == "baked" && row["textureSet"] == 0 && row.get("reason").is_none()), "{log}"); + + session.bake_log.set_failed(0, "The high poly file could not be read."); + 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}"); +} diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 3abb3a97..feb3627f 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -305,6 +305,14 @@ also `session.inspect`'s `bakePreview`: "sets": [{"set": 0, "order": ["id", "ambientOcclusion", "curvature", "height"], "done": ["id", "ambientOcclusion"]}]} ``` +`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`: + +```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"}]} +``` + `{"active": false}` when no bake is shown; setting `show` then is an error. Drive a bake with `ui.bake.start` and poll `ui.inspect`'s `bakeStatus` / `bakePreview` (and `viewport.screenshot`) until `baking` is `null`.