1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-08-06 07:27:23 +02:00

Reimplemeted woven sheets with an eye to speed and interface consistancy.

This commit is contained in:
Chris Palmer
2020-12-23 21:44:05 +00:00
parent ab50b6f9a6
commit cc1e3baaf6
6 changed files with 103 additions and 115 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 854 KiB

After

Width:  |  Height:  |  Size: 859 KiB

View File

@@ -3127,8 +3127,12 @@ The "Soft" parameter can be used to determinesif the sheet material needs machin
The "Colour" parameter is a quad-array: [R, G, B, Alpha], or can be a named colour, see [OpenSCAD_User_Manual](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#color). The "Colour" parameter is a quad-array: [R, G, B, Alpha], or can be a named colour, see [OpenSCAD_User_Manual](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#color).
For speed sheets should be modelled in 2D by subtracting holes from 2D templates made by ```sheet_2D()``` and then extruded to 3D with ```render_2D_sheet()```. For speed sheets should be modelled in 2D by subtracting holes from 2D templates made by `sheet_2D()` and then extruded to 3D with `render_2D_sheet()`.
Note that modules that drill holes will return a 2D object if ```h``` is set to 0 to facilitate this. Note that modules that drill holes will return a 2D object if `h` is set to 0 to facilitate this.
If 3D features are needed, for example countersinks, then sheets can be modelled in 3D using `sheet()` and then coloured with `render_sheet()`.
When woven sheets (e.g. carbon fibre) are rendered it is necessary to specify the dimensions again to `render_sheet()` or `render_2D_sheet()`.
[vitamins/sheets.scad](vitamins/sheets.scad) Object definitions. [vitamins/sheets.scad](vitamins/sheets.scad) Object definitions.
@@ -3141,16 +3145,25 @@ Note that modules that drill holes will return a 2D object if ```h``` is set to
| Function | Description | | Function | Description |
|:--- |:--- | |:--- |:--- |
| ```sheet_colour(type)``` | Colour | | ```sheet_colour(type)``` | Colour |
| ```sheet_colour2(type)``` | Second colour for a woven sheet |
| ```sheet_is_soft(type)``` | Is soft enough for wood screws | | ```sheet_is_soft(type)``` | Is soft enough for wood screws |
| ```sheet_thickness(type)``` | Thickness | | ```sheet_thickness(type)``` | Thickness |
| ```sheet_warp(type)``` | Wovern sheet warp |
| ```sheet_weft(type)``` | Wovern sheet weft |
### Functions
| Function | Description |
|:--- |:--- |
| ```sheet_is_woven(type)``` | Is a woven sheet, eg carbon fiber |
### Modules ### Modules
| Module | Description | | Module | Description |
|:--- |:--- | |:--- |:--- |
| ```render_2D_sheet(type, colour = false)``` | Extrude a 2D sheet template and give it the correct colour | | ```render_2D_sheet(type, colour = false, colour2 = false, w = undef, d = undef)``` | Extrude a 2D sheet template and give it the correct colour |
| ```render_sheet(type, colour = false)``` | Render a sheet in the correct colour after holes have been subtracted | | ```render_sheet(type, colour = false, colour2 = false, w = undef, d = undef)``` | Render a sheet in the correct colour after holes have been subtracted |
| ```sheet(type, w, d, corners = [0, 0, 0, 0])``` | Draw specified sheet | | ```sheet(type, w, d, corners = [0, 0, 0, 0])``` | Draw specified sheet |
| ```sheet_2D(type, w, d, corners = [0, 0, 0, 0])``` | 2D sheet template with specified size and optionally rounded corners | | ```sheet_2D(type, w, d, corners = [0, 0, 0, 0])``` | 2D sheet template with specified size and optionally rounded corners |
| ```woven_sheet(type, thickness, colour, colour2, w, d)``` | Create a woven 2D sheet with specified thickness and colours |
![sheets](tests/png/sheets.png) ![sheets](tests/png/sheets.png)
@@ -3173,6 +3186,9 @@ Note that modules that drill holes will return a 2D object if ```h``` is set to
| 1 | ```sheet(PMMA3, 30, 30, 2)``` | Sheet acrylic 30mm x 30mm x 3mm | | 1 | ```sheet(PMMA3, 30, 30, 2)``` | Sheet acrylic 30mm x 30mm x 3mm |
| 1 | ```sheet(PMMA6, 30, 30, 2)``` | Sheet acrylic 30mm x 30mm x 6mm | | 1 | ```sheet(PMMA6, 30, 30, 2)``` | Sheet acrylic 30mm x 30mm x 6mm |
| 1 | ```sheet(PMMA8, 30, 30, 2)``` | Sheet acrylic 30mm x 30mm x 8mm | | 1 | ```sheet(PMMA8, 30, 30, 2)``` | Sheet acrylic 30mm x 30mm x 8mm |
| 2 | ```sheet(CF1, 30, 30, 2)``` | Sheet carbon fiber 30mm x 30mm x 1mm |
| 2 | ```sheet(CF2, 30, 30, 2)``` | Sheet carbon fiber 30mm x 30mm x 2mm |
| 2 | ```sheet(CF3, 30, 30, 2)``` | Sheet carbon fiber 30mm x 30mm x 3mm |
| 1 | ```sheet(glass2, 30, 30, 2)``` | Sheet glass 30mm x 30mm x 2mm | | 1 | ```sheet(glass2, 30, 30, 2)``` | Sheet glass 30mm x 30mm x 2mm |
| 1 | ```sheet(Steel06, 30, 30, 2)``` | Sheet mild steel 30mm x 30mm x 0.6mm | | 1 | ```sheet(Steel06, 30, 30, 2)``` | Sheet mild steel 30mm x 30mm x 0.6mm |

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 42 KiB

View File

@@ -20,32 +20,30 @@ include <../utils/core/core.scad>
use <../utils/layout.scad> use <../utils/layout.scad>
include <../vitamins/sheets.scad> include <../vitamins/sheets.scad>
include <../vitamins/screws.scad>
width = 30; width = 30;
2d = true;
module sheets() module sheets()
layout([for(s = sheets) width], 5) layout([for(s = sheets) width], 5)
render_sheet(sheets[$i]) sheet(sheets[$i], width, width, 2); let(sheet = sheets[$i], w = sheet_is_woven(sheet) ? width : undef)
if(2d)
render_2D_sheet(sheet, w = w, d = w)
difference() {
sheet_2D(sheet, width, width, 2);
module test2() { circle(3);
render_sheet(CF3) sheet(CF3, width, width, 2); }
translate([40,0,0]) else
render_2D_sheet(CF3) sheet_2D(CF3, width, width, 2); render_sheet(sheet, w = w, d = w)
translate([80,0,0]) difference() {
sheet(CF3, width, width, 2); sheet(sheet, width, width, 2);
translate([120,0,0])
sheet_2D(CF3, width, width, 2); translate_z(sheet_thickness(sheet) / 2)
screw_countersink(M3_cs_cap_screw);
}
translate([160,0,0])
render_sheet(MDF6) sheet(MDF6, width, width, 2);
translate([200,0,0])
render_2D_sheet(MDF6) sheet_2D(MDF6, width, width, 2);
translate([240,0,0])
sheet(MDF6, width, width, 2);
translate([280,0,0])
sheet_2D(MDF6, width, width, 2);
}
if($preview) if($preview)
sheets(); sheets();
//test2();

View File

@@ -27,8 +27,12 @@
//! //!
//! The "Colour" parameter is a quad-array: [R, G, B, Alpha], or can be a named colour, see [OpenSCAD_User_Manual](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#color). //! The "Colour" parameter is a quad-array: [R, G, B, Alpha], or can be a named colour, see [OpenSCAD_User_Manual](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#color).
//! //!
//! For speed sheets should be modelled in 2D by subtracting holes from 2D templates made by ```sheet_2D()``` and then extruded to 3D with ```render_2D_sheet()```. //! For speed sheets should be modelled in 2D by subtracting holes from 2D templates made by `sheet_2D()` and then extruded to 3D with `render_2D_sheet()`.
//! Note that modules that drill holes will return a 2D object if ```h``` is set to 0 to facilitate this. //! Note that modules that drill holes will return a 2D object if `h` is set to 0 to facilitate this.
//!
//! If 3D features are needed, for example countersinks, then sheets can be modelled in 3D using `sheet()` and then coloured with `render_sheet()`.
//!
//! When woven sheets (e.g. carbon fibre) are rendered it is necessary to specify the dimensions again to `render_sheet()` or `render_2D_sheet()`.
// //
include <../utils/core/core.scad> include <../utils/core/core.scad>
@@ -36,7 +40,9 @@ function sheet_thickness(type) = type[2]; //! Thickness
function sheet_colour(type) = type[3]; //! Colour function sheet_colour(type) = type[3]; //! Colour
function sheet_is_soft(type) = type[4]; //! Is soft enough for wood screws function sheet_is_soft(type) = type[4]; //! Is soft enough for wood screws
function sheet_is_woven(type) = !is_undef(type[5]); //! Is a woven sheet, eg carbon fiber function sheet_is_woven(type) = !is_undef(type[5]); //! Is a woven sheet, eg carbon fiber
function sheet_colour2(type) = is_undef(type[7]) ? sheet_colour(type) * 0.8 : type[7]; //! Second colour for a woven sheet function sheet_warp(type) = type[5]; //! Wovern sheet warp
function sheet_weft(type) = type[6]; //! Wovern sheet weft
function sheet_colour2(type) = type[7]; //! Second colour for a woven sheet
module corner(r) { module corner(r) {
if(r > 0) if(r > 0)
@@ -52,7 +58,10 @@ module corner(r) {
square(1, center = true); square(1, center = true);
} }
module corner_hull(w, d, corners) { module sheet_2D(type, w, d, corners = [0, 0, 0, 0]) { //! 2D sheet template with specified size and optionally rounded corners
t = sheet_thickness(type);
vitamin(str("sheet(", type[0], ", ", w, ", ", d, arg(corners, [0, 0, 0, 0]), "): ", type[1], " ", round(w), "mm x ", round(d), "mm x ", t, "mm"));
c = is_list(corners) ? corners : corners * [1, 1, 1, 1]; c = is_list(corners) ? corners : corners * [1, 1, 1, 1];
hull() { hull() {
@@ -73,108 +82,73 @@ module corner_hull(w, d, corners) {
} }
} }
module sheet_2D(type, w, d, corners = [0, 0, 0, 0]) { //! 2D sheet template with specified size and optionally rounded corners
t = sheet_thickness(type);
vitamin(str("sheet(", type[0], ", ", w, ", ", d, arg(corners, [0, 0, 0, 0]), "): ", type[1], " ", round(w), "mm x ", round(d), "mm x ", t, "mm"));
if (sheet_is_woven(type)) {
if (is_undef($sheet_woven_positive)) {
// not being called from within render_2D_sheet, so do both colours
color(sheet_colour(type))
let($sheet_woven_positive = true)
woven_sheet_2D(type, w, d, corners);
color(sheet_colour2(type))
let($sheet_woven_positive = false)
woven_sheet_2D(type, w, d, corners);
} else {
// being called from within render_2D_sheet
woven_sheet_2D(type, w, d, corners);
}
} else {
color(sheet_colour(type))
corner_hull(w, d, corners);
}
}
module sheet(type, w, d, corners = [0, 0, 0, 0]) //! Draw specified sheet module sheet(type, w, d, corners = [0, 0, 0, 0]) //! Draw specified sheet
if (sheet_is_woven(type) && is_undef($sheet_woven_positive)) { linear_extrude(sheet_thickness(type), center = true)
// not being called from within render_3D_sheet, so do both colours sheet_2D(type, w, d, corners);
color(sheet_colour(type))
linear_extrude(sheet_thickness(type), center = true)
let($sheet_woven_positive = true)
woven_sheet_2D(type, w, d, corners);
color(sheet_colour2(type))
linear_extrude(sheet_thickness(type), center = true)
let($sheet_woven_positive = false)
woven_sheet_2D(type, w, d, corners);
} else {
color(sheet_colour(type))
linear_extrude(sheet_thickness(type), center = true)
sheet_2D(type, w, d, corners);
}
module render_sheet(type, colour = false, colour2 = false, w = undef, d = undef) { //! Render a sheet in the correct colour after holes have been subtracted
module render_sheet(type, colour = false, colour2 = false) { //! Render a sheet in the correct colour after holes have been subtracted woven = sheet_is_woven(type);
color(colour ? colour : sheet_colour(type)) t = sheet_thickness(type);
colour = colour ? colour : sheet_colour(type);
colour2 = colour2 ? colour2 : sheet_colour2(type);
color(woven ? colour2 : colour)
render() render()
let($sheet_woven_positive = true) scale([1, 1, woven ? (t - 2 * eps) / t : 1])
children(); children();
if (sheet_is_woven(type)) if(woven)
color(colour2 ? colour2 : sheet_colour2(type)) for(side = [-1, 1], z = side * (t - eps) / 2)
render() translate_z(z)
let($sheet_woven_positive = false) woven_sheet(type, eps, colour, colour2, w, d)
children(); projection(cut = true)
translate_z(-z)
children();
} }
module render_2D_sheet(type, colour = false, colour2 = false) { //! Extrude a 2D sheet template and give it the correct colour module render_2D_sheet(type, colour = false, colour2 = false, w = undef, d = undef) { //! Extrude a 2D sheet template and give it the correct colour
let($dxf_colour = colour ? colour : sheet_colour(type)) colour = colour ? colour : sheet_colour(type);
color($dxf_colour) colour2 = colour2 ? colour2 : sheet_colour2(type);
let($sheet_woven_positive = true) let($dxf_colour = colour)
linear_extrude(sheet_thickness(type), center = true) if(sheet_is_woven(type))
children(); woven_sheet(type, sheet_thickness(type), colour, colour2, w, d)
children();
if (sheet_is_woven(type)) else
color(colour2 ? colour2 : sheet_colour2(type)) color($dxf_colour)
let($sheet_woven_positive = false)
linear_extrude(sheet_thickness(type), center = true) linear_extrude(sheet_thickness(type), center = true)
children(); children();
} }
module woven_sheet_2D(type, w, d, corners = [0, 0, 0, 0], warp = 2, weft) {//! Create a woven 2D sheet with specified size, colours, warp and weft module woven_sheet(type, thickness, colour, colour2, w, d) {//! Create a woven 2D sheet with specified thickness and colours
size = [w, d]; ;
warp = sheet_warp(type);
weft = sheet_weft(type);
warp_doublet_count = assert(!is_undef(w) && !is_undef(d), "Must specify the dimensions to render woven sheets") ceil(w / (2 * warp));
weft_count = ceil(d / weft);
weft = weft ? weft : warp; module chequerboard(odd = 0)
warp_doublet_count = floor(size.x / (2 * warp)) + 1; translate([-w / 2, -d / 2])
for (y = [0 : weft_count - 1], x = [0 : warp_doublet_count - 1])
translate([warp * (2 * x + ((y + odd) % 2)), weft * y])
square([warp, weft]);
module layer(weft) { module negative()
for (x = [0 : warp_doublet_count - 1])
translate([2 * x * warp, 0, 0])
square([warp, weft]);
}
module positive() {
intersection() {
translate([-size.x / 2, -size.y / 2]) {
weft_count = floor(size.y / weft) + 1;
for (y = [0 : weft_count - 1])
translate([warp * (y % 2), weft * y, 0])
layer(weft);
}
corner_hull(w, d, corners);
}
}
module negative() {
difference() { difference() {
corner_hull(size.x, size.y, corners); square(size, center = true);
positive(); positive();
} }
}
if (is_undef($sheet_woven_positive) || $sheet_woven_positive==true) color(colour)
positive(); linear_extrude(thickness)
else intersection() {
negative(); chequerboard();
children();
}
if(thickness > eps)
color(colour2)
linear_extrude(thickness)
intersection() {
chequerboard(1);
children();
}
} }

View File

@@ -50,6 +50,6 @@ CF2 = [ "CF2", "Sheet carbon fiber", 2, grey(30),
CF3 = [ "CF3", "Sheet carbon fiber", 3, grey(30), false, 2, 2, grey(25)]; CF3 = [ "CF3", "Sheet carbon fiber", 3, grey(30), false, 2, 2, grey(25)];
sheets = [MDF6, MDF10, MDF12, MDF19, PMMA2, PMMA3, PMMA6, PMMA8, PMMA10, glass2, DiBond, DiBond6, Cardboard, FoilTape, Foam20, AL6, AL8, Steel06, CF1, CF2, CF3]; sheets = [CF1, CF2, CF3, MDF6, MDF10, MDF12, MDF19, PMMA2, PMMA3, PMMA6, PMMA8, PMMA10, glass2, DiBond, DiBond6, Cardboard, FoilTape, Foam20, AL6, AL8, Steel06];
use <sheet.scad> use <sheet.scad>