Puppet: a pin added to a bent mesh holds it where it is; nothing jumps (#318)
Cause: puppet::solve binds each moving pin to its nearest mesh vertex and fixes that vertex at position + (vertex - rest), an offset in rest space with no rotation or scale. puppet.addPin set a new pin's position to the click, so in a bent region the bound vertex was pulled to where it would be unrotated, and the mesh jumped as soon as the pin was added. Fix: addPin picks the position that keeps the bound vertex at its current deformed place: the vertex's deformed position minus the rest offset. On an unbent mesh that is the click itself (round-off is snapped back to it), so existing pins behave as before. Test: a_pin_added_to_a_bent_mesh_moves_nothing (two pins, one moved to bend the layer, then pins added at three places on the bent part: at most a few edge pixels change from solver round-off; before the fix about 250 did). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QiAJeFttZp83Fh7YuzAR5f (cherry picked from commit 16151203b304d565b425873fdd33ae082cae483b)
This commit is contained in:
@@ -203,6 +203,28 @@ fn first_puppet_pin_leaves_the_layer_still() {
|
||||
}
|
||||
}
|
||||
|
||||
/// #318: a pin added to an already-bent mesh holds the mesh where it is: nothing jumps.
|
||||
#[test]
|
||||
fn a_pin_added_to_a_bent_mesh_moves_nothing() {
|
||||
let (mut s, id) = setup();
|
||||
s.execute("puppet.addPin", json!({"layer": id, "position": [5, 30]})).unwrap();
|
||||
s.execute("puppet.addPin", json!({"layer": id, "position": [95, 30]})).unwrap();
|
||||
s.set_time(Tick::from_seconds_f64(1.0));
|
||||
s.execute("puppet.movePin", json!({"layer": id, "pin": "Puppet Pin 2", "position": [80, 70]})).unwrap();
|
||||
let cid = s.active_comp_id().unwrap();
|
||||
let t = Tick::from_seconds_f64(1.0);
|
||||
let before = s.render(cid, t, RenderOpts::default());
|
||||
for at in [[50, 54], [30, 42], [70, 62]] {
|
||||
s.execute("puppet.addPin", json!({"layer": id, "position": at})).unwrap();
|
||||
let after = s.render(cid, t, RenderOpts::default());
|
||||
let moved = after.data.iter().zip(&before.data).filter(|(a, b)| (a[3] - b[3]).abs() > 0.25).count();
|
||||
// (Before #318 the pin at [50, 54] moved about 250 edge pixels; the solver's round-off
|
||||
// still touches a few.)
|
||||
assert!(moved <= 16, "a pin at {at:?} moved {moved} pixels");
|
||||
s.undo();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puppet_pin_kinds_and_mesh_options() {
|
||||
let (mut s, id) = setup();
|
||||
|
||||
Reference in New Issue
Block a user