mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-22 07:20:45 +01:00
Merge pull request #77 from test-bit-sys/fix/cli-info-builtin
cli: support builtin:<id> in info command
This commit is contained in:
4 files changed
+26
-3
No files matched your search
@@ -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!({
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user