forked from 1b-agent/opencadstudio-upstream
fix(render): preserve f64 precision until world_offset subtraction
Entity converters were casting WCS coordinates to f32 before the renderer subtracted world_offset, which destroyed sub-unit precision on drawings sitting at large coordinates (typical UTM-style CAD files). The multileader case made it visible — glyphs warped under rotation — but every entity that emits TruckObject::Lines/SegmentedLines/key_vertices/fill_tris was affected. Type changes (in src/scene/acad_to_truck.rs): - TruckObject::Lines / SegmentedLines: Vec<[f32; 3]> → Vec<[f64; 3]> - TruckEntity::key_vertices / fill_tris: f32 → f64 All ~17 producer files updated to keep WCS coordinates in f64 right up to the TruckEntity boundary. The consumer in scene/tessellate.rs now performs `(x - ox) as f32` (f64 subtract, then cast) for points, key_vertices, and fill_tris — preserving precision near the camera origin even when the drawing sits at million-unit coordinates. catmull_rom_pts (multileader spline) is now f64; the scene path widens its offset-relative f32 ctrl points to f64 around the call and narrows back at the output. Notes: - Table layout still uses glam::Vec3 (f32) internally; widened to f64 only at the TruckEntity boundary for type compatibility. Separate cleanup to switch its internal math to f64 is tracked. - snap_pts and tangent_geoms remain f32 — they are UI feedback (snap candidates, tangent hints) and the precision is sufficient there.
This commit is contained in:
1 parent
8bfa5088c4
commit
288ccff95a
20 files changed
+371
-360
No files matched your search
@@ -22,9 +22,13 @@ pub enum TruckObject {
|
||||
Contour(Wire),
|
||||
Text(Vec<TextStroke>),
|
||||
/// Pre-computed NaN-separated 3-D point list (leader lines, arrowheads, etc.).
|
||||
Lines(Vec<[f32; 3]>),
|
||||
/// Points are stored in WCS as **f64** so the large world_offset can be
|
||||
/// subtracted in full precision in tessellate.rs before the f32 cast.
|
||||
/// Casting WCS coordinates to f32 in the entity converters used to wreck
|
||||
/// rotated sub-glyph precision on drawings far from origin.
|
||||
Lines(Vec<[f64; 3]>),
|
||||
/// Like Lines but linetype pattern restarts at each NaN-separated segment (plinegen=false).
|
||||
SegmentedLines(Vec<[f32; 3]>),
|
||||
SegmentedLines(Vec<[f64; 3]>),
|
||||
Volume(Solid),
|
||||
}
|
||||
|
||||
@@ -32,10 +36,13 @@ pub struct TruckEntity {
|
||||
pub object: TruckObject,
|
||||
pub snap_pts: Vec<(Vec3, SnapHint)>,
|
||||
pub tangent_geoms: Vec<TangentGeom>,
|
||||
pub key_vertices: Vec<[f32; 3]>,
|
||||
/// Pre-triangulated fill geometry: flat list of [f32;3] vertices, 3 per triangle.
|
||||
/// Non-empty for mesh-like entities (PolyfaceMesh, PolygonMesh) that need solid fill.
|
||||
pub fill_tris: Vec<[f32; 3]>,
|
||||
/// Polyline vertex positions in WCS f64; converted to offset-relative f32
|
||||
/// at the wire-model boundary.
|
||||
pub key_vertices: Vec<[f64; 3]>,
|
||||
/// Pre-triangulated fill geometry: flat list of WCS f64 vertices, 3 per
|
||||
/// triangle. Non-empty for mesh-like entities (PolyfaceMesh, PolygonMesh)
|
||||
/// that need solid fill.
|
||||
pub fill_tris: Vec<[f64; 3]>,
|
||||
}
|
||||
|
||||
pub fn convert(entity: &EntityType, document: &CadDocument) -> Option<TruckEntity> {
|
||||
|
||||
+35
-16
@@ -142,6 +142,12 @@ pub fn tessellate(
|
||||
}
|
||||
|
||||
let snap_pts = offset_snap_pts(te.snap_pts, world_offset);
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let key_vertices: Vec<[f32; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [(x - ox) as f32, (y - oy) as f32, (z - oz) as f32])
|
||||
.collect();
|
||||
return WireModel {
|
||||
name,
|
||||
points,
|
||||
@@ -153,7 +159,7 @@ pub fn tessellate(
|
||||
snap_pts,
|
||||
tangent_geoms: te.tangent_geoms,
|
||||
aci: 0,
|
||||
key_vertices: te.key_vertices,
|
||||
key_vertices,
|
||||
aabb: WireModel::UNBOUNDED_AABB,
|
||||
plinegen: true,
|
||||
vp_scissor: None,
|
||||
@@ -168,6 +174,14 @@ pub fn tessellate(
|
||||
TruckTessResult::Point([x, y, z]) => {
|
||||
let s = 0.1_f32;
|
||||
let snap_pts = offset_snap_pts(te.snap_pts, world_offset);
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let key_vertices: Vec<[f32; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
.map(|[kx, ky, kz]| {
|
||||
[(kx - ox) as f32, (ky - oy) as f32, (kz - oz) as f32]
|
||||
})
|
||||
.collect();
|
||||
return WireModel {
|
||||
name,
|
||||
points: vec![
|
||||
@@ -184,7 +198,7 @@ pub fn tessellate(
|
||||
snap_pts,
|
||||
tangent_geoms: te.tangent_geoms,
|
||||
aci: 0,
|
||||
key_vertices: te.key_vertices,
|
||||
key_vertices,
|
||||
aabb: WireModel::UNBOUNDED_AABB,
|
||||
plinegen: true,
|
||||
vp_scissor: None,
|
||||
@@ -202,7 +216,7 @@ pub fn tessellate(
|
||||
let key_vertices: Vec<[f32; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [x - ox as f32, y - oy as f32, z - oz as f32])
|
||||
.map(|[x, y, z]| [(x - ox) as f32, (y - oy) as f32, (z - oz) as f32])
|
||||
.collect();
|
||||
return WireModel {
|
||||
name,
|
||||
@@ -231,7 +245,7 @@ pub fn tessellate(
|
||||
let key_vertices: Vec<[f32; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [x - ox as f32, y - oy as f32, z - oz as f32])
|
||||
.map(|[x, y, z]| [(x - ox) as f32, (y - oy) as f32, (z - oz) as f32])
|
||||
.collect();
|
||||
return WireModel {
|
||||
name,
|
||||
@@ -254,17 +268,18 @@ pub fn tessellate(
|
||||
}
|
||||
|
||||
TruckObject::Lines(points) => {
|
||||
// Points are world-space f32 from entity converters (polyline,
|
||||
// leader, mesh, solid2d, etc.). Subtract world_offset so the
|
||||
// geometry lands in local space alongside Line/Arc/Circle.
|
||||
// Points are world-space f64 from entity converters (polyline,
|
||||
// leader, mesh, solid2d, etc.). Subtract world_offset in f64
|
||||
// before casting to f32 so drawings at large UTM-style
|
||||
// coordinates keep sub-unit precision in the wire model.
|
||||
let [ox, oy, oz] = world_offset;
|
||||
let local_pts: Vec<[f32; 3]> = points
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| {
|
||||
if x.is_nan() {
|
||||
[x, y, z]
|
||||
[f32::NAN, f32::NAN, f32::NAN]
|
||||
} else {
|
||||
[x - ox as f32, y - oy as f32, z - oz as f32]
|
||||
[(x - ox) as f32, (y - oy) as f32, (z - oz) as f32]
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
@@ -272,12 +287,12 @@ pub fn tessellate(
|
||||
let key_vertices: Vec<[f32; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [x - ox as f32, y - oy as f32, z - oz as f32])
|
||||
.map(|[x, y, z]| [(x - ox) as f32, (y - oy) as f32, (z - oz) as f32])
|
||||
.collect();
|
||||
let fill_tris: Vec<[f32; 3]> = te
|
||||
.fill_tris
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [x - ox as f32, y - oy as f32, z - oz as f32])
|
||||
.map(|[x, y, z]| [(x - ox) as f32, (y - oy) as f32, (z - oz) as f32])
|
||||
.collect();
|
||||
return WireModel {
|
||||
name,
|
||||
@@ -304,9 +319,9 @@ pub fn tessellate(
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| {
|
||||
if x.is_nan() {
|
||||
[x, y, z]
|
||||
[f32::NAN, f32::NAN, f32::NAN]
|
||||
} else {
|
||||
[x - ox as f32, y - oy as f32, z - oz as f32]
|
||||
[(x - ox) as f32, (y - oy) as f32, (z - oz) as f32]
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
@@ -314,7 +329,7 @@ pub fn tessellate(
|
||||
let key_vertices: Vec<[f32; 3]> = te
|
||||
.key_vertices
|
||||
.into_iter()
|
||||
.map(|[x, y, z]| [x - ox as f32, y - oy as f32, z - oz as f32])
|
||||
.map(|[x, y, z]| [(x - ox) as f32, (y - oy) as f32, (z - oz) as f32])
|
||||
.collect();
|
||||
return WireModel {
|
||||
name,
|
||||
@@ -657,8 +672,12 @@ pub fn tessellate_multileader(
|
||||
}
|
||||
|
||||
if ml.path_type == MultiLeaderPathType::Spline && ctrl.len() >= 2 {
|
||||
for pt in catmull_rom_pts(&ctrl, 8) {
|
||||
points.push(pt);
|
||||
let ctrl_f64: Vec<[f64; 3]> = ctrl
|
||||
.iter()
|
||||
.map(|c| [c[0] as f64, c[1] as f64, c[2] as f64])
|
||||
.collect();
|
||||
for pt in catmull_rom_pts(&ctrl_f64, 8) {
|
||||
points.push([pt[0] as f32, pt[1] as f32, pt[2] as f32]);
|
||||
}
|
||||
} else {
|
||||
for &c in &ctrl {
|
||||
|
||||
Reference in new issue
Block a user