mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-30 10:03:56 +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.
114 lines
4.7 KiB
Rust
114 lines
4.7 KiB
Rust
//! The Clone tool marks its source in the 2D view, forgets it when another texture set becomes
|
|
//! active, and has an Aligned option in its panel.
|
|
|
|
use egui::{Pos2, Shape};
|
|
use egui_kittest::Harness;
|
|
use egui_kittest::kittest::Queryable;
|
|
use serde_json::json;
|
|
use texturecraft_engine::execute;
|
|
use texturecraft_ui_egui::TextureCraftApp;
|
|
use texturecraft_ui_egui::state::ViewLayout;
|
|
|
|
/// Radius of the crosshair's circle, and the stroke width of its coloured pass
|
|
const MARKER_RADIUS: f32 = 7.0;
|
|
const MARKER_STROKE: f32 = 1.2;
|
|
|
|
fn clone_app() -> Harness<'static, TextureCraftApp> {
|
|
let session = texturecraft_engine::sample_session(256, 64).unwrap();
|
|
let mut harness = Harness::builder().with_size(egui::vec2(1600.0, 960.0)).build_eframe(|cc| TextureCraftApp::new(cc, session));
|
|
harness.state_mut().ui.layout = ViewLayout::Only2D;
|
|
execute(&mut harness.state_mut().session, "tool.clone", &serde_json::Value::Null).unwrap();
|
|
harness.run_steps(4);
|
|
harness
|
|
}
|
|
|
|
fn set_source(harness: &mut Harness<'_, TextureCraftApp>, uv: [f32; 2]) {
|
|
execute(&mut harness.state_mut().session, "tool.cloneSource", &json!({ "uv": uv })).unwrap();
|
|
harness.run_steps(3);
|
|
}
|
|
|
|
/// Centres of the crosshair circles in the last frame
|
|
fn markers(harness: &Harness<'_, TextureCraftApp>) -> Vec<Pos2> {
|
|
fn walk(shape: &Shape, out: &mut Vec<Pos2>) {
|
|
match shape {
|
|
Shape::Vec(shapes) => shapes.iter().for_each(|shape| walk(shape, out)),
|
|
Shape::Circle(circle) if circle.radius == MARKER_RADIUS && (circle.stroke.width - MARKER_STROKE).abs() < 1e-3 => out.push(circle.center),
|
|
_ => {}
|
|
}
|
|
}
|
|
let mut out = Vec::new();
|
|
harness.output().shapes.iter().for_each(|clipped| walk(&clipped.shape, &mut out));
|
|
out
|
|
}
|
|
|
|
fn marker_at(harness: &Harness<'_, TextureCraftApp>) -> Pos2 {
|
|
let found = markers(harness);
|
|
assert_eq!(found.len(), 1, "one crosshair: {found:?}");
|
|
found[0]
|
|
}
|
|
|
|
#[test]
|
|
fn the_2d_view_draws_a_crosshair_at_the_clone_source() {
|
|
let mut harness = clone_app();
|
|
assert!(markers(&harness).is_empty(), "no source, no crosshair");
|
|
set_source(&mut harness, [0.25, 0.5]);
|
|
let left = marker_at(&harness);
|
|
set_source(&mut harness, [0.5, 0.5]);
|
|
let middle = marker_at(&harness);
|
|
set_source(&mut harness, [0.75, 0.5]);
|
|
let right = marker_at(&harness);
|
|
assert!((left.y - middle.y).abs() < 0.5 && (right.y - middle.y).abs() < 0.5, "same texture row: {left:?} {middle:?} {right:?}");
|
|
assert!(middle.x - left.x > 50.0, "the crosshair follows the source in u: {left:?} {middle:?}");
|
|
assert!(((middle.x - left.x) - (right.x - middle.x)).abs() < 0.5, "evenly spaced in u: {left:?} {middle:?} {right:?}");
|
|
set_source(&mut harness, [0.5, 0.25]);
|
|
let top = marker_at(&harness);
|
|
assert!((top.x - middle.x).abs() < 0.5 && top.y < middle.y - 50.0, "v runs upwards on screen: {top:?} {middle:?}");
|
|
}
|
|
|
|
#[test]
|
|
fn the_2d_view_draws_the_crosshair_for_a_source_on_the_far_edge() {
|
|
let mut harness = clone_app();
|
|
set_source(&mut harness, [1.0, 0.5]);
|
|
let edge = marker_at(&harness);
|
|
set_source(&mut harness, [0.5, 0.5]);
|
|
let middle = marker_at(&harness);
|
|
assert!(edge.x > middle.x + 50.0, "the edge source sits right of the middle: {edge:?} {middle:?}");
|
|
set_source(&mut harness, [0.5, 1.0]);
|
|
let bottom = marker_at(&harness);
|
|
assert!(bottom.y > middle.y + 50.0, "v = 1.0 shows too: {bottom:?} {middle:?}");
|
|
}
|
|
|
|
#[test]
|
|
fn the_2d_crosshair_only_shows_for_the_clone_tool() {
|
|
let mut harness = clone_app();
|
|
set_source(&mut harness, [0.5, 0.5]);
|
|
assert_eq!(markers(&harness).len(), 1);
|
|
execute(&mut harness.state_mut().session, "tool.paint", &serde_json::Value::Null).unwrap();
|
|
harness.run_steps(3);
|
|
assert!(markers(&harness).is_empty(), "the paint tool shows no source");
|
|
}
|
|
|
|
#[test]
|
|
fn switching_the_texture_set_removes_the_clone_source_and_its_crosshair() {
|
|
let mut harness = clone_app();
|
|
set_source(&mut harness, [0.5, 0.5]);
|
|
assert_eq!(markers(&harness).len(), 1);
|
|
let other = if harness.state().session.ts() == 0 { 1 } else { 0 };
|
|
execute(&mut harness.state_mut().session, "textureSet.select", &json!({ "ts": other })).unwrap();
|
|
harness.run_steps(3);
|
|
assert!(harness.state().session.tool.clone_source.is_none());
|
|
assert!(markers(&harness).is_empty(), "no crosshair for a source of the other set");
|
|
}
|
|
|
|
#[test]
|
|
fn the_aligned_checkbox_sets_the_clone_mode() {
|
|
let mut harness = clone_app();
|
|
assert!(harness.state().session.tool.clone_aligned, "aligned by default");
|
|
harness.get_by_label("Aligned").click();
|
|
harness.run_steps(3);
|
|
assert!(!harness.state().session.tool.clone_aligned);
|
|
harness.get_by_label("Aligned").click();
|
|
harness.run_steps(3);
|
|
assert!(harness.state().session.tool.clone_aligned);
|
|
}
|