Files
texturecraft/crates/engine/tests/it/bake_resolution.rs
T
vangel76 d9bdef92b2 TextureCraft UI parity batch: 45 changes in one commit
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.
2026-11-17 22:51:06 +01:00

132 lines
6.3 KiB
Rust

use std::sync::Arc;
use serde_json::json;
use texturecraft_engine::bake::Progress;
use texturecraft_engine::core::BakedMap;
use texturecraft_engine::geom::{NO_TRI, UvGBuffer, primitives};
use texturecraft_engine::{Session, execute};
fn session() -> Session {
let mut session = Session::new_project("Bake detail", primitives::udim_plane(), "builtin:udim_plane", None, 256).unwrap();
execute(&mut session, "bake.settings", &json!({"resolution": 128, "maps": ["position"], "dilation": 0, "patch": {"common": {"apply_diffusion": false}}}))
.unwrap();
session
}
#[test]
fn working_tile_resolution_preserves_bake_samples_and_pixels() {
let mut session = session();
let original = session.bake_task(0).unwrap().run(&Progress::new()).unwrap();
execute(&mut session, "textureSet.tile.resolution", &json!({"tile": 1002, "resolution": 128})).unwrap();
let task = session.bake_task(0).unwrap();
let output = task.run(&Progress::new()).unwrap();
assert_eq!((output.resolution, output.height), (256, 128));
let gbuffer = UvGBuffer::new(&task.mesh, task.material, output.resolution, output.height);
let mut samples = [0usize; 2];
for (index, triangle) in gbuffer.tri.iter().enumerate() {
if *triangle != NO_TRI {
samples[(index % 256) / 128] += 1;
}
}
assert_eq!(samples, [128 * 128; 2], "each tile receives the full Bake Output Size");
assert_eq!(output.maps, original.maps);
}
#[test]
fn changing_working_resolution_never_resamples_stored_bakes() {
let mut session = session();
let output = session.bake_task(0).unwrap().run(&Progress::new()).unwrap();
session.apply_bake(0, output).unwrap();
let original = session.doc.baked[&0].clone();
for resolution in [128, 512, 256] {
execute(&mut session, "textureSet.tile.resolution", &json!({"tile": 1002, "resolution": resolution})).unwrap();
let current = &session.doc.baked[&0];
assert!(Arc::ptr_eq(&current.maps[&BakedMap::Position], &original.maps[&BakedMap::Position]), "working resize must retain the bake buffer");
assert_eq!(current, &original);
let reopened = Session::from_project_bytes(&session.to_project_bytes().unwrap()).unwrap();
assert_eq!(reopened.doc.baked[&0], original);
}
session.undo().unwrap();
assert_eq!(session.doc.baked[&0], original);
session.redo().unwrap();
assert_eq!(session.doc.baked[&0], original);
for resolution in [512, 128] {
execute(&mut session, "textureSet.resolution", &json!({"resolution": resolution})).unwrap();
assert!(Arc::ptr_eq(&session.doc.baked[&0].maps[&BakedMap::Position], &original.maps[&BakedMap::Position]));
}
}
#[test]
fn rectangular_bakes_and_excluded_vertical_tiles_ignore_working_resolution() {
let mut mesh = primitives::udim_plane();
let second_plane = mesh.uvs.len() / 2;
for uv in mesh.uvs.iter_mut().skip(second_plane) {
uv.x -= 1.0;
uv.y -= 1.0;
}
let mut session = Session::new_project("Vertical bake", mesh, "builtin:udim_plane", None, 256).unwrap();
execute(
&mut session,
"bake.settings",
&json!({"resolution": 64, "maps": ["position"], "dilation": 0, "patch": {"common": {"resolution_height": "R128", "apply_diffusion": false}}}),
)
.unwrap();
let original = session.bake_task(0).unwrap().run(&Progress::new()).unwrap();
assert_eq!((original.resolution, original.height), (64, 256));
let pixels = original.maps.clone();
session.apply_bake(0, original).unwrap();
execute(&mut session, "textureSet.tile.resolution", &json!({"tile": 1011, "resolution": 128})).unwrap();
execute(&mut session, "bake.tile.set", &json!({"tile": 1011, "enabled": false})).unwrap();
let output = session.bake_task(0).unwrap().run(&Progress::new()).unwrap();
assert_eq!(output.maps, pixels, "rebaked and excluded tiles both keep their full rectangular detail");
}
#[test]
fn imported_mesh_maps_display_and_export_the_entire_overridden_tile() {
use texturecraft_engine::compose::{DisplayKind, tile_bytes};
use texturecraft_engine::formats::export::{Dest, ExportOptions, ExportPreset, FileFormat, MapSpec, SourceRef};
let mut session = session();
execute(&mut session, "textureSet.tile.resolution", &json!({"tile": 1002, "resolution": 128})).unwrap();
let image = image::GrayImage::from_fn(128, 128, |x, y| image::Luma([(x + y) as u8]));
let mut bytes = Vec::new();
image.write_to(&mut std::io::Cursor::new(&mut bytes), image::ImageFormat::Png).unwrap();
for tile in [1001, 1002] {
session.import_resource_bytes(&format!("ao.{tile}.png"), bytes.clone()).unwrap();
}
execute(&mut session, "textureSet.meshMap.set", &json!({"map": "ambientOcclusion", "image": "ao.1001.png"})).unwrap();
while session.update() {}
let baked = &session.doc.baked[&0];
let map = BakedMap::AmbientOcclusion;
assert!((baked.scalar(map, 248, 120, (256, 128)).unwrap() - 240.0 / 255.0).abs() < 0.001);
let composite = &session.caches[0].composite;
let display = tile_bytes(composite, baked, DisplayKind::Orm, 5, 1);
assert_eq!(display[((56 * 64 + 56) * 4) as usize], 240, "the viewport samples the far corner of the smaller working tile");
let options = ExportOptions::new(ExportPreset {
name: "Bake detail".into(),
maps: vec![MapSpec {
file: "ao.$udim".into(),
format: FileFormat::Png,
bit_depth: 8,
channels: vec![(Dest::L, SourceRef::Baked { map, component: 0 })],
inverted: Vec::new(),
}],
});
let files = session.export_files(&[0], &options).unwrap();
let file = files.iter().find(|file| file.name == "ao.1002.png").unwrap();
let exported = image::load_from_memory(&file.bytes).unwrap().to_luma8();
assert_eq!(exported.dimensions(), (128, 128));
assert_eq!(exported.get_pixel(120, 120)[0], 240);
assert_eq!(exported.get_pixel(10, 10)[0], 20);
let layer = session.doc.project.texture_sets[0].stack[0];
execute(&mut session, "mask.add.black", &json!({"layer": layer.0})).unwrap();
execute(&mut session, "effect.add.generator", &json!({"layer": layer.0, "generator": "ambientOcclusion"})).unwrap();
let mask = session.mask_at(layer, &[(376, 120), (266, 10)]).unwrap();
assert_eq!(mask, vec![1.0, 0.0], "generators sample the whole bake through the working layout");
}