* claim: #5592 * Canvas and Decal: send the picked face, so a large design takes the image (#5592) A click with Canvas or Decal sent only the point, so the engine searched every face of every body for it and gave up on a large design ("face capture work limit exceeded"). Send the picked body, face index and path as Create Sketch does; canvas.decal takes that face pick too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Canvas and Decal test: drop the check that a point alone gives up On upstream main a sketch on a face by its point alone no longer gives up on this design, so the test keeps only what the picked face has to do: both images land on it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,7 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
CommandSpec::new("canvas.decal", "Decal", add_decal)
|
||||
.at("SKETCH", "INSERT")
|
||||
.icon("decal")
|
||||
.params("path | data; face: [x,y,z] on a planar face (the image is centred there); width?: mm; angle?: deg; opacity?: (default 1)"),
|
||||
.params("path | data; face: [x,y,z] on a planar face (the image is centred there), or the picked face as sketch.create's plane takes it ({face, body, index, path?}); width?: mm; angle?: deg; opacity?: (default 1)"),
|
||||
CommandSpec::new("canvas.edit", "Edit Canvas", edit_canvas).at("SKETCH", "INSERT").icon("canvas").params("canvas: id or name; center?, width?, angle?: deg, opacity?, flip?, visible?, name?"),
|
||||
CommandSpec::new("canvas.calibrate", "Calibrate Canvas", calibrate).icon("measure")
|
||||
.params("canvas: id or name; a, b: two points on the canvas plane [x,y]; distance: their true distance (mm): scales the image about a"),
|
||||
@@ -88,9 +88,11 @@ fn add_canvas(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
fn add_decal(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "canvas.decal";
|
||||
let face = p.get("face").cloned().ok_or_else(|| bad(cmd, "`face` must be a point [x,y,z] on a planar face"))?;
|
||||
// A picked face as `sketch.create` takes it ({face, body, index, path?}) is used as it is.
|
||||
let plane = if face.get("face").is_some() { face } else { json!({"face": face}) };
|
||||
let mut q = p.clone();
|
||||
if let Some(o) = q.as_object_mut() {
|
||||
o.insert("plane".into(), json!({"face": face}));
|
||||
o.insert("plane".into(), plane);
|
||||
}
|
||||
make(s, &q, cmd, true)
|
||||
}
|
||||
|
||||
@@ -473,4 +473,35 @@ mod tests {
|
||||
let n = doc.canvas_plane(&vals, canvas).unwrap().normal();
|
||||
assert!(n.z.abs() > 0.99, "the canvas lies on {n:?}, not on XY");
|
||||
}
|
||||
|
||||
/// A canvas and a decal clicked onto a face of a design with many curved faces land on it.
|
||||
/// The click sent only the point, and the engine's search of every face of every body for it
|
||||
/// gave up ("face capture work limit exceeded"), as on an imported trophy of nine bodies.
|
||||
#[test]
|
||||
fn a_canvas_and_a_decal_clicked_onto_a_face_of_a_large_design_land_on_it() {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
h.app.run("solid.box", json!({"length": 200, "width": 120, "height": 40, "corner": [20, 20, 0]})).unwrap();
|
||||
for i in 0..8 {
|
||||
let center = [60 + 45 * (i % 4), 50 + 60 * (i / 4), 60];
|
||||
h.app.run("solid.torus", json!({"major": 30, "minor": 8, "center": center, "operation": "new_body"})).unwrap();
|
||||
}
|
||||
for command in ["canvas.insert", "canvas.decal"] {
|
||||
for step in [
|
||||
json!({"make_image": "pic.png"}),
|
||||
json!({"choose_file": "pic.png"}),
|
||||
json!({"call": "ui.view", "params": {"view": "iso"}}),
|
||||
json!({"start": command}),
|
||||
json!({"click": {"world": [30, 30, 40]}}),
|
||||
] {
|
||||
h.step(&step).unwrap();
|
||||
}
|
||||
}
|
||||
let doc = &h.app.session.doc;
|
||||
assert_eq!(doc.canvases.len(), 2, "both images are placed");
|
||||
let (vals, _) = doc.param_values();
|
||||
for canvas in &doc.canvases {
|
||||
let plane = doc.canvas_plane(&vals, canvas).unwrap();
|
||||
assert!(plane.normal().z.abs() > 0.99 && (plane.origin.z - 40.0).abs() < 1e-6, "{} lies on {plane:?}", canvas.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -868,7 +868,15 @@ pub fn on_click(app: &mut SolveApp, tool: &mut Tool, proj: &Proj, pos: Pos2) {
|
||||
let (_, ray) = proj.ray(pos);
|
||||
let seen = |name: &str| crate::dialogs::plane_by_name(&app.session, name).is_some_and(|pl| pl.normal().dot(ray).abs() > 0.2 * ray.len());
|
||||
let target = hits.iter().find_map(|h| match h {
|
||||
Hit::Face { point, .. } => Some((json!({"face": [point.x, point.y, point.z]}), *point)),
|
||||
// The picked body and face, as Create Sketch sends them: a point alone makes the
|
||||
// engine search every face of every body, which gives up on a large design.
|
||||
Hit::Face { body, index, point } => {
|
||||
let face = solidcraft_engine::Sel::Face { body: body.clone(), index: *index, point: *point };
|
||||
Some((
|
||||
crate::sketch_attachment_ui::face_plane(app, &face).unwrap_or_else(|| json!({"face": [point.x, point.y, point.z]})),
|
||||
*point,
|
||||
))
|
||||
}
|
||||
Hit::Plane { name, point } if !decal && seen(name) => Some((json!(name), *point)),
|
||||
_ => None,
|
||||
});
|
||||
@@ -886,7 +894,7 @@ pub fn on_click(app: &mut SolveApp, tool: &mut Tool, proj: &Proj, pos: Pos2) {
|
||||
});
|
||||
let Some((plane, at)) = target else { return };
|
||||
let p = if decal {
|
||||
json!({"path": path, "face": plane.get("face").cloned().unwrap_or(Value::Null)})
|
||||
json!({"path": path, "face": if plane.get("face").is_some() { plane } else { Value::Null }})
|
||||
} else {
|
||||
json!({"path": path, "plane": plane, "at": [at.x, at.y, at.z]})
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user