Declare std::offsetPlane in KCL (#6344)
* Declare std::offsetPlane in KCL Signed-off-by: Nick Cameron <nrc@ncameron.org> * Use two axes to define planes in KCL Signed-off-by: Nick Cameron <nrc@ncameron.org> --------- Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
@ -1108,7 +1108,6 @@ impl<'a> FromKclValue<'a> for super::sketch::PlaneData {
|
||||
origin: value.origin,
|
||||
x_axis: value.x_axis,
|
||||
y_axis: value.y_axis,
|
||||
z_axis: value.z_axis,
|
||||
});
|
||||
}
|
||||
// Case 1: predefined plane
|
||||
@ -1129,13 +1128,7 @@ impl<'a> FromKclValue<'a> for super::sketch::PlaneData {
|
||||
let origin = plane.get("origin").and_then(FromKclValue::from_kcl_val)?;
|
||||
let x_axis = plane.get("xAxis").and_then(FromKclValue::from_kcl_val)?;
|
||||
let y_axis = plane.get("yAxis").and_then(FromKclValue::from_kcl_val)?;
|
||||
let z_axis = plane.get("zAxis").and_then(FromKclValue::from_kcl_val)?;
|
||||
Some(Self::Plane {
|
||||
origin,
|
||||
x_axis,
|
||||
y_axis,
|
||||
z_axis,
|
||||
})
|
||||
Some(Self::Plane { origin, x_axis, y_axis })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,6 @@ lazy_static! {
|
||||
Box::new(crate::std::shell::Hollow),
|
||||
Box::new(crate::std::sweep::Sweep),
|
||||
Box::new(crate::std::loft::Loft),
|
||||
Box::new(crate::std::planes::OffsetPlane),
|
||||
Box::new(crate::std::math::Acos),
|
||||
Box::new(crate::std::math::Asin),
|
||||
Box::new(crate::std::math::Atan),
|
||||
@ -207,6 +206,10 @@ pub(crate) fn std_fn(path: &str, fn_name: &str) -> (crate::std::StdFn, StdFnProp
|
||||
|e, a| Box::pin(crate::std::revolve::revolve(e, a)),
|
||||
StdFnProps::default("std::revolve").include_in_feature_tree(),
|
||||
),
|
||||
("prelude", "offsetPlane") => (
|
||||
|e, a| Box::pin(crate::std::planes::offset_plane(e, a)),
|
||||
StdFnProps::default("std::offsetPlane").include_in_feature_tree(),
|
||||
),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
//! Standard library plane helpers.
|
||||
|
||||
use kcl_derive_docs::stdlib;
|
||||
use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, shared::Color, ModelingCmd};
|
||||
use kittycad_modeling_cmds as kcmc;
|
||||
|
||||
@ -19,98 +18,6 @@ pub async fn offset_plane(exec_state: &mut ExecState, args: Args) -> Result<KclV
|
||||
Ok(KclValue::Plane { value: Box::new(plane) })
|
||||
}
|
||||
|
||||
/// Offset a plane by a distance along its normal.
|
||||
///
|
||||
/// For example, if you offset the 'XZ' plane by 10, the new plane will be parallel to the 'XZ'
|
||||
/// plane and 10 units away from it.
|
||||
///
|
||||
/// ```no_run
|
||||
/// // Loft a square and a circle on the `XY` plane using offset.
|
||||
/// squareSketch = startSketchOn('XY')
|
||||
/// |> startProfileAt([-100, 200], %)
|
||||
/// |> line(end = [200, 0])
|
||||
/// |> line(end = [0, -200])
|
||||
/// |> line(end = [-200, 0])
|
||||
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
/// |> close()
|
||||
///
|
||||
/// circleSketch = startSketchOn(offsetPlane('XY', offset = 150))
|
||||
/// |> circle( center = [0, 100], radius = 50 )
|
||||
///
|
||||
/// loft([squareSketch, circleSketch])
|
||||
/// ```
|
||||
///
|
||||
/// ```no_run
|
||||
/// // Loft a square and a circle on the `XZ` plane using offset.
|
||||
/// squareSketch = startSketchOn('XZ')
|
||||
/// |> startProfileAt([-100, 200], %)
|
||||
/// |> line(end = [200, 0])
|
||||
/// |> line(end = [0, -200])
|
||||
/// |> line(end = [-200, 0])
|
||||
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
/// |> close()
|
||||
///
|
||||
/// circleSketch = startSketchOn(offsetPlane('XZ', offset = 150))
|
||||
/// |> circle( center = [0, 100], radius = 50 )
|
||||
///
|
||||
/// loft([squareSketch, circleSketch])
|
||||
/// ```
|
||||
///
|
||||
/// ```no_run
|
||||
/// // Loft a square and a circle on the `YZ` plane using offset.
|
||||
/// squareSketch = startSketchOn('YZ')
|
||||
/// |> startProfileAt([-100, 200], %)
|
||||
/// |> line(end = [200, 0])
|
||||
/// |> line(end = [0, -200])
|
||||
/// |> line(end = [-200, 0])
|
||||
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
/// |> close()
|
||||
///
|
||||
/// circleSketch = startSketchOn(offsetPlane('YZ', offset = 150))
|
||||
/// |> circle( center = [0, 100], radius = 50 )
|
||||
///
|
||||
/// loft([squareSketch, circleSketch])
|
||||
/// ```
|
||||
///
|
||||
/// ```no_run
|
||||
/// // Loft a square and a circle on the `-XZ` plane using offset.
|
||||
/// squareSketch = startSketchOn('-XZ')
|
||||
/// |> startProfileAt([-100, 200], %)
|
||||
/// |> line(end = [200, 0])
|
||||
/// |> line(end = [0, -200])
|
||||
/// |> line(end = [-200, 0])
|
||||
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
/// |> close()
|
||||
///
|
||||
/// circleSketch = startSketchOn(offsetPlane('-XZ', offset = -150))
|
||||
/// |> circle( center = [0, 100], radius = 50 )
|
||||
///
|
||||
/// loft([squareSketch, circleSketch])
|
||||
/// ```
|
||||
/// ```no_run
|
||||
/// // A circle on the XY plane
|
||||
/// startSketchOn("XY")
|
||||
/// |> startProfileAt([0, 0], %)
|
||||
/// |> circle( radius = 10, center = [0, 0] )
|
||||
///
|
||||
/// // Triangle on the plane 4 units above
|
||||
/// startSketchOn(offsetPlane("XY", offset = 4))
|
||||
/// |> startProfileAt([0, 0], %)
|
||||
/// |> line(end = [10, 0])
|
||||
/// |> line(end = [0, 10])
|
||||
/// |> close()
|
||||
/// ```
|
||||
|
||||
#[stdlib {
|
||||
name = "offsetPlane",
|
||||
feature_tree_operation = true,
|
||||
keywords = true,
|
||||
unlabeled_first = true,
|
||||
args = {
|
||||
plane = { docs = "The plane (e.g. XY) which this new plane is created from." },
|
||||
offset = { docs = "Distance from the standard plane this new plane will be created at." },
|
||||
}
|
||||
}]
|
||||
async fn inner_offset_plane(
|
||||
plane: PlaneData,
|
||||
offset: TyF64,
|
||||
@ -122,7 +29,8 @@ async fn inner_offset_plane(
|
||||
// standard planes themselves.
|
||||
plane.value = PlaneType::Custom;
|
||||
|
||||
plane.origin += plane.z_axis * offset.to_length_units(plane.origin.units);
|
||||
let normal = plane.x_axis.cross(&plane.y_axis);
|
||||
plane.origin += normal * offset.to_length_units(plane.origin.units);
|
||||
make_offset_plane_in_engine(&plane, exec_state, args).await?;
|
||||
|
||||
Ok(plane)
|
||||
|
@ -960,9 +960,6 @@ pub enum PlaneData {
|
||||
/// What should the plane’s Y axis be?
|
||||
#[serde(rename = "yAxis")]
|
||||
y_axis: Point3d,
|
||||
/// The z-axis (normal).
|
||||
#[serde(rename = "zAxis")]
|
||||
z_axis: Point3d,
|
||||
},
|
||||
}
|
||||
|
||||
@ -1229,7 +1226,6 @@ async fn start_sketch_on_face(
|
||||
// TODO: get this from the extrude plane data.
|
||||
x_axis: solid.sketch.on.x_axis(),
|
||||
y_axis: solid.sketch.on.y_axis(),
|
||||
z_axis: solid.sketch.on.z_axis(),
|
||||
units: solid.units,
|
||||
solid,
|
||||
meta: vec![args.source_range.into()],
|
||||
@ -1247,49 +1243,18 @@ async fn make_sketch_plane_from_orientation(
|
||||
let clobber = false;
|
||||
let size = LengthUnit(60.0);
|
||||
let hide = Some(true);
|
||||
match data {
|
||||
PlaneData::XY | PlaneData::NegXY | PlaneData::XZ | PlaneData::NegXZ | PlaneData::YZ | PlaneData::NegYZ => {
|
||||
// TODO: ignoring the default planes here since we already created them, breaks the
|
||||
// front end for the feature tree which is stupid and we should fix it.
|
||||
let x_axis = match data {
|
||||
PlaneData::NegXY => Point3d::new(-1.0, 0.0, 0.0, UnitLen::Mm),
|
||||
PlaneData::NegXZ => Point3d::new(-1.0, 0.0, 0.0, UnitLen::Mm),
|
||||
PlaneData::NegYZ => Point3d::new(0.0, -1.0, 0.0, UnitLen::Mm),
|
||||
_ => plane.x_axis,
|
||||
};
|
||||
args.batch_modeling_cmd(
|
||||
plane.id,
|
||||
ModelingCmd::from(mcmd::MakePlane {
|
||||
clobber,
|
||||
origin: plane.origin.into(),
|
||||
size,
|
||||
x_axis: x_axis.into(),
|
||||
y_axis: plane.y_axis.into(),
|
||||
hide,
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
PlaneData::Plane {
|
||||
origin,
|
||||
x_axis,
|
||||
y_axis,
|
||||
z_axis: _,
|
||||
} => {
|
||||
args.batch_modeling_cmd(
|
||||
plane.id,
|
||||
ModelingCmd::from(mcmd::MakePlane {
|
||||
clobber,
|
||||
origin: origin.into(),
|
||||
size,
|
||||
x_axis: x_axis.into(),
|
||||
y_axis: y_axis.into(),
|
||||
hide,
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
args.batch_modeling_cmd(
|
||||
plane.id,
|
||||
ModelingCmd::from(mcmd::MakePlane {
|
||||
clobber,
|
||||
origin: plane.origin.into(),
|
||||
size,
|
||||
x_axis: plane.x_axis.into(),
|
||||
y_axis: plane.y_axis.into(),
|
||||
hide,
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(Box::new(plane))
|
||||
}
|
||||
@ -1384,7 +1349,8 @@ pub(crate) async fn inner_start_profile_at(
|
||||
adjust_camera: false,
|
||||
planar_normal: if let SketchSurface::Plane(plane) = &sketch_surface {
|
||||
// We pass in the normal for the plane here.
|
||||
Some(plane.z_axis.into())
|
||||
let normal = plane.x_axis.cross(&plane.y_axis);
|
||||
Some(normal.into())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
|
Reference in New Issue
Block a user