mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-28 00:59:29 +01:00
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.
This commit is contained in:
1 parent
ec17def337
commit
dfafec43c1
7 files changed
+65
-6
No files matched your search
@@ -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<BakeLogMap>,
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
@@ -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<CommandSpec> {
|
||||
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<Value> {
|
||||
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::<Result<Vec<Value>>>()?;
|
||||
Ok(json!({ "running": session.bake_log.is_running(), "maps": maps }))
|
||||
}
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
@@ -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`.
|
||||
|
||||
Reference in new issue
Block a user