Struct Scad

Source
pub struct Scad {
    pub op: ScadOp,
    pub children: Vec<Scad>,
}
Expand description

A tree of OpenSCAD operations.

Should not need to construct manually in end user code. We have macros and functions to do it for us.

Fields§

§op: ScadOp§children: Vec<Scad>

Implementations§

Source§

impl Scad

Source

pub fn external_circle_chamfer( size: f64, oversize: f64, radius: f64, degrees: f64, segments: u64, ) -> Self

Creates a curved chamfer shape.

size: The size of the angled part of the chamfer profile.

oversize: How much non-angled part there is on the chamfer.

radius: The radius of the arc that the chamfer takes.

degrees: The degrees of the arc that the chamfer is extruded through.

segments: The number of segments in a circle.

return: The mesh.

Source

pub fn external_cylinder_chamfer( size: f64, oversize: f64, radius: f64, height: f64, segments: u64, center: bool, ) -> Self

Creates two external circle chamfers for chamfering a cylinder.

size: The size of the angled part of the chamfer profile.

oversize: How much non-angled part there is on the chamfer.

radius: The radius of the cylinder to be chamfered.

height: The height of the cylinder to be chamfered.

segments: The number of segments in a circle.

return: The mesh.

Source

pub fn polar_array(scad: &Scad, count: u64, degrees: f64) -> Scad

Create a circular array around the Z axis

Source

pub fn save(&self, path: &str)

