forked from 1b-agent/opencadstudio-upstream
Expand GPU analytical curves to interactive previews and transformations
This commit is contained in:
1 parent
84e95e4781
commit
ec3b6b89f6
8 files changed
+464
-19
No files matched your search
@@ -7,7 +7,7 @@ use cadkernel::geom2d::{self, Curve as KernelCurve};
|
||||
|
||||
use crate::command::{CadCommand, CmdResult, WorkingPlane};
|
||||
use crate::modules::IconKind;
|
||||
use crate::scene::model::wire_model::WireModel;
|
||||
use crate::scene::model::wire_model::{TangentGeom, WireModel};
|
||||
use glam::DVec3;
|
||||
|
||||
const TAU: f64 = std::f64::consts::TAU;
|
||||
@@ -71,9 +71,9 @@ fn arc_preview(
|
||||
end_angle: f64,
|
||||
plane: WorkingPlane,
|
||||
) -> Option<WireModel> {
|
||||
let center = plane.to_local(center);
|
||||
let center_local = plane.to_local(center);
|
||||
let arc = geom2d::bounded_arc(
|
||||
[center.x, center.y],
|
||||
[center_local.x, center_local.y],
|
||||
radius,
|
||||
start_angle,
|
||||
end_angle,
|
||||
@@ -81,14 +81,23 @@ fn arc_preview(
|
||||
let points = KernelCurve::Arc(arc)
|
||||
.tessellate_angle(TAU / 64.0)
|
||||
.into_iter()
|
||||
.map(|point| plane.to_world(DVec3::new(point[0], point[1], center.z)).to_array())
|
||||
.map(|point| plane.to_world(DVec3::new(point[0], point[1], center_local.z)).to_array())
|
||||
.collect();
|
||||
Some(WireModel::solid_f64(
|
||||
let mut wire = WireModel::solid_f64(
|
||||
"rubber_band".into(),
|
||||
points,
|
||||
WireModel::CYAN,
|
||||
false,
|
||||
))
|
||||
);
|
||||
wire.tangent_geoms.push(TangentGeom::Arc {
|
||||
center: [center.x, center.y, center.z],
|
||||
axis_x: plane.x.to_array(),
|
||||
axis_y: plane.y.to_array(),
|
||||
radius: arc.radius,
|
||||
start_angle: arc.start_angle,
|
||||
end_angle: arc.end_angle,
|
||||
});
|
||||
Some(wire)
|
||||
}
|
||||
|
||||
fn make_arc(
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::t;
|
||||
use crate::command::{CadCommand, CmdResult, DynField, TangentObject, WorkingPlane};
|
||||
use crate::modules::draw::defaults;
|
||||
use crate::modules::IconKind;
|
||||
use crate::scene::model::wire_model::WireModel;
|
||||
use crate::scene::model::wire_model::{TangentGeom, WireModel};
|
||||
use glam::DVec3;
|
||||
|
||||
const TAU: f64 = std::f64::consts::TAU;
|
||||
@@ -56,16 +56,23 @@ pub const ICON: IconKind = ICON_CR;
|
||||
// ── Shared geometry ────────────────────────────────────────────────────────
|
||||
|
||||
fn circle_wire(center: DVec3, radius: f64, plane: WorkingPlane) -> WireModel {
|
||||
let center = plane.to_local(center);
|
||||
let center_local = plane.to_local(center);
|
||||
let points = KernelCurve::Circle(KernelCircle {
|
||||
centre: [center.x, center.y],
|
||||
centre: [center_local.x, center_local.y],
|
||||
radius,
|
||||
})
|
||||
.tessellate_angle(TAU / 64.0)
|
||||
.into_iter()
|
||||
.map(|point| plane.to_world(DVec3::new(point[0], point[1], center.z)).to_array())
|
||||
.map(|point| plane.to_world(DVec3::new(point[0], point[1], center_local.z)).to_array())
|
||||
.collect();
|
||||
WireModel::solid_f64("rubber_band".into(), points, WireModel::CYAN, false)
|
||||
let mut wire = WireModel::solid_f64("rubber_band".into(), points, WireModel::CYAN, false);
|
||||
wire.tangent_geoms.push(TangentGeom::PlanarCircle {
|
||||
center: [center.x, center.y, center.z],
|
||||
axis_x: plane.x.to_array(),
|
||||
axis_y: plane.y.to_array(),
|
||||
radius,
|
||||
});
|
||||
wire
|
||||
}
|
||||
|
||||
fn make_circle(center: DVec3, radius: f64, plane: WorkingPlane) -> EntityType {
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::t;
|
||||
|
||||
use crate::command::{CadCommand, CmdResult, WorkingPlane};
|
||||
use crate::modules::IconKind;
|
||||
use crate::scene::model::wire_model::WireModel;
|
||||
use crate::scene::model::wire_model::{TangentGeom, WireModel};
|
||||
use glam::DVec3;
|
||||
|
||||
fn parse_num(text: &str) -> Option<f64> {
|
||||
@@ -75,7 +75,16 @@ fn ellipse_wire(
|
||||
[p.x, p.y, p.z]
|
||||
})
|
||||
.collect();
|
||||
WireModel::solid_f64("rubber_band".into(), pts, WireModel::CYAN, false)
|
||||
let mut wire = WireModel::solid_f64("rubber_band".into(), pts, WireModel::CYAN, false);
|
||||
wire.tangent_geoms.push(TangentGeom::PlanarEllipse {
|
||||
center: [center.x, center.y, center.z],
|
||||
major_axis: [major.x, major.y, major.z],
|
||||
normal: plane.z.to_array(),
|
||||
minor_axis_ratio: ratio,
|
||||
start_param: t_start,
|
||||
end_param: t_e,
|
||||
});
|
||||
wire
|
||||
}
|
||||
|
||||
/// Convert a world point to the parametric angle on the ellipse.
|
||||
|
||||
Reference in new issue
Block a user