From 67a5cb3a09480eb87cbe720091a5fa2b30264f53 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 2 Nov 2026 21:20:04 +0700 Subject: [PATCH] A light pen tap paints a small dab A pen lifts reporting no pressure, and a tap paints on that frame, so a tap painted at full pressure. The release now keeps the pen's contact pressure (a touch without pressure, such as a finger, starts fresh). Browsers report pen pressure only for pens that send touch events; desktop browsers deliver pens as a mouse, so the docs say so. --- README.md | 3 +- ROADMAP.md | 8 ++-- crates/ui-egui/src/viewport.rs | 27 +++++++++++--- crates/ui-egui/tests/pen_pressure.rs | 56 ++++++++++++++++++++-------- docs/features.md | 4 +- 5 files changed, 70 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 2ae3fd88..80f807b6 100644 --- a/README.md +++ b/README.md @@ -200,7 +200,8 @@ from our code against public documentation. **What's missing:** - hardware ray tracing in Rendering mode; -- pen tilt, and pen pressure on Linux and macOS (the windowing layer doesn't report them yet); +- pen tilt, and pen pressure on Linux, macOS and desktop browsers (the windowing layer doesn't + report them yet); - Alembic files in the older HDF5 container, and Alembic animation (the first sample is read); - a native-speaker review of the translations; - the first signed release on every platform. diff --git a/ROADMAP.md b/ROADMAP.md index 4bb26bd2..ede75790 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -14,7 +14,7 @@ end to end today (engine + UI + automation + tests), not what is planned. | Project and files | 8 | 95% | New project from glTF/GLB, FBX (binary and ASCII, 6.x and 7.x), COLLADA, **USD (usda, usdc, usdz)**, **Alembic (Ogawa)**, OBJ, PLY, STL or built-in meshes (auto-unwrap when UVs are missing; a `.gltf`'s buffers and images and a loose USD layer's textures are read from its folder and kept in the project), **project templates** (built-in and saved from a project), `.tcraft` open/save/save as/save a copy, autosave, **asks to save unsaved changes** before quitting or replacing the project (in the browser too, and before the tab closes), recent files, drag and drop, reimport mesh **with strokes preserved on the surface**, **MaterialX import** (`file.importMaterialX`: a `.mtlx` material with `open_pbr_surface`, `standard_surface` or `gltf_pbr` becomes one fill layer with its textures and values), image resources, remove unused resources, textured OBJ (MTL), GLB and **USD** mesh export, browser open/save/download | HDF5 Alembic; Alembic animation (first sample only) | | Texture sets | 6 | 95% | One set per material, **UDIM / UV tiles** (auto-detected or switched on later with resampling, **a resolution per tile**, one texture per tile at its own size, `$udim` export), list with visibility (show or hide all, invert, **focus** on one set), sizes 128–8192 with resampling, add/remove channels (19 channel types incl. coat, sheen, anisotropy and scattering), height strength, normal format | Filter radii and height slopes of a tile smaller than its atlas block follow the block | | Layer stack | 16 | 98% | Paint, fill, folder and **instance** layers; 32 per-channel blend modes and opacities; white/black/painted masks with **mask with height**; generator, fill, levels (with a histogram of its input), invert/threshold, color selection, compare, blur, sharpen and HSL effects on masks and layer content; anchor points; effects **dragged to reorder**, duplicated, and **copied, cut and pasted** across layers, masks and sets (Ctrl+C, Ctrl+X, Ctrl+V, Ctrl+D and Delete act on a selected effect); smart masks; mask view (Alt+click); Alt+click a material channel to keep it alone; duplicate, group, drag to reorder, rename, color tags, copy/cut/paste (also as instance) across sets, flatten, instantiate across sets, save layers as smart materials; **30 library filters** (adjustments incl. histogram scan, range and shift, blur/sharpen/high pass, bevel, glow, edge detect, warps, mosaic, baked lighting, material finishes); **geometry masks** (a layer on chosen mesh parts) | A few niche filters of the reference app's catalog | -| Painting tools | 14 | 91% | Paint, eraser, projection with image stencils, polygon fill, **path** and **lasso fill**, smudge, clone, color picker, quick mask, Shift+click lines with preview, 2D view painting; size, flow, stroke opacity, spacing, hardness, angle, follow path, jitters, alignment, angle fade, backface culling, lazy mouse, **Ctrl+drag in a view for size, hardness, flow and angle**, X/Y/Z mirror and **radial symmetry**, pen pressure in the 3D and 2D views (Windows and the browser), procedural and image alphas, **text** in any installed font (as an alpha or a decal), **particle brush** | Pen tilt, and pen pressure on Linux and macOS (not exposed by the windowing layer) | +| Painting tools | 14 | 91% | Paint, eraser, projection with image stencils, polygon fill, **path** and **lasso fill**, smudge, clone, color picker, quick mask, Shift+click lines with preview, 2D view painting; size, flow, stroke opacity, spacing, hardness, angle, follow path, jitters, alignment, angle fade, backface culling, lazy mouse, **Ctrl+drag in a view for size, hardness, flow and angle**, X/Y/Z mirror and **radial symmetry**, pen pressure in the 3D and 2D views (Windows Ink, and touch pens in the browser), procedural and image alphas, **text** in any installed font (as an alpha or a decal), **particle brush** | Pen tilt, and pen pressure on Linux, macOS and desktop browsers (not exposed by the windowing layer) | | Materials and assets | 8 | 92% | **MaterialCraft materials** (`.mcmat`, sent to the shelf from MaterialCraft) as fill layers whose graph inputs and presets stay editable, re-cooked at the set's resolution with its baked mesh maps; 63 procedural materials (incl. car paint, velvet, brushed steel, skin, wax, ice, snow, bark), 21 smart materials, 18 smart masks, **67 procedural brush alphas**, **18 brush presets** plus user presets, 23 procedurals, 6 environments plus imported HDR/EXR panoramas, image resources, a user smart material library, a tabbed shelf with search and **drag and drop** onto layers and the viewport | A smaller bundled library than the reference app's | | Baking | 10 | 100% | AO, curvature (also from the normal map), thickness, world normal, position, ID, normal, height, **bent normals, opacity, color map and world-space direction**; **high-poly meshes**, cage, frontal/rear distances, average normals, **skew correction** (`bake.skew.set`, painted in the 2D view with `bake.skew.paint` and saved in the project: a greyscale map over the atlas that turns the transfer rays onto the base normal, with hard-edge protection), **match by mesh name**; per-texture-set selection, common and per-map parameters, progress and cancel; **Auto-rebake** (`bake.autoRebake`: one map bakes itself again in the background when its bake settings, the low poly, the high polys or the skew map change); **mesh maps from images** (baked elsewhere or edited) dropped on a slot; high-poly base color textures embedded or in files beside a `.gltf`, FBX or USD layer | — | | Viewport and display | 12 | 95% | PBR with image-based lighting, 6 procedural environments or imported HDR/EXR panoramas with exposure, rotation, blur, opacity, ACES/linear tone mapping, HDR pipeline with bloom, vignette, sharpen and grain, key-light shadows, 4× MSAA plus idle temporal accumulation, the baked normal map under the painted normal, channel / mesh-map / mask / UV checker views, 3D and 2D wireframes of the mesh's own polygons, brush cursor, axis gizmos, subsurface scattering blur, **depth of field**, saved cameras and cameras from glTF, FBX, COLLADA and USD files, displacement (also in shadows and the path tracers), **path-traced Rendering mode** (F10, on the GPU or the CPU) with environment importance sampling and an edge-aware **denoiser**; picks a discrete GPU on multi-GPU machines (`--gpu`, `WGPU_ADAPTER_NAME`, `WGPU_POWER_PREF`), and display textures are made on demand so a mesh with many materials imports on a small GPU | Hardware ray tracing | @@ -36,7 +36,7 @@ parallel on separate crates: | Milestone | Scope | Estimate | |---|---|---:| | M1 Layer stack depth | Done | 0 h | -| M2 Tools | Pen tilt, and pen pressure on Linux and macOS, once the windowing layer reports them | 0.5 h | +| M2 Tools | Pen tilt, and pen pressure on Linux, macOS and desktop browsers, once the windowing layer reports them | 0.5 h | | M3 Assets | Done | 0 h | | M4 Baking | Done | 0 h | | M5 Viewport | Hardware ray tracing: wgpu's ray queries are experimental and need an `unsafe` opt-in, which the workspace forbids (owner decision) | 1.5 h | @@ -55,5 +55,5 @@ parallel on separate crates: 2. Hardware ray tracing in Rendering mode (M5) waits on an owner decision: wgpu exposes ray queries only as an experimental feature behind an `unsafe` opt-in, and the workspace forbids `unsafe` (craftrules allows it only in an isolated, tested helper crate). -3. Pen tilt, and pen pressure on Linux and macOS (M2), once the windowing layer reports them; - Alembic files in the HDF5 container and Alembic animation. +3. Pen tilt, and pen pressure on Linux, macOS and desktop browsers (M2), once the windowing + layer reports them; Alembic files in the HDF5 container and Alembic animation. diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index 3ce556fe..a809c341 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -903,17 +903,32 @@ fn brush_cursor(app: &TextureCraftApp, ui: &Ui, rect: Rect, pos: Vec3, nrm: Vec3 } /// This frame's pen pressure (0..1), or 1 without a pen. Pressure arrives as touch force: the -/// windowing layer reports it for Windows Ink pens and in the browser; Linux and macOS pens come -/// through as a mouse. +/// windowing layer reports it for Windows Ink pens, and in the browser for pens that send touch +/// events (tablets and phones); other pens come through as a mouse. /// shortcut: the windowing layer reports no pen tilt, so tilt can't drive the brush angle yet. fn pen_pressure(ui: &Ui) -> f32 { - ui.input(|i| { + let id = egui::Id::unique("pen_pressure"); + let touch = ui.input(|i| { i.raw.events.iter().rev().find_map(|e| match e { - egui::Event::Touch { force: Some(f), .. } if f.is_finite() => Some(f.clamp(0.0, 1.0)), + egui::Event::Touch { phase, force, .. } => Some((*phase, force.filter(|f| f.is_finite()))), _ => None, }) - }) - .unwrap_or(1.0) + }); + match touch { + Some((_, Some(f))) => { + let f = f.clamp(0.0, 1.0); + ui.data_mut(|d| d.insert_temp(id, f)); + f + } + // A pen lifts with no pressure, and a tap paints on that frame: keep its contact pressure. + Some((egui::TouchPhase::End, None)) => ui.data(|d| d.get_temp(id)).unwrap_or(1.0), + // A touch without pressure (a finger) must not inherit an earlier pen's. + Some((egui::TouchPhase::Start, None)) => { + ui.data_mut(|d| d.remove_temp::(id)); + 1.0 + } + _ => 1.0, + } } fn view_2d(app: &mut TextureCraftApp, ui: &mut Ui, rect: Rect, sync: &mut PendingSync) { diff --git a/crates/ui-egui/tests/pen_pressure.rs b/crates/ui-egui/tests/pen_pressure.rs index 1b44f95c..f2c1fcee 100644 --- a/crates/ui-egui/tests/pen_pressure.rs +++ b/crates/ui-egui/tests/pen_pressure.rs @@ -6,12 +6,12 @@ use texturecraft_engine::core::Channel; use texturecraft_ui_egui::TextureCraftApp; use texturecraft_ui_egui::state::ViewLayout; -/// One frame of pen input: the windowing layer sends a pen sample as a touch with force plus the -/// pointer events it drives, in the same frame (None: a mouse, which reports no force). -fn frame(h: &mut Harness<'_, TextureCraftApp>, force: Option, pos: Pos2, phase: TouchPhase, button: Option) { +/// One frame of input: the windowing layer sends a pen sample as a touch (`pen`: its phase and +/// force) plus the pointer events it drives, in the same frame. A mouse sends no touch. +fn frame(h: &mut Harness<'_, TextureCraftApp>, pen: Option<(TouchPhase, Option)>, pos: Pos2, button: Option) { let events = &mut h.input_mut().events; - if let Some(force) = force { - events.push(Event::Touch { device_id: TouchDeviceId(1), id: TouchId(1), phase, pos, force: Some(force) }); + if let Some((phase, force)) = pen { + events.push(Event::Touch { device_id: TouchDeviceId(1), id: TouchId(1), phase, pos, force }); } events.push(Event::PointerMoved(pos)); if let Some(pressed) = button { @@ -20,24 +20,42 @@ fn frame(h: &mut Harness<'_, TextureCraftApp>, force: Option, pos: Pos2, ph h.step(); } -/// Paint one stroke across the 2D view and return the summed base color alpha it added. -fn stroke_2d(force: Option) -> f64 { +/// Paint in the 2D view with `input` and return the summed base color alpha it added. +fn paint_2d(input: impl FnOnce(&mut Harness<'_, TextureCraftApp>)) -> f64 { let session = texturecraft_engine::sample_session(256, 64).unwrap(); let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1500.0)).build_eframe(|cc| TextureCraftApp::new(cc, session)); h.state_mut().ui.layout = ViewLayout::Only2D; h.state_mut().session.tool.brush.min_size = 0.0; h.run_steps(4); let before = painted(&h); - let (from, to) = (pos2(600.0, 500.0), pos2(800.0, 500.0)); - frame(&mut h, force, from, TouchPhase::Start, Some(true)); - for k in 1..=8 { - frame(&mut h, force, from + (to - from) * (k as f32 / 8.0), TouchPhase::Move, None); - } - frame(&mut h, force, to, TouchPhase::End, Some(false)); + input(&mut h); h.run_steps(3); painted(&h) - before } +const FROM: Pos2 = pos2(600.0, 500.0); + +/// One stroke across the view, with pen `force` on every sample (None: a mouse). +fn stroke(force: Option) -> f64 { + let pen = |phase| force.map(|f| (phase, Some(f))); + let to = pos2(800.0, 500.0); + paint_2d(|h| { + frame(h, pen(TouchPhase::Start), FROM, Some(true)); + for k in 1..=8 { + frame(h, pen(TouchPhase::Move), FROM + (to - FROM) * (k as f32 / 8.0), None); + } + frame(h, pen(TouchPhase::End), to, Some(false)); + }) +} + +/// A tap; a pen lifts reporting no pressure (as Windows Ink does), and the dab paints then. +fn tap(force: Option) -> f64 { + paint_2d(|h| { + frame(h, force.map(|f| (TouchPhase::Start, Some(f))), FROM, Some(true)); + frame(h, force.map(|_| (TouchPhase::End, None)), FROM, Some(false)); + }) +} + /// The selected layer's summed base color alpha. fn painted(h: &Harness<'_, TextureCraftApp>) -> f64 { let s = &h.state().session; @@ -49,8 +67,16 @@ fn painted(h: &Harness<'_, TextureCraftApp>) -> f64 { #[test] fn pen_pressure_thins_strokes_in_the_2d_view() { - let mouse = stroke_2d(None); - let light = stroke_2d(Some(0.2)); + let mouse = stroke(None); + let light = stroke(Some(0.2)); assert!(mouse > 10.0, "the mouse stroke painted: {mouse}"); assert!(light > 0.0 && light < mouse * 0.5, "a light pen paints a thinner stroke: {light} vs {mouse}"); } + +#[test] +fn a_light_pen_tap_paints_a_small_dab() { + let mouse = tap(None); + let light = tap(Some(0.2)); + assert!(mouse > 1.0, "the mouse click painted: {mouse}"); + assert!(light > 0.0 && light < mouse * 0.25, "the tap keeps its contact pressure: {light} vs {mouse}"); +} diff --git a/docs/features.md b/docs/features.md index 6185412c..945800f6 100644 --- a/docs/features.md +++ b/docs/features.md @@ -7,8 +7,8 @@ Everything TextureCraft does today, by area. What's still missing is in [`ROADMA - **Brushes** with size, flow, stroke opacity, spacing, hardness, angle and follow path; size, angle, flow and position jitter; tangent or camera alignment, angle fade, backface culling, lazy mouse, X/Y/Z mirror and radial symmetry (copies paint the far side too) and pen pressure in the - 3D and 2D views (Windows Ink pens and the browser; on Linux and macOS a pen works as a mouse for - now). + 3D and 2D views (Windows Ink pens, and pens that send touch events in the browser, such as on + tablets; on Linux, macOS and desktop browsers a pen works as a mouse for now). Ctrl+drag in a view sets them on the fly: right-drag the size and hardness, left-drag the flow and angle. **67 procedural brush alphas** in their own shelf tab, or any imported image as the alpha.