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 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 5 committed 2026-08-10 01:08:50 +03:00
1 parent 1f642bb40a
commit 8c7ebdc9f1
58 files changed
+947 -1761

No files matched your search

+10 -11
View File
@@ -11,8 +11,7 @@ use crate::command::{CadCommand, CmdResult};
use crate::modules::{IconKind, ModuleEvent, ToolDef};
use crate::scene::model::wire_model::WireModel;
use glam::DVec3;
use truck_modeling::base::{BoundedCurve, ParametricCurve};
use truck_modeling::{BSplineCurve, KnotVec, Point3};
use acadrust::kernel::space::NurbsCurve3;
#[allow(dead_code)]
pub fn tool() -> ToolDef {
@@ -87,19 +86,19 @@ fn sample_curve(pts: &[DVec3]) -> Vec<[f32; 3]> {
.collect();
}
let degree = 3_usize.min(n - 1);
let ctrl: Vec<Point3> = pts
.iter()
.map(|p| Point3::new(p.x, p.y, p.z))
.collect();
let curve = BSplineCurve::new(KnotVec::from(uniform_knots(n, degree)), ctrl);
let (t0, t1) = curve.range_tuple();
let ctrl: Vec<[f64; 3]> = pts.iter().map(|p| [p.x, p.y, p.z]).collect();
let Some(curve) = NurbsCurve3::new(degree, ctrl, uniform_knots(n, degree), None) else {
return pts
.iter()
.map(|p| [p.x as f32, p.y as f32, p.z as f32])
.collect();
};
// Resolution scales with span count so long splines stay smooth.
let steps = 24 * (n - 1);
(0..=steps)
.map(|i| {
let t = t0 + (t1 - t0) * (i as f64 / steps as f64);
let p = curve.subs(t);
[p.x as f32, p.y as f32, p.z as f32]
let p = curve.point_at(i as f64 / steps as f64);
[p[0] as f32, p[1] as f32, p[2] as f32]
})
.collect()
}
+30 -52
View File
@@ -11,8 +11,7 @@ use acadrust::types::Vector3;
use acadrust::{EntityType, Handle};
use glam::DVec3;
use crate::t;
use truck_modeling::base::{BoundedCurve, ParametricCurve, Vector4};
use truck_modeling::{BSplineCurve, KnotVec, NurbsCurve, Point3};
use acadrust::kernel::space::NurbsCurve3;
use crate::command::{CadCommand, CmdOption, CmdResult};
use crate::entities::common::BulgeArc;
@@ -563,51 +562,34 @@ fn spline_control_endpoint(spline: &Spline, click: DVec3) -> Option<EndpointFram
if degree == 0 || count <= degree {
return None;
}
let knots = if spline.knots.len() == count + degree + 1 {
KnotVec::from(spline.knots.clone())
} else {
KnotVec::uniform_knot(degree, count - 1)
};
// The kernel's space curve holds the rational and the polynomial case
// alike — weights absent means polynomial — so there is nothing here to
// tell apart, and a malformed knot vector is replaced with a clamped
// uniform one rather than refused.
let controls: Vec<[f64; 3]> = spline
.control_points
.iter()
.map(|point| [point.x, point.y, point.z])
.collect();
let weights = (spline.weights.len() == count).then(|| {
spline
.weights
.iter()
.map(|weight| if weight.abs() <= EPS { 1.0 } else { *weight })
.collect()
});
let curve = NurbsCurve3::new(degree, controls, spline.knots.clone(), weights)?;
if spline.weights.len() == count {
let homogeneous: Vec<Vector4> = spline
.control_points
.iter()
.zip(&spline.weights)
.map(|(point, &weight)| {
let weight = if weight.abs() <= EPS { 1.0 } else { weight };
Vector4::new(point.x * weight, point.y * weight, point.z * weight, weight)
})
.collect();
let curve = NurbsCurve::new(BSplineCurve::new(knots, homogeneous));
let (start, end) = curve.range_tuple();
let at_start = click.distance_squared(point_to_dvec(curve.subs(start)))
<= click.distance_squared(point_to_dvec(curve.subs(end)));
let parameter = if at_start { start } else { end };
curve_frame(
point_to_dvec(curve.subs(parameter)),
vector_to_dvec(curve.der(parameter)),
vector_to_dvec(curve.der2(parameter)),
at_start,
)
} else {
let controls: Vec<Point3> = spline
.control_points
.iter()
.map(|point| Point3::new(point.x, point.y, point.z))
.collect();
let curve = BSplineCurve::new(knots, controls);
let (start, end) = curve.range_tuple();
let at_start = click.distance_squared(point_to_dvec(curve.subs(start)))
<= click.distance_squared(point_to_dvec(curve.subs(end)));
let parameter = if at_start { start } else { end };
curve_frame(
point_to_dvec(curve.subs(parameter)),
vector_to_dvec(curve.der(parameter)),
vector_to_dvec(curve.der2(parameter)),
at_start,
)
}
let (start, end) = curve.domain();
let at_start = click.distance_squared(point_to_dvec(curve.point_at_knot(start)))
<= click.distance_squared(point_to_dvec(curve.point_at_knot(end)));
let parameter = if at_start { start } else { end };
curve_frame(
point_to_dvec(curve.point_at_knot(parameter)),
point_to_dvec(curve.tangent_at_knot(parameter)),
point_to_dvec(curve.acceleration_at_knot(parameter)),
at_start,
)
}
fn curve_frame(
@@ -666,12 +648,8 @@ fn to_dvec(point: Vector3) -> DVec3 {
DVec3::new(point.x, point.y, point.z)
}
fn point_to_dvec(point: Point3) -> DVec3 {
DVec3::new(point.x, point.y, point.z)
}
fn vector_to_dvec(vector: truck_modeling::Vector3) -> DVec3 {
DVec3::new(vector.x, vector.y, vector.z)
fn point_to_dvec(point: [f64; 3]) -> DVec3 {
DVec3::new(point[0], point[1], point[2])
}
inventory::submit!(crate::command::CommandRegistration {
+2 -2
View File
@@ -1,7 +1,7 @@
// 2D→3D modelling commands — EXTRUDE, REVOLVE, SWEEP, LOFT.
//
// Each picks profile/path entities and emits a `CmdResult` whose handler
// builds a truck solid and inserts its MeshModel into scene.meshes under a
// builds a solid and inserts its MeshModel into scene.meshes under a
// minimal placeholder Solid3D entity (empty ACIS — saving will not restore
// the mesh). The standalone primitives (BOX/CYLINDER/CONE/SPHERE/WEDGE/TORUS)
// live in the Model tab (`modules::model::primitive_cmd`).
@@ -13,7 +13,7 @@ use crate::t;
use crate::command::{CadCommand, CmdResult};
// BOX / SPHERE / CYLINDER (and CONE / WEDGE / TORUS) now live in the Model tab
// (`modules::model::primitive_cmd`), which builds them as truck B-reps cached
// (`modules::model::primitive_cmd`), which builds them as B-reps cached
// for the Design-group boolean tools. EXTRUDE / REVOLVE / SWEEP / LOFT remain
// here as 2D→3D operations.
+2 -2
View File
@@ -1,6 +1,6 @@
// Boolean operations on 3D solids (Design group). The actual CSG runs in
// `App::solid_boolean` (src/app/model_ops.rs) using truck-shapeops on the
// session-cached truck B-reps; this module just names the operations.
// `App::solid_boolean` (src/app/model_ops.rs) using the kernel on the
// session-cached B-reps; this module just names the operations.
/// Which boolean a Design-group tool performs on the two selected solids.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
+1 -1
View File
@@ -2,7 +2,7 @@
//
// Model group : create primitive solids (box, cylinder, cone, sphere, …)
// as ACIS Solid3D entities via acadrust's primitive builders.
// Design group : combine solids with truck boolean operations
// Design group : combine solids with the kernel boolean operations
// (union / subtract / intersect).
pub mod boolean_cmd;
+1 -1
View File
@@ -4,7 +4,7 @@
// `acis::primitives` builders. `Scene::add_entity` tessellates the SAT B-rep
// into the 3D mesh pipeline, so the solid renders, selects, and saves to DXF.
//
// A matching truck `Solid` is cached on the scene (see model/mod.rs) when the
// A matching the kernel `Solid` is cached on the scene (see model/mod.rs) when the
// entity is committed, so the Design-group boolean tools can combine it.
use acadrust::entities::Solid3D;