From f0242058f2280fd89b31d60d8259cd64e67e5843 Mon Sep 17 00:00:00 2001 From: test-bit-sys Date: Sun, 1 Nov 2026 23:06:43 +0100 Subject: [PATCH 1/2] cli: support builtin: in info command (#63) --- apps/texturecraft-cli/src/main.rs | 12 ++++++++++-- apps/texturecraft-cli/tests/cli.rs | 10 ++++++++++ crates/formats/src/lib.rs | 2 +- crates/formats/src/mesh_import/mod.rs | 5 +++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/apps/texturecraft-cli/src/main.rs b/apps/texturecraft-cli/src/main.rs index ec1e4f2d..d53f2827 100644 --- a/apps/texturecraft-cli/src/main.rs +++ b/apps/texturecraft-cli/src/main.rs @@ -10,14 +10,14 @@ use serde_json::{Value, json}; use texturecraft_automation::security::{client_token, server_token}; use texturecraft_automation::{AuthorizedWorkspace, BridgeClient, Filesystem, Headless, RenderOptions, TexturecraftMcp, rpc}; use texturecraft_engine::core::PROJECT_EXT; -use texturecraft_engine::formats::{MeshReport, import_mesh, import_mesh_bytes}; +use texturecraft_engine::formats::{MeshReport, import_mesh, import_mesh_bytes, mesh_report}; const USAGE: &str = "\ texturecraft-cli: headless TextureCraft USAGE: texturecraft-cli --version - texturecraft-cli info + texturecraft-cli info > Texture sets, layers, triangles, materials and the UV report, as JSON. texturecraft-cli commands [--filter ] List the engine commands (id, label, params). @@ -217,6 +217,14 @@ fn report_json(r: &MeshReport) -> Value { fn info(a: &Args) -> R { let file = a.pos(0, "")?; + if let Some(id) = file.strip_prefix("builtin:") { + let m = texturecraft_engine::geom::primitives::builtin(id).ok_or_else(|| format!("unknown built-in mesh `{id}`"))?; + let report = mesh_report(&m); + return print_json(&json!({ + "file": file, "kind": "mesh", "triangles": m.triangle_count(), "vertices": m.vertex_count(), + "materials": m.materials, "textureSets": m.materials, "uv": report_json(&report), + })); + } if !is_project(file) { let m = import_mesh(Path::new(file)).map_err(|e| format!("cannot read {file}: {e}"))?; return print_json(&json!({ diff --git a/apps/texturecraft-cli/tests/cli.rs b/apps/texturecraft-cli/tests/cli.rs index 254eabb4..0c1b0ae2 100644 --- a/apps/texturecraft-cli/tests/cli.rs +++ b/apps/texturecraft-cli/tests/cli.rs @@ -97,6 +97,16 @@ fn info_on_a_mesh_reports_uvs() { let _ = std::fs::remove_dir_all(&d); } +#[test] +fn info_on_a_builtin_mesh() { + let info = json(&["info", "builtin:cube"]); + assert_eq!(info["kind"], "mesh"); + assert_eq!(info["file"], "builtin:cube"); + assert_eq!(info["triangles"], 1728); + assert_eq!(info["uv"]["uvsGenerated"], false); + assert_eq!(cli(&["info", "builtin:bogus"]).status.code(), Some(1)); +} + #[test] fn render_writes_a_png() { let d = tmp("render"); diff --git a/crates/formats/src/lib.rs b/crates/formats/src/lib.rs index 249ff0f7..3b589832 100644 --- a/crates/formats/src/lib.rs +++ b/crates/formats/src/lib.rs @@ -33,7 +33,7 @@ pub use export::{ }; pub use image_res::{DecodedImage, decode_image}; pub use mesh_export::{GlbTextures, UsdExport, UsdFormat, glb_bytes, glb_export_options, obj_bytes, usd_bytes, usd_export_options}; -pub use mesh_import::{HighPolyMesh, ImportedMesh, MeshFile, MeshReport, import_high_poly_bytes, import_mesh_bytes, self_contained_mesh}; +pub use mesh_import::{HighPolyMesh, ImportedMesh, MeshFile, MeshReport, import_high_poly_bytes, import_mesh_bytes, mesh_report, self_contained_mesh}; #[cfg(not(target_arch = "wasm32"))] pub use presets::load_preset; pub use presets::{builtin_preset, builtin_presets, preset_from_json, preset_to_json}; diff --git a/crates/formats/src/mesh_import/mod.rs b/crates/formats/src/mesh_import/mod.rs index 361d7837..3daff3c2 100644 --- a/crates/formats/src/mesh_import/mod.rs +++ b/crates/formats/src/mesh_import/mod.rs @@ -496,6 +496,11 @@ fn smooth_normals(mesh: &Mesh) -> Vec { weld.iter().map(|w| acc.get(*w as usize).and_then(|n| n.try_normalize()).unwrap_or(Vec3::Y)).collect() } +/// Inspects `mesh` and generates its UV report (overlaps, out-of-range UVs, warnings). +pub fn mesh_report(mesh: &Mesh) -> MeshReport { + report(mesh, false, Vec::new()) +} + fn report(mesh: &Mesh, uvs_generated: bool, mut warnings: Vec) -> MeshReport { let (mut out_of_range, mut zero_area) = (0, 0); for t in 0..mesh.triangle_count() { From 5a64fa20f9ddcd45432781f3e81de46fce78b295 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 2 Nov 2026 12:36:18 +0700 Subject: [PATCH 2/2] Effect paste: keep the active target, offer it on any row A paste into a layer of another texture set set the session's target to the new effect, so a later stroke in the active set could commit to it. The target now changes only for a paste into the active set. The layer and effect row menus offered Paste effect only while a layer was already selected, though a click selects the row first; they now check the clipboard alone. --- crates/engine/src/effect_clipboard.rs | 7 +++++-- crates/engine/tests/content_effects.rs | 15 +++++++++++++++ crates/ui-egui/src/dock.rs | 6 ++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/effect_clipboard.rs b/crates/engine/src/effect_clipboard.rs index 8132c9ca..36aa5f3a 100644 --- a/crates/engine/src/effect_clipboard.rs +++ b/crates/engine/src/effect_clipboard.rs @@ -27,7 +27,7 @@ pub fn specs() -> Vec { } /// The copied effect, if the clipboard holds one. -fn clipboard_effect(s: &Session) -> Option { +pub fn clipboard_effect(s: &Session) -> Option { s.clipboard.as_ref().and_then(|(doc, id)| doc.project.effect(*id).map(|_| *id)) } @@ -114,10 +114,13 @@ fn paste(s: &mut Session, p: &Value) -> Result { s.doc.pixels.layers.insert((new, c), fit(img, size, &empty_texel(c))); } } + // The target belongs to the active set's selection: a paste into another set leaves it. if let Some((lts, _, _)) = s.doc.project.locate(layer) { s.selected.insert(lts, layer); + if lts == s.ts() { + s.target = StackTarget::Effect(new); + } } - s.target = StackTarget::Effect(new); Ok(new) })?; Ok(json!({ "effect": new.0 })) diff --git a/crates/engine/tests/content_effects.rs b/crates/engine/tests/content_effects.rs index e6c75e1e..70eb81cf 100644 --- a/crates/engine/tests/content_effects.rs +++ b/crates/engine/tests/content_effects.rs @@ -200,6 +200,21 @@ fn effects_copy_and_paste_between_layers_and_stacks() { assert!(execute(&mut s, "effect.paste", &Value::Null).is_err(), "the anchor is on the layer itself"); } +#[test] +fn pasting_an_effect_into_another_texture_set_keeps_the_active_target() { + let mut s = texturecraft_engine::sample_session(256, 64).unwrap(); + execute(&mut s, "layer.add.fill", &Value::Null).unwrap(); + execute(&mut s, "effect.add.filter", &json!({"target": "content", "filter": "invert"})).unwrap(); + execute(&mut s, "effect.copy", &Value::Null).unwrap(); + execute(&mut s, "textureSet.select", &json!({"ts": 1})).unwrap(); + let other = id(execute(&mut s, "layer.add.fill", &Value::Null).unwrap(), "layer"); + execute(&mut s, "textureSet.select", &json!({"ts": 0})).unwrap(); + let before = s.target; + let pasted = id(execute(&mut s, "effect.paste", &json!({"layer": other})).unwrap(), "effect"); + assert_eq!(s.target, before, "the active set's selection keeps its target"); + assert_eq!(s.doc.project.effect(LayerId(pasted)).map(|(owner, _)| owner), Some(LayerId(other))); +} + #[test] fn histogram_counts_what_an_effect_reads() { let mut s = session(); diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs index 5d0f6186..659e5895 100644 --- a/crates/ui-egui/src/dock.rs +++ b/crates/ui-egui/src/dock.rs @@ -582,7 +582,8 @@ fn effect_row(app: &mut TextureCraftApp, ui: &mut Ui, layer: &Layer, stack: &[Ef } resp.context_menu(|ui| { let keymap = app.ui.keymap.clone(); - let paste = crate::menus::enabled(app, "effect.paste"); + // The row is selected before the paste runs, so a copied effect is all it needs. + let paste = texturecraft_engine::effect_clipboard::clipboard_effect(&app.session).is_some(); // The clipboard items show the layer clipboard's shortcuts, which act on a selected effect. for (label, id, keys, enabled) in [ (tr("Copy effect"), "effect.copy", Some("layer.copy"), true), @@ -693,7 +694,8 @@ fn layer_context_menu(app: &mut TextureCraftApp, ui: &mut Ui, layer: &Layer) { ui.separator(); run(app, ui, tr("Cut layer(s)"), "layer.cut", json!({"layer": lid}), true); run(app, ui, tr("Copy layer(s)"), "layer.copy", json!({"layer": lid}), true); - let (paste_layer, paste_effect) = (crate::menus::enabled(app, "layer.paste"), crate::menus::enabled(app, "effect.paste")); + let paste_layer = crate::menus::enabled(app, "layer.paste"); + let paste_effect = texturecraft_engine::effect_clipboard::clipboard_effect(&app.session).is_some(); run(app, ui, tr("Paste layer(s)"), "layer.paste", json!({}), paste_layer); run(app, ui, tr("Paste effect"), "effect.paste", json!({}), paste_effect); let paste_instance = crate::menus::enabled(app, "layer.pasteInstance");