Examples found in repository?
examples/loft.rs (line 32)
28fn main() {
29    let lower_profile = dim2::circle(10.0, 14);
30    let upper_profile = dim2::star(7, 10.0, 20.0);
31    let polyhedron = Polyhedron::loft(&lower_profile, &upper_profile, 30.0);
32    polyhedron.into_scad().save("output/loft.scad");
33}
More examples
Hide additional examples
examples/bottle.rs (line 38)
32fn make_cap() {
33    let cylinder = Polyhedron::cylinder(23.0, 12.0, 128).into_scad();
34    let mut tap = metric_thread::tap(40, 14.0, 128, false, false);
35    tap = translate!([0.0, 0.0, 2.0], tap;);
36
37    let cap = cylinder - tap;
38    cap.save("output/bottle_cap.scad");
39}
40
41fn make_bottle() {
42    let mut outside_profile = Pt2s::new();
43    outside_profile.push(Pt2::new(0.0, 125.0));
44    outside_profile.append(&mut dim2::cubic_bezier(
45        Pt2::new(19.0, 125.0),
46        Pt2::new(22.5, 110.0),
47        Pt2::new(32.5, 105.0),
48        Pt2::new(32.5, 100.0),
49        6,
50    ));
51    outside_profile.append(&mut dim2::quadratic_bezier(
52        Pt2::new(32.5, 5.0),
53        Pt2::new(32.5, 0.0),
54        Pt2::new(27.5, 0.0),
55        6,
56    ));
57    outside_profile.push(Pt2::new(0.0, 0.0));
58
59    let mut inside_profile = Pt2s::new();
60    inside_profile.push(Pt2::new(0.0, 140.0));
61    inside_profile.push(Pt2::new(16.0, 140.0));
62    inside_profile.append(&mut dim2::cubic_bezier(
63        Pt2::new(16.0, 125.0),
64        Pt2::new(20.5, 110.0),
65        Pt2::new(30.5, 105.0),
66        Pt2::new(30.5, 100.0),
67        6,
68    ));
69    inside_profile.append(&mut dim2::quadratic_bezier(
70        Pt2::new(30.5, 7.0),
71        Pt2::new(30.5, 2.0),
72        Pt2::new(25.5, 2.0),
73        6,
74    ));
75    inside_profile.push(Pt2::new(0.0, 2.0));
76
77    let outside = rotate_extrude!(angle=360.0, convexity=10, fn=128, polygon!(outside_profile););
78    let inside = rotate_extrude!(angle=360.0, convexity=10, fn=128, polygon!(inside_profile););
79
80    let threaded_rod = translate!([0.0,0.0,120.0], metric_thread::threaded_rod(40, 15.0, 128, 0.0, 180.0, false, false););
81
82    let bottle = outside + threaded_rod - inside;
83
84    bottle.save("output/bottle.scad");
85}
examples/cup.rs (line 76)
27fn main() {
28    let segments: u64 = 72;
29    let cup_segments: u64 = 144;
30    let slices: u64 = 48;
31
32    let mut cup_blank_profile = Pt2s::new();
33    cup_blank_profile.push(Pt2::new(0.0, 0.0));
34    cup_blank_profile.append(&mut dim2::cubic_bezier(
35        Pt2::new(40.0, 0.0),
36        Pt2::new(40.0, 33.0),
37        Pt2::new(60.0, 66.0),
38        Pt2::new(60.0, 100.0),
39        slices,
40    ));
41    cup_blank_profile.push(Pt2::new(0.0, 100.0));
42
43    let cup_blank = rotate_extrude!(angle=360.0, convexity=2, fn=cup_segments,
44        polygon!(cup_blank_profile);
45    );
46
47    let mut cup_inner_profile = Pt2s::new();
48    cup_inner_profile.push(Pt2::new(0.0, 3.0));
49    cup_inner_profile.append(&mut dim2::cubic_bezier(
50        Pt2::new(37.0, 3.0),
51        Pt2::new(37.0, 33.0),
52        Pt2::new(57.0, 66.0),
53        Pt2::new(57.0, 103.0),
54        slices,
55    ));
56    cup_inner_profile.push(Pt2::new(0.0, 103.0));
57
58    let cup_inner = rotate_extrude!(angle=360.0, convexity=1, fn=cup_segments,
59        polygon!(cup_inner_profile);
60    );
61
62    let handle_path = dim3::cubic_bezier(
63        Pt3::new(37.0, 20.0, 0.0),
64        Pt3::new(70.0, 30.0, 0.0),
65        Pt3::new(120.0, 90.0, 0.0),
66        Pt3::new(57.0, 90.0, 0.0),
67        segments,
68    );
69
70    let handle_profile = dim2::rounded_rect(8.0, 20.0, 2.5, segments, true);
71    let mut handle = Polyhedron::sweep(&handle_profile, &handle_path, 0.0, false);
72    handle.rotate_x(90.0);
73
74    let cup = cup_blank + handle.into_scad_with_convexity(2) - cup_inner;
75
76    cup.save("output/cup.scad");
77}
examples/scad_tree.rs (line 51)
26fn main() {
27    // The Scad struct and the ScadOp enum are the main types in the library.
28    // This tree is the difference of a cube and a sphere but it's a little
29    // unwieldy to write.
30    Scad {
31        op: ScadOp::Difference,
32        children: vec![
33            Scad {
34                op: ScadOp::Cube {
35                    size: Pt3::new(2.0, 2.0, 2.0),
36                    center: false,
37                },
38                children: Vec::new(),
39            },
40            Scad {
41                op: ScadOp::Sphere {
42                    radius: 1.0,
43                    fa: None,
44                    fs: None,
45                    fn_: Some(24),
46                },
47                children: Vec::new(),
48            },
49        ],
50    }
51    .save("output/scad_tree1.scad");
52
53    // Thats where the macros come in. All the operations from the 2D, 3D, and transformations
54    // sections of the OpenSCAD cheatsheet (https://openscad.org/cheatsheet) are covered by macros.
55    // All of the macros except scad_file expand to a Scad struct literal like above. The scad_file
56    // macro specifies the file to save and allows setting $fa, $fs, and $fn globally.
57
58    // This snippet of macro code produces the tree above but is a bit easier to read and write.
59    // If you squint hard enough it resembles OpenSCAD code!
60    scad_file!(32,
61        "output/scad_tree2.scad",
62        difference!(
63            cube!(2.0);
64            sphere!(1.0, fn=24);
65        );
66    );
67
68    // Maybe your not a fan of OpenSCAD structured code. Since each macro expands to part of a tree
69    // it's easy to save to variables or return a Scad from a funtion. This code produces the same
70    // output as the above.
71    let cube = cube!(2.0);
72    let sphere = sphere!(1.0, fn=24);
73    let difference = difference!(cube; sphere;);
74    difference.save("output/scad_tree3.scad");
75
76    // Maybe you want it to look like math!
77    let cube = cube!(2.0);
78    let sphere = sphere!(1.0, fn=24);
79    (cube - sphere).save("output/scad_tree4.scad");
80}

Trait Implementations§

Source§

impl Add for Scad

Source§

type Output = Scad

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Scad

Source§

fn clone(&self) -> Scad

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Display for Scad

Since we are outputting text we leverage the Display trait to format output.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Scad

Source§

fn eq(&self, other: &Scad) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub for Scad

Source§

type Output = Scad

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl StructuralPartialEq for Scad

Auto Trait Implementations§

§

impl Freeze for Scad

§

impl RefUnwindSafe for Scad

§

impl Send for Scad

§

impl Sync for Scad

§

impl Unpin for Scad

§

impl UnwindSafe for Scad

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.