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;
|
||||
|
||||
Reference in new issue
Block a user