forked from 1b-agent/opencadstudio-upstream
fix(ucs): grid axis lines and grid snap follow the active UCS
Two leftovers from the UCS grid work: - The coloured X/Y/Z axis lines (draw_axes) were drawn at the world origin along world axes; they now run through the UCS origin along the UCS axes, matching the grid lines. - Grid snap rounded the cursor on the world XYZ lattice; it now rounds in the UCS grid frame (to-UCS, round, back-to-world) so it lands on the grid the user sees. The UCS origin (wire space) + rotation reach the snapper via DocumentTab::ucs_grid_basis; identity outside model space. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
2509396ba0
commit
481adba66b
4 files changed
+72
-36
No files matched your search
@@ -195,6 +195,23 @@ impl DocumentTab {
|
||||
self.scene.viewcube_ucs = self.ucs_xform().rotation_mat();
|
||||
}
|
||||
|
||||
/// Grid origin (render/wire space) and UCS→world rotation for grid snap and
|
||||
/// the grid overlay. Identity / origin-at-zero outside model space.
|
||||
pub(super) fn ucs_grid_basis(&self) -> (glam::Vec3, glam::Mat4) {
|
||||
if self.scene.current_layout != "Model" {
|
||||
return (glam::Vec3::ZERO, glam::Mat4::IDENTITY);
|
||||
}
|
||||
let xf = self.ucs_xform();
|
||||
let (o, ..) = xf.axes();
|
||||
let wo = self.scene.world_offset;
|
||||
let origin = glam::Vec3::new(
|
||||
o.x - wo[0] as f32,
|
||||
o.y - wo[1] as f32,
|
||||
o.z - wo[2] as f32,
|
||||
);
|
||||
(origin, xf.rotation_mat())
|
||||
}
|
||||
|
||||
pub(super) fn new_drawing(n: usize) -> Self {
|
||||
let mut scene = Scene::new();
|
||||
linetypes::populate_document(&mut scene.document);
|
||||
|
||||
+7
-3
@@ -2643,7 +2643,9 @@ impl OpenCADStudio {
|
||||
let all_wires = self.tabs[i].scene.hit_test_wires();
|
||||
// Grip drag has no single rubber-band origin for a perp foot.
|
||||
self.snapper.from_point = None;
|
||||
let snap_hit = self.snapper.snap(raw, p, &all_wires[..], vp_mat, bounds);
|
||||
let (go, gr) = self.tabs[i].ucs_grid_basis();
|
||||
let snap_hit =
|
||||
self.snapper.snap(raw, p, &all_wires[..], vp_mat, bounds, go, gr);
|
||||
let mut snapped = snap_hit.map(|s| s.world).unwrap_or(raw);
|
||||
self.tabs[i].snap_result = snap_hit;
|
||||
if let Some(s) = self.tabs[i].snap_result.as_mut() {
|
||||
@@ -2817,9 +2819,10 @@ impl OpenCADStudio {
|
||||
bounds,
|
||||
)
|
||||
} else {
|
||||
let (go, gr) = self.tabs[i].ucs_grid_basis();
|
||||
self.snapper.from_point = self.last_point;
|
||||
self.snapper
|
||||
.snap(cursor_world, p, &all_wires[..], view_proj, bounds)
|
||||
.snap(cursor_world, p, &all_wires[..], view_proj, bounds, go, gr)
|
||||
};
|
||||
|
||||
// Object Snap Tracking: update dwell, then align the cursor
|
||||
@@ -3445,8 +3448,9 @@ impl OpenCADStudio {
|
||||
self.snapper
|
||||
.snap_tangent_only(raw, p, &all_wires[..], vp_mat, bounds)
|
||||
} else {
|
||||
let (go, gr) = self.tabs[i].ucs_grid_basis();
|
||||
self.snapper.from_point = self.last_point;
|
||||
self.snapper.snap(raw, p, &all_wires[..], vp_mat, bounds)
|
||||
self.snapper.snap(raw, p, &all_wires[..], vp_mat, bounds, go, gr)
|
||||
};
|
||||
// snap.world is in paper-space (projected wire coords in MSPACE);
|
||||
// convert to model-space so commands receive consistent coordinates.
|
||||
|
||||
Reference in new issue
Block a user