diff --git a/tests/sheets.scad b/tests/sheets.scad index 97f871a..fcf1e08 100644 --- a/tests/sheets.scad +++ b/tests/sheets.scad @@ -27,5 +27,25 @@ module sheets() layout([for(s = sheets) width], 5) render_sheet(sheets[$i]) sheet(sheets[$i], width, width, 2); +module test2() { + render_sheet(CF3) sheet(CF3, width, width, 2); + translate([40,0,0]) + render_2D_sheet(CF3) sheet_2D(CF3, width, width, 2); + translate([80,0,0]) + sheet(CF3, width, width, 2); + translate([120,0,0]) + sheet_2D(CF3, width, width, 2); + + 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) sheets(); + //test2(); diff --git a/vitamins/sheet.scad b/vitamins/sheet.scad index 8ec5d43..a433cbc 100644 --- a/vitamins/sheet.scad +++ b/vitamins/sheet.scad @@ -35,6 +35,8 @@ include <../utils/core/core.scad> function sheet_thickness(type) = type[2]; //! Thickness function sheet_colour(type) = type[3]; //! Colour 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_colour2(type) = is_undef(type[7]) ? sheet_colour(type) * 0.8 : type[7]; //! Second colour for a woven sheet module corner(r) { if(r > 0) @@ -50,10 +52,7 @@ module corner(r) { square(1, center = true); } -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")); - +module corner_hull(w, d, corners) { c = is_list(corners) ? corners : corners * [1, 1, 1, 1]; hull() { @@ -74,16 +73,108 @@ module sheet_2D(type, w, d, corners = [0, 0, 0, 0]) { //! 2D sheet template with } } +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 - linear_extrude(sheet_thickness(type), center = true) - sheet_2D(type, w, d, corners); + if (sheet_is_woven(type) && is_undef($sheet_woven_positive)) { + // not being called from within render_3D_sheet, so do both colours + 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) //! 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 color(colour ? colour : sheet_colour(type)) - render() children(); + render() + let($sheet_woven_positive = true) + children(); -module render_2D_sheet(type, colour = false) //! Extrude a 2D sheet template and give it the correct colour + if (sheet_is_woven(type)) + color(colour2 ? colour2 : sheet_colour2(type)) + render() + let($sheet_woven_positive = false) + children(); +} + +module render_2D_sheet(type, colour = false, colour2 = false) { //! Extrude a 2D sheet template and give it the correct colour let($dxf_colour = colour ? colour : sheet_colour(type)) color($dxf_colour) - linear_extrude(sheet_thickness(type), center = true) - children(); + let($sheet_woven_positive = true) + linear_extrude(sheet_thickness(type), center = true) + children(); + + if (sheet_is_woven(type)) + color(colour2 ? colour2 : sheet_colour2(type)) + let($sheet_woven_positive = false) + linear_extrude(sheet_thickness(type), center = true) + 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 + size = [w, d]; + + weft = weft ? weft : warp; + warp_doublet_count = floor(size.x / (2 * warp)) + 1; + + module layer(weft) { + 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() { + corner_hull(size.x, size.y, corners); + positive(); + } + } + + if (is_undef($sheet_woven_positive) || $sheet_woven_positive==true) + positive(); + else + negative(); +} + diff --git a/vitamins/sheets.scad b/vitamins/sheets.scad index ad4346e..6cff95d 100644 --- a/vitamins/sheets.scad +++ b/vitamins/sheets.scad @@ -22,7 +22,7 @@ // // -// [ Code, Description, Thickness, Color, Soft] +// [ Code, Description, Thickness, Color, Soft, Warp, Weft, Color2] // mdf_colour = "#BEA587"; // sampled from a photo @@ -45,7 +45,11 @@ Foam20 = [ "Foam20", "Foam sponge", 20,[0.3, 0.3, 0.3, 1 ], AL6 = [ "AL6", "Aluminium tooling plate", 6, [0.9, 0.9, 0.9, 1 ], false]; AL8 = [ "AL8", "Aluminium tooling plate", 8, [0.9, 0.9, 0.9, 1 ], false]; Steel06 = [ "Steel06", "Sheet mild steel", 0.6,"silver" , false]; +CF1 = [ "CF1", "Sheet carbon fiber", 1, grey(30), false, 2, 2, grey(25)]; +CF2 = [ "CF2", "Sheet carbon fiber", 2, 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]; + +sheets = [MDF6, MDF10, MDF12, MDF19, PMMA2, PMMA3, PMMA6, PMMA8, PMMA10, glass2, DiBond, DiBond6, Cardboard, FoilTape, Foam20, AL6, AL8, Steel06, CF1, CF2, CF3]; use