diff --git a/global_defs.scad b/global_defs.scad index f7f635a..d9960ba 100644 --- a/global_defs.scad +++ b/global_defs.scad @@ -29,6 +29,7 @@ rr_green = [0, 146/255, 0]; // Rep crimson = [220/255, 20/255, 60/255]; layer_height = is_undef($layer_height) ? 0.25 : $layer_height; // layer height when printing +layer_height0 = is_undef($layer_height0) ? layer_height : $layer_height0; // height of first layer if different extrusion_width = is_undef($extrusion_width) ? 0.5 : $extrusion_width; // filament width when printing nozzle = is_undef($nozzle) ? 0.45 : $nozzle; // 3D printer nozzle cnc_bit_r = is_undef($cnc_bit_r) ? 1.2 : $cnc_bit_r; // minimum tool radius when milling 2D objects @@ -51,10 +52,7 @@ eps = 1/128; // small fudge factor to stop CSG barfing on coincident faces. $fa = 6; $fs = extrusion_width / 2; -function round_to_layer(z) = ceil(z / layer_height) * layer_height; //! Round up to a multiple of layer_height. - // Some additional named colours -function grey(n) = [0.01, 0.01, 0.01] * n; //! Generate a shade of grey to pass to color(). silver = [0.75, 0.75, 0.75]; gold = [255, 215, 0] / 255; brass = [255, 220, 100] / 255; diff --git a/readme.md b/readme.md index 80b9415..15b854a 100644 --- a/readme.md +++ b/readme.md @@ -6918,6 +6918,7 @@ Original version by Doug Moen on the OpenSCAD forum ## Global Global constants, functions and modules. This file is used directly or indirectly in every scad file. +See [global_defs.scad](../../global_defs.scad) for a list of global constants. [utils/core/global.scad](utils/core/global.scad) Implementation. @@ -6930,6 +6931,7 @@ Global constants, functions and modules. This file is used directly or indirectl | `cm(x)` | cm to mm conversion | | `echoit(x)` | Echo expression and return it, useful for debugging | | `foot(x)` | Foot to mm conversion | +| `grey(n)` | Generate a shade of grey to pass to color(). | | `in(list, x)` | Returns true if `x` is an element in the `list` | | `inch(x)` | Inch to mm conversion (For fractional inches, 'inch(1 + 7/8)' will work as expected.) | | `limit(x, min, max)` | Force x in range min <= x <= max | @@ -6938,6 +6940,7 @@ Global constants, functions and modules. This file is used directly or indirectl | `no_point(str)` | Replace decimal point in string with 'p' | | `r2sides(r)` | Replicates the OpenSCAD logic to calculate the number of sides from the radius | | `r2sides4n(r)` | Round up the number of sides to a multiple of 4 to ensure points land on all axes | +| `round_to_layer(z)` | Round up to a layer boundary using `layer_height0` for the first layer and `layer_height` for subsequent layers. | | `slice(list, start = 0, end = undef)` | Slice a list or string with Python type semantics | | `sqr(x)` | Returns the square of `x` | | `yard(x)` | Yard to mm conversion | diff --git a/utils/core/global.scad b/utils/core/global.scad index f0d9949..63499d4 100644 --- a/utils/core/global.scad +++ b/utils/core/global.scad @@ -19,6 +19,7 @@ // //! Global constants, functions and modules. This file is used directly or indirectly in every scad file. +//! See [global_defs.scad](../../global_defs.scad) for a list of global constants. // include <../../global_defs.scad> @@ -38,6 +39,13 @@ function r2sides(r) = $fn ? $fn : ceil(max(min(360/ $fa, r * 2 * PI / $fs), 5)); function r2sides4n(r) = floor((r2sides(r) + 3) / 4) * 4; //! Round up the number of sides to a multiple of 4 to ensure points land on all axes function limit(x, min, max) = max(min(x, max), min); //! Force x in range min <= x <= max +function round_to_layer(z) = //! Round up to a layer boundary using `layer_height0` for the first layer and `layer_height` for subsequent layers. + z <= 0 ? 0 : + z <= layer_height0 ? layer_height0 : + ceil((z -layer_height0) / layer_height) * layer_height + layer_height0; + +function grey(n) = [0.01, 0.01, 0.01] * n; //! Generate a shade of grey to pass to color(). + module translate_z(z) //! Shortcut for Z only translations translate([0, 0, z]) children();