1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-08-11 18:04:02 +02:00

Added layer_height0 global variable and updated round_to_layer() to handle it.

Moved functions from global_defs.scad to global.scad so they get documented.
This commit is contained in:
Chris
2022-09-25 18:22:29 +01:00
parent 87b794d4a2
commit 0f36c02b5e
3 changed files with 12 additions and 3 deletions

View File

@@ -29,6 +29,7 @@ rr_green = [0, 146/255, 0]; // Rep
crimson = [220/255, 20/255, 60/255]; crimson = [220/255, 20/255, 60/255];
layer_height = is_undef($layer_height) ? 0.25 : $layer_height; // layer height when printing 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 extrusion_width = is_undef($extrusion_width) ? 0.5 : $extrusion_width; // filament width when printing
nozzle = is_undef($nozzle) ? 0.45 : $nozzle; // 3D printer nozzle 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 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; $fa = 6;
$fs = extrusion_width / 2; $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 // 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]; silver = [0.75, 0.75, 0.75];
gold = [255, 215, 0] / 255; gold = [255, 215, 0] / 255;
brass = [255, 220, 100] / 255; brass = [255, 220, 100] / 255;

View File

@@ -6918,6 +6918,7 @@ Original version by Doug Moen on the OpenSCAD forum
<a name="Global"></a> <a name="Global"></a>
## Global ## Global
Global constants, functions and modules. This file is used directly or indirectly in every scad file. 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. [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 | | `cm(x)` | cm to mm conversion |
| `echoit(x)` | Echo expression and return it, useful for debugging | | `echoit(x)` | Echo expression and return it, useful for debugging |
| `foot(x)` | Foot to mm conversion | | `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` | | `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.) | | `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 | | `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' | | `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 | | `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 | | `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 | | `slice(list, start = 0, end = undef)` | Slice a list or string with Python type semantics |
| `sqr(x)` | Returns the square of `x` | | `sqr(x)` | Returns the square of `x` |
| `yard(x)` | Yard to mm conversion | | `yard(x)` | Yard to mm conversion |

View File

@@ -19,6 +19,7 @@
// //
//! Global constants, functions and modules. This file is used directly or indirectly in every scad file. //! 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> 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 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 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 module translate_z(z) //! Shortcut for Z only translations
translate([0, 0, z]) children(); translate([0, 0, z]) children();