forked from 1b-agent/opencadstudio-upstream
refactor: drop truck, and evaluate every curve through the kernel
The last four truck crates are gone from the manifest. What they were doing falls into three parts, and each now has one answer instead of two. NURBS evaluation. truck was carrying B-spline curves and surfaces for the SPLINE entity, hatch boundaries, BLEND's endpoint frames, the spline preview and ACIS spline-surface faces. The kernel now has both, over one de Boor written across however many coordinates a control point holds — so a plane curve and a space curve cannot drift apart, and a surface is the same algorithm applied twice. The rational and the polynomial cases stop being separate types: weights absent means polynomial. The entity conversion. Every LINE, ARC, ELLIPSE, SPLINE and polyline was built into truck topology purely so it could be sampled back into points. They are sampled through `entities::curve` now, which is where each one's geometry is already defined once and what EXTRUDE and REVOLVE read — so a circle drawn on screen and a circle handed to the Model tab come from the same definition. That retires four of TruckObject's variants and the module is renamed for what it does. SWEEP and LOFT. Both only ever produced a mesh, so both are built from point lists: a band of quads per span, and a lid where a profile closes. Lofting profiles of different densities resamples them by distance rather than by index, so a circle lofted to a square no longer twists. Two things worth noting for anyone reading the old comments. The tolerance globals that lived in the tessellation module were never about truck at all — they are the per-frame chord height, and they move to `curve_tol`. And the rule that a profile handed over as `Lines` silently broke EXTRUDE and REVOLVE no longer holds: those read the curve directly and never look at this channel. The two `automation` test failures are unchanged from before this and are not caused by it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1f642bb40a
commit
8c7ebdc9f1
58 files changed
+947
-1761
No files matched your search
+26
-227
@@ -2728,18 +2728,14 @@ impl OpenCADStudio {
|
||||
self.tabs[i].scene.clear_preview_wire();
|
||||
self.restore_pre_cmd_tangent();
|
||||
}
|
||||
// ── SWEEP ──────────────────────────────────────────────────────
|
||||
// ── SWEEP ─────────────────────────────────────────────────────
|
||||
CmdResult::SweepEntity {
|
||||
profile_handle,
|
||||
path_handle,
|
||||
color,
|
||||
} => {
|
||||
use crate::entities::traits::EntityTypeOps;
|
||||
use crate::modules::insert::solid3d_cmds::empty_solid3d;
|
||||
use crate::scene::convert::acad_to_truck::TruckObject;
|
||||
use crate::scene::convert::truck_tess;
|
||||
use truck_modeling::builder;
|
||||
use truck_modeling::Vector3 as TruckVec3;
|
||||
use crate::scene::model::sweep_model;
|
||||
|
||||
let profile_ent = self.tabs[i]
|
||||
.scene
|
||||
@@ -2747,154 +2743,24 @@ impl OpenCADStudio {
|
||||
.get_entity(profile_handle)
|
||||
.cloned();
|
||||
let path_ent = self.tabs[i].scene.document.get_entity(path_handle).cloned();
|
||||
let result = profile_ent
|
||||
.zip(path_ent)
|
||||
.and_then(|(profile, path)| sweep_model::swept(&profile, &path, color));
|
||||
|
||||
let result = profile_ent.zip(path_ent).and_then(|(prof_e, path_e)| {
|
||||
let prof_truck = prof_e.to_truck_entity(&self.tabs[i].scene.document)?;
|
||||
let path_truck = path_e.to_truck_entity(&self.tabs[i].scene.document)?;
|
||||
|
||||
// Profile must be a wire (closed or open).
|
||||
let profile_wire: truck_modeling::Wire = match prof_truck.object {
|
||||
TruckObject::Contour(w) => w,
|
||||
TruckObject::Curve(e) => std::iter::once(e).collect(),
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
// Path determines the sweep operation.
|
||||
let mesh = match path_truck.object {
|
||||
// Linear path: translate profile along the line direction.
|
||||
TruckObject::Curve(edge) => {
|
||||
let p_start = edge.front().point();
|
||||
let p_end = edge.back().point();
|
||||
let dir = TruckVec3::new(
|
||||
p_end.x - p_start.x,
|
||||
p_end.y - p_start.y,
|
||||
p_end.z - p_start.z,
|
||||
);
|
||||
// Try to build a face from the profile; if it's a closed
|
||||
// wire we get a Solid, otherwise a Shell.
|
||||
if let Ok(face) = builder::try_attach_plane(&[profile_wire.clone()]) {
|
||||
let solid = builder::tsweep(&face, dir);
|
||||
match truck_tess::tessellate_solid(&solid) {
|
||||
truck_tess::TruckTessResult::Mesh {
|
||||
verts,
|
||||
verts_low,
|
||||
normals,
|
||||
indices,
|
||||
} => Some(crate::scene::model::mesh_model::MeshModel {
|
||||
name: String::new(),
|
||||
verts,
|
||||
verts_low,
|
||||
normals,
|
||||
indices,
|
||||
triangle_material_handles: Vec::new(),
|
||||
triangle_colors: Vec::new(),
|
||||
color,
|
||||
selected: false,
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
} else {
|
||||
let shell = builder::tsweep(&profile_wire, dir);
|
||||
match truck_tess::tessellate_shell(&shell) {
|
||||
truck_tess::TruckTessResult::Mesh {
|
||||
verts,
|
||||
verts_low,
|
||||
normals,
|
||||
indices,
|
||||
} => Some(crate::scene::model::mesh_model::MeshModel {
|
||||
name: String::new(),
|
||||
verts,
|
||||
verts_low,
|
||||
normals,
|
||||
indices,
|
||||
triangle_material_handles: Vec::new(),
|
||||
triangle_colors: Vec::new(),
|
||||
color,
|
||||
selected: false,
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Contour path (polyline): sweep along the polyline using the
|
||||
// first edge's direction as approximation (multi-segment sweep
|
||||
// requires NURBS deformation — not supported here).
|
||||
TruckObject::Contour(path_wire) => {
|
||||
// Use start→end of the whole wire as translation vector.
|
||||
let p_start = path_wire.front_vertex()?.point();
|
||||
let p_end = path_wire.back_vertex()?.point();
|
||||
let dir = TruckVec3::new(
|
||||
p_end.x - p_start.x,
|
||||
p_end.y - p_start.y,
|
||||
p_end.z - p_start.z,
|
||||
);
|
||||
if let Ok(face) = builder::try_attach_plane(&[profile_wire.clone()]) {
|
||||
let solid = builder::tsweep(&face, dir);
|
||||
match truck_tess::tessellate_solid(&solid) {
|
||||
truck_tess::TruckTessResult::Mesh {
|
||||
verts,
|
||||
verts_low,
|
||||
normals,
|
||||
indices,
|
||||
} => Some(crate::scene::model::mesh_model::MeshModel {
|
||||
name: String::new(),
|
||||
verts,
|
||||
verts_low,
|
||||
normals,
|
||||
indices,
|
||||
triangle_material_handles: Vec::new(),
|
||||
triangle_colors: Vec::new(),
|
||||
color,
|
||||
selected: false,
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
} else {
|
||||
let shell = builder::tsweep(&profile_wire, dir);
|
||||
match truck_tess::tessellate_shell(&shell) {
|
||||
truck_tess::TruckTessResult::Mesh {
|
||||
verts,
|
||||
verts_low,
|
||||
normals,
|
||||
indices,
|
||||
} => Some(crate::scene::model::mesh_model::MeshModel {
|
||||
name: String::new(),
|
||||
verts,
|
||||
verts_low,
|
||||
normals,
|
||||
indices,
|
||||
triangle_material_handles: Vec::new(),
|
||||
triangle_colors: Vec::new(),
|
||||
color,
|
||||
selected: false,
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_ => None,
|
||||
};
|
||||
mesh
|
||||
});
|
||||
|
||||
if let Some(mut mesh) = result {
|
||||
if let Some(mut set) = result {
|
||||
let pending = self.begin_undo(i, "SWEEP", 1, true);
|
||||
let new_entity = empty_solid3d();
|
||||
let new_handle = self.tabs[i].scene.add_entity(new_entity);
|
||||
mesh.name = format!("{}", new_handle.value());
|
||||
self.tabs[i]
|
||||
.scene
|
||||
.meshes
|
||||
.insert(new_handle, crate::scene::MeshLodSet::from_single(mesh));
|
||||
let new_handle = self.tabs[i].scene.add_entity(empty_solid3d());
|
||||
for mesh in &mut set.lods {
|
||||
mesh.name = format!("{}", new_handle.value());
|
||||
}
|
||||
self.tabs[i].scene.meshes.insert(new_handle, set);
|
||||
self.tabs[i].dirty = true;
|
||||
self.command_line.push_output(crate::t!("SWEEP: solid created.").as_ref());
|
||||
if let Some(pd) = pending {
|
||||
self.commit_undo_delta(i, pd);
|
||||
}
|
||||
} else {
|
||||
self.command_line.push_error(crate::t!("SWEEP: could not sweep profile along path. Use a closed 2D profile and a Line or Polyline path.").as_ref());
|
||||
self.command_line.push_error(crate::t!("SWEEP: could not sweep the profile along the path.").as_ref());
|
||||
}
|
||||
self.tabs[i].active_cmd = None;
|
||||
self.tabs[i].snap_result = None;
|
||||
@@ -2902,96 +2768,29 @@ impl OpenCADStudio {
|
||||
self.restore_pre_cmd_tangent();
|
||||
}
|
||||
|
||||
// ── LOFT ───────────────────────────────────────────────────────
|
||||
// ── LOFT ──────────────────────────────────────────────────────
|
||||
CmdResult::LoftEntities { handles, color } => {
|
||||
use crate::entities::traits::EntityTypeOps;
|
||||
use crate::modules::insert::solid3d_cmds::empty_solid3d;
|
||||
use crate::scene::convert::acad_to_truck::TruckObject;
|
||||
use crate::scene::convert::truck_tess;
|
||||
use truck_modeling::builder;
|
||||
use crate::scene::model::sweep_model;
|
||||
|
||||
// Collect wires from each profile.
|
||||
let mut wires: Vec<truck_modeling::Wire> = Vec::new();
|
||||
for h in &handles {
|
||||
if let Some(ent) = self.tabs[i].scene.document.get_entity(*h).cloned() {
|
||||
if let Some(te) = ent.to_truck_entity(&self.tabs[i].scene.document) {
|
||||
let wire = match te.object {
|
||||
TruckObject::Contour(w) => Some(w),
|
||||
TruckObject::Curve(e) => Some(std::iter::once(e).collect()),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(w) = wire {
|
||||
wires.push(w);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let result: Option<crate::scene::model::mesh_model::MeshModel> = (|| {
|
||||
if wires.len() < 2 {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Build ruled shells between consecutive profile pairs.
|
||||
let mut all_faces: Vec<truck_modeling::Face> = Vec::new();
|
||||
|
||||
for pair in wires.windows(2) {
|
||||
let shell = builder::try_wire_homotopy(&pair[0], &pair[1]).ok()?;
|
||||
for face in shell.into_iter() {
|
||||
all_faces.push(face);
|
||||
}
|
||||
}
|
||||
|
||||
// Cap the first and last profiles if they are closed.
|
||||
if let Ok(cap) = builder::try_attach_plane(&[wires.first()?.clone()]) {
|
||||
all_faces.push(cap);
|
||||
}
|
||||
if let Ok(cap) = builder::try_attach_plane(&[wires.last()?.clone()]) {
|
||||
all_faces.push(cap);
|
||||
}
|
||||
|
||||
let shell = truck_modeling::Shell::from(all_faces);
|
||||
match truck_tess::tessellate_shell(&shell) {
|
||||
truck_tess::TruckTessResult::Mesh {
|
||||
verts,
|
||||
verts_low,
|
||||
normals,
|
||||
indices,
|
||||
} => Some(crate::scene::model::mesh_model::MeshModel {
|
||||
name: String::new(),
|
||||
verts,
|
||||
verts_low,
|
||||
normals,
|
||||
indices,
|
||||
triangle_material_handles: Vec::new(),
|
||||
triangle_colors: Vec::new(),
|
||||
color,
|
||||
selected: false,
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
})(
|
||||
);
|
||||
|
||||
if let Some(mut mesh) = result {
|
||||
let profiles: Vec<acadrust::EntityType> = handles
|
||||
.iter()
|
||||
.filter_map(|handle| self.tabs[i].scene.document.get_entity(*handle).cloned())
|
||||
.collect();
|
||||
if let Some(mut set) = sweep_model::lofted(&profiles, color) {
|
||||
let pending = self.begin_undo(i, "LOFT", 1, true);
|
||||
let new_entity = empty_solid3d();
|
||||
let new_handle = self.tabs[i].scene.add_entity(new_entity);
|
||||
mesh.name = format!("{}", new_handle.value());
|
||||
self.tabs[i]
|
||||
.scene
|
||||
.meshes
|
||||
.insert(new_handle, crate::scene::MeshLodSet::from_single(mesh));
|
||||
let new_handle = self.tabs[i].scene.add_entity(empty_solid3d());
|
||||
for mesh in &mut set.lods {
|
||||
mesh.name = format!("{}", new_handle.value());
|
||||
}
|
||||
self.tabs[i].scene.meshes.insert(new_handle, set);
|
||||
self.tabs[i].dirty = true;
|
||||
self.command_line.push_output(crate::tf!(
|
||||
"LOFT: solid created from {} profiles.",
|
||||
handles.len()
|
||||
).as_ref());
|
||||
self.command_line.push_output(crate::t!("LOFT: solid created.").as_ref());
|
||||
if let Some(pd) = pending {
|
||||
self.commit_undo_delta(i, pd);
|
||||
}
|
||||
} else {
|
||||
self.command_line.push_error(crate::t!("LOFT: could not loft profiles. Ensure sections have the same edge count and are compatible.").as_ref());
|
||||
self.command_line.push_error(crate::t!("LOFT: select at least two closed profiles.").as_ref());
|
||||
}
|
||||
self.tabs[i].active_cmd = None;
|
||||
self.tabs[i].snap_result = None;
|
||||
|
||||
@@ -411,7 +411,7 @@ impl OpenCADStudio {
|
||||
}
|
||||
|
||||
// BOX / SPHERE / CYLINDER / CONE / WEDGE / TORUS are handled by the
|
||||
// Model-tab primitive command above (with truck boolean caching).
|
||||
// Model-tab primitive command above (with the kernel boolean caching).
|
||||
|
||||
// ── EXTRUDE ────────────────────────────────────────────────────
|
||||
// PRESSPULL on a closed boundary creates a solid by extruding it to a
|
||||
|
||||
@@ -32,7 +32,7 @@ impl super::OpenCADStudio {
|
||||
/// selected solids whose B-reps are in the session cache.
|
||||
pub(super) fn solid_boolean(&mut self, op: BoolOp) -> Task<Message> {
|
||||
let i = self.active_tab;
|
||||
// Selected entities that have a cached truck B-rep.
|
||||
// Selected entities that have a cached B-rep.
|
||||
let handles: Vec<Handle> = self.tabs[i]
|
||||
.scene
|
||||
.selected
|
||||
@@ -63,7 +63,7 @@ impl super::OpenCADStudio {
|
||||
self.tabs[i].scene.erase_entities(&handles);
|
||||
// The result is freshly combined geometry with no ACIS parametrisation,
|
||||
// so it lives as a Solid3D whose render/boolean data is the injected
|
||||
// truck mesh + cached B-rep; its edge wires make it pickable.
|
||||
// mesh + cached B-rep; its edge wires make it pickable.
|
||||
let mut s3d = Solid3D::new();
|
||||
s3d.wires = solid_model::edge_wires(&result);
|
||||
let handle = self.add_solid_model(EntityType::Solid3D(s3d), result);
|
||||
@@ -79,7 +79,7 @@ impl super::OpenCADStudio {
|
||||
/// Slice the one selected solid with an axis-aligned plane (axis 0/1/2 =
|
||||
/// X/Y/Z at `value`), keeping the lower side when `keep_low` is true. The
|
||||
/// kept half is the intersection of the solid with a half-space box, reusing
|
||||
/// the same truck-shapeops path as the boolean tools.
|
||||
/// the same boolean path the Design-group tools use.
|
||||
pub(super) fn solid_slice(&mut self, axis: usize, value: f64, keep_low: bool) -> Task<Message> {
|
||||
let i = self.active_tab;
|
||||
let handles: Vec<Handle> = self.tabs[i]
|
||||
@@ -191,7 +191,7 @@ impl super::OpenCADStudio {
|
||||
|
||||
/// 3DROTATE — rotate the one selected solid about the X/Y/Z axis (0/1/2)
|
||||
/// through its centre by `angle_deg` degrees. Rotation preserves the solid's
|
||||
/// orientation, so it reuses the cached truck B-rep directly.
|
||||
/// orientation, so it reuses the cached B-rep directly.
|
||||
pub(super) fn solid_rotate3d(&mut self, axis: usize, angle_deg: f64) -> Task<Message> {
|
||||
let i = self.active_tab;
|
||||
let handles: Vec<Handle> = self.tabs[i]
|
||||
|
||||
@@ -220,14 +220,14 @@ fn plot_scene_content(
|
||||
}
|
||||
|
||||
impl OpenCADStudio {
|
||||
/// Before a save, give every cached truck solid that still has no ACIS
|
||||
/// Before a save, give every cached solid that still has no ACIS
|
||||
/// geometry (EXTRUDE/REVOLVE/SWEEP/LOFT/boolean results) an exact modeler
|
||||
/// body derived from its truck B-rep, so the written DWG/DXF carries real
|
||||
/// body derived from its B-rep, so the written DWG/DXF carries real
|
||||
/// 3-D geometry other CAD apps can open instead of an empty data stream.
|
||||
/// Curved solids that the exact planar path can't yet express are left
|
||||
/// untouched (handled by the NURBS path).
|
||||
#[cfg(feature = "solid3d")]
|
||||
fn sync_truck_solids_to_acis(&mut self, i: usize) {
|
||||
fn sync_solid_models_to_acis(&mut self, i: usize) {
|
||||
use acadrust::EntityType;
|
||||
let scene = &mut self.tabs[i].scene;
|
||||
let targets: Vec<acadrust::Handle> = scene
|
||||
@@ -257,7 +257,7 @@ impl OpenCADStudio {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "solid3d"))]
|
||||
fn sync_truck_solids_to_acis(&mut self, _i: usize) {}
|
||||
fn sync_solid_models_to_acis(&mut self, _i: usize) {}
|
||||
|
||||
/// Snapshot the persisted UI preferences from live state.
|
||||
pub(in crate::app) fn current_settings(&self) -> crate::app::settings::UserSettings {
|
||||
@@ -1340,7 +1340,7 @@ pub(super) fn on_open_file(&mut self) -> Task<Message> {
|
||||
self.stamp_header_sysvars(i);
|
||||
self.tabs[i].scene.document.header.user_real1 =
|
||||
self.tabs[i].scene.annotation_scale as f64;
|
||||
self.sync_truck_solids_to_acis(i);
|
||||
self.sync_solid_models_to_acis(i);
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
@@ -2032,7 +2032,7 @@ pub(super) fn on_open_file(&mut self) -> Task<Message> {
|
||||
let close = self.close_save_dialog_window();
|
||||
sync_annotation_scale_header(&mut self.tabs[i].scene);
|
||||
self.stamp_header_sysvars(i);
|
||||
self.sync_truck_solids_to_acis(i);
|
||||
self.sync_solid_models_to_acis(i);
|
||||
self.stamp_thumbnail(i, version);
|
||||
let mut recent_task = Task::none();
|
||||
let saved = match crate::io::save_to_bytes(
|
||||
|
||||
Reference in new issue
Block a user