From 8d56b926da80dcfc7f260ce41f388ebec99be0aa Mon Sep 17 00:00:00 2001 From: Simon Kirkby Date: Mon, 24 Jul 2023 21:25:42 +0800 Subject: [PATCH 1/3] bowl and flywheel examples --- crates/opencascade/examples/bowl.rs | 39 ++++++++++++++++ crates/opencascade/examples/flywheel.rs | 61 +++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 crates/opencascade/examples/bowl.rs create mode 100644 crates/opencascade/examples/flywheel.rs diff --git a/crates/opencascade/examples/bowl.rs b/crates/opencascade/examples/bowl.rs new file mode 100644 index 00000000..861c0c1e --- /dev/null +++ b/crates/opencascade/examples/bowl.rs @@ -0,0 +1,39 @@ +use glam::dvec3; +use opencascade::{ + primitives::{self, Direction, Solid}, + workplane::Workplane, +}; + +// Demonstrates filleting a 2D profile, extruding it, then chamfering +// the top edges, resulting in a nice, rounded chamfer. +pub fn main() { + let bot_rad: f64 = 30.0; + let top_rad: f64 = 40.0; + let height: f64 = 30.0; + let thickness: f64 = 2.0; + // the base bowl + let mut loft = bowly_shape(bot_rad, top_rad, height, 0.); + + // inner ( shell does not exist yest) + let inner = bowly_shape(bot_rad - thickness, top_rad - thickness, height, thickness); + (loft, _) = loft.subtract_shape(&inner); + + // rouind out the top + let top_side = loft.faces().farthest(Direction::PosZ).edges(); + loft.fillet_edges(thickness / 2.0, top_side); + + loft.write_stl("bowl.stl").unwrap(); +} + +fn bowly_shape(bot_rad: f64, top_rad: f64, height: f64, offset: f64) -> primitives::Shape { + let bottom = Workplane::xy().circle(0., 0., bot_rad); + let mut top = Workplane::xy().circle(0., 0., top_rad); + top.translate(dvec3(0., 0., height)); + let mut loft = Solid::loft([&bottom, &top]).to_shape(); + loft.set_global_translation(dvec3(0., 0., offset)); + // round out the bottom + let bottom_side = loft.faces().farthest(Direction::NegZ).edges(); + loft.fillet_edges(4., bottom_side); + + loft +} diff --git a/crates/opencascade/examples/flywheel.rs b/crates/opencascade/examples/flywheel.rs new file mode 100644 index 00000000..a675ca15 --- /dev/null +++ b/crates/opencascade/examples/flywheel.rs @@ -0,0 +1,61 @@ +use glam::dvec3; +use opencascade::{ + angle::Angle, + primitives::Shape, + workplane::Workplane, +}; + +pub fn main() { + let outer: f64 = 30.0; + let height: f64 = 8.0; + let thickness: f64 = 8.0; + let spoke_count: usize = 7; + let hub_outer: f64 = 8.0; + + let ring = rim(outer,thickness,height); + let sp = spokes(outer-thickness/2.0,thickness/2.0,spoke_count); + let (mut fly ,smooth ) = ring.union_shape(&sp); + fly.fillet_edges(1.0,smooth); + + let the_hub = hub(hub_outer, thickness); + let (mut fly , hub_con) = fly.union_shape(&the_hub); + fly.fillet_edges(1.0,hub_con); + + fly.write_stl("flywheel.stl").unwrap(); +} + +fn rim(outer:f64 , thickness: f64,height: f64) -> Shape { + let outer_wire = Workplane::xy().circle(0., 0., outer); + let mut ring = outer_wire.to_face().extrude(dvec3(0.0, 0.0, height)).to_shape(); + let inner_wire = Workplane::xy().circle(0.,0.0, outer - thickness/2.0); + let inner_ring = inner_wire.to_face().extrude(dvec3(0.0,0.0,height)).to_shape(); + (ring, _ ) = ring.subtract_shape(&inner_ring); + ring.chamfer(0.1); + ring +} + +fn hub(outer: f64 , height: f64) -> Shape { + let outer_wire = Workplane::xy().circle(0., 0., outer); + let mut hub = outer_wire.to_face().extrude(dvec3(0.0, 0.0, height)).to_shape(); + hub.chamfer(0.1); + hub +} + +fn spoke(length: f64,thickness:f64,rotation:f64) -> Shape { + let mut wp = Workplane::xy(); + wp.set_rotation((Angle::Degrees(90.0),Angle::Degrees(rotation),Angle::Degrees(0.0))); + let inner_wire = wp.circle(0., 0., thickness/2.0); + let mut spoke = inner_wire.to_face().extrude(wp.normal()*length).to_shape(); + spoke.set_global_translation(dvec3(0.0, 0.0, thickness)); + spoke +} + +fn spokes(length: f64 , thickness: f64,count: usize) -> Shape { + let incr = 360.0 / count as f64; + let mut first_s = spoke(length,thickness,0.0); + for i in 1..count { + let s = spoke(length,thickness,incr * i as f64); + (first_s , _) = first_s.union_shape(&s); + } + first_s +} From 151859268f8b7c32e6e11a37bef558c87f63e125 Mon Sep 17 00:00:00 2001 From: Simon Kirkby Date: Mon, 24 Jul 2023 21:29:22 +0800 Subject: [PATCH 2/3] remove cut pasted comments --- crates/opencascade/examples/bowl.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/opencascade/examples/bowl.rs b/crates/opencascade/examples/bowl.rs index 861c0c1e..62266b14 100644 --- a/crates/opencascade/examples/bowl.rs +++ b/crates/opencascade/examples/bowl.rs @@ -4,8 +4,6 @@ use opencascade::{ workplane::Workplane, }; -// Demonstrates filleting a 2D profile, extruding it, then chamfering -// the top edges, resulting in a nice, rounded chamfer. pub fn main() { let bot_rad: f64 = 30.0; let top_rad: f64 = 40.0; From 6adeee5d96a3cbfdd48eb3dac979f4d850515fca Mon Sep 17 00:00:00 2001 From: Simon Kirkby Date: Tue, 25 Jul 2023 07:36:52 +0800 Subject: [PATCH 3/3] Fix formatting and trailing zeros --- crates/opencascade/examples/bowl.rs | 14 +++---- crates/opencascade/examples/flywheel.rs | 52 ++++++++++++------------- 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/crates/opencascade/examples/bowl.rs b/crates/opencascade/examples/bowl.rs index 62266b14..9755bfe2 100644 --- a/crates/opencascade/examples/bowl.rs +++ b/crates/opencascade/examples/bowl.rs @@ -1,6 +1,6 @@ use glam::dvec3; use opencascade::{ - primitives::{self, Direction, Solid}, + primitives::{self, Direction, Solid}, workplane::Workplane, }; @@ -10,7 +10,7 @@ pub fn main() { let height: f64 = 30.0; let thickness: f64 = 2.0; // the base bowl - let mut loft = bowly_shape(bot_rad, top_rad, height, 0.); + let mut loft = bowly_shape(bot_rad, top_rad, height, 0.0); // inner ( shell does not exist yest) let inner = bowly_shape(bot_rad - thickness, top_rad - thickness, height, thickness); @@ -24,14 +24,14 @@ pub fn main() { } fn bowly_shape(bot_rad: f64, top_rad: f64, height: f64, offset: f64) -> primitives::Shape { - let bottom = Workplane::xy().circle(0., 0., bot_rad); - let mut top = Workplane::xy().circle(0., 0., top_rad); - top.translate(dvec3(0., 0., height)); + let bottom = Workplane::xy().circle(0.0, 0.0, bot_rad); + let mut top = Workplane::xy().circle(0.0, 0.0, top_rad); + top.translate(dvec3(0.0, 0.0, height)); let mut loft = Solid::loft([&bottom, &top]).to_shape(); - loft.set_global_translation(dvec3(0., 0., offset)); + loft.set_global_translation(dvec3(0.0, 0.0, offset)); // round out the bottom let bottom_side = loft.faces().farthest(Direction::NegZ).edges(); - loft.fillet_edges(4., bottom_side); + loft.fillet_edges(4.0, bottom_side); loft } diff --git a/crates/opencascade/examples/flywheel.rs b/crates/opencascade/examples/flywheel.rs index a675ca15..351dc932 100644 --- a/crates/opencascade/examples/flywheel.rs +++ b/crates/opencascade/examples/flywheel.rs @@ -1,9 +1,5 @@ use glam::dvec3; -use opencascade::{ - angle::Angle, - primitives::Shape, - workplane::Workplane, -}; +use opencascade::{angle::Angle, primitives::Shape, workplane::Workplane}; pub fn main() { let outer: f64 = 30.0; @@ -12,50 +8,50 @@ pub fn main() { let spoke_count: usize = 7; let hub_outer: f64 = 8.0; - let ring = rim(outer,thickness,height); - let sp = spokes(outer-thickness/2.0,thickness/2.0,spoke_count); - let (mut fly ,smooth ) = ring.union_shape(&sp); - fly.fillet_edges(1.0,smooth); + let ring = rim(outer, thickness, height); + let sp = spokes(outer - thickness / 2.0, thickness / 2.0, spoke_count); + let (mut fly, smooth) = ring.union_shape(&sp); + fly.fillet_edges(1.0, smooth); let the_hub = hub(hub_outer, thickness); - let (mut fly , hub_con) = fly.union_shape(&the_hub); - fly.fillet_edges(1.0,hub_con); + let (mut fly, hub_con) = fly.union_shape(&the_hub); + fly.fillet_edges(1.0, hub_con); fly.write_stl("flywheel.stl").unwrap(); } -fn rim(outer:f64 , thickness: f64,height: f64) -> Shape { - let outer_wire = Workplane::xy().circle(0., 0., outer); +fn rim(outer: f64, thickness: f64, height: f64) -> Shape { + let outer_wire = Workplane::xy().circle(0.0, 0.0, outer); let mut ring = outer_wire.to_face().extrude(dvec3(0.0, 0.0, height)).to_shape(); - let inner_wire = Workplane::xy().circle(0.,0.0, outer - thickness/2.0); - let inner_ring = inner_wire.to_face().extrude(dvec3(0.0,0.0,height)).to_shape(); - (ring, _ ) = ring.subtract_shape(&inner_ring); + let inner_wire = Workplane::xy().circle(0.0, 0.0, outer - thickness / 2.0); + let inner_ring = inner_wire.to_face().extrude(dvec3(0.0, 0.0, height)).to_shape(); + (ring, _) = ring.subtract_shape(&inner_ring); ring.chamfer(0.1); - ring + ring } -fn hub(outer: f64 , height: f64) -> Shape { - let outer_wire = Workplane::xy().circle(0., 0., outer); +fn hub(outer: f64, height: f64) -> Shape { + let outer_wire = Workplane::xy().circle(0.0, 0.0, outer); let mut hub = outer_wire.to_face().extrude(dvec3(0.0, 0.0, height)).to_shape(); hub.chamfer(0.1); hub } -fn spoke(length: f64,thickness:f64,rotation:f64) -> Shape { +fn spoke(length: f64, thickness: f64, rotation: f64) -> Shape { let mut wp = Workplane::xy(); - wp.set_rotation((Angle::Degrees(90.0),Angle::Degrees(rotation),Angle::Degrees(0.0))); - let inner_wire = wp.circle(0., 0., thickness/2.0); - let mut spoke = inner_wire.to_face().extrude(wp.normal()*length).to_shape(); + wp.set_rotation((Angle::Degrees(90.0), Angle::Degrees(rotation), Angle::Degrees(0.0))); + let inner_wire = wp.circle(0.0, 0.0, thickness / 2.0); + let mut spoke = inner_wire.to_face().extrude(wp.normal() * length).to_shape(); spoke.set_global_translation(dvec3(0.0, 0.0, thickness)); spoke } -fn spokes(length: f64 , thickness: f64,count: usize) -> Shape { +fn spokes(length: f64, thickness: f64, count: usize) -> Shape { let incr = 360.0 / count as f64; - let mut first_s = spoke(length,thickness,0.0); - for i in 1..count { - let s = spoke(length,thickness,incr * i as f64); - (first_s , _) = first_s.union_shape(&s); + let mut first_s = spoke(length, thickness, 0.0); + for i in 1..count { + let s = spoke(length, thickness, incr * i as f64); + (first_s, _) = first_s.union_shape(&s); } first_s }