cad-editor/src/scene/acad_to_truck.rs
Hakan Seven 048bb41aef feat(render): solid fill for PolyfaceMesh and PolygonMesh entities
PolyfaceMesh and PolygonMesh were wireframe-only. They now render with
the same flat-color solid fill as Face3D entities.

- Add fill_tris: Vec<[f32;3]> to TruckEntity and WireModel
- PolyfaceMesh: fan-triangulate each face into fill_tris
- PolygonMesh: triangulate each grid quad into fill_tris
- tessellate.rs Lines branch: apply world_offset to fill_tris
- Face3DGpu::from_wires: collect fill_tris from all wires in addition
  to Face3D key_vertices quads
- upload_face3d: pass all_wires so fill_tris are batched into one draw call
2026-05-06 23:24:26 +03:00

43 lines
1.4 KiB
Rust

// acadrust -> truck topology conversion layer.
use acadrust::{CadDocument, EntityType};
use glam::Vec3;
use truck_modeling::{Edge, Solid, Vertex, Wire};
use crate::entities::traits::EntityTypeOps;
use crate::scene::wire_model::{SnapHint, TangentGeom};
/// 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.
pub struct TextStroke {
pub strokes: Vec<Vec<[f32; 2]>>,
pub origin: [f64; 2],
}
#[allow(dead_code)]
pub enum TruckObject {
Point(Vertex),
Curve(Edge),
Contour(Wire),
Text(Vec<TextStroke>),
/// Pre-computed NaN-separated 3-D point list (leader lines, arrowheads, etc.).
Lines(Vec<[f32; 3]>),
/// Like Lines but linetype pattern restarts at each NaN-separated segment (plinegen=false).
SegmentedLines(Vec<[f32; 3]>),
Volume(Solid),
}
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]>,
}
pub fn convert(entity: &EntityType, document: &CadDocument) -> Option<TruckEntity> {
entity.to_truck_entity(document)
}