forked from 1b-agent/opencadstudio-upstream
refactor: remove dead world_offset plumbing (RTE migration is complete)
Now that geometry reaches the GPU/CPU as absolute coordinates via the double-single relative-to-eye path, world_offset is always [0,0,0]. Strip the parameter that was threaded through the whole tessellation / block- expansion / fallback / camera-decode chain and the ExpandCtx field that carried it — ~340 references across 20 files, all subtracting zero. - truck_tess: to_local / to_local_low / tessellate_* drop the offset arg; to_local is now a pure double-single split. - tessellate: offset_to_ds → points_to_ds (pure DS split); tessellate(), tessellate_entity(), fallback_geometry(), solid_wire_fallback(), entity_aabb(), expand_insert(), expand_block_meshes(), the dimension helpers (vec3_local, dimension_snap_pts, …), text_support, leader, multileader, image_model, xclip and camera_from_view all lose the param. - block_cache: ExpandCtx loses its world_offset field. - Remove the now-dead offset_snap_pts and the unused set_grid_snap. Behaviour is unchanged (the offset was zero everywhere); the compiler verifies every call site. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
02d40bd2ec
commit
56d507fd88
20 files changed
+190
-343
No files matched your search
@@ -43,13 +43,12 @@ fn split_ds_xyz(x: f64, y: f64, z: f64) -> ([f32; 3], [f32; 3]) {
|
||||
([xh, yh, zh], [xl, yl, zl])
|
||||
}
|
||||
|
||||
/// Subtract `world_offset` from each f64 source point and split the residual
|
||||
/// into double-single (high, low) f32 buffers in one pass.
|
||||
fn offset_to_ds(
|
||||
/// Split each absolute f64 source point into double-single (high, low) f32
|
||||
/// buffers in one pass — the relative-to-eye residual the GPU/CPU reconstruct
|
||||
/// to f64 precision at UTM-scale coordinates.
|
||||
fn points_to_ds(
|
||||
src: impl IntoIterator<Item = [f64; 3]>,
|
||||
world_offset: [f64; 3],
|
||||
) -> (Vec<[f32; 3]>, Vec<[f32; 3]>) {
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let it = src.into_iter();
|
||||
let (lo, hi) = it.size_hint();
|
||||
let cap = hi.unwrap_or(lo);
|
||||
@@ -62,7 +61,7 @@ fn offset_to_ds(
|
||||
low.push([0.0; 3]);
|
||||
continue;
|
||||
}
|
||||
let (h, l) = split_ds_xyz(x - ox, y - oy, z - oz);
|
||||
let (h, l) = split_ds_xyz(x, y, z);
|
||||
high.push(h);
|
||||
low.push(l);
|
||||
}
|
||||
@@ -85,7 +84,6 @@ pub fn tessellate(
|
||||
pattern_length: f32,
|
||||
pattern: [f32; 8],
|
||||
line_weight_px: f32,
|
||||
world_offset: [f64; 3],
|
||||
anno_scale: f32,
|
||||
world_per_pixel: Option<f32>,
|
||||
) -> Vec<WireModel> {
|
||||
@@ -127,7 +125,6 @@ pub fn tessellate(
|
||||
selected,
|
||||
entity_color,
|
||||
line_weight_px,
|
||||
world_offset,
|
||||
anno_scale,
|
||||
)];
|
||||
}
|
||||
@@ -148,7 +145,7 @@ pub fn tessellate(
|
||||
// single MTEXT can hand back N colour-distinct wires when the
|
||||
// value mixes inline colours.
|
||||
TruckObject::Text(stroke_groups) => {
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let [ox, oy, oz] = [0.0_f64; 3];
|
||||
let entity_zf = entity_z(entity) as f64;
|
||||
let elev_v = entity_zf - oz;
|
||||
|
||||
@@ -212,7 +209,7 @@ pub fn tessellate(
|
||||
}
|
||||
}
|
||||
|
||||
let snap_pts = offset_snap_pts(te.snap_pts, world_offset);
|
||||
let snap_pts = te.snap_pts;
|
||||
let key_vertices: Vec<[f64; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
@@ -287,12 +284,12 @@ pub fn tessellate(
|
||||
|
||||
// ── Standard topology objects ─────────────────────────────────
|
||||
TruckObject::Point(v) => {
|
||||
let result = tessellate_vertex(&v, world_offset);
|
||||
let result = tessellate_vertex(&v);
|
||||
match result {
|
||||
TruckTessResult::Point([x, y, z], [xl, yl, zl]) => {
|
||||
let s = 0.1_f32;
|
||||
let snap_pts = offset_snap_pts(te.snap_pts, world_offset);
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let snap_pts = te.snap_pts;
|
||||
let [ox, oy, oz] = [0.0_f64; 3];
|
||||
let key_vertices: Vec<[f64; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
@@ -333,10 +330,10 @@ pub fn tessellate(
|
||||
|
||||
TruckObject::Curve(e) => {
|
||||
if let TruckTessResult::Lines(points, points_low) =
|
||||
tessellate_edge(&e, world_offset)
|
||||
tessellate_edge(&e)
|
||||
{
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let snap_pts = offset_snap_pts(te.snap_pts, world_offset);
|
||||
let [ox, oy, oz] = [0.0_f64; 3];
|
||||
let snap_pts = te.snap_pts;
|
||||
let key_vertices: Vec<[f64; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
@@ -366,10 +363,10 @@ pub fn tessellate(
|
||||
|
||||
TruckObject::Contour(w) => {
|
||||
if let TruckTessResult::Lines(points, points_low) =
|
||||
tessellate_wire(&w, world_offset)
|
||||
tessellate_wire(&w)
|
||||
{
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let snap_pts = offset_snap_pts(te.snap_pts, world_offset);
|
||||
let [ox, oy, oz] = [0.0_f64; 3];
|
||||
let snap_pts = te.snap_pts;
|
||||
let key_vertices: Vec<[f64; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
@@ -404,15 +401,15 @@ pub fn tessellate(
|
||||
// GPU shader pairs them so drawings at large UTM-style
|
||||
// coordinates keep sub-unit precision in the wire model and
|
||||
// don't jitter on camera movement.
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let (local_pts, local_pts_low) = offset_to_ds(points, world_offset);
|
||||
let snap_pts = offset_snap_pts(te.snap_pts, world_offset);
|
||||
let [ox, oy, oz] = [0.0_f64; 3];
|
||||
let (local_pts, local_pts_low) = points_to_ds(points);
|
||||
let snap_pts = te.snap_pts;
|
||||
let key_vertices: Vec<[f64; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [x - ox, y - oy, z - oz])
|
||||
.collect();
|
||||
let (fill_tris, fill_tris_low) = offset_to_ds(te.fill_tris, world_offset);
|
||||
let (fill_tris, fill_tris_low) = points_to_ds(te.fill_tris);
|
||||
return vec![WireModel {
|
||||
name,
|
||||
points: local_pts,
|
||||
@@ -435,9 +432,9 @@ pub fn tessellate(
|
||||
}
|
||||
|
||||
TruckObject::SegmentedLines(points) => {
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let (local_pts, local_pts_low) = offset_to_ds(points, world_offset);
|
||||
let snap_pts = offset_snap_pts(te.snap_pts, world_offset);
|
||||
let [ox, oy, oz] = [0.0_f64; 3];
|
||||
let (local_pts, local_pts_low) = points_to_ds(points);
|
||||
let snap_pts = te.snap_pts;
|
||||
let key_vertices: Vec<[f64; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
@@ -470,10 +467,10 @@ pub fn tessellate(
|
||||
// edge wires stored in the entity when present (e.g. from
|
||||
// SOLVIEW output or when the SAT kernel cannot parse the
|
||||
// ACIS data).
|
||||
let wire_pts = solid_wire_fallback(entity, world_offset);
|
||||
let wire_pts = solid_wire_fallback(entity);
|
||||
let mut wm = WireModel::solid_f64(name, wire_pts, color, selected);
|
||||
// Add insertion snap at point_of_reference.
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let [ox, oy, oz] = [0.0_f64; 3];
|
||||
if let Some(p) = crate::entities::solid3d::point_of_reference(entity) {
|
||||
let sp = glam::DVec3::new(p.x - ox, p.y - oy, p.z - oz);
|
||||
wm.snap_pts.push((sp, SnapHint::Insertion));
|
||||
@@ -485,7 +482,7 @@ pub fn tessellate(
|
||||
|
||||
// ── Fallback for Viewport / Insert / Hatch / Ole2Frame ────────────────
|
||||
let (points_f64, snap_pts, tangent_geoms, key_vertices) =
|
||||
fallback_geometry(entity, world_offset);
|
||||
fallback_geometry(entity);
|
||||
// `points_f64` are absolute world coords; split into the double-single
|
||||
// high/low pair so the outline reconstructs to f64 precision at UTM scale
|
||||
// (a NaN separator stays NaN in both buffers).
|
||||
@@ -691,12 +688,12 @@ pub(crate) fn entity_z(entity: &EntityType) -> f32 {
|
||||
use crate::entities::traits::FallbackTess;
|
||||
use crate::scene::convert::tess_util::FallbackGeometry as Geometry;
|
||||
|
||||
fn fallback_geometry(entity: &EntityType, world_offset: [f64; 3]) -> Geometry {
|
||||
fn fallback_geometry(entity: &EntityType) -> Geometry {
|
||||
match entity {
|
||||
EntityType::Viewport(vp) => vp.fallback_geometry(world_offset),
|
||||
EntityType::Insert(ins) => ins.fallback_geometry(world_offset),
|
||||
EntityType::Hatch(h) => h.fallback_geometry(world_offset),
|
||||
EntityType::Ole2Frame(ole) => ole.fallback_geometry(world_offset),
|
||||
EntityType::Viewport(vp) => vp.fallback_geometry(),
|
||||
EntityType::Insert(ins) => ins.fallback_geometry(),
|
||||
EntityType::Hatch(h) => h.fallback_geometry(),
|
||||
EntityType::Ole2Frame(ole) => ole.fallback_geometry(),
|
||||
// Modeler solids render as meshes (solid3d_tess). Their wire path
|
||||
// contributes only the pre-computed edge wires (empty for binary SAB)
|
||||
// plus an insertion snap — never the placeholder segment below, which
|
||||
@@ -706,10 +703,10 @@ fn fallback_geometry(entity: &EntityType, world_offset: [f64; 3]) -> Geometry {
|
||||
| EntityType::Region(_)
|
||||
| EntityType::Body(_)
|
||||
| EntityType::Surface(_) => {
|
||||
let pts = solid_wire_fallback(entity, world_offset);
|
||||
let pts = solid_wire_fallback(entity);
|
||||
let mut snap = vec![];
|
||||
if let Some(p) = crate::entities::solid3d::point_of_reference(entity) {
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let [ox, oy, oz] = [0.0_f64; 3];
|
||||
snap.push((
|
||||
Vec3::new((p.x - ox) as f32, (p.y - oy) as f32, (p.z - oz) as f32),
|
||||
SnapHint::Insertion,
|
||||
@@ -729,8 +726,8 @@ fn fallback_geometry(entity: &EntityType, world_offset: [f64; 3]) -> Geometry {
|
||||
/// AutoCAD stores explicit wire geometry (from SOLVIEW / 3DPLOT) alongside the
|
||||
/// ACIS data. We use this as a visible fallback when the SAT tessellator
|
||||
/// produces no mesh (e.g. binary SAB data or unsupported geometry).
|
||||
fn solid_wire_fallback(entity: &EntityType, world_offset: [f64; 3]) -> Vec<[f64; 3]> {
|
||||
let [ox, oy, oz] = world_offset;
|
||||
fn solid_wire_fallback(entity: &EntityType) -> Vec<[f64; 3]> {
|
||||
let [ox, oy, oz] = [0.0_f64; 3];
|
||||
let Some(wires) = crate::entities::solid3d::fallback_wires(entity) else {
|
||||
return vec![];
|
||||
};
|
||||
@@ -878,16 +875,6 @@ pub(crate) fn add_polyline(points: &mut Vec<[f32; 3]>, polyline: &[Vec3]) {
|
||||
points.extend(polyline.iter().map(|p| [p.x, p.y, p.z]));
|
||||
}
|
||||
|
||||
pub(crate) fn offset_snap_pts(
|
||||
pts: Vec<(glam::DVec3, SnapHint)>,
|
||||
off: [f64; 3],
|
||||
) -> Vec<(glam::DVec3, SnapHint)> {
|
||||
let [ox, oy, oz] = off;
|
||||
pts.into_iter()
|
||||
.map(|(p, h)| (glam::DVec3::new(p.x - ox, p.y - oy, p.z - oz), h))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Returns the text position of a dimension in DXF world-space (f64, no offset applied).
|
||||
/// Used when building a synthetic Text entity so tessellate() can apply world_offset itself.
|
||||
/// When the saved `text_middle_point` is zero (i.e. AutoCAD never wrote one),
|
||||
|
||||
@@ -94,11 +94,11 @@ pub enum TruckTessResult {
|
||||
/// before truncating. This preserves sub-unit decimal precision even when the
|
||||
/// raw world coordinates are in the millions (e.g. Turkish UTM).
|
||||
#[inline]
|
||||
fn to_local(x: f64, y: f64, z: f64, off: [f64; 3]) -> [f32; 3] {
|
||||
fn to_local(x: f64, y: f64, z: f64) -> [f32; 3] {
|
||||
[
|
||||
(x - off[0]) as f32,
|
||||
(y - off[1]) as f32,
|
||||
(z - off[2]) as f32,
|
||||
x as f32,
|
||||
y as f32,
|
||||
z as f32,
|
||||
]
|
||||
}
|
||||
|
||||
@@ -106,26 +106,26 @@ fn to_local(x: f64, y: f64, z: f64, off: [f64; 3]) -> [f32; 3] {
|
||||
/// with the high half so the double-single shader path reconstructs the f64
|
||||
/// source even when the high half is quantized to half a metre at UTM scale.
|
||||
#[inline]
|
||||
fn to_local_low(x: f64, y: f64, z: f64, off: [f64; 3], hi: [f32; 3]) -> [f32; 3] {
|
||||
fn to_local_low(x: f64, y: f64, z: f64, hi: [f32; 3]) -> [f32; 3] {
|
||||
[
|
||||
((x - off[0]) - hi[0] as f64) as f32,
|
||||
((y - off[1]) - hi[1] as f64) as f32,
|
||||
((z - off[2]) - hi[2] as f64) as f32,
|
||||
(x - hi[0] as f64) as f32,
|
||||
(y - hi[1] as f64) as f32,
|
||||
(z - hi[2] as f64) as f32,
|
||||
]
|
||||
}
|
||||
|
||||
// ── Vertex ────────────────────────────────────────────────────────────────
|
||||
|
||||
pub fn tessellate_vertex(v: &Vertex, offset: [f64; 3]) -> TruckTessResult {
|
||||
pub fn tessellate_vertex(v: &Vertex) -> TruckTessResult {
|
||||
let p = v.point();
|
||||
let hi = to_local(p.x, p.y, p.z, offset);
|
||||
let lo = to_local_low(p.x, p.y, p.z, offset, hi);
|
||||
let hi = to_local(p.x, p.y, p.z);
|
||||
let lo = to_local_low(p.x, p.y, p.z, hi);
|
||||
TruckTessResult::Point(hi, lo)
|
||||
}
|
||||
|
||||
// ── Edge ──────────────────────────────────────────────────────────────────
|
||||
|
||||
pub fn tessellate_edge(e: &Edge, offset: [f64; 3]) -> TruckTessResult {
|
||||
pub fn tessellate_edge(e: &Edge) -> TruckTessResult {
|
||||
// oriented_curve() respects the edge direction (inverts if needed).
|
||||
let curve = e.oriented_curve();
|
||||
let (t0, t1) = curve.range_tuple();
|
||||
@@ -136,8 +136,8 @@ pub fn tessellate_edge(e: &Edge, offset: [f64; 3]) -> TruckTessResult {
|
||||
let mut high: Vec<[f32; 3]> = Vec::with_capacity(pts.len());
|
||||
let mut low: Vec<[f32; 3]> = Vec::with_capacity(pts.len());
|
||||
for p in &pts {
|
||||
let hi = to_local(p.x, p.y, p.z, offset);
|
||||
let lo = to_local_low(p.x, p.y, p.z, offset, hi);
|
||||
let hi = to_local(p.x, p.y, p.z);
|
||||
let lo = to_local_low(p.x, p.y, p.z, hi);
|
||||
high.push(hi);
|
||||
low.push(lo);
|
||||
}
|
||||
@@ -146,11 +146,11 @@ pub fn tessellate_edge(e: &Edge, offset: [f64; 3]) -> TruckTessResult {
|
||||
|
||||
// ── Wire ──────────────────────────────────────────────────────────────────
|
||||
|
||||
pub fn tessellate_wire(w: &Wire, offset: [f64; 3]) -> TruckTessResult {
|
||||
pub fn tessellate_wire(w: &Wire) -> TruckTessResult {
|
||||
let mut high: Vec<[f32; 3]> = Vec::new();
|
||||
let mut low: Vec<[f32; 3]> = Vec::new();
|
||||
for edge in w.edge_iter() {
|
||||
if let TruckTessResult::Lines(eh, el) = tessellate_edge(edge, offset) {
|
||||
if let TruckTessResult::Lines(eh, el) = tessellate_edge(edge) {
|
||||
if high.is_empty() {
|
||||
high = eh;
|
||||
low = el;
|
||||
@@ -169,14 +169,14 @@ pub fn tessellate_wire(w: &Wire, offset: [f64; 3]) -> TruckTessResult {
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[cfg(feature = "solid3d")]
|
||||
pub fn tessellate_shell(s: &Shell, offset: [f64; 3]) -> TruckTessResult {
|
||||
pub fn tessellate_shell(s: &Shell) -> TruckTessResult {
|
||||
let meshed = s.triangulation(MESH_TOL);
|
||||
polygon_to_result(meshed.to_polygon(), offset)
|
||||
polygon_to_result(meshed.to_polygon())
|
||||
}
|
||||
|
||||
/// Without `solid3d` (e.g. wasm) there is no mesher; a shell yields no mesh.
|
||||
#[cfg(not(feature = "solid3d"))]
|
||||
pub fn tessellate_shell(_s: &Shell, _offset: [f64; 3]) -> TruckTessResult {
|
||||
pub fn tessellate_shell(_s: &Shell) -> TruckTessResult {
|
||||
TruckTessResult::Mesh {
|
||||
verts: Vec::new(),
|
||||
verts_low: Vec::new(),
|
||||
@@ -189,15 +189,15 @@ pub fn tessellate_shell(_s: &Shell, _offset: [f64; 3]) -> TruckTessResult {
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[cfg(feature = "solid3d")]
|
||||
pub fn tessellate_solid(s: &Solid, offset: [f64; 3]) -> TruckTessResult {
|
||||
pub fn tessellate_solid(s: &Solid) -> TruckTessResult {
|
||||
let meshed = s.triangulation(MESH_TOL);
|
||||
polygon_to_result(meshed.to_polygon(), offset)
|
||||
polygon_to_result(meshed.to_polygon())
|
||||
}
|
||||
|
||||
/// Without `solid3d` (e.g. wasm) there is no mesher; a solid yields no mesh.
|
||||
#[allow(dead_code)]
|
||||
#[cfg(not(feature = "solid3d"))]
|
||||
pub fn tessellate_solid(_s: &Solid, _offset: [f64; 3]) -> TruckTessResult {
|
||||
pub fn tessellate_solid(_s: &Solid) -> TruckTessResult {
|
||||
TruckTessResult::Mesh {
|
||||
verts: Vec::new(),
|
||||
verts_low: Vec::new(),
|
||||
@@ -209,13 +209,13 @@ pub fn tessellate_solid(_s: &Solid, _offset: [f64; 3]) -> TruckTessResult {
|
||||
// ── Internal ─────────────────────────────────────────────────────────────
|
||||
|
||||
#[cfg(feature = "solid3d")]
|
||||
fn polygon_to_result(mesh: PolygonMesh, offset: [f64; 3]) -> TruckTessResult {
|
||||
fn polygon_to_result(mesh: PolygonMesh) -> TruckTessResult {
|
||||
let positions = mesh.positions();
|
||||
let mut verts: Vec<[f32; 3]> = Vec::with_capacity(positions.len());
|
||||
let mut verts_low: Vec<[f32; 3]> = Vec::with_capacity(positions.len());
|
||||
for p in positions.iter() {
|
||||
let hi = to_local(p.x, p.y, p.z, offset);
|
||||
verts_low.push(to_local_low(p.x, p.y, p.z, offset, hi));
|
||||
let hi = to_local(p.x, p.y, p.z);
|
||||
verts_low.push(to_local_low(p.x, p.y, p.z, hi));
|
||||
verts.push(hi);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user