Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions crates/opencascade/examples/bowl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use glam::dvec3;
use opencascade::{
primitives::{self, Direction, Solid},
workplane::Workplane,
};

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.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, 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, 0.0, offset));
// round out the bottom
let bottom_side = loft.faces().farthest(Direction::NegZ).edges();
loft.fillet_edges(4.0, bottom_side);

loft
}
57 changes: 57 additions & 0 deletions crates/opencascade/examples/flywheel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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, 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.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, 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, 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
}