cli: support builtin:<id> in info command (#63)

This commit is contained in:
test-bit-sys committed 2026-11-01 23:06:43 +01:00
1 parent 0788317deb
commit f0242058f2
4 files changed
+26 -3

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).
@@ -217,6 +217,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
@@ -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");
+1 -1
View File
@@ -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};
+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() {