2026-03-22 14:56:27 +03:00
|
|
|
// acadrust -> truck topology conversion layer.
|
|
|
|
|
|
|
|
|
|
use acadrust::{CadDocument, EntityType};
|
|
|
|
|
use truck_modeling::{Edge, Solid, Vertex, Wire};
|
|
|
|
|
|
|
|
|
|
use crate::entities::traits::EntityTypeOps;
|
2026-06-16 11:33:46 +03:00
|
|
|
use crate::scene::model::wire_model::{SnapHint, TangentGeom};
|
2026-03-22 14:56:27 +03:00
|
|
|
|
2026-04-29 20:58:44 +03:00
|
|
|
/// One group of glyph strokes with its world-space origin stored in f64.
|
|
|
|
|
/// Strokes are in glyph-local space (origin = [0,0]) so that the large
|
|
|
|
|
/// world offset can be subtracted with f64 precision in tessellate.rs.
|
2026-05-21 23:42:22 +03:00
|
|
|
///
|
|
|
|
|
/// `color`, when set, overrides the entity colour for just this group — used
|
|
|
|
|
/// by MTEXT inline `\C` / `\c` per-run colour. Strokes sharing the same
|
|
|
|
|
/// (color, None) override are merged into one WireModel downstream; runs with
|
|
|
|
|
/// distinct colours emit their own WireModel.
|
2026-04-29 20:58:44 +03:00
|
|
|
pub struct TextStroke {
|
|
|
|
|
pub strokes: Vec<Vec<[f32; 2]>>,
|
2026-05-12 10:36:15 +03:00
|
|
|
pub origin: [f64; 2],
|
2026-05-21 23:42:22 +03:00
|
|
|
pub color: Option<[f32; 3]>,
|
2026-06-25 18:17:01 +01:00
|
|
|
pub fill_tris: Vec<[f32; 2]>,
|
2026-04-29 20:58:44 +03:00
|
|
|
}
|
|
|
|
|
|
2026-03-22 14:56:27 +03:00
|
|
|
#[allow(dead_code)]
|
|
|
|
|
pub enum TruckObject {
|
|
|
|
|
Point(Vertex),
|
|
|
|
|
Curve(Edge),
|
|
|
|
|
Contour(Wire),
|
2026-04-29 20:58:44 +03:00
|
|
|
Text(Vec<TextStroke>),
|
2026-03-22 14:56:27 +03:00
|
|
|
/// Pre-computed NaN-separated 3-D point list (leader lines, arrowheads, etc.).
|
2026-05-12 23:47:40 +03:00
|
|
|
/// 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]>),
|
2026-05-06 06:55:28 +03:00
|
|
|
/// Like Lines but linetype pattern restarts at each NaN-separated segment (plinegen=false).
|
2026-05-12 23:47:40 +03:00
|
|
|
SegmentedLines(Vec<[f64; 3]>),
|
2026-03-22 14:56:27 +03:00
|
|
|
Volume(Solid),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct TruckEntity {
|
|
|
|
|
pub object: TruckObject,
|
refactor(snap): producers emit f64 snap points (world_offset removal P3)
TruckEntity.snap_pts is now DVec3 and every entity producer builds snap
candidates straight from the acadrust f64 coordinates instead of casting
to f32 first (text, mtext, arc, circle, ellipse, point, shape, solid,
mline, mtext, attribute, tolerance, table, underlay, ole2frame, mesh,
multileader, dimension, block-cache). offset_snap_pts stays f64
throughout. Still offset-relative (inert) — but snap precision is no
longer capped at ~0.5 m by an early f32 cast, which fixes a latent
UTM-scale snap error and sets up the absolute-coordinate switch.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-23 22:10:29 +03:00
|
|
|
pub snap_pts: Vec<(glam::DVec3, SnapHint)>,
|
2026-03-22 14:56:27 +03:00
|
|
|
pub tangent_geoms: Vec<TangentGeom>,
|
2026-05-12 23:47:40 +03:00
|
|
|
/// 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]>,
|
2026-03-22 14:56:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn convert(entity: &EntityType, document: &CadDocument) -> Option<TruckEntity> {
|
|
|
|
|
entity.to_truck_entity(document)
|
|
|
|
|
}
|