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
+23
-5
@@ -428,7 +428,16 @@ impl Snapper {
|
||||
dwell_acquired: false,
|
||||
from_point: None,
|
||||
};
|
||||
tmp.snap(cursor_world, cursor_screen, wires, view_proj, bounds)
|
||||
// Tangent-only: Grid is disabled here, so the grid basis is irrelevant.
|
||||
tmp.snap(
|
||||
cursor_world,
|
||||
cursor_screen,
|
||||
wires,
|
||||
view_proj,
|
||||
bounds,
|
||||
Vec3::ZERO,
|
||||
Mat4::IDENTITY,
|
||||
)
|
||||
}
|
||||
|
||||
/// Find the best snap candidate near the cursor.
|
||||
@@ -439,6 +448,10 @@ impl Snapper {
|
||||
wires: &[WireModel],
|
||||
view_proj: Mat4,
|
||||
bounds: Rectangle,
|
||||
// Grid origin (render/wire space) and UCS→world rotation, so grid snap
|
||||
// lands on the UCS grid the user sees. `(ZERO, IDENTITY)` = world grid.
|
||||
grid_origin: Vec3,
|
||||
grid_rot: Mat4,
|
||||
) -> Option<SnapResult> {
|
||||
if !self.snap_enabled {
|
||||
return None;
|
||||
@@ -727,10 +740,15 @@ impl Snapper {
|
||||
// ── Grid ───────────────────────────────────────────────────────────
|
||||
if self.is_on(SnapType::Grid) {
|
||||
let s = self.grid_spacing;
|
||||
let gx = (cursor_world.x / s).round() * s;
|
||||
let gy = (cursor_world.y / s).round() * s;
|
||||
let gz = (cursor_world.z / s).round() * s;
|
||||
try_pt(Vec3::new(gx, gy, gz), SnapType::Grid);
|
||||
// Round in the UCS grid frame, then map back to world.
|
||||
let ax = grid_rot.transform_vector3(Vec3::X);
|
||||
let ay = grid_rot.transform_vector3(Vec3::Y);
|
||||
let az = grid_rot.transform_vector3(Vec3::Z);
|
||||
let rel = cursor_world - grid_origin;
|
||||
let ux = (rel.dot(ax) / s).round() * s;
|
||||
let uy = (rel.dot(ay) / s).round() * s;
|
||||
let uz = (rel.dot(az) / s).round() * s;
|
||||
try_pt(grid_origin + ax * ux + ay * uy + az * uz, SnapType::Grid);
|
||||
}
|
||||
|
||||
// ── Tangent ────────────────────────────────────────────────────────
|
||||
|
||||
Reference in new issue
Block a user