Merge remote-tracking branch 'origin/main' into fix/review-followups

This commit is contained in:
bflatastic committed 2026-11-02 13:26:21 +07:00
commit 3b1160def5
7 files changed
+50 -7

No files matched your search

+10 -2
View File
@@ -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 <project.tcraft | mesh file>
texturecraft-cli info <project.tcraft | mesh file | builtin:<id>>
Texture sets, layers, triangles, materials and the UV report, as JSON.
texturecraft-cli commands [--filter <text>]
List the engine commands (id, label, params).
@@ -220,6 +220,14 @@ fn report_json(r: &MeshReport) -> Value {
fn info(a: &Args) -> R {
let file = a.pos(0, "<file>")?;
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!({
+10
View File
@@ -115,6 +115,16 @@ fn serve_takes_the_automation_root_spelling_too() {
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");
+5 -2
View File
@@ -27,7 +27,7 @@ pub fn specs() -> Vec<CommandSpec> {
}
/// The copied effect, if the clipboard holds one.
fn clipboard_effect(s: &Session) -> Option<LayerId> {
pub fn clipboard_effect(s: &Session) -> Option<LayerId> {
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<Value> {
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 }))
+15
View File
@@ -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();
+1 -1
View File
@@ -39,7 +39,7 @@ pub use export::{
};
pub use image_res::{DecodedImage, coverage_png, 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};
+5
View File
@@ -496,6 +496,11 @@ fn smooth_normals(mesh: &Mesh) -> Vec<Vec3> {
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<String>) -> MeshReport {
let (mut out_of_range, mut zero_area) = (0, 0);
for t in 0..mesh.triangle_count() {
+4 -2
View File
@@ -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");