Puppet: the tools stay on the rigged layer and pins go on the deformed mesh (#284)
With a Puppet tool, a click off the pins picked the topmost layer under the pointer by its own bounds, and selected it. So a click where the deformation had stretched the mesh past the layer's bounds went to the layer behind (selecting it and giving it a Puppet effect), and any click on another layer switched to it. While selected layers have a Puppet effect, a click (or a press that might start a pin marquee) now works only on them, as in After Effects: on the layer whose mesh, as deformed now, is under the pointer (the pin lands on the deformed shape), else the one whose own art is (a new mesh); elsewhere nothing happens and the selection stays. Without a rigged layer selected, the tools pick and rig the layer under the pointer as before. `puppet::contains` tests a point against a deformed mesh; `puppet.addPin` uses it too (its own test only held for one triangle winding). Test: puppet_pins_go_on_the_deformed_mesh_and_the_tool_stays_on_the_rigged_layer (ui_viewer). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
065f0c91e7
commit
02bc2b8f9a
@@ -387,6 +387,14 @@ pub fn unmap(mesh: &Mesh, deformed: &[[f64; 2]], p: [f64; 2]) -> [f64; 2] {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `p` (layer space) is on the mesh as `deformed` places its vertices.
|
||||
pub fn contains(mesh: &Mesh, deformed: &[[f64; 2]], p: [f64; 2]) -> bool {
|
||||
mesh.tris.iter().any(|t| match (deformed.get(t[0]), deformed.get(t[1]), deformed.get(t[2])) {
|
||||
(Some(a), Some(b), Some(c)) => bary(*a, *b, *c, p).is_some_and(|l| l.iter().all(|x| *x >= -1e-9)),
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn bary(a: [f64; 2], b: [f64; 2], c: [f64; 2], p: [f64; 2]) -> Option<[f64; 3]> {
|
||||
let d = (b[1] - c[1]) * (a[0] - c[0]) + (c[0] - b[0]) * (a[1] - c[1]);
|
||||
|
||||
Reference in New Issue
Block a user