mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-23 07:50:45 +01:00
Combines 45 open pull requests so the Windows proof build runs once. Included: - Fill layers can color from dark to light with a gradient map (PR #535, fixes #482) - Front, side and top views, and F5/F6 switch between perspective and orthographic (PR #539, part of #241) - Textures export as DDS, with compressed normal and grayscale maps for game engines (PR #543, fixes #354) - The active layer and the eye in the Layers panel are much easier to see (PR #561, fixes #553) - Export dialog can also write a MaterialX file for each texture set (PR #563, fixes #558) - Layers toolbar stays on one row and cut-off layer names show on hover in small windows (PR #564, fixes #560) - Save a layer's mask as an image file or copy it to the clipboard from the layer menu (PR #565, fixes #559) - Shift + wheel and Ctrl + wheel change the brush size, and Ctrl+drag brush changes have a fine mode (PR #566, part of #545) - Select several layers in the Layers panel with Shift+click, Ctrl+click and Ctrl+A (PR #567, fixes #247) - Pressing F frames the object you are painting, so a floor plane no longer throws off the view (PR #568, fixes #478) - Save a mask as your own smart mask and reuse it on other layers and projects (PR #569, fixes #562) - Show one layer alone in the viewport, with or without its mask (PR #570, fixes #544) - On-screen orbit, pan and zoom buttons let a pen tablet move the 3D and 2D views (PR #573, fixes #288) - Decals can be mirrored to the opposite side of the mesh across X, Y or Z, with optional U or V flip (PR #576, fixes #272) - Shift+click lines in the 3D view start at the spot you last painted, even after turning the view (PR #578, fixes #574) - History steps now name the tool and layer and appear in the interface language (PR #580, fixes #572) - Path tool keeps your points when you click in the other view and tells you why (PR #582, fixes #575) - Brush, symmetry and tool settings stay when you open another project or restart the app (PR #584, fixes #571) - Reset only the panel layout from the Window menu, and Reset UI now asks first (PR #586, fixes #577) - Output templates ask before deleting and before dropping an unfinished edit (PR #588, fixes #579) - Clone tool shows its source in the 2D view, forgets it when you switch texture set, and can restart at the source each stroke (PR #590, fixes #581) - Move the symmetry plane to the model's middle or to a clicked point in one click (PR #591, fixes #585) - Projection stencil can be dropped in from Assets, moved and reset with fields, turned in snapped steps, and the 2D view says projection works in 3D (PR #593, fixes #583) - Smudge now shows which channels it drags and lets you switch them (PR #594, fixes #587) - Save panel layouts under a name and switch between them from the Window menu (PR #595, fixes #589) - Clone and Smudge now work on layer masks (PR #596, fixes #592) - A layer image menu test no longer fails when another test switches the interface language (PR #597) - Clicking a material in the shelf now paints with it instead of adding a layer (PR #599, fixes #305) - Alt+click on a mask thumbnail now labels the mask view and blanks the other texture sets (PR #605, fixes #600) - Painting on a texture set that is not active now shows a hint why nothing happens (PR #607, fixes #601) - Ctrl+Shift+click draws straight lines that snap to 15 degree steps (PR #609, fixes #604) - Output template channels can be inverted (PR #611, fixes #603) - Smudge now follows the mirror and radial symmetry planes (PR #613, fixes #602) - The shortcut list now shows the stencil, clone source, straight line and path gestures (PR #614, fixes #608) - Symmetry now also mirrors strokes painted in the 2D view (PR #615, fixes #610) - Decals keep their image's proportions while sizing and can be flipped (PR #617, fixes #606) - Polygon fill now also fills the mirrored side when symmetry is on (PR #619, fixes #612) - A decal dragged over a curved or differently facing surface now turns with it instead of tilting or flipping (PR #622, fixes #616) - Every brush alpha now has size, roundness, contrast and invert settings (PR #623, part of #598) - Decals placed as a mask can now be sized, turned and moved from Properties like decal layers (PR #624, fixes #618) - Renaming effects and linking fills to mask anchor points are now tested in the interface (PR #626, fixes #621) - Path points can be corners, so paths can have hard edges (PR #627, fixes #620) - Layer menu can apply a layer's blending mode and opacity to all channels, and copy/paste channel blending (PR #631, fixes #629) - Display Settings can now set glow, vignette, sharpen and film grain (PR #632, fixes #630) - Every command a key can run can now get a keyboard shortcut (PR #633, fixes #628) Fixes found while combining them: the named layouts window is drawn again, layer remove/duplicate/group/visibility stay bindable to keys, the Clone tool's Aligned switch is kept with the other tool settings, smudge copies in the 2D view keep their own trails, and a UI or control-channel camera command during a view glide is no longer undone by the glide.
208 lines
8.4 KiB
Rust
208 lines
8.4 KiB
Rust
//! Drives the `texturecraft-cli` binary.
|
|
|
|
use std::ffi::OsString;
|
|
use std::path::{Path, PathBuf};
|
|
use std::process::{Command, Output};
|
|
|
|
use serde_json::Value;
|
|
|
|
// Nextest 0.9.130+ remaps this variable when an archive is extracted on another
|
|
// runner. Cargo's compile-time path still supports ordinary `cargo test`.
|
|
fn cli_binary() -> OsString {
|
|
cli_binary_path(std::env::var_os("CARGO_BIN_EXE_texturecraft-cli"))
|
|
}
|
|
|
|
fn cli_binary_path(runner_path: Option<OsString>) -> OsString {
|
|
runner_path.unwrap_or_else(|| env!("CARGO_BIN_EXE_texturecraft-cli").into())
|
|
}
|
|
|
|
#[test]
|
|
fn cli_binary_prefers_relocated_runner_path() {
|
|
let relocated = OsString::from("relocated archive/texturecraft-cli");
|
|
assert_eq!(cli_binary_path(Some(relocated.clone())), relocated);
|
|
}
|
|
|
|
#[test]
|
|
fn cli_binary_defaults_to_cargo_path() {
|
|
assert_eq!(cli_binary_path(None), OsString::from(env!("CARGO_BIN_EXE_texturecraft-cli")));
|
|
}
|
|
|
|
fn cli(args: &[&str]) -> Output {
|
|
Command::new(cli_binary()).args(args).output().unwrap()
|
|
}
|
|
|
|
fn ok(args: &[&str]) -> String {
|
|
let o = cli(args);
|
|
assert!(o.status.success(), "{args:?} failed: {}", String::from_utf8_lossy(&o.stderr));
|
|
String::from_utf8(o.stdout).unwrap()
|
|
}
|
|
|
|
fn json(args: &[&str]) -> Value {
|
|
serde_json::from_str(&ok(args)).unwrap()
|
|
}
|
|
|
|
fn tmp(name: &str) -> PathBuf {
|
|
let d = std::env::temp_dir().join(format!("tc-cli-{}-{name}", std::process::id()));
|
|
let _ = std::fs::remove_dir_all(&d);
|
|
std::fs::create_dir_all(&d).unwrap();
|
|
d
|
|
}
|
|
|
|
fn p(path: &Path) -> &str {
|
|
path.to_str().unwrap()
|
|
}
|
|
|
|
#[test]
|
|
fn version_and_usage_errors() {
|
|
let v = ok(&["--version"]);
|
|
assert!(v.starts_with("TextureCraft "), "{v}");
|
|
assert_eq!(v.lines().count(), 1);
|
|
assert!(ok(&["--help"]).contains("texturecraft-cli mcp"));
|
|
assert_eq!(cli(&[]).status.code(), Some(2));
|
|
assert_eq!(cli(&["frobnicate"]).status.code(), Some(2));
|
|
assert_eq!(cli(&["info", "--bogus"]).status.code(), Some(2));
|
|
let o = cli(&["info", "does/not/exist.tcraft"]);
|
|
assert_eq!(o.status.code(), Some(1));
|
|
assert!(String::from_utf8_lossy(&o.stderr).contains("error"));
|
|
assert_eq!(cli(&["run", "builtin:nope", "layer.add.fill"]).status.code(), Some(1));
|
|
assert_eq!(cli(&["run", "builtin:cube", "layer.add.fill", "{not json"]).status.code(), Some(1));
|
|
assert_eq!(cli(&["render", "builtin:cube", "x.png", "--size", "big"]).status.code(), Some(1));
|
|
}
|
|
|
|
#[test]
|
|
fn new_info_run_bake_export_batch() {
|
|
let d = tmp("flow");
|
|
let a = d.join("a.tcraft");
|
|
ok(&["new", "builtin:cube", p(&a), "--resolution", "128"]);
|
|
let info = json(&["info", p(&a)]);
|
|
assert_eq!(info["kind"], "project");
|
|
assert_eq!(info["textureSets"][0]["resolution"], 128);
|
|
assert!(info["mesh"]["triangles"].as_u64().unwrap() >= 12);
|
|
|
|
let b = d.join("b.tcraft");
|
|
let r = json(&["run", p(&a), "layer.add.fill", r#"{"color":[1,0,0],"roughness":0.3}"#, "-o", p(&b)]);
|
|
assert!(r["layer"].is_u64(), "{r}");
|
|
assert_eq!(json(&["info", p(&b)])["layers"][0]["kind"], "fill");
|
|
|
|
ok(&["bake", p(&b), "--resolution", "128", "--maps", "ambientOcclusion,curvature"]);
|
|
let maps = json(&["info", p(&b)])["textureSets"][0]["baked"]["maps"].clone();
|
|
assert_eq!(maps.as_array().unwrap().len(), 2, "{maps}");
|
|
|
|
let tex = d.join("tex");
|
|
let files = ok(&["export", p(&b), p(&tex), "--preset", "glTF PBR Metal Roughness", "--size", "128"]);
|
|
assert!(files.lines().count() >= 3, "{files}");
|
|
for f in files.lines() {
|
|
assert!(Path::new(f).is_file(), "{f}");
|
|
}
|
|
|
|
let script = d.join("script.json");
|
|
let c = d.join("c.tcraft");
|
|
let body = serde_json::json!({"open": p(&b), "steps": [{"id": "layer.add.paint", "params": {"name": "Scripted"}}], "save": p(&c)});
|
|
std::fs::write(&script, body.to_string()).unwrap();
|
|
assert_eq!(json(&["batch", p(&script)])["completed"], 1);
|
|
assert_eq!(json(&["info", p(&c)])["layers"][0]["name"], "Scripted");
|
|
std::fs::write(&script, r#"[{"id":"layer.add.paint"},{"id":"no.such"}]"#).unwrap();
|
|
assert_eq!(cli(&["batch", p(&script)]).status.code(), Some(1));
|
|
let _ = std::fs::remove_dir_all(&d);
|
|
}
|
|
|
|
#[test]
|
|
fn export_writes_dds_with_its_options() {
|
|
let d = tmp("dds");
|
|
let tex = d.join("tex");
|
|
let files = ok(&["export", "builtin:cube", p(&tex), "--format", "dds", "--size", "128", "--dds-compression", "bc1", "--dds-mipmaps"]);
|
|
assert!(files.lines().count() >= 3, "{files}");
|
|
let le32 = |b: &[u8], at: usize| u32::from_le_bytes(b[at..at + 4].try_into().unwrap());
|
|
for f in files.lines() {
|
|
assert!(f.ends_with(".dds"), "{f}");
|
|
let b = std::fs::read(f).unwrap();
|
|
assert_eq!((&b[..4], &b[84..88]), (&b"DDS "[..], &b"DXT1"[..]), "{f}");
|
|
assert_eq!(le32(&b, 28), 8, "{f}: 128 px down to 1 px is eight mip levels");
|
|
}
|
|
assert_eq!(cli(&["export", "builtin:cube", p(&tex), "--format", "dds", "--dds-compression", "bc9"]).status.code(), Some(1));
|
|
let _ = std::fs::remove_dir_all(&d);
|
|
}
|
|
|
|
#[test]
|
|
fn info_on_a_mesh_reports_uvs() {
|
|
let d = tmp("mesh");
|
|
let obj = d.join("quad.obj");
|
|
std::fs::write(&obj, "v 0 0 0\nv 1 0 0\nv 1 1 0\nv 0 1 0\nvt 0 0\nvt 1 0\nvt 1 1\nvt 0 1\nusemtl Paint\nf 1/1 2/2 3/3 4/4\n").unwrap();
|
|
let info = json(&["info", p(&obj)]);
|
|
assert_eq!(info["kind"], "mesh");
|
|
assert_eq!(info["triangles"], 2);
|
|
assert_eq!(info["materials"][0], "Paint");
|
|
assert_eq!(info["uv"]["uvsGenerated"], false);
|
|
let _ = std::fs::remove_dir_all(&d);
|
|
}
|
|
|
|
#[test]
|
|
fn serve_takes_the_automation_root_spelling_too() {
|
|
use std::io::Write as _;
|
|
let d = tmp("automation-root");
|
|
let mut child = Command::new(cli_binary())
|
|
.args(["serve", "--automation-write-root", p(&d)])
|
|
.stdin(std::process::Stdio::piped())
|
|
.stdout(std::process::Stdio::piped())
|
|
.spawn()
|
|
.unwrap();
|
|
child.stdin.take().unwrap().write_all(b"{\"id\":1,\"method\":\"project.save\",\"params\":{\"path\":\"a.tcraft\"}}\n").unwrap();
|
|
let out = child.wait_with_output().unwrap();
|
|
let reply: Value = serde_json::from_slice(&out.stdout).unwrap();
|
|
assert_eq!(reply["ok"], true, "{reply}");
|
|
assert!(d.join("a.tcraft").is_file());
|
|
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");
|
|
let out = d.join("ball.png");
|
|
let o = cli(&["render", "builtin:material_ball", p(&out), "--size", "160x120", "--yaw", "30"]);
|
|
if !o.status.success() {
|
|
let err = String::from_utf8_lossy(&o.stderr);
|
|
assert!(err.contains("cannot render"), "{err}");
|
|
eprintln!("skipping: {err}");
|
|
return;
|
|
}
|
|
let img = image::open(&out).unwrap();
|
|
assert_eq!((img.width(), img.height()), (160, 120));
|
|
let _ = std::fs::remove_dir_all(&d);
|
|
}
|
|
|
|
#[test]
|
|
fn path_traced_render_needs_no_gpu() {
|
|
let d = tmp("trace");
|
|
let out = d.join("ball.png");
|
|
// On the GPU where it has compute shaders, then forced onto the CPU.
|
|
for extra in [None, Some("--cpu")] {
|
|
let mut args = vec!["render", "builtin:material_ball", p(&out), "--size", "96x64", "--samples", "4"];
|
|
args.extend(extra);
|
|
ok(&args);
|
|
let img = image::open(&out).unwrap().to_rgb8();
|
|
assert_eq!(img.dimensions(), (96, 64));
|
|
// The lit ball in the middle is brighter than the dark backdrop corner.
|
|
let lum = |x, y| img.get_pixel(x, y).0.iter().map(|v| *v as u32).sum::<u32>();
|
|
assert!(lum(48, 28) > lum(1, 1) + 60);
|
|
}
|
|
// --camera looks through a camera saved in the project; an unknown name is an error.
|
|
let proj = d.join("cams.tcraft");
|
|
ok(&["run", "builtin:cube", "camera.set", r#"{"yaw": 80, "distance": 9}"#, "-o", p(&proj)]);
|
|
ok(&["run", p(&proj), "camera.add", r#"{"name": "Side"}"#, "-o", p(&proj)]);
|
|
ok(&["render", p(&proj), p(&out), "--size", "48x32", "--camera", "Side", "--samples", "2", "--cpu"]);
|
|
assert_eq!(cli(&["render", p(&proj), p(&out), "--camera", "Nope", "--samples", "2", "--cpu"]).status.code(), Some(1));
|
|
assert_eq!(cli(&["render", "builtin:cube", p(&out), "--samples", "0"]).status.code(), Some(1));
|
|
assert_eq!(cli(&["render", "builtin:cube", p(&out), "--samples", "4", "--view", "2d"]).status.code(), Some(1));
|
|
let _ = std::fs::remove_dir_all(&d);
|
|
}
|