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:
parent
8bfa5088c4
commit
288ccff95a
20 changed files with 371 additions and 360 deletions
|
|
@ -16,17 +16,21 @@ use crate::scene::wire_model::SnapHint;
|
|||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
fn v3(v: &acadrust::types::Vector3) -> [f32; 3] {
|
||||
fn v3(v: &acadrust::types::Vector3) -> [f64; 3] {
|
||||
[v.x, v.y, v.z]
|
||||
}
|
||||
|
||||
fn v3f32(v: &acadrust::types::Vector3) -> [f32; 3] {
|
||||
[v.x as f32, v.y as f32, v.z as f32]
|
||||
}
|
||||
|
||||
/// Small cross marker at the insertion point (used when no clip boundary).
|
||||
fn cross_wire(origin: [f32; 3], size: f32) -> Vec<[f32; 3]> {
|
||||
fn cross_wire(origin: [f64; 3], size: f64) -> Vec<[f64; 3]> {
|
||||
let [ox, oy, oz] = origin;
|
||||
vec![
|
||||
[ox - size, oy, oz],
|
||||
[ox + size, oy, oz],
|
||||
[f32::NAN; 3],
|
||||
[f64::NAN; 3],
|
||||
[ox, oy - size, oz],
|
||||
[ox, oy + size, oz],
|
||||
]
|
||||
|
|
@ -37,23 +41,24 @@ fn cross_wire(origin: [f32; 3], size: f32) -> Vec<[f32; 3]> {
|
|||
impl TruckConvertible for Underlay {
|
||||
fn to_truck(&self, _document: &acadrust::CadDocument) -> Option<TruckEntity> {
|
||||
let origin = v3(&self.insertion_point);
|
||||
let origin_f32 = v3f32(&self.insertion_point);
|
||||
|
||||
if !self.clip_boundary_vertices.is_empty() {
|
||||
// Draw clip boundary polygon + close it.
|
||||
let world_verts = self.world_clip_boundary();
|
||||
let mut pts: Vec<[f32; 3]> = world_verts
|
||||
let mut pts: Vec<[f64; 3]> = world_verts
|
||||
.iter()
|
||||
.map(|v| [v.x as f32, v.y as f32, v.z as f32])
|
||||
.map(|v| [v.x, v.y, v.z])
|
||||
.collect();
|
||||
// Close polygon.
|
||||
if let Some(&first) = pts.first() {
|
||||
pts.push(first);
|
||||
}
|
||||
// Insertion grip.
|
||||
let key: Vec<[f32; 3]> = pts.clone();
|
||||
let key: Vec<[f64; 3]> = pts.clone();
|
||||
Some(TruckEntity {
|
||||
object: TruckObject::Lines(pts),
|
||||
snap_pts: vec![(Vec3::from(origin), SnapHint::Node)],
|
||||
snap_pts: vec![(Vec3::from(origin_f32), SnapHint::Node)],
|
||||
tangent_geoms: vec![],
|
||||
key_vertices: key,
|
||||
fill_tris: vec![],
|
||||
|
|
@ -63,7 +68,7 @@ impl TruckConvertible for Underlay {
|
|||
let pts = cross_wire(origin, 1.0);
|
||||
Some(TruckEntity {
|
||||
object: TruckObject::Lines(pts),
|
||||
snap_pts: vec![(Vec3::from(origin), SnapHint::Node)],
|
||||
snap_pts: vec![(Vec3::from(origin_f32), SnapHint::Node)],
|
||||
tangent_geoms: vec![],
|
||||
key_vertices: vec![origin],
|
||||
fill_tris: vec![],
|
||||
|
|
@ -76,7 +81,7 @@ impl TruckConvertible for Underlay {
|
|||
|
||||
impl Grippable for Underlay {
|
||||
fn grips(&self) -> Vec<GripDef> {
|
||||
let origin = Vec3::from(v3(&self.insertion_point));
|
||||
let origin = Vec3::from(v3f32(&self.insertion_point));
|
||||
let mut grips = vec![square_grip(0, origin)];
|
||||
|
||||
if !self.clip_boundary_vertices.is_empty() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue