diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..08a81aa --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,16 @@ +CHANGELOG: + V2.0.0: + * added $fa values for minkowski and shape - so you can customize how much rounding there is + * rejiggered `key.scad` pipeline for more clarity and less shapes + * implemented "3d_surface" dish - still in beta + * super cool though, you can even change the distribution of points on the surface! just make sure you use monotonically increasing functions + * created "hull" folder to house different ways of creating the overall key shape + * promoted "feature" folder to first-class folder with keytext and switch clearance as new residents + * wrote this changelog! + * implemented `$inner_shape_type`, use "flat" for less geometry or "disable" to make a completely solid key easily. didn't help render rounded keys though + * side-printed keycaps are first class! you can use the `sideways()` modifier to set up sideways keycaps that have flat sides to print on. + * it's much easier to make quick artisans now that the inside of the keycap is differenced from any additive features placed on top + * `$linear_extrude_shape` and `$skin_extrude_shape` retired in favor of `$hull_shape_type` + * added regular_polygon shape and octagonal and hexagonal key profiles + * added beta kailh choc + * Finally got ISO Enter working correctly! \ No newline at end of file diff --git a/README.md b/README.md index abed6dd..93d2b53 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,14 @@ Relevant links: * Shapeways: https://www.shapeways.com/designer/rsheldiii/creations * Buy me a coffee: https://ko-fi.com/rsheldiii, but only if you want to! +# V2.0.0 Cutover + +As of February 19th, 2022, the v2.0.0 branch has been merged into master. + +This branch completely rewrote key.scad to be much simpler and faster. If you're just starting out, please use master and report any bugs you find. + +If you branched off this repo previously, merging to master will probably break any additions you've made. If you need the prior version of the code for whatever reason, v1.1.0 is master just before the v2.0.0 merge. I will be backporting bugfixes to the v1 branch, so if you see v1.1.1 or higher, use that instead. + ## How to run #### OpenSCAD Proper (recommended way) @@ -19,9 +27,15 @@ First, you'll need OpenSCAD: http://www.openscad.org/downloads.html. I highly re After you have openSCAD installed, you need to download the code and run it. running `git clone https://github.com/rsheldiii/openSCAD-projects.git` if you have git, or downloading [this zip](https://github.com/rsheldiii/openSCAD-projects/archive/master.zip) and extracting the directory should do it. -To make your own key, all you need to do is open `keys.scad` with openSCAD and [modify this line](https://github.com/rsheldiii/KeyV2/blob/master/keys.scad#L12)! (Line 12) -Here is an example you can replace the line with to get started. This is for a ctrl key on an OEM keyboard: -`u(1.25) oem_row(3) legend("ctrl", size=4.5) key();` +To make your own key, all you need to do is open `keys.scad` with openSCAD and modify this line: + +``` +dcs_row(5) legend("⇪", size=9) key(); +``` + +To be whatever you want. For example, this is for a ctrl key on an OEM keyboard: + +```u(1.25) oem_row(3) legend("ctrl", size=4.5) key();``` It is possible to edit this project with an external editor by checking off Design => 'Automatic Reload and Preview' in OpenSCAD. @@ -175,7 +189,7 @@ Prints from this library are still challenging, despite all efforts to the contr 1. If your stem isn't fitting in the switch, try upping the slop factor, accessed by giving your keystem function a numeric value (eg `cherry(0.5) key()`). This will lengthen the cross and decrease the overall size of the keystem. The default value is 0.3, and represents millimeters. Note that even if you have a resin printer, you should probably keep the default value; keys printed with 0 slop will barely fit on the stem. -2. If your keystem breaks off the bed mid-print, you can enable a brim by adding the `brimmed()` modifier. This will give a solid base for the keystem to anchor into. +2. If your keystem breaks off the bed mid-print, you can enable a brim by adding the `brimmed_stem_support()` modifier. This will give a solid base for the keystem to anchor into. 3. If you are unsatisfied with the quality of the top surface, you can try printing the keycap on a different surface than the bottom, though it may impact the quality of the stem. diff --git a/TIPS_AND_TRICKS.md b/TIPS_AND_TRICKS.md index ee0761d..49f96ad 100644 --- a/TIPS_AND_TRICKS.md +++ b/TIPS_AND_TRICKS.md @@ -14,7 +14,7 @@ At the end of the day though, all the columnular sculpting is doing is adding ex ## skin mode -SA, HiPro and DSA keycaps take _forever_ to render. This is a multifaceted issue that I don't want to get into here, but suffice to say _one_ of the reasons it takes so long is how the keycap is constructed from multiple, smaller slices. OpenSCAD takes more time to render the more objects you have, regardless of how they interact. Enter `$skin_extrude_shape = true`. +SA, HiPro and DSA keycaps take _forever_ to render. This is a multifaceted issue that I don't want to get into here, but suffice to say _one_ of the reasons it takes so long is how the keycap is constructed from multiple, smaller slices. OpenSCAD takes more time to render the more objects you have, regardless of how they interact. Enter `$hull_shape_type = "skin"`. `skin()` is a list comprehension function available [here](https://github.com/openscad/list-comprehension-demos/blob/master/skin.scad). The gist of it is that instead of having x number of keycap slices unioned together, we give `skin()` a set of profiles and it makes a single object out of it for us. This reduces the number of objects per keycap, which makes it easier to render them. diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..29b60c8 --- /dev/null +++ b/TODO.md @@ -0,0 +1,9 @@ +TODO: + * Make flat stem support default + * make flat inner shape default + * support repositioning to print on the back surface of the keycap + * implement regular polygon for skin extrusions + * switch to skin-shaped extrusions by default + * kailh choc has a non-square key unit; should I get that working for layouts etc? + * move everything over to layouts requiring a child key + * add an "errors" or "warnings" or "suggestions" echo section in key.scad, right when the key is being made, so the errors don't get lost / repeated diff --git a/customizer.scad b/customizer.scad index b3519d9..e32a494 100644 --- a/customizer.scad +++ b/customizer.scad @@ -89,6 +89,7 @@ $rounded_cherry_stem_d = 5.5; // How much higher the stem is than the bottom of the keycap. // Inset stem requires support but is more accurate in some profiles +// can be negative to make outset stems! $stem_inset = 0; // How many degrees to rotate the stems. useful for sideways keycaps, maybe $stem_rotation = 0; @@ -117,7 +118,11 @@ $dish_depth = 1; $dish_skew_x = 0; // How skewed in the y direction (height) the dish is $dish_skew_y = 0; -// If you need the dish to extend further, you can 'overdraw' the rectangle it will hit + + +$dish_offset_x = 0; + +// If you need the dish to extend further, you can 'overdraw' the rectangle it will hit. this was mostly for iso enter and should be deprecated $dish_overdraw_width = 0; // Same as width but for height $dish_overdraw_height = 0; @@ -133,12 +138,10 @@ $font="DejaVu Sans Mono:style=Book"; // Whether or not to render fake keyswitches to check clearances $clearance_check = false; // Should be faster, also required for concave shapes -// Use linear_extrude instead of hull slices to make the shape of the key -$linear_extrude_shape = false; -// warns in trajectory.scad but it looks benign -// brand new, more correct, hopefully faster, lots more work -$skin_extrude_shape = false; +// what kind of extrusion we use to create the keycap. "hull" is standard, "linear extrude" is legacy, "skin" is new and not well supported. +$hull_shape_type = "hull"; // ["hull", "linear extrude", "skin"] + // This doesn't work very well, but you can try $rounded_key = false; //minkowski radius. radius of sphere used in minkowski sum for minkowski_key function. 1.75 for G20 @@ -179,6 +182,9 @@ $inset_legend_depth = 0.2; // Dimensions of alps stem $alps_stem = [4.45, 2.25]; +// Dimensions of choc stem +$choc_stem = [1.2, 3]; + // Enable stabilizer stems, to hold onto your cherry or costar stabilizers $stabilizer_type = "costar_stabilizer"; // [costar_stabilizer, cherry_stabilizer, disable] @@ -209,6 +215,9 @@ $3d_surface_size = 100; // resolution in each axis. 10 = 10 divisions per x/y = 100 points total $3d_surface_step = 10; +// "flat" / "dished" / "disable" +$inner_shape_type = "flat"; + // key width functions module u(u=1) { @@ -228,6 +237,10 @@ module 1_5u() { u(1.5) children(); } +module 1_75u(){ + u(1.75) children(); +} + module 2u() { u(2) children(); } @@ -236,6 +249,10 @@ module 2_25u() { u(2.25) children(); } +module 2_50u() { + u(2.5) children(); +} + module 2_75u() { u(2.75) children(); } @@ -382,7 +399,7 @@ module dsa_row(row=3, column = 0) { $dish_skew_y = 0; $height_slices = 10; $enable_side_sculpting = true; - $corner_radius = 0.25; + $corner_radius = 1; $top_tilt_y = side_tilt(column); extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; @@ -419,9 +436,7 @@ module sa_row(n=3, column=0) { $dish_skew_y = 0; $top_skew = 0; $height_slices = 10; - // might wanna change this if you don't minkowski - // do you even minkowski bro - $corner_radius = 0.25; + $corner_radius = 1; // this is _incredibly_ intensive /* $rounded_key = true; */ @@ -513,9 +528,7 @@ module hipro_row(row=3, column=0) { $dish_skew_y = 0; $top_skew = 0; $height_slices = 10; - // might wanna change this if you don't minkowski - // do you even minkowski bro - $corner_radius = 0.25; + $corner_radius = 1; $top_tilt_y = side_tilt(column); extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; @@ -544,8 +557,8 @@ module hipro_row(row=3, column=0) { module grid_row(row=3, column = 0) { $bottom_key_width = 18.16; $bottom_key_height = 18.16; - $width_difference = 0.2; - $height_difference = 0.2; + $width_difference = 1; + $height_difference = 1; $top_tilt = 0; $top_skew = 0; $dish_type = "old spherical"; @@ -554,11 +567,11 @@ module grid_row(row=3, column = 0) { $dish_skew_x = 0; $dish_skew_y = 0; - $linear_extrude_shape = true; + $hull_shape_type = "linear extrude"; - $dish_overdraw_width = -8; - $dish_overdraw_height = -8; + $dish_overdraw_width = -6.5; + $dish_overdraw_height = -6.5; $minkowski_radius = 0.5; //also, @@ -567,7 +580,7 @@ module grid_row(row=3, column = 0) { $top_tilt_y = side_tilt(column); extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; - $total_depth = 6 + abs((row-3) * 0.5) + extra_height; + $total_depth = 7 + abs((row-3) * 0.5) + extra_height; if (row == 5 || row == 0) { /* $top_tilt = -18.55; */ @@ -588,7 +601,172 @@ module grid_row(row=3, column = 0) { children(); } } +// a safe theoretical distance between two vertices such that they don't collapse. hard to use +SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; +// Regular polygon shapes CIRCUMSCRIBE the sphere of diameter $bottom_key_width +// This is to make tiling them easier, like in the case of hexagonal keycaps etc +// this function doesn't set the key shape, so you can't use it directly without some fiddling +module regular_polygon_row(n=3, column=0) { + $bottom_key_width = $unit - 0.5; + $bottom_key_height = $unit - 0.5; + $width_difference = 0; + $height_difference = 0; + $dish_type = "spherical"; + $dish_depth = 0.85; + $dish_skew_x = 0; + $dish_skew_y = 0; + $top_skew = 0; + $height_slices = 1; + $corner_radius = 1; + + // this is _incredibly_ intensive + /* $rounded_key = true; */ + + $top_tilt_y = side_tilt(column); + extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; + + base_depth = 7.5; + if (n <= 1){ + $total_depth = base_depth + 2.5 + extra_height; + $top_tilt = -13; + + children(); + } else if (n == 2) { + $total_depth = base_depth + 0.5 + extra_height; + $top_tilt = -7; + + children(); + } else if (n == 3) { + $total_depth = base_depth + extra_height; + $top_tilt = 0; + + children(); + } else if (n == 4){ + $total_depth = base_depth + 0.5 + extra_height; + $top_tilt = 7; + + children(); + } else { + $total_depth = base_depth + extra_height; + $top_tilt = 0; + + children(); + } +} + +module hexagonal_row(n=3, column=0) { + $key_shape_type = "hexagon"; + regular_polygon_row(n,column) { + children(); + } +} + +module octagonal_row(n=3, column=0) { + $key_shape_type = "octagon"; + regular_polygon_row(n, column) { + children(); + } +} +// based off GMK keycap set + +module cherry_row(row=3, column=0) { + $bottom_key_width = 18.16; + $bottom_key_height = 18.16; + $width_difference = $bottom_key_width - 11.85; + $height_difference = $bottom_key_height - 14.64; + $dish_type = "cylindrical"; + $dish_depth = 0.65; + $dish_skew_x = 0; + $dish_skew_y = 0; + $top_skew = 2; + + $top_tilt_y = side_tilt(column); + extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; + + // NOTE: cherry keycaps have this stem inset, but I'm reticent to turn it on + // since it'll be surprising to folks. the height has been adjusted accordingly + // $stem_inset = 0.6; + extra_stem_inset_height = max(0.6 - $stem_inset, 0); + + // <= is a hack so you can do these in a for loop. function row = 0 + if (row <= 1) { + $total_depth = 9.8 - extra_stem_inset_height + extra_height; + $top_tilt = 0; + + children(); + } else if (row == 2) { + $total_depth = 7.45 - extra_stem_inset_height + extra_height; + $top_tilt = 2.5; + + children(); + } else if (row == 3) { + $total_depth = 6.55 - extra_stem_inset_height + extra_height; + $top_tilt = 5; + children(); + } else if (row == 3) { + $total_depth = 6.7 + 0.65 - extra_stem_inset_height + extra_height; + $top_tilt = 11.5; + children(); + } else if (row >= 4) { + $total_depth = 6.7 + 0.65 - extra_stem_inset_height + extra_height; + $top_tilt = 11.5; + children(); + } else { + children(); + } +} +module dss_row(n=3, column=0) { + $key_shape_type = "sculpted_square"; + $bottom_key_width = 18.24; + $bottom_key_height = 18.24; + $width_difference = 6; + $height_difference = 6; + $dish_type = "spherical"; + $dish_depth = 1.2; + $dish_skew_x = 0; + $dish_skew_y = 0; + $top_skew = 0; + $height_slices = 10; + $enable_side_sculpting = true; + // might wanna change this if you don't minkowski + // do you even minkowski bro + $corner_radius = 1; + + // this is _incredibly_ intensive + /* $rounded_key = true; */ + + $top_tilt_y = side_tilt(column); + extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; + + // 5th row is usually unsculpted or the same as the row below it + // making a super-sculpted top row (or bottom row!) would be real easy + // bottom row would just be 13 tilt and 14.89 total depth + // top row would be something new entirely - 18 tilt maybe? + if (n <= 1){ + $total_depth = 10.5 + extra_height; + $top_tilt = -1; + children(); + } else if (n == 2) { + $total_depth = 8.6 + extra_height; + $top_tilt = 3; + children(); + } else if (n == 3) { + $total_depth = 7.9 + extra_height; + $top_tilt = 8; + children(); + } else if (n == 4){ + $total_depth = 9.1 + extra_height; + $top_tilt = 16; + children(); + } else { + $total_depth = 7.9 + extra_height; + $top_tilt = 8; + children(); + } +} // man, wouldn't it be so cool if functions were first order module key_profile(key_profile_type, row, column=0) { if (key_profile_type == "dcs") { @@ -597,6 +775,8 @@ module key_profile(key_profile_type, row, column=0) { oem_row(row, column) children(); } else if (key_profile_type == "dsa") { dsa_row(row, column) children(); + } else if (key_profile_type == "dss") { + dss_row(row, column) children(); } else if (key_profile_type == "sa") { sa_row(row, column) children(); } else if (key_profile_type == "g20") { @@ -605,15 +785,97 @@ module key_profile(key_profile_type, row, column=0) { hipro_row(row, column) children(); } else if (key_profile_type == "grid") { grid_row(row, column) children(); + } else if (key_profile_type == "hexagon") { + hexagonal_row(row, column) children(); + } else if (key_profile_type == "octagon") { + octagonal_row(row, column) children(); + } else if (key_profile_type == "cherry") { + cherry_row(row, column) children(); } else if (key_profile_type == "disable") { children(); } else { echo("Warning: unsupported key_profile_type"); } } +// a safe theoretical distance between two vertices such that they don't collapse. hard to use +SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; + +// I use functions when I need to compute special variables off of other special variables +// functions need to be explicitly included, unlike special variables, which +// just need to have been set before they are used. hence this file + +function stem_height() = $total_depth - $dish_depth - $stem_inset; + +// cherry stem dimensions +function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; + +// cherry stabilizer stem dimensions +function outer_cherry_stabilizer_stem(slop) = [4.85 - slop * 2, 6.05 - slop * 2]; + +// box (kailh) switches have a bit less to work with +function outer_box_cherry_stem(slop) = [6 - slop, 6 - slop]; + +// .005 purely for aesthetics, to get rid of that ugly crosshatch +function cherry_cross(slop, extra_vertical = 0) = [ + // horizontal tine + [4.03 + slop, 1.25 + slop / 3], + // vertical tine + [1.15 + slop / 3, 4.23 + extra_vertical + slop / 3 + SMALLEST_POSSIBLE], +]; + +// actual mm key width and height +function total_key_width(delta = 0) = $bottom_key_width + $unit * ($key_length - 1) - delta; +function total_key_height(delta = 0) = $bottom_key_height + $unit * ($key_height - 1) - delta; + +// actual mm key width and height at the top +function top_total_key_width() = $bottom_key_width + ($unit * ($key_length - 1)) - $width_difference; +function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1)) - $height_difference; + +function side_tilt(column) = asin($unit * column / $double_sculpt_radius); +// tan of 0 is 0, division by 0 is nan, so we have to guard +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; + +// (I think) extra length of the side of the keycap due to the keytop being tilted. +// necessary for calculating flat sided keycaps +function vertical_inclination_due_to_top_tilt() = sin($top_tilt) * (top_total_key_height() - $corner_radius * 2) * 0.5; +// how much you have to expand the front or back of the keytop to make the side +// of the keycap a flat plane. 1 = front, -1 = back +// I derived this through a bunch of trig reductions I don't really understand. +function extra_keytop_length_for_flat_sides() = ($width_difference * vertical_inclination_due_to_top_tilt()) / ($total_depth); + +// 3d surface functions (still in beta) + +// monotonically increasing function that distributes the points of the surface mesh +// only for polar_3d_surface right now +// if it's linear it's a grid. sin(dim) * size concentrates detail around the edges +function surface_distribution_function(dim, size) = sin(dim) * size; + +// the function that actually determines what the surface is. +// feel free to override, the last one wins + +// debug +function surface_function(x,y) = 1; +// cylindrical +function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); +// spherical +function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ +/* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; + module spacebar() { - $inverted_dish = true; - $dish_type = "sideways cylindrical"; + $inverted_dish = $dish_type != "disable"; + $dish_type = $dish_type != "disable" ? "sideways cylindrical" : "disable"; 6_25u() stabilized(mm=50) children(); } @@ -656,26 +918,31 @@ module iso_enter() { $key_length = 1.5; $key_height = 2; - $top_tilt = 0; + $dish_offset_x = -(unit_length(1.5) - unit_length(1.25))/2; + + /* $top_tilt = 0; */ $stem_support_type = "disable"; $key_shape_type = "iso_enter"; - /* $linear_extrude_shape = true; */ + $hull_shape_type = "skin"; $linear_extrude_height_adjustment = 19.05 * 0.5; // this equals (unit_length(1.5) - unit_length(1.25)) / 2 - $dish_overdraw_width = 2.38125; + /* $dish_overdraw_width = 2.38125; */ - - stabilized(vertical=true) { - children(); + render() { + stabilized(vertical=true) { + children(); + } } } // kind of a catch-all at this point for any directive that doesn't fit in the other files -//TODO duplicate def to not make this a special var. maybe not worth it -unit = 19.05; +// a safe theoretical distance between two vertices such that they don't collapse. hard to use +SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; module translate_u(x=0, y=0, z=0){ - translate([x * unit, y*unit, z*unit]) children(); + translate([x * $unit, y*$unit, z*$unit]) children(); } module no_stem_support() { @@ -715,6 +982,12 @@ module rotated() { children(); } +module vertically_stabilized(mm=12, vertical=true, type=undef) { + stabilized(mm,vertical,type) { + children(); + } +} + module stabilized(mm=12, vertical = false, type=undef) { if (vertical) { $stabilizer_type = (type ? type : ($stabilizer_type ? $stabilizer_type : "costar_stabilizer")); @@ -757,30 +1030,58 @@ module blank() { children(); } -module cherry(slop) { - $stem_slop = slop ? slop : $stem_slop; +module cherry(slop = undef) { + $stem_slop = slop != undef ? slop : $stem_slop; $stem_type = "cherry"; children(); } -module alps(slop) { - $stem_slop = slop ? slop : $stem_slop; +module alps(slop = undef) { + $stem_slop = slop != undef ? slop : $stem_slop; $stem_type = "alps"; children(); } -module rounded_cherry(slop) { - $stem_slop = slop ? slop : $stem_slop; +module rounded_cherry(slop = undef) { + $stem_slop = slop != undef ? slop : $stem_slop; $stem_type = "rounded_cherry"; children(); } -module box_cherry(slop) { - $stem_slop = slop ? slop : $stem_slop; +module box_cherry(slop = undef) { + $stem_slop = slop != undef ? slop : $stem_slop; $stem_type = "box_cherry"; children(); } +module choc(slop = 0.05) { + echo("WARN:\n\n * choc support is experimental.\n * $stem_slop is overridden.\n * it is also recommended to print them upside down if you can\n\n"); + $stem_throw = 3; + $stem_slop = slop; + + $bottom_key_width = 18; + $bottom_key_height = 17; + + $stem_type = "choc"; + children(); +} + +// a hacky way to make "low profile" keycaps +module low_profile() { + $width_difference = $width_difference / 1.5; + $height_difference = $height_difference / 1.5; + // helps tilted keycaps not have holes if worst comes to worst + $inner_shape_type = "dished"; + + $top_tilt = $top_tilt / 1.25; + + $total_depth = ($total_depth / 2) < 7 ? 7 : $total_depth / 2; + + // just to make sure + $stem_throw = 3; + children(); +} + module flared_support() { $support_type = "flared"; children(); @@ -848,6 +1149,19 @@ module debug() { %children(); } + +// auto-place children in a grid. +// For this to work all children have to be single keys, no for loops etc +module auto_place() { + num_children = $children; + row_size = round(pow(num_children, 0.5)); + + for (child_index = [0:num_children-1]) { + x = child_index % row_size; + y = floor(child_index / row_size); + translate_u(x,-y) children(child_index); + } +} module arrows(profile, rows = [4,4,4,3]) { positions = [[0, 0], [1, 0], [2, 0], [1, 1]]; legends = ["←", "↓", "→", "↑"]; @@ -880,12 +1194,21 @@ module row_profile(profile, unsculpted = false) { } } // files +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; +// a safe theoretical distance between two vertices such that they don't collapse. hard to use +SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; // I use functions when I need to compute special variables off of other special variables // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -913,7 +1236,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -939,14 +1262,788 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ -$fs=.1; -unit = 19.05; +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; +// a safe theoretical distance between two vertices such that they don't collapse. hard to use +SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; +// a safe theoretical distance between two vertices such that they don't collapse. hard to use +SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; + +// I use functions when I need to compute special variables off of other special variables +// functions need to be explicitly included, unlike special variables, which +// just need to have been set before they are used. hence this file + +function stem_height() = $total_depth - $dish_depth - $stem_inset; + +// cherry stem dimensions +function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; + +// cherry stabilizer stem dimensions +function outer_cherry_stabilizer_stem(slop) = [4.85 - slop * 2, 6.05 - slop * 2]; + +// box (kailh) switches have a bit less to work with +function outer_box_cherry_stem(slop) = [6 - slop, 6 - slop]; + +// .005 purely for aesthetics, to get rid of that ugly crosshatch +function cherry_cross(slop, extra_vertical = 0) = [ + // horizontal tine + [4.03 + slop, 1.25 + slop / 3], + // vertical tine + [1.15 + slop / 3, 4.23 + extra_vertical + slop / 3 + SMALLEST_POSSIBLE], +]; + +// actual mm key width and height +function total_key_width(delta = 0) = $bottom_key_width + $unit * ($key_length - 1) - delta; +function total_key_height(delta = 0) = $bottom_key_height + $unit * ($key_height - 1) - delta; + +// actual mm key width and height at the top +function top_total_key_width() = $bottom_key_width + ($unit * ($key_length - 1)) - $width_difference; +function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1)) - $height_difference; + +function side_tilt(column) = asin($unit * column / $double_sculpt_radius); +// tan of 0 is 0, division by 0 is nan, so we have to guard +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; + +// (I think) extra length of the side of the keycap due to the keytop being tilted. +// necessary for calculating flat sided keycaps +function vertical_inclination_due_to_top_tilt() = sin($top_tilt) * (top_total_key_height() - $corner_radius * 2) * 0.5; +// how much you have to expand the front or back of the keytop to make the side +// of the keycap a flat plane. 1 = front, -1 = back +// I derived this through a bunch of trig reductions I don't really understand. +function extra_keytop_length_for_flat_sides() = ($width_difference * vertical_inclination_due_to_top_tilt()) / ($total_depth); + +// 3d surface functions (still in beta) + +// monotonically increasing function that distributes the points of the surface mesh +// only for polar_3d_surface right now +// if it's linear it's a grid. sin(dim) * size concentrates detail around the edges +function surface_distribution_function(dim, size) = sin(dim) * size; + +// the function that actually determines what the surface is. +// feel free to override, the last one wins + +// debug +function surface_function(x,y) = 1; +// cylindrical +function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); +// spherical +function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ +/* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; +// Library: round-anything +// Version: 1.0 +// Author: IrevDev +// Contributors: TLC123 +// Copyright: 2020 +// License: MIT + + +function addZcoord(points,displacement)=[for(i=[0:len(points)-1])[points[i].x,points[i].y, displacement]]; +function translate3Dcoords(points,tran=[0,0,0],mult=[1,1,1])=[for(i=[0:len(points)-1])[ + (points[i].x*mult.x)+tran.x, + (points[i].y*mult.y)+tran.y, + (points[i].z*mult.z)+tran.z +]]; +function offsetPolygonPoints(points, offset=0)= +// Work sthe same as the offset does, except for the fact that instead of a 2d shape +// It works directly on polygon points +// It returns the same number of points just offset into or, away from the original shape. +// points= a series of x,y points[[x1,y1],[x2,y2],...] +// offset= amount to offset by, negative numbers go inwards into the shape, positive numbers go out +// return= a series of x,y points[[x1,y1],[x2,y2],...] +let( + isCWorCCW=sign(offset)*CWorCCW(points)*-1, + lp=len(points) +) +[for(i=[0:lp-1]) parallelFollow([ + points[listWrap(i-1,lp)], + points[i], + points[listWrap(i+1,lp)], +],thick=offset,mode=isCWorCCW)]; + +function makeCurvedPartOfPolyHedron(radiiPoints,r,fn,minR=0.01)= +// this is a private function that I'm not expecting library users to use directly +// radiiPoints= serise of x, y, r points +// r= radius of curve that will be put on the end of the extrusion +// fn= amount of subdivisions +// minR= if one of the points in radiiPoints is less than r, it's likely to converge and form a sharp edge, +// the min radius on these converged edges can be controled with minR, though because of legacy reasons it can't be 0, but can be a very small number. +// return= array of [polyhedronPoints, Polyhedronfaces, theLength of a singe layer in the curve] +let( + lp=len(radiiPoints), + radii=[for(i=[0:lp-1])radiiPoints[i].z], + isCWorCCWOverall=CWorCCW(radiiPoints), + dir=sign(r), + absR=abs(r), + fractionOffLp=1-1/fn, + allPoints=[for(fraction=[0:1/fn:1]) + let( + iterationOffset=dir*sqrt(sq(absR)-sq(fraction*absR))-dir*absR, + theOffsetPoints=offsetPolygonPoints(radiiPoints,iterationOffset), + polyRoundOffsetPoints=[for(i=[0:lp-1]) + let( + pointsAboutCurrent=[ + theOffsetPoints[listWrap(i-1,lp)], + theOffsetPoints[i], + theOffsetPoints[listWrap(i+1,lp)] + ], + isCWorCCWLocal=CWorCCW(pointsAboutCurrent), + isInternalRadius=(isCWorCCWLocal*isCWorCCWOverall)==-1, + // the radius names are only true for positive r, + // when are r is negative increasingRadius is actually decreasing and vice-vs + // increasingRadiusWithPositiveR is just to verbose of a variable name for my liking + increasingRadius=max(radii[i]-iterationOffset, minR), + decreasingRadius=max(radii[i]+iterationOffset, minR) + ) + [theOffsetPoints[i].x, theOffsetPoints[i].y, isInternalRadius? increasingRadius: decreasingRadius] + ], + pointsForThisLayer=polyRound(polyRoundOffsetPoints,fn) + ) + addZcoord(pointsForThisLayer,fraction*absR) + ], + polyhedronPoints=flatternArray(allPoints), + allLp=len(allPoints), + layerLength=len(allPoints[0]), + loopToSecondLastLayer=allLp-2, + sideFaces=[for(layerIndex=[0:loopToSecondLastLayer])let( + currentLayeroffset=layerIndex*layerLength, + nextLayeroffset=(layerIndex+1)*layerLength, + layerFaces=[for(subLayerIndex=[0:layerLength-1]) + [ + currentLayeroffset+subLayerIndex, currentLayeroffset + listWrap(subLayerIndex+1,layerLength), nextLayeroffset+listWrap(subLayerIndex+1,layerLength), nextLayeroffset+subLayerIndex] + ] + )layerFaces], + polyhedronFaces=flatternArray(sideFaces) +) +[polyhedronPoints, polyhedronFaces, layerLength]; + +function flatternRecursion(array, init=[], currentIndex)= +// this is a private function, init and currentIndex are for the function's use +// only for when it's calling itself, which is why there is a simplified version flatternArray that just calls this one +// array= array to flattern by one level of nesting +// init= the array used to cancat with the next call, only for when the function calls itself +// currentIndex= so the function can keep track of how far it's progressed through the array, only for when it's calling itself +// returns= flatterned array, by one level of nesting +let( + shouldKickOffRecursion=currentIndex==undef?1:0, + isLastIndex=currentIndex+1==len(array)?1:0, + flatArray=shouldKickOffRecursion?flatternRecursion(array,[],0): + isLastIndex?concat(init,array[currentIndex]): + flatternRecursion(array,concat(init,array[currentIndex]),currentIndex+1) +) +flatArray; + +function flatternArray(array)= +// public version of flatternRecursion, has simplified params to avoid confusion +// array= array to be flatterned +// return= array that been flatterend by one level of nesting +flatternRecursion(array); + +function offsetAllFacesBy(array,offset)=[ + // polyhedron faces are simply a list of indices to points, if your concat points together than you probably need to offset + // your faces array to points to the right place in the new list + // array= array of point indicies + // offset= number to offset all indecies by + // return= array of point indices (i.e. faces) with offset applied + for(faceIndex=[0:len(array)-1])[ + for(pointIndex=[0:len(array[faceIndex])-1])array[faceIndex][pointIndex]+offset + ] +]; + +function extrudePolygonWithRadius(radiiPoints,h=5,r1=1,r2=1,fn=4)= +// this basically calls makeCurvedPartOfPolyHedron twice to get the curved section of the final polyhedron +// and then goes about assmbling them, as the side faces and the top and bottom face caps are missing +// radiiPoints= series of [x,y,r] points, +// h= height of the extrude (total including radius sections) +// r1,r2= define the radius at the top and bottom of the extrud respectively, negative number flange out the extrude +// fn= number of subdivisions +// returns= [polyhedronPoints, polyhedronFaces] +let( + // top is the top curved part of the extrude + top=makeCurvedPartOfPolyHedron(radiiPoints,r1,fn), + topRadiusPoints=translate3Dcoords(top[0],[0,0,h-r1]), + singeLayerLength=top[2], + topRadiusFaces=top[1], + radiusPointsLength=len(topRadiusPoints), // is the same length as bottomRadiusPoints + // bottom is the bottom curved part of the extrude + bottom=makeCurvedPartOfPolyHedron(radiiPoints,r2,fn), + // Z axis needs to be multiplied by -1 to flip it so the radius is going in the right direction [1,1,-1] + bottomRadiusPoints=translate3Dcoords(bottom[0],[0,0,abs(r2)],[1,1,-1]), + // becaues the points will be all concatenated into the same array, and the bottom points come second, than + // the original indices the faces are points towards are wrong and need to have an offset applied to them + bottomRadiusFaces=offsetAllFacesBy(bottom[1],radiusPointsLength), + // all of the side panel of the extrusion, connecting points from the inner layers of each + // of the curved sections + sideFaces=[for(i=[0:singeLayerLength-1])[ + i, + listWrap(i+1,singeLayerLength), + radiusPointsLength + listWrap(i+1,singeLayerLength), + radiusPointsLength + i + ]], + // both of these caps are simple every point from the last layer of the radius points + topCapFace=[for(i=[0:singeLayerLength-1])radiusPointsLength-singeLayerLength+i], + bottomCapFace=[for(i=[0:singeLayerLength-1])radiusPointsLength*2-singeLayerLength+i], + finalPolyhedronPoints=concat(topRadiusPoints,bottomRadiusPoints), + finalPolyhedronFaces=concat(topRadiusFaces,bottomRadiusFaces, sideFaces, [topCapFace], [bottomCapFace]) +) +[ + finalPolyhedronPoints, + finalPolyhedronFaces +]; + +module polyRoundExtrude(radiiPoints,length=5,r1=1,r2=1,fn=10,convexity=10) { + polyhedronPointsNFaces=extrudePolygonWithRadius(radiiPoints,length,r1,r2,fn); + polyhedron(points=polyhedronPointsNFaces[0], faces=polyhedronPointsNFaces[1], convexity=convexity); +} + + +// testingInternals(); +module testingInternals(){ + //example of rounding random points, this has no current use but is a good demonstration + random=[for(i=[0:20])[rnd(0,50),rnd(0,50),/*rnd(0,30)*/1000]]; + R =polyRound(random,7); + translate([-25,25,0]){ + polyline(R); + } + + //example of different modes of the CentreN2PointsArc() function 0=shortest arc, 1=longest arc, 2=CW, 3=CCW + p1=[0,5];p2=[10,5];centre=[5,0]; + translate([60,0,0]){ + color("green"){ + polygon(CentreN2PointsArc(p1,p2,centre,0,20));//draws the shortest arc + } + color("cyan"){ + polygon(CentreN2PointsArc(p1,p2,centre,1,20));//draws the longest arc + } + } + translate([75,0,0]){ + color("purple"){ + polygon(CentreN2PointsArc(p1,p2,centre,2,20));//draws the arc CW (which happens to be the short arc) + } + color("red"){ + polygon(CentreN2PointsArc(p2,p1,centre,2,20));//draws the arc CW but p1 and p2 swapped order resulting in the long arc being drawn + } + } + + radius=6; + radiipoints=[[0,0,0],[10,20,radius],[20,0,0]]; + tangentsNcen=round3points(radiipoints); + translate([10,0,0]){ + for(i=[0:2]){ + color("red")translate(getpoints(radiipoints)[i])circle(1);//plots the 3 input points + color("cyan")translate(tangentsNcen[i])circle(1);//plots the two tangent poins and the circle centre + } + translate([tangentsNcen[2][0],tangentsNcen[2][1],-0.2])circle(r=radius,$fn=25);//draws the cirle + %polygon(getpoints(radiipoints));//draws a polygon + } +} + +function polyRound(radiipoints,fn=5,mode=0)= + /*Takes a list of radii points of the format [x,y,radius] and rounds each point + with fn resolution + mode=0 - automatic radius limiting - DEFAULT + mode=1 - Debug, output radius reduction for automatic radius limiting + mode=2 - No radius limiting*/ + let( + p=getpoints(radiipoints), //make list of coordinates without radii + Lp=len(p), + //remove the middle point of any three colinear points, otherwise adding a radius to the middle of a straigh line causes problems + radiiPointsWithoutTrippleColinear=[ + for(i=[0:len(p)-1]) if( + // keep point if it isn't colinear or if the radius is 0 + !isColinear( + p[listWrap(i-1,Lp)], + p[listWrap(i+0,Lp)], + p[listWrap(i+1,Lp)] + )|| + p[listWrap(i+0,Lp)].z!=0 + ) radiipoints[listWrap(i+0,Lp)] + ], + newrp2=processRadiiPoints(radiiPointsWithoutTrippleColinear), + plusMinusPointRange=mode==2?1:2, + temp=[ + for(i=[0:len(newrp2)-1]) //for each point in the radii array + let( + thepoints=[for(j=[-plusMinusPointRange:plusMinusPointRange])newrp2[listWrap(i+j,len(newrp2))]],//collect 5 radii points + temp2=mode==2?round3points(thepoints,fn):round5points(thepoints,fn,mode) + ) + mode==1?temp2:newrp2[i][2]==0? + [[newrp2[i][0],newrp2[i][1]]]: //return the original point if the radius is 0 + CentreN2PointsArc(temp2[0],temp2[1],temp2[2],0,fn) //return the arc if everything is normal + ] + ) + [for (a = temp) for (b = a) b];//flattern and return the array + +function round5points(rp,fn,debug=0)= + rp[2][2]==0&&debug==0?[[rp[2][0],rp[2][1]]]://return the middle point if the radius is 0 + rp[2][2]==0&&debug==1?0://if debug is enabled and the radius is 0 return 0 + let( + p=getpoints(rp), //get list of points + r=[for(i=[1:3]) abs(rp[i][2])],//get the centre 3 radii + //start by determining what the radius should be at point 3 + //find angles at points 2 , 3 and 4 + a2=cosineRuleAngle(p[0],p[1],p[2]), + a3=cosineRuleAngle(p[1],p[2],p[3]), + a4=cosineRuleAngle(p[2],p[3],p[4]), + //find the distance between points 2&3 and between points 3&4 + d23=pointDist(p[1],p[2]), + d34=pointDist(p[2],p[3]), + //find the radius factors + F23=(d23*tan(a2/2)*tan(a3/2))/(r[0]*tan(a3/2)+r[1]*tan(a2/2)), + F34=(d34*tan(a3/2)*tan(a4/2))/(r[1]*tan(a4/2)+r[2]*tan(a3/2)), + newR=min(r[1],F23*r[1],F34*r[1]),//use the smallest radius + //now that the radius has been determined, find tangent points and circle centre + tangD=newR/tan(a3/2),//distance to the tangent point from p3 + circD=newR/sin(a3/2),//distance to the circle centre from p3 + //find the angle from the p3 + an23=getAngle(p[1],p[2]),//angle from point 3 to 2 + an34=getAngle(p[3],p[2]),//angle from point 3 to 4 + //find tangent points + t23=[p[2][0]-cos(an23)*tangD,p[2][1]-sin(an23)*tangD],//tangent point between points 2&3 + t34=[p[2][0]-cos(an34)*tangD,p[2][1]-sin(an34)*tangD],//tangent point between points 3&4 + //find circle centre + tmid=getMidpoint(t23,t34),//midpoint between the two tangent points + anCen=getAngle(tmid,p[2]),//angle from point 3 to circle centre + cen=[p[2][0]-cos(anCen)*circD,p[2][1]-sin(anCen)*circD] + ) + //circle center by offseting from point 3 + //determine the direction of rotation + debug==1?//if debug in disabled return arc (default) + (newR-r[1]): + [t23,t34,cen]; + +function round3points(rp,fn)= + rp[1][2]==0?[[rp[1][0],rp[1][1]]]://return the middle point if the radius is 0 + let( + p=getpoints(rp), //get list of points + r=rp[1][2],//get the centre 3 radii + ang=cosineRuleAngle(p[0],p[1],p[2]),//angle between the lines + //now that the radius has been determined, find tangent points and circle centre + tangD=r/tan(ang/2),//distance to the tangent point from p2 + circD=r/sin(ang/2),//distance to the circle centre from p2 + //find the angles from the p2 with respect to the postitive x axis + angleFromPoint1ToPoint2=getAngle(p[0],p[1]), + angleFromPoint2ToPoint3=getAngle(p[2],p[1]), + //find tangent points + t12=[p[1][0]-cos(angleFromPoint1ToPoint2)*tangD,p[1][1]-sin(angleFromPoint1ToPoint2)*tangD],//tangent point between points 1&2 + t23=[p[1][0]-cos(angleFromPoint2ToPoint3)*tangD,p[1][1]-sin(angleFromPoint2ToPoint3)*tangD],//tangent point between points 2&3 + //find circle centre + tmid=getMidpoint(t12,t23),//midpoint between the two tangent points + angCen=getAngle(tmid,p[1]),//angle from point 2 to circle centre + cen=[p[1][0]-cos(angCen)*circD,p[1][1]-sin(angCen)*circD] //circle center by offseting from point 2 + ) + [t12,t23,cen]; + +function parallelFollow(rp,thick=4,minR=1,mode=1)= + //rp[1][2]==0?[rp[1][0],rp[1][1],0]://return the middle point if the radius is 0 + thick==0?[rp[1][0],rp[1][1],0]://return the middle point if the radius is 0 + let( + p=getpoints(rp), //get list of points + r=thick,//get the centre 3 radii + ang=cosineRuleAngle(p[0],p[1],p[2]),//angle between the lines + //now that the radius has been determined, find tangent points and circle centre + tangD=r/tan(ang/2),//distance to the tangent point from p2 + sgn=CWorCCW(rp),//rotation of the three points cw or ccw?let(sgn=mode==0?1:-1) + circD=mode*sgn*r/sin(ang/2),//distance to the circle centre from p2 + //find the angles from the p2 with respect to the postitive x axis + angleFromPoint1ToPoint2=getAngle(p[0],p[1]), + angleFromPoint2ToPoint3=getAngle(p[2],p[1]), + //find tangent points + t12=[p[1][0]-cos(angleFromPoint1ToPoint2)*tangD,p[1][1]-sin(angleFromPoint1ToPoint2)*tangD],//tangent point between points 1&2 + t23=[p[1][0]-cos(angleFromPoint2ToPoint3)*tangD,p[1][1]-sin(angleFromPoint2ToPoint3)*tangD],//tangent point between points 2&3 + //find circle centre + tmid=getMidpoint(t12,t23),//midpoint between the two tangent points + angCen=getAngle(tmid,p[1]),//angle from point 2 to circle centre + cen=[p[1][0]-cos(angCen)*circD,p[1][1]-sin(angCen)*circD],//circle center by offseting from point 2 + outR=max(minR,rp[1][2]-thick*sgn*mode) //ensures radii are never too small. + ) + concat(cen,outR); + +function findPoint(ang1,refpoint1,ang2,refpoint2,r=0)= + let( + m1=tan(ang1), + c1=refpoint1.y-m1*refpoint1.x, + m2=tan(ang2), + c2=refpoint2.y-m2*refpoint2.x, + outputX=(c2-c1)/(m1-m2), + outputY=m1*outputX+c1 + ) + [outputX,outputY,r]; + +function beamChain(radiiPoints,offset1=0,offset2,mode=0,minR=0,startAngle,endAngle)= + /*This function takes a series of radii points and plots points to run along side at a consistant distance, think of it as offset but for line instead of a polygon + radiiPoints=radii points, + offset1 & offset2= The two offsets that give the beam it's thickness. When using with mode=2 only offset1 is needed as there is no return path for the polygon + minR=min radius, if all of your radii are set properly within the radii points this value can be ignored + startAngle & endAngle= Angle at each end of the beam, different mode determine if this angle is relative to the ending legs of the beam or absolute. + mode=1 - include endpoints startAngle&2 are relative to the angle of the last two points and equal 90deg if not defined + mode=2 - Only the forward path is defined, useful for combining the beam with other radii points, see examples for a use-case. + mode=3 - include endpoints startAngle&2 are absolute from the x axis and are 0 if not defined + negative radiuses only allowed for the first and last radii points + + As it stands this function could probably be tidied a lot, but it works, I'll tidy later*/ + let( + offset2undef=offset2==undef?1:0, + offset2=offset2undef==1?0:offset2, + CWorCCW1=sign(offset1)*CWorCCW(radiiPoints), + CWorCCW2=sign(offset2)*CWorCCW(radiiPoints), + offset1=abs(offset1), + offset2b=abs(offset2), + Lrp3=len(radiiPoints)-3, + Lrp=len(radiiPoints), + startAngle=mode==0&&startAngle==undef? + getAngle(radiiPoints[0],radiiPoints[1])+90: + mode==2&&startAngle==undef? + 0: + mode==0? + getAngle(radiiPoints[0],radiiPoints[1])+startAngle: + startAngle, + endAngle=mode==0&&endAngle==undef? + getAngle(radiiPoints[Lrp-1],radiiPoints[Lrp-2])+90: + mode==2&&endAngle==undef? + 0: + mode==0? + getAngle(radiiPoints[Lrp-1],radiiPoints[Lrp-2])+endAngle: + endAngle, + OffLn1=[for(i=[0:Lrp3]) offset1==0?radiiPoints[i+1]:parallelFollow([radiiPoints[i],radiiPoints[i+1],radiiPoints[i+2]],offset1,minR,mode=CWorCCW1)], + OffLn2=[for(i=[0:Lrp3]) offset2==0?radiiPoints[i+1]:parallelFollow([radiiPoints[i],radiiPoints[i+1],radiiPoints[i+2]],offset2b,minR,mode=CWorCCW2)], + Rp1=abs(radiiPoints[0].z), + Rp2=abs(radiiPoints[Lrp-1].z), + endP1a=findPoint(getAngle(radiiPoints[0],radiiPoints[1]), OffLn1[0], startAngle,radiiPoints[0], Rp1), + endP1b=findPoint(getAngle(radiiPoints[Lrp-1],radiiPoints[Lrp-2]), OffLn1[len(OffLn1)-1], endAngle,radiiPoints[Lrp-1], Rp2), + endP2a=findPoint(getAngle(radiiPoints[0],radiiPoints[1]), OffLn2[0], startAngle,radiiPoints[0], Rp1), + endP2b=findPoint(getAngle(radiiPoints[Lrp-1],radiiPoints[Lrp-2]), OffLn2[len(OffLn1)-1], endAngle,radiiPoints[Lrp-1], Rp2), + absEnda=getAngle(endP1a,endP2a), + absEndb=getAngle(endP1b,endP2b), + negRP1a=[cos(absEnda)*radiiPoints[0].z*10+endP1a.x, sin(absEnda)*radiiPoints[0].z*10+endP1a.y, 0.0], + negRP2a=[cos(absEnda)*-radiiPoints[0].z*10+endP2a.x, sin(absEnda)*-radiiPoints[0].z*10+endP2a.y, 0.0], + negRP1b=[cos(absEndb)*radiiPoints[Lrp-1].z*10+endP1b.x, sin(absEndb)*radiiPoints[Lrp-1].z*10+endP1b.y, 0.0], + negRP2b=[cos(absEndb)*-radiiPoints[Lrp-1].z*10+endP2b.x, sin(absEndb)*-radiiPoints[Lrp-1].z*10+endP2b.y, 0.0], + OffLn1b=(mode==0||mode==2)&&radiiPoints[0].z<0&&radiiPoints[Lrp-1].z<0? + concat([negRP1a],[endP1a],OffLn1,[endP1b],[negRP1b]) + :(mode==0||mode==2)&&radiiPoints[0].z<0? + concat([negRP1a],[endP1a],OffLn1,[endP1b]) + :(mode==0||mode==2)&&radiiPoints[Lrp-1].z<0? + concat([endP1a],OffLn1,[endP1b],[negRP1b]) + :mode==0||mode==2? + concat([endP1a],OffLn1,[endP1b]) + : + OffLn1, + OffLn2b=(mode==0||mode==2)&&radiiPoints[0].z<0&&radiiPoints[Lrp-1].z<0? + concat([negRP2a],[endP2a],OffLn2,[endP2b],[negRP2b]) + :(mode==0||mode==2)&&radiiPoints[0].z<0? + concat([negRP2a],[endP2a],OffLn2,[endP2b]) + :(mode==0||mode==2)&&radiiPoints[Lrp-1].z<0? + concat([endP2a],OffLn2,[endP2b],[negRP2b]) + :mode==0||mode==2? + concat([endP2a],OffLn2,[endP2b]) + : + OffLn2 + )//end of let() + offset2undef==1?OffLn1b:concat(OffLn2b,revList(OffLn1b)); + +function revList(list)=//reverse list + let(Llist=len(list)-1) + [for(i=[0:Llist]) list[Llist-i]]; + +function CWorCCW(p)= + let( + Lp=len(p), + e=[for(i=[0:Lp-1]) + (p[listWrap(i+0,Lp)].x-p[listWrap(i+1,Lp)].x)*(p[listWrap(i+0,Lp)].y+p[listWrap(i+1,Lp)].y) + ] + ) + sign(sum(e)); + +function CentreN2PointsArc(p1,p2,cen,mode=0,fn)= + /* This function plots an arc from p1 to p2 with fn increments using the cen as the centre of the arc. + the mode determines how the arc is plotted + mode==0, shortest arc possible + mode==1, longest arc possible + mode==2, plotted clockwise + mode==3, plotted counter clockwise + */ + let( + isCWorCCW=CWorCCW([cen,p1,p2]),//determine the direction of rotation + //determine the arc angle depending on the mode + p1p2Angle=cosineRuleAngle(p2,cen,p1), + arcAngle= + mode==0?p1p2Angle: + mode==1?p1p2Angle-360: + mode==2&&isCWorCCW==-1?p1p2Angle: + mode==2&&isCWorCCW== 1?p1p2Angle-360: + mode==3&&isCWorCCW== 1?p1p2Angle: + mode==3&&isCWorCCW==-1?p1p2Angle-360: + cosineRuleAngle(p2,cen,p1), + r=pointDist(p1,cen),//determine the radius + p1Angle=getAngle(cen,p1) //angle of line 1 + ) + [for(i=[0:fn]) + let(angleIncrement=(arcAngle/fn)*i*isCWorCCW) + [cos(p1Angle+angleIncrement)*r+cen.x,sin(p1Angle+angleIncrement)*r+cen.y]]; + +function translateRadiiPoints(radiiPoints,tran=[0,0],rot=0)= + [for(i=radiiPoints) + let( + a=getAngle([0,0],[i.x,i.y]),//get the angle of the this point + h=pointDist([0,0],[i.x,i.y]) //get the hypotenuse/radius + ) + [h*cos(a+rot)+tran.x,h*sin(a+rot)+tran.y,i.z]//calculate the point's new position + ]; + +module round2d(OR=3,IR=1){ + offset(OR,$fn=100){ + offset(-IR-OR,$fn=100){ + offset(IR,$fn=100){ + children(); + } + } + } +} + +module shell2d(offset1,offset2=0,minOR=0,minIR=0){ + difference(){ + round2d(minOR,minIR){ + offset(max(offset1,offset2)){ + children(0);//original 1st child forms the outside of the shell + } + } + round2d(minIR,minOR){ + difference(){//round the inside cutout + offset(min(offset1,offset2)){ + children(0);//shrink the 1st child to form the inside of the shell + } + if($children>1){ + for(i=[1:$children-1]){ + children(i);//second child and onwards is used to add material to inside of the shell + } + } + } + } + } +} + +module internalSq(size,r,center=0){ + tran=center==1?[0,0]:size/2; + translate(tran){ + square(size,true); + offs=sin(45)*r; + for(i=[-1,1],j=[-1,1]){ + translate([(size.x/2-offs)*i,(size.y/2-offs)*j])circle(r); + } + } +} + +module extrudeWithRadius(length,r1=0,r2=0,fn=30){ + n1=sign(r1);n2=sign(r2); + r1=abs(r1);r2=abs(r2); + translate([0,0,r1]){ + linear_extrude(length-r1-r2){ + children(); + } + } + for(i=[0:fn-1]){ + translate([0,0,i/fn*r1]){ + linear_extrude(r1/fn+0.01){ + offset(n1*sqrt(sq(r1)-sq(r1-i/fn*r1))-n1*r1){ + children(); + } + } + } + translate([0,0,length-r2+i/fn*r2]){ + linear_extrude(r2/fn+0.01){ + offset(n2*sqrt(sq(r2)-sq(i/fn*r2))-n2*r2){ + children(); + } + } + } + } +} + +function mirrorPoints(radiiPoints,rot=0,endAttenuation=[0,0])= //mirrors a list of points about Y, ignoring the first and last points and returning them in reverse order for use with polygon or polyRound + let( + a=translateRadiiPoints(radiiPoints,[0,0],-rot), + temp3=[for(i=[0+endAttenuation[0]:len(a)-1-endAttenuation[1]]) + [a[i][0],-a[i][1],a[i][2]] + ], + temp=translateRadiiPoints(temp3,[0,0],rot), + temp2=revList(temp3) + ) + concat(radiiPoints,temp2); + +function processRadiiPoints(rp)= + [for(i=[0:len(rp)-1]) + processRadiiPoints2(rp,i) + ]; + +function processRadiiPoints2(list,end=0,idx=0,result=0)= + idx>=end+1?result: + processRadiiPoints2(list,end,idx+1,relationalRadiiPoints(result,list[idx])); + +function cosineRuleBside(a,c,C)=c*cos(C)-sqrt(sq(a)+sq(c)+sq(cos(C))-sq(c)); + +function absArelR(po,pn)= + let( + th2=atan(po[1]/po[0]), + r2=sqrt(sq(po[0])+sq(po[1])), + r3=cosineRuleBside(r2,pn[1],th2-pn[0]) + ) + [cos(pn[0])*r3,sin(pn[0])*r3,pn[2]]; + +function relationalRadiiPoints(po,pi)= + let( + p0=pi[0], + p1=pi[1], + p2=pi[2], + pv0=pi[3][0], + pv1=pi[3][1], + pt0=pi[3][2], + pt1=pi[3][3], + pn= + (pv0=="y"&&pv1=="x")||(pv0=="r"&&pv1=="a")||(pv0=="y"&&pv1=="a")||(pv0=="x"&&pv1=="a")||(pv0=="y"&&pv1=="r")||(pv0=="x"&&pv1=="r")? + [p1,p0,p2,concat(pv1,pv0,pt1,pt0)]: + [p0,p1,p2,concat(pv0,pv1,pt0,pt1)], + n0=pn[0], + n1=pn[1], + n2=pn[2], + nv0=pn[3][0], + nv1=pn[3][1], + nt0=pn[3][2], + nt1=pn[3][3], + temp= + pn[0]=="l"? + [po[0],pn[1],pn[2]] + :pn[1]=="l"? + [pn[0],po[1],pn[2]] + :nv0==undef? + [pn[0],pn[1],pn[2]]//abs x, abs y as default when undefined + :nv0=="a"? + nv1=="r"? + nt0=="a"? + nt1=="a"||nt1==undef? + [cos(n0)*n1,sin(n0)*n1,n2]//abs angle, abs radius + :absArelR(po,pn)//abs angle rel radius + :nt1=="r"||nt1==undef? + [po[0]+cos(pn[0])*pn[1],po[1]+sin(pn[0])*pn[1],pn[2]]//rel angle, rel radius + :[pn[0],pn[1],pn[2]]//rel angle, abs radius + :nv1=="x"? + nt0=="a"? + nt1=="a"||nt1==undef? + [pn[1],pn[1]*tan(pn[0]),pn[2]]//abs angle, abs x + :[po[0]+pn[1],(po[0]+pn[1])*tan(pn[0]),pn[2]]//abs angle rel x + :nt1=="r"||nt1==undef? + [po[0]+pn[1],po[1]+pn[1]*tan(pn[0]),pn[2]]//rel angle, rel x + :[pn[1],po[1]+(pn[1]-po[0])*tan(pn[0]),pn[2]]//rel angle, abs x + :nt0=="a"? + nt1=="a"||nt1==undef? + [pn[1]/tan(pn[0]),pn[1],pn[2]]//abs angle, abs y + :[(po[1]+pn[1])/tan(pn[0]),po[1]+pn[1],pn[2]]//abs angle rel y + :nt1=="r"||nt1==undef? + [po[0]+(pn[1]-po[0])/tan(90-pn[0]),po[1]+pn[1],pn[2]]//rel angle, rel y + :[po[0]+(pn[1]-po[1])/tan(pn[0]),pn[1],pn[2]]//rel angle, abs y + :nv0=="r"? + nv1=="x"? + nt0=="a"? + nt1=="a"||nt1==undef? + [pn[1],sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1])),pn[2]]//abs radius, abs x + :[po[0]+pn[1],sign(pn[0])*sqrt(sq(pn[0])-sq(po[0]+pn[1])),pn[2]]//abs radius rel x + :nt1=="r"||nt1==undef? + [po[0]+pn[1],po[1]+sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1])),pn[2]]//rel radius, rel x + :[pn[1],po[1]+sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1]-po[0])),pn[2]]//rel radius, abs x + :nt0=="a"? + nt1=="a"||nt1==undef? + [sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1])),pn[1],pn[2]]//abs radius, abs y + :[sign(pn[0])*sqrt(sq(pn[0])-sq(po[1]+pn[1])),po[1]+pn[1],pn[2]]//abs radius rel y + :nt1=="r"||nt1==undef? + [po[0]+sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1])),po[1]+pn[1],pn[2]]//rel radius, rel y + :[po[0]+sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1]-po[1])),pn[1],pn[2]]//rel radius, abs y + :nt0=="a"? + nt1=="a"||nt1==undef? + [pn[0],pn[1],pn[2]]//abs x, abs y + :[pn[0],po[1]+pn[1],pn[2]]//abs x rel y + :nt1=="r"||nt1==undef? + [po[0]+pn[0],po[1]+pn[1],pn[2]]//rel x, rel y + :[po[0]+pn[0],pn[1],pn[2]]//rel x, abs y + ) + temp; + +function invtan(run,rise)= + let(a=abs(atan(rise/run))) + rise==0&&run>0? + 0:rise>0&&run>0? + a:rise>0&&run==0? + 90:rise>0&&run<0? + 180-a:rise==0&&run<0? + 180:rise<0&&run<0? + a+180:rise<0&&run==0? + 270:rise<0&&run>0? + 360-a:"error"; + +function cosineRuleAngle(p1,p2,p3)= + let( + p12=abs(pointDist(p1,p2)), + p13=abs(pointDist(p1,p3)), + p23=abs(pointDist(p2,p3)) + ) + acos((sq(p23)+sq(p12)-sq(p13))/(2*p23*p12)); + +function sum(list, idx = 0, result = 0) = + idx >= len(list) ? result : sum(list, idx + 1, result + list[idx]); + +function sq(x)=x*x; +function getGradient(p1,p2)=(p2.y-p1.y)/(p2.x-p1.x); +function getAngle(p1,p2)=p1==p2?0:invtan(p2[0]-p1[0],p2[1]-p1[1]); +function getMidpoint(p1,p2)=[(p1[0]+p2[0])/2,(p1[1]+p2[1])/2]; //returns the midpoint of two points +function pointDist(p1,p2)=sqrt(abs(sq(p1[0]-p2[0])+sq(p1[1]-p2[1]))); //returns the distance between two points +function isColinear(p1,p2,p3)=getGradient(p1,p2)==getGradient(p2,p3)?1:0;//return 1 if 3 points are colinear +module polyline(p, width=0.3) { + for(i=[0:max(0,len(p)-1)]){ + color([i*1/len(p),1-i*1/len(p),0,0.5])line(p[i],p[listWrap(i+1,len(p) )],width); + } +} // polyline plotter +module line(p1, p2 ,width=0.3) { // single line plotter + hull() { + translate(p1){ + circle(width); + } + translate(p2){ + circle(width); + } + } +} + +function getpoints(p)=[for(i=[0:len(p)-1])[p[i].x,p[i].y]];// gets [x,y]list of[x,y,r]list +function listWrap(x,x_max=1,x_min=0) = (((x - x_min) % (x_max - x_min)) + (x_max - x_min)) % (x_max - x_min) + x_min; // wraps numbers inside boundaries +function rnd(a = 1, b = 0, s = []) = + s == [] ? + (rands(min(a, b), max( a, b), 1)[0]):(rands(min(a, b), max(a, b), 1, s)[0]); // nice rands wrapper + +width_ratio = unit_length(1.25) / unit_length(1.5); +height_ratio = unit_length(1) / unit_length(2); + -// corollary is rounded_square -// NOT 3D -function unit_length(length) = unit * (length - 1) + 18.16; module ISO_enter_shape(size, delta, progress){ width = size[0]; @@ -959,97 +2056,71 @@ module ISO_enter_shape(size, delta, progress){ // and wants to pass just width and height, we make these ratios to know where // to put the elbow joint - width_ratio = unit_length(1.25) / unit_length(1.5); - height_ratio = unit_length(1) / unit_length(2); + delta = delta / 2; pointArray = [ - [ 0, 0], // top right - [ 0, -height], // bottom right - [-width * width_ratio, -height], // bottom left - [-width * width_ratio,-height * height_ratio], // inner middle point - [ -width,-height * height_ratio], // outer middle point - [ -width, 0] // top left + [ 0-delta.x, 0-delta.y], // top right + [ 0-delta.x, -height+delta.y], // bottom right + [-width * width_ratio+delta.x, -height+delta.y], // bottom left + [-width * width_ratio + delta.x,-height * height_ratio+delta.y], // inner middle point + [ -width + delta.x,-height * height_ratio + delta.y], // outer middle point + [ -width + delta.x, 0-delta.y] // top left ]; minkowski(){ - circle(r=corner_size); + circle(r=$corner_radius); // gives us rounded inner corner - offset(r=-corner_size*2) { + offset(r=-$corner_radius*2) { translate([(width * width_ratio)/2, height/2]) polygon(points=pointArray); } } } -function iso_enter_vertices(width, height, width_ratio, height_ratio, wd, hd) = [ - [ 0-wd, 0-hd], // top right - [ 0-wd, -height+hd], // bottom right - [-width * width_ratio+wd, -height+hd], // bottom left - [-width * width_ratio+wd,-height * height_ratio+hd], // inner middle point - [ -width+wd,-height * height_ratio+hd], // outer middle point - [ -width+wd, 0-hd] // top left +function iso_enter_vertices(size, delta, progress, thickness_difference) = [ + [ 0-delta.x/2 * progress - thickness_difference/8, 0 - delta.y / 2 * progress - thickness_difference/8], // top right + [ 0-delta.x/2 * progress - thickness_difference/8, -size[1] + delta.y / 2 * progress + thickness_difference/8], // bottom right + [-size[0] * width_ratio + delta.x/2 * progress + thickness_difference/8, -size[1] + delta.y / 2 * progress + thickness_difference/8], // bottom left + [-size[0] * width_ratio + delta.x/2 * progress + thickness_difference/8,-size[1] * height_ratio + delta.y / 2 * progress + thickness_difference/2], // inner middle point + [ -size[0] + delta.x/2 * progress + thickness_difference/8,-size[1] * height_ratio + delta.y / 2 * progress + thickness_difference/2], // outer middle point + [ -size[0] + delta.x/2 * progress + thickness_difference/8, 0 - delta.y / 2 * progress - thickness_difference/8] // top left ] + [ - [(width * width_ratio)/2, height/2 ], - [(width * width_ratio)/2, height/2 ], - [(width * width_ratio)/2, height/2 ], - [(width * width_ratio)/2, height/2 ], - [(width * width_ratio)/2, height/2 ], - [(width * width_ratio)/2, height/2 ] + [(size[0] * width_ratio)/2, size[1]/2 ], + [(size[0] * width_ratio)/2, size[1]/2 ], + [(size[0] * width_ratio)/2, size[1]/2 ], + [(size[0] * width_ratio)/2, size[1]/2 ], + [(size[0] * width_ratio)/2, size[1]/2 ], + [(size[0] * width_ratio)/2, size[1]/2 ] ]; // no rounding on the corners at all function skin_iso_enter_shape(size, delta, progress, thickness_difference) = - iso_enter_vertices(size.x, size.y, unit_length(1.25) / unit_length(1.5), unit_length(1) / unit_length(2), thickness_difference/2 + delta.x * progress/2, thickness_difference/2 + delta.y * progress/2); -function sign_x(i,n) = - i < n/4 || i > n*3/4 ? 1 : - i > n/4 && i < n*3/4 ? -1 : - 0; - -function sign_y(i,n) = - i > 0 && i < n/2 ? 1 : - i > n/2 ? -1 : - 0; - - -function rectangle_profile(size=[1,1],fn=32) = [ - for (index = [0:fn-1]) - let(a = index/fn*360) - sign_x(index, fn) * [size[0]/2,0] - + sign_y(index, fn) * [0,size[1]/2] -]; - -function rounded_rectangle_profile(size=[1,1],r=1,fn=32) = [ - let(max_fn = max(fn,8)) - for (index = [0:max_fn-1]) - let(a = index/max_fn*360) - r * [cos(a), sin(a)] - + sign_x(index, max_fn) * [size[0]/2-r,0] - + sign_y(index, max_fn) * [0,size[1]/2-r] -]; - -function double_rounded_rectangle_profile(size=[1,1], r=1, fn=32) = [ - let(max_fn = max(fn,8)) - for (index = [0:max_fn-1]) - let(a = index/max_fn*360) - r * [cos(a), sin(a)] - + sign_x(index, max_fn) * [size[0]/2-r,0] - + sign_y(index, max_fn) * [0,size[1]/2-r] -]; - + polyRound( + add_rounding( + iso_enter_vertices( + size, + delta, + progress, + thickness_difference + ), + $corner_radius + ), + $shape_facets + ); // rounded square shape with additional sculpting functions to better approximate // When sculpting sides, how much in should the tops come -$side_sculpting_factor = 4.5; +side_sculpting_factor = 4.5; // When sculpting corners, how much extra radius should be added -$corner_sculpting_factor = 1; +corner_sculpting_factor = 1; // When doing more side sculpting corners, how much extra radius should be added -$more_side_sculpting_factor = 0.4; +more_side_sculpting_factor = 0.4; // side sculpting functions // bows the sides out on stuff like SA and DSA keycaps -function side_sculpting(progress) = (1 - progress) * $side_sculpting_factor; +function side_sculpting(progress) = (1 - progress) * side_sculpting_factor; // makes the rounded corners of the keycap grow larger as they move upwards -function corner_sculpting(progress) = pow(progress, 2) * $corner_sculpting_factor; +function corner_sculpting(progress) = pow(progress, 2) * corner_sculpting_factor; module sculpted_square_shape(size, delta, progress) { width = size[0]; @@ -1074,13 +2145,40 @@ module sculpted_square_shape(size, delta, progress) { offset(r = extra_corner_radius_this_slice, $fa=360/$shape_facets) { offset(r = -extra_corner_radius_this_slice) { - side_rounded_square(square_size, r = $more_side_sculpting_factor * progress); + side_rounded_square(square_size, r = more_side_sculpting_factor * progress); } } } -// fudging the hell out of this, I don't remember what the negative-offset-positive-offset was doing in the module above -// also no 'bowed' square shape for now +function new_side_rounded_square(size, r, cornerRadius=0) = + let( + width = (size.x - r)/2, + height = (size.y - r)/2, + + // fudge numbers! the radius conflict resolution in polyround smooths out + // the entire shape based on the ratios between conflicting radii. bumping + // these up makes the whole shape more fluid + widthRadius = r ? width*8 : 0, + heightRadius = r ? height*8 : 0, + + bow = r/2, + + // close enough :/ + facets = 360 / $shape_facets/2, + + points = [ + [-width,-height,cornerRadius], + [0,-height-bow,widthRadius], + [width,-height,cornerRadius], + [width + bow,0,heightRadius], + [width,height,cornerRadius], + [0,height + bow,widthRadius], + [-width,height,cornerRadius], + [-width-bow,0,heightRadius] + ] + ) polyRound(points,facets); + + function skin_sculpted_square_shape(size, delta, progress, thickness_difference) = let( width = size[0], @@ -1102,13 +2200,7 @@ function skin_sculpted_square_shape(size, delta, progress, thickness_difference) width - extra_width_this_slice - thickness_difference, height - extra_height_this_slice - thickness_difference ] - ) double_rounded_rectangle_profile(square_size - [extra_corner_radius_this_slice, extra_corner_radius_this_slice]/4, fn=$shape_facets, r=extra_corner_radius_this_slice/1.5 + $more_side_sculpting_factor * progress); - - /* offset(r = extra_corner_radius_this_slice) { - offset(r = -extra_corner_radius_this_slice) { - side_rounded_square(square_size, r = $more_side_sculpting_factor * progress); - } - } */ + ) new_side_rounded_square(square_size, more_side_sculpting_factor * progress, extra_corner_radius_this_slice); module side_rounded_square(size, r) { @@ -1128,58 +2220,17 @@ module side_rounded_square(size, r) { square([iw, ih], center=true); } } -function sign_x(i,n) = - i < n/4 || i > n*3/4 ? 1 : - i > n/4 && i < n*3/4 ? -1 : - 0; - -function sign_y(i,n) = - i > 0 && i < n/2 ? 1 : - i > n/2 ? -1 : - 0; - - -function rectangle_profile(size=[1,1],fn=32) = [ - for (index = [0:fn-1]) - let(a = index/fn*360) - sign_x(index, fn) * [size[0]/2,0] - + sign_y(index, fn) * [0,size[1]/2] -]; - -function rounded_rectangle_profile(size=[1,1],r=1,fn=32) = [ - let(max_fn = max(fn,8)) - for (index = [0:max_fn-1]) - let(a = index/max_fn*360) - r * [cos(a), sin(a)] - + sign_x(index, max_fn) * [size[0]/2-r,0] - + sign_y(index, max_fn) * [0,size[1]/2-r] -]; - -function double_rounded_rectangle_profile(size=[1,1], r=1, fn=32) = [ - let(max_fn = max(fn,8)) - for (index = [0:max_fn-1]) - let(a = index/max_fn*360) - r * [cos(a), sin(a)] - + sign_x(index, max_fn) * [size[0]/2-r,0] - + sign_y(index, max_fn) * [0,size[1]/2-r] -]; - -module rounded_square_shape(size, delta, progress, center = true) { - offset(r=$corner_radius, $fa=360/$shape_facets){ - square_shape([size.x - $corner_radius*2, size.y - $corner_radius*2], delta, progress); - } -} - -// for skin - -function skin_rounded_square(size, delta, progress, thickness_difference) = - rounded_rectangle_profile(size - (delta * progress), fn=$shape_facets, r=$corner_radius); +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; // I use functions when I need to compute special variables off of other special variables // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -1207,7 +2258,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -1233,44 +2284,17 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ -function sign_x(i,n) = - i < n/4 || i > n*3/4 ? 1 : - i > n/4 && i < n*3/4 ? -1 : - 0; - -function sign_y(i,n) = - i > 0 && i < n/2 ? 1 : - i > n/2 ? -1 : - 0; - - -function rectangle_profile(size=[1,1],fn=32) = [ - for (index = [0:fn-1]) - let(a = index/fn*360) - sign_x(index, fn) * [size[0]/2,0] - + sign_y(index, fn) * [0,size[1]/2] -]; - -function rounded_rectangle_profile(size=[1,1],r=1,fn=32) = [ - let(max_fn = max(fn,8)) - for (index = [0:max_fn-1]) - let(a = index/max_fn*360) - r * [cos(a), sin(a)] - + sign_x(index, max_fn) * [size[0]/2-r,0] - + sign_y(index, max_fn) * [0,size[1]/2-r] -]; - -function double_rounded_rectangle_profile(size=[1,1], r=1, fn=32) = [ - let(max_fn = max(fn,8)) - for (index = [0:max_fn-1]) - let(a = index/max_fn*360) - r * [cos(a), sin(a)] - + sign_x(index, max_fn) * [size[0]/2-r,0] - + sign_y(index, max_fn) * [0,size[1]/2-r] -]; - +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; // we do this weird key_shape_type check here because rounded_square uses // square_shape, and we want flat sides to work for that too. @@ -1293,14 +2317,23 @@ module square_shape(size, delta, progress){ // shape makes the sides flat by making the top a trapezoid. // This obviously doesn't work with rounded sides at all module flat_sided_square_shape(size, delta, progress) { - polygon(points=[ - [(-size.x + (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2, (-size.y + delta.y * progress)/2], - [(size.x - (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2,(-size.y + delta.y * progress)/2], - [(size.x - (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2], - [(-size.x + (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2] - ]); + polygon(skin_flat_sided_square_shape(size, delta, progress)); } +function skin_flat_sided_square_shape(size,delta,progress) = [ + [(-size.x + (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2, (-size.y + delta.y * progress)/2], + [(size.x - (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2,(-size.y + delta.y * progress)/2], + [(size.x - (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2], + [(-size.x + (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2] +]; + +function rectangle_profile(size) = [ + [-size.x/2, -size.y/2], + [size.x/2, -size.y/2], + [size.x/2, size.y/2], + [-size.x/2, size.y/2], +]; + function skin_square_shape(size, delta, progress, thickness_difference) = let( width = size[0], @@ -1313,7 +2346,831 @@ function skin_square_shape(size, delta, progress, thickness_difference) = width - width_difference - thickness_difference, height - height_difference - thickness_difference ] - ) rectangle_profile(square_size, fn=36); + ) $key_shape_type == "flat_sided_square" ? skin_flat_sided_square_shape(size, delta, progress) : rectangle_profile(square_size); +// Library: round-anything +// Version: 1.0 +// Author: IrevDev +// Contributors: TLC123 +// Copyright: 2020 +// License: MIT + + +function addZcoord(points,displacement)=[for(i=[0:len(points)-1])[points[i].x,points[i].y, displacement]]; +function translate3Dcoords(points,tran=[0,0,0],mult=[1,1,1])=[for(i=[0:len(points)-1])[ + (points[i].x*mult.x)+tran.x, + (points[i].y*mult.y)+tran.y, + (points[i].z*mult.z)+tran.z +]]; +function offsetPolygonPoints(points, offset=0)= +// Work sthe same as the offset does, except for the fact that instead of a 2d shape +// It works directly on polygon points +// It returns the same number of points just offset into or, away from the original shape. +// points= a series of x,y points[[x1,y1],[x2,y2],...] +// offset= amount to offset by, negative numbers go inwards into the shape, positive numbers go out +// return= a series of x,y points[[x1,y1],[x2,y2],...] +let( + isCWorCCW=sign(offset)*CWorCCW(points)*-1, + lp=len(points) +) +[for(i=[0:lp-1]) parallelFollow([ + points[listWrap(i-1,lp)], + points[i], + points[listWrap(i+1,lp)], +],thick=offset,mode=isCWorCCW)]; + +function makeCurvedPartOfPolyHedron(radiiPoints,r,fn,minR=0.01)= +// this is a private function that I'm not expecting library users to use directly +// radiiPoints= serise of x, y, r points +// r= radius of curve that will be put on the end of the extrusion +// fn= amount of subdivisions +// minR= if one of the points in radiiPoints is less than r, it's likely to converge and form a sharp edge, +// the min radius on these converged edges can be controled with minR, though because of legacy reasons it can't be 0, but can be a very small number. +// return= array of [polyhedronPoints, Polyhedronfaces, theLength of a singe layer in the curve] +let( + lp=len(radiiPoints), + radii=[for(i=[0:lp-1])radiiPoints[i].z], + isCWorCCWOverall=CWorCCW(radiiPoints), + dir=sign(r), + absR=abs(r), + fractionOffLp=1-1/fn, + allPoints=[for(fraction=[0:1/fn:1]) + let( + iterationOffset=dir*sqrt(sq(absR)-sq(fraction*absR))-dir*absR, + theOffsetPoints=offsetPolygonPoints(radiiPoints,iterationOffset), + polyRoundOffsetPoints=[for(i=[0:lp-1]) + let( + pointsAboutCurrent=[ + theOffsetPoints[listWrap(i-1,lp)], + theOffsetPoints[i], + theOffsetPoints[listWrap(i+1,lp)] + ], + isCWorCCWLocal=CWorCCW(pointsAboutCurrent), + isInternalRadius=(isCWorCCWLocal*isCWorCCWOverall)==-1, + // the radius names are only true for positive r, + // when are r is negative increasingRadius is actually decreasing and vice-vs + // increasingRadiusWithPositiveR is just to verbose of a variable name for my liking + increasingRadius=max(radii[i]-iterationOffset, minR), + decreasingRadius=max(radii[i]+iterationOffset, minR) + ) + [theOffsetPoints[i].x, theOffsetPoints[i].y, isInternalRadius? increasingRadius: decreasingRadius] + ], + pointsForThisLayer=polyRound(polyRoundOffsetPoints,fn) + ) + addZcoord(pointsForThisLayer,fraction*absR) + ], + polyhedronPoints=flatternArray(allPoints), + allLp=len(allPoints), + layerLength=len(allPoints[0]), + loopToSecondLastLayer=allLp-2, + sideFaces=[for(layerIndex=[0:loopToSecondLastLayer])let( + currentLayeroffset=layerIndex*layerLength, + nextLayeroffset=(layerIndex+1)*layerLength, + layerFaces=[for(subLayerIndex=[0:layerLength-1]) + [ + currentLayeroffset+subLayerIndex, currentLayeroffset + listWrap(subLayerIndex+1,layerLength), nextLayeroffset+listWrap(subLayerIndex+1,layerLength), nextLayeroffset+subLayerIndex] + ] + )layerFaces], + polyhedronFaces=flatternArray(sideFaces) +) +[polyhedronPoints, polyhedronFaces, layerLength]; + +function flatternRecursion(array, init=[], currentIndex)= +// this is a private function, init and currentIndex are for the function's use +// only for when it's calling itself, which is why there is a simplified version flatternArray that just calls this one +// array= array to flattern by one level of nesting +// init= the array used to cancat with the next call, only for when the function calls itself +// currentIndex= so the function can keep track of how far it's progressed through the array, only for when it's calling itself +// returns= flatterned array, by one level of nesting +let( + shouldKickOffRecursion=currentIndex==undef?1:0, + isLastIndex=currentIndex+1==len(array)?1:0, + flatArray=shouldKickOffRecursion?flatternRecursion(array,[],0): + isLastIndex?concat(init,array[currentIndex]): + flatternRecursion(array,concat(init,array[currentIndex]),currentIndex+1) +) +flatArray; + +function flatternArray(array)= +// public version of flatternRecursion, has simplified params to avoid confusion +// array= array to be flatterned +// return= array that been flatterend by one level of nesting +flatternRecursion(array); + +function offsetAllFacesBy(array,offset)=[ + // polyhedron faces are simply a list of indices to points, if your concat points together than you probably need to offset + // your faces array to points to the right place in the new list + // array= array of point indicies + // offset= number to offset all indecies by + // return= array of point indices (i.e. faces) with offset applied + for(faceIndex=[0:len(array)-1])[ + for(pointIndex=[0:len(array[faceIndex])-1])array[faceIndex][pointIndex]+offset + ] +]; + +function extrudePolygonWithRadius(radiiPoints,h=5,r1=1,r2=1,fn=4)= +// this basically calls makeCurvedPartOfPolyHedron twice to get the curved section of the final polyhedron +// and then goes about assmbling them, as the side faces and the top and bottom face caps are missing +// radiiPoints= series of [x,y,r] points, +// h= height of the extrude (total including radius sections) +// r1,r2= define the radius at the top and bottom of the extrud respectively, negative number flange out the extrude +// fn= number of subdivisions +// returns= [polyhedronPoints, polyhedronFaces] +let( + // top is the top curved part of the extrude + top=makeCurvedPartOfPolyHedron(radiiPoints,r1,fn), + topRadiusPoints=translate3Dcoords(top[0],[0,0,h-r1]), + singeLayerLength=top[2], + topRadiusFaces=top[1], + radiusPointsLength=len(topRadiusPoints), // is the same length as bottomRadiusPoints + // bottom is the bottom curved part of the extrude + bottom=makeCurvedPartOfPolyHedron(radiiPoints,r2,fn), + // Z axis needs to be multiplied by -1 to flip it so the radius is going in the right direction [1,1,-1] + bottomRadiusPoints=translate3Dcoords(bottom[0],[0,0,abs(r2)],[1,1,-1]), + // becaues the points will be all concatenated into the same array, and the bottom points come second, than + // the original indices the faces are points towards are wrong and need to have an offset applied to them + bottomRadiusFaces=offsetAllFacesBy(bottom[1],radiusPointsLength), + // all of the side panel of the extrusion, connecting points from the inner layers of each + // of the curved sections + sideFaces=[for(i=[0:singeLayerLength-1])[ + i, + listWrap(i+1,singeLayerLength), + radiusPointsLength + listWrap(i+1,singeLayerLength), + radiusPointsLength + i + ]], + // both of these caps are simple every point from the last layer of the radius points + topCapFace=[for(i=[0:singeLayerLength-1])radiusPointsLength-singeLayerLength+i], + bottomCapFace=[for(i=[0:singeLayerLength-1])radiusPointsLength*2-singeLayerLength+i], + finalPolyhedronPoints=concat(topRadiusPoints,bottomRadiusPoints), + finalPolyhedronFaces=concat(topRadiusFaces,bottomRadiusFaces, sideFaces, [topCapFace], [bottomCapFace]) +) +[ + finalPolyhedronPoints, + finalPolyhedronFaces +]; + +module polyRoundExtrude(radiiPoints,length=5,r1=1,r2=1,fn=10,convexity=10) { + polyhedronPointsNFaces=extrudePolygonWithRadius(radiiPoints,length,r1,r2,fn); + polyhedron(points=polyhedronPointsNFaces[0], faces=polyhedronPointsNFaces[1], convexity=convexity); +} + + +// testingInternals(); +module testingInternals(){ + //example of rounding random points, this has no current use but is a good demonstration + random=[for(i=[0:20])[rnd(0,50),rnd(0,50),/*rnd(0,30)*/1000]]; + R =polyRound(random,7); + translate([-25,25,0]){ + polyline(R); + } + + //example of different modes of the CentreN2PointsArc() function 0=shortest arc, 1=longest arc, 2=CW, 3=CCW + p1=[0,5];p2=[10,5];centre=[5,0]; + translate([60,0,0]){ + color("green"){ + polygon(CentreN2PointsArc(p1,p2,centre,0,20));//draws the shortest arc + } + color("cyan"){ + polygon(CentreN2PointsArc(p1,p2,centre,1,20));//draws the longest arc + } + } + translate([75,0,0]){ + color("purple"){ + polygon(CentreN2PointsArc(p1,p2,centre,2,20));//draws the arc CW (which happens to be the short arc) + } + color("red"){ + polygon(CentreN2PointsArc(p2,p1,centre,2,20));//draws the arc CW but p1 and p2 swapped order resulting in the long arc being drawn + } + } + + radius=6; + radiipoints=[[0,0,0],[10,20,radius],[20,0,0]]; + tangentsNcen=round3points(radiipoints); + translate([10,0,0]){ + for(i=[0:2]){ + color("red")translate(getpoints(radiipoints)[i])circle(1);//plots the 3 input points + color("cyan")translate(tangentsNcen[i])circle(1);//plots the two tangent poins and the circle centre + } + translate([tangentsNcen[2][0],tangentsNcen[2][1],-0.2])circle(r=radius,$fn=25);//draws the cirle + %polygon(getpoints(radiipoints));//draws a polygon + } +} + +function polyRound(radiipoints,fn=5,mode=0)= + /*Takes a list of radii points of the format [x,y,radius] and rounds each point + with fn resolution + mode=0 - automatic radius limiting - DEFAULT + mode=1 - Debug, output radius reduction for automatic radius limiting + mode=2 - No radius limiting*/ + let( + p=getpoints(radiipoints), //make list of coordinates without radii + Lp=len(p), + //remove the middle point of any three colinear points, otherwise adding a radius to the middle of a straigh line causes problems + radiiPointsWithoutTrippleColinear=[ + for(i=[0:len(p)-1]) if( + // keep point if it isn't colinear or if the radius is 0 + !isColinear( + p[listWrap(i-1,Lp)], + p[listWrap(i+0,Lp)], + p[listWrap(i+1,Lp)] + )|| + p[listWrap(i+0,Lp)].z!=0 + ) radiipoints[listWrap(i+0,Lp)] + ], + newrp2=processRadiiPoints(radiiPointsWithoutTrippleColinear), + plusMinusPointRange=mode==2?1:2, + temp=[ + for(i=[0:len(newrp2)-1]) //for each point in the radii array + let( + thepoints=[for(j=[-plusMinusPointRange:plusMinusPointRange])newrp2[listWrap(i+j,len(newrp2))]],//collect 5 radii points + temp2=mode==2?round3points(thepoints,fn):round5points(thepoints,fn,mode) + ) + mode==1?temp2:newrp2[i][2]==0? + [[newrp2[i][0],newrp2[i][1]]]: //return the original point if the radius is 0 + CentreN2PointsArc(temp2[0],temp2[1],temp2[2],0,fn) //return the arc if everything is normal + ] + ) + [for (a = temp) for (b = a) b];//flattern and return the array + +function round5points(rp,fn,debug=0)= + rp[2][2]==0&&debug==0?[[rp[2][0],rp[2][1]]]://return the middle point if the radius is 0 + rp[2][2]==0&&debug==1?0://if debug is enabled and the radius is 0 return 0 + let( + p=getpoints(rp), //get list of points + r=[for(i=[1:3]) abs(rp[i][2])],//get the centre 3 radii + //start by determining what the radius should be at point 3 + //find angles at points 2 , 3 and 4 + a2=cosineRuleAngle(p[0],p[1],p[2]), + a3=cosineRuleAngle(p[1],p[2],p[3]), + a4=cosineRuleAngle(p[2],p[3],p[4]), + //find the distance between points 2&3 and between points 3&4 + d23=pointDist(p[1],p[2]), + d34=pointDist(p[2],p[3]), + //find the radius factors + F23=(d23*tan(a2/2)*tan(a3/2))/(r[0]*tan(a3/2)+r[1]*tan(a2/2)), + F34=(d34*tan(a3/2)*tan(a4/2))/(r[1]*tan(a4/2)+r[2]*tan(a3/2)), + newR=min(r[1],F23*r[1],F34*r[1]),//use the smallest radius + //now that the radius has been determined, find tangent points and circle centre + tangD=newR/tan(a3/2),//distance to the tangent point from p3 + circD=newR/sin(a3/2),//distance to the circle centre from p3 + //find the angle from the p3 + an23=getAngle(p[1],p[2]),//angle from point 3 to 2 + an34=getAngle(p[3],p[2]),//angle from point 3 to 4 + //find tangent points + t23=[p[2][0]-cos(an23)*tangD,p[2][1]-sin(an23)*tangD],//tangent point between points 2&3 + t34=[p[2][0]-cos(an34)*tangD,p[2][1]-sin(an34)*tangD],//tangent point between points 3&4 + //find circle centre + tmid=getMidpoint(t23,t34),//midpoint between the two tangent points + anCen=getAngle(tmid,p[2]),//angle from point 3 to circle centre + cen=[p[2][0]-cos(anCen)*circD,p[2][1]-sin(anCen)*circD] + ) + //circle center by offseting from point 3 + //determine the direction of rotation + debug==1?//if debug in disabled return arc (default) + (newR-r[1]): + [t23,t34,cen]; + +function round3points(rp,fn)= + rp[1][2]==0?[[rp[1][0],rp[1][1]]]://return the middle point if the radius is 0 + let( + p=getpoints(rp), //get list of points + r=rp[1][2],//get the centre 3 radii + ang=cosineRuleAngle(p[0],p[1],p[2]),//angle between the lines + //now that the radius has been determined, find tangent points and circle centre + tangD=r/tan(ang/2),//distance to the tangent point from p2 + circD=r/sin(ang/2),//distance to the circle centre from p2 + //find the angles from the p2 with respect to the postitive x axis + angleFromPoint1ToPoint2=getAngle(p[0],p[1]), + angleFromPoint2ToPoint3=getAngle(p[2],p[1]), + //find tangent points + t12=[p[1][0]-cos(angleFromPoint1ToPoint2)*tangD,p[1][1]-sin(angleFromPoint1ToPoint2)*tangD],//tangent point between points 1&2 + t23=[p[1][0]-cos(angleFromPoint2ToPoint3)*tangD,p[1][1]-sin(angleFromPoint2ToPoint3)*tangD],//tangent point between points 2&3 + //find circle centre + tmid=getMidpoint(t12,t23),//midpoint between the two tangent points + angCen=getAngle(tmid,p[1]),//angle from point 2 to circle centre + cen=[p[1][0]-cos(angCen)*circD,p[1][1]-sin(angCen)*circD] //circle center by offseting from point 2 + ) + [t12,t23,cen]; + +function parallelFollow(rp,thick=4,minR=1,mode=1)= + //rp[1][2]==0?[rp[1][0],rp[1][1],0]://return the middle point if the radius is 0 + thick==0?[rp[1][0],rp[1][1],0]://return the middle point if the radius is 0 + let( + p=getpoints(rp), //get list of points + r=thick,//get the centre 3 radii + ang=cosineRuleAngle(p[0],p[1],p[2]),//angle between the lines + //now that the radius has been determined, find tangent points and circle centre + tangD=r/tan(ang/2),//distance to the tangent point from p2 + sgn=CWorCCW(rp),//rotation of the three points cw or ccw?let(sgn=mode==0?1:-1) + circD=mode*sgn*r/sin(ang/2),//distance to the circle centre from p2 + //find the angles from the p2 with respect to the postitive x axis + angleFromPoint1ToPoint2=getAngle(p[0],p[1]), + angleFromPoint2ToPoint3=getAngle(p[2],p[1]), + //find tangent points + t12=[p[1][0]-cos(angleFromPoint1ToPoint2)*tangD,p[1][1]-sin(angleFromPoint1ToPoint2)*tangD],//tangent point between points 1&2 + t23=[p[1][0]-cos(angleFromPoint2ToPoint3)*tangD,p[1][1]-sin(angleFromPoint2ToPoint3)*tangD],//tangent point between points 2&3 + //find circle centre + tmid=getMidpoint(t12,t23),//midpoint between the two tangent points + angCen=getAngle(tmid,p[1]),//angle from point 2 to circle centre + cen=[p[1][0]-cos(angCen)*circD,p[1][1]-sin(angCen)*circD],//circle center by offseting from point 2 + outR=max(minR,rp[1][2]-thick*sgn*mode) //ensures radii are never too small. + ) + concat(cen,outR); + +function findPoint(ang1,refpoint1,ang2,refpoint2,r=0)= + let( + m1=tan(ang1), + c1=refpoint1.y-m1*refpoint1.x, + m2=tan(ang2), + c2=refpoint2.y-m2*refpoint2.x, + outputX=(c2-c1)/(m1-m2), + outputY=m1*outputX+c1 + ) + [outputX,outputY,r]; + +function beamChain(radiiPoints,offset1=0,offset2,mode=0,minR=0,startAngle,endAngle)= + /*This function takes a series of radii points and plots points to run along side at a consistant distance, think of it as offset but for line instead of a polygon + radiiPoints=radii points, + offset1 & offset2= The two offsets that give the beam it's thickness. When using with mode=2 only offset1 is needed as there is no return path for the polygon + minR=min radius, if all of your radii are set properly within the radii points this value can be ignored + startAngle & endAngle= Angle at each end of the beam, different mode determine if this angle is relative to the ending legs of the beam or absolute. + mode=1 - include endpoints startAngle&2 are relative to the angle of the last two points and equal 90deg if not defined + mode=2 - Only the forward path is defined, useful for combining the beam with other radii points, see examples for a use-case. + mode=3 - include endpoints startAngle&2 are absolute from the x axis and are 0 if not defined + negative radiuses only allowed for the first and last radii points + + As it stands this function could probably be tidied a lot, but it works, I'll tidy later*/ + let( + offset2undef=offset2==undef?1:0, + offset2=offset2undef==1?0:offset2, + CWorCCW1=sign(offset1)*CWorCCW(radiiPoints), + CWorCCW2=sign(offset2)*CWorCCW(radiiPoints), + offset1=abs(offset1), + offset2b=abs(offset2), + Lrp3=len(radiiPoints)-3, + Lrp=len(radiiPoints), + startAngle=mode==0&&startAngle==undef? + getAngle(radiiPoints[0],radiiPoints[1])+90: + mode==2&&startAngle==undef? + 0: + mode==0? + getAngle(radiiPoints[0],radiiPoints[1])+startAngle: + startAngle, + endAngle=mode==0&&endAngle==undef? + getAngle(radiiPoints[Lrp-1],radiiPoints[Lrp-2])+90: + mode==2&&endAngle==undef? + 0: + mode==0? + getAngle(radiiPoints[Lrp-1],radiiPoints[Lrp-2])+endAngle: + endAngle, + OffLn1=[for(i=[0:Lrp3]) offset1==0?radiiPoints[i+1]:parallelFollow([radiiPoints[i],radiiPoints[i+1],radiiPoints[i+2]],offset1,minR,mode=CWorCCW1)], + OffLn2=[for(i=[0:Lrp3]) offset2==0?radiiPoints[i+1]:parallelFollow([radiiPoints[i],radiiPoints[i+1],radiiPoints[i+2]],offset2b,minR,mode=CWorCCW2)], + Rp1=abs(radiiPoints[0].z), + Rp2=abs(radiiPoints[Lrp-1].z), + endP1a=findPoint(getAngle(radiiPoints[0],radiiPoints[1]), OffLn1[0], startAngle,radiiPoints[0], Rp1), + endP1b=findPoint(getAngle(radiiPoints[Lrp-1],radiiPoints[Lrp-2]), OffLn1[len(OffLn1)-1], endAngle,radiiPoints[Lrp-1], Rp2), + endP2a=findPoint(getAngle(radiiPoints[0],radiiPoints[1]), OffLn2[0], startAngle,radiiPoints[0], Rp1), + endP2b=findPoint(getAngle(radiiPoints[Lrp-1],radiiPoints[Lrp-2]), OffLn2[len(OffLn1)-1], endAngle,radiiPoints[Lrp-1], Rp2), + absEnda=getAngle(endP1a,endP2a), + absEndb=getAngle(endP1b,endP2b), + negRP1a=[cos(absEnda)*radiiPoints[0].z*10+endP1a.x, sin(absEnda)*radiiPoints[0].z*10+endP1a.y, 0.0], + negRP2a=[cos(absEnda)*-radiiPoints[0].z*10+endP2a.x, sin(absEnda)*-radiiPoints[0].z*10+endP2a.y, 0.0], + negRP1b=[cos(absEndb)*radiiPoints[Lrp-1].z*10+endP1b.x, sin(absEndb)*radiiPoints[Lrp-1].z*10+endP1b.y, 0.0], + negRP2b=[cos(absEndb)*-radiiPoints[Lrp-1].z*10+endP2b.x, sin(absEndb)*-radiiPoints[Lrp-1].z*10+endP2b.y, 0.0], + OffLn1b=(mode==0||mode==2)&&radiiPoints[0].z<0&&radiiPoints[Lrp-1].z<0? + concat([negRP1a],[endP1a],OffLn1,[endP1b],[negRP1b]) + :(mode==0||mode==2)&&radiiPoints[0].z<0? + concat([negRP1a],[endP1a],OffLn1,[endP1b]) + :(mode==0||mode==2)&&radiiPoints[Lrp-1].z<0? + concat([endP1a],OffLn1,[endP1b],[negRP1b]) + :mode==0||mode==2? + concat([endP1a],OffLn1,[endP1b]) + : + OffLn1, + OffLn2b=(mode==0||mode==2)&&radiiPoints[0].z<0&&radiiPoints[Lrp-1].z<0? + concat([negRP2a],[endP2a],OffLn2,[endP2b],[negRP2b]) + :(mode==0||mode==2)&&radiiPoints[0].z<0? + concat([negRP2a],[endP2a],OffLn2,[endP2b]) + :(mode==0||mode==2)&&radiiPoints[Lrp-1].z<0? + concat([endP2a],OffLn2,[endP2b],[negRP2b]) + :mode==0||mode==2? + concat([endP2a],OffLn2,[endP2b]) + : + OffLn2 + )//end of let() + offset2undef==1?OffLn1b:concat(OffLn2b,revList(OffLn1b)); + +function revList(list)=//reverse list + let(Llist=len(list)-1) + [for(i=[0:Llist]) list[Llist-i]]; + +function CWorCCW(p)= + let( + Lp=len(p), + e=[for(i=[0:Lp-1]) + (p[listWrap(i+0,Lp)].x-p[listWrap(i+1,Lp)].x)*(p[listWrap(i+0,Lp)].y+p[listWrap(i+1,Lp)].y) + ] + ) + sign(sum(e)); + +function CentreN2PointsArc(p1,p2,cen,mode=0,fn)= + /* This function plots an arc from p1 to p2 with fn increments using the cen as the centre of the arc. + the mode determines how the arc is plotted + mode==0, shortest arc possible + mode==1, longest arc possible + mode==2, plotted clockwise + mode==3, plotted counter clockwise + */ + let( + isCWorCCW=CWorCCW([cen,p1,p2]),//determine the direction of rotation + //determine the arc angle depending on the mode + p1p2Angle=cosineRuleAngle(p2,cen,p1), + arcAngle= + mode==0?p1p2Angle: + mode==1?p1p2Angle-360: + mode==2&&isCWorCCW==-1?p1p2Angle: + mode==2&&isCWorCCW== 1?p1p2Angle-360: + mode==3&&isCWorCCW== 1?p1p2Angle: + mode==3&&isCWorCCW==-1?p1p2Angle-360: + cosineRuleAngle(p2,cen,p1), + r=pointDist(p1,cen),//determine the radius + p1Angle=getAngle(cen,p1) //angle of line 1 + ) + [for(i=[0:fn]) + let(angleIncrement=(arcAngle/fn)*i*isCWorCCW) + [cos(p1Angle+angleIncrement)*r+cen.x,sin(p1Angle+angleIncrement)*r+cen.y]]; + +function translateRadiiPoints(radiiPoints,tran=[0,0],rot=0)= + [for(i=radiiPoints) + let( + a=getAngle([0,0],[i.x,i.y]),//get the angle of the this point + h=pointDist([0,0],[i.x,i.y]) //get the hypotenuse/radius + ) + [h*cos(a+rot)+tran.x,h*sin(a+rot)+tran.y,i.z]//calculate the point's new position + ]; + +module round2d(OR=3,IR=1){ + offset(OR,$fn=100){ + offset(-IR-OR,$fn=100){ + offset(IR,$fn=100){ + children(); + } + } + } +} + +module shell2d(offset1,offset2=0,minOR=0,minIR=0){ + difference(){ + round2d(minOR,minIR){ + offset(max(offset1,offset2)){ + children(0);//original 1st child forms the outside of the shell + } + } + round2d(minIR,minOR){ + difference(){//round the inside cutout + offset(min(offset1,offset2)){ + children(0);//shrink the 1st child to form the inside of the shell + } + if($children>1){ + for(i=[1:$children-1]){ + children(i);//second child and onwards is used to add material to inside of the shell + } + } + } + } + } +} + +module internalSq(size,r,center=0){ + tran=center==1?[0,0]:size/2; + translate(tran){ + square(size,true); + offs=sin(45)*r; + for(i=[-1,1],j=[-1,1]){ + translate([(size.x/2-offs)*i,(size.y/2-offs)*j])circle(r); + } + } +} + +module extrudeWithRadius(length,r1=0,r2=0,fn=30){ + n1=sign(r1);n2=sign(r2); + r1=abs(r1);r2=abs(r2); + translate([0,0,r1]){ + linear_extrude(length-r1-r2){ + children(); + } + } + for(i=[0:fn-1]){ + translate([0,0,i/fn*r1]){ + linear_extrude(r1/fn+0.01){ + offset(n1*sqrt(sq(r1)-sq(r1-i/fn*r1))-n1*r1){ + children(); + } + } + } + translate([0,0,length-r2+i/fn*r2]){ + linear_extrude(r2/fn+0.01){ + offset(n2*sqrt(sq(r2)-sq(i/fn*r2))-n2*r2){ + children(); + } + } + } + } +} + +function mirrorPoints(radiiPoints,rot=0,endAttenuation=[0,0])= //mirrors a list of points about Y, ignoring the first and last points and returning them in reverse order for use with polygon or polyRound + let( + a=translateRadiiPoints(radiiPoints,[0,0],-rot), + temp3=[for(i=[0+endAttenuation[0]:len(a)-1-endAttenuation[1]]) + [a[i][0],-a[i][1],a[i][2]] + ], + temp=translateRadiiPoints(temp3,[0,0],rot), + temp2=revList(temp3) + ) + concat(radiiPoints,temp2); + +function processRadiiPoints(rp)= + [for(i=[0:len(rp)-1]) + processRadiiPoints2(rp,i) + ]; + +function processRadiiPoints2(list,end=0,idx=0,result=0)= + idx>=end+1?result: + processRadiiPoints2(list,end,idx+1,relationalRadiiPoints(result,list[idx])); + +function cosineRuleBside(a,c,C)=c*cos(C)-sqrt(sq(a)+sq(c)+sq(cos(C))-sq(c)); + +function absArelR(po,pn)= + let( + th2=atan(po[1]/po[0]), + r2=sqrt(sq(po[0])+sq(po[1])), + r3=cosineRuleBside(r2,pn[1],th2-pn[0]) + ) + [cos(pn[0])*r3,sin(pn[0])*r3,pn[2]]; + +function relationalRadiiPoints(po,pi)= + let( + p0=pi[0], + p1=pi[1], + p2=pi[2], + pv0=pi[3][0], + pv1=pi[3][1], + pt0=pi[3][2], + pt1=pi[3][3], + pn= + (pv0=="y"&&pv1=="x")||(pv0=="r"&&pv1=="a")||(pv0=="y"&&pv1=="a")||(pv0=="x"&&pv1=="a")||(pv0=="y"&&pv1=="r")||(pv0=="x"&&pv1=="r")? + [p1,p0,p2,concat(pv1,pv0,pt1,pt0)]: + [p0,p1,p2,concat(pv0,pv1,pt0,pt1)], + n0=pn[0], + n1=pn[1], + n2=pn[2], + nv0=pn[3][0], + nv1=pn[3][1], + nt0=pn[3][2], + nt1=pn[3][3], + temp= + pn[0]=="l"? + [po[0],pn[1],pn[2]] + :pn[1]=="l"? + [pn[0],po[1],pn[2]] + :nv0==undef? + [pn[0],pn[1],pn[2]]//abs x, abs y as default when undefined + :nv0=="a"? + nv1=="r"? + nt0=="a"? + nt1=="a"||nt1==undef? + [cos(n0)*n1,sin(n0)*n1,n2]//abs angle, abs radius + :absArelR(po,pn)//abs angle rel radius + :nt1=="r"||nt1==undef? + [po[0]+cos(pn[0])*pn[1],po[1]+sin(pn[0])*pn[1],pn[2]]//rel angle, rel radius + :[pn[0],pn[1],pn[2]]//rel angle, abs radius + :nv1=="x"? + nt0=="a"? + nt1=="a"||nt1==undef? + [pn[1],pn[1]*tan(pn[0]),pn[2]]//abs angle, abs x + :[po[0]+pn[1],(po[0]+pn[1])*tan(pn[0]),pn[2]]//abs angle rel x + :nt1=="r"||nt1==undef? + [po[0]+pn[1],po[1]+pn[1]*tan(pn[0]),pn[2]]//rel angle, rel x + :[pn[1],po[1]+(pn[1]-po[0])*tan(pn[0]),pn[2]]//rel angle, abs x + :nt0=="a"? + nt1=="a"||nt1==undef? + [pn[1]/tan(pn[0]),pn[1],pn[2]]//abs angle, abs y + :[(po[1]+pn[1])/tan(pn[0]),po[1]+pn[1],pn[2]]//abs angle rel y + :nt1=="r"||nt1==undef? + [po[0]+(pn[1]-po[0])/tan(90-pn[0]),po[1]+pn[1],pn[2]]//rel angle, rel y + :[po[0]+(pn[1]-po[1])/tan(pn[0]),pn[1],pn[2]]//rel angle, abs y + :nv0=="r"? + nv1=="x"? + nt0=="a"? + nt1=="a"||nt1==undef? + [pn[1],sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1])),pn[2]]//abs radius, abs x + :[po[0]+pn[1],sign(pn[0])*sqrt(sq(pn[0])-sq(po[0]+pn[1])),pn[2]]//abs radius rel x + :nt1=="r"||nt1==undef? + [po[0]+pn[1],po[1]+sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1])),pn[2]]//rel radius, rel x + :[pn[1],po[1]+sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1]-po[0])),pn[2]]//rel radius, abs x + :nt0=="a"? + nt1=="a"||nt1==undef? + [sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1])),pn[1],pn[2]]//abs radius, abs y + :[sign(pn[0])*sqrt(sq(pn[0])-sq(po[1]+pn[1])),po[1]+pn[1],pn[2]]//abs radius rel y + :nt1=="r"||nt1==undef? + [po[0]+sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1])),po[1]+pn[1],pn[2]]//rel radius, rel y + :[po[0]+sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1]-po[1])),pn[1],pn[2]]//rel radius, abs y + :nt0=="a"? + nt1=="a"||nt1==undef? + [pn[0],pn[1],pn[2]]//abs x, abs y + :[pn[0],po[1]+pn[1],pn[2]]//abs x rel y + :nt1=="r"||nt1==undef? + [po[0]+pn[0],po[1]+pn[1],pn[2]]//rel x, rel y + :[po[0]+pn[0],pn[1],pn[2]]//rel x, abs y + ) + temp; + +function invtan(run,rise)= + let(a=abs(atan(rise/run))) + rise==0&&run>0? + 0:rise>0&&run>0? + a:rise>0&&run==0? + 90:rise>0&&run<0? + 180-a:rise==0&&run<0? + 180:rise<0&&run<0? + a+180:rise<0&&run==0? + 270:rise<0&&run>0? + 360-a:"error"; + +function cosineRuleAngle(p1,p2,p3)= + let( + p12=abs(pointDist(p1,p2)), + p13=abs(pointDist(p1,p3)), + p23=abs(pointDist(p2,p3)) + ) + acos((sq(p23)+sq(p12)-sq(p13))/(2*p23*p12)); + +function sum(list, idx = 0, result = 0) = + idx >= len(list) ? result : sum(list, idx + 1, result + list[idx]); + +function sq(x)=x*x; +function getGradient(p1,p2)=(p2.y-p1.y)/(p2.x-p1.x); +function getAngle(p1,p2)=p1==p2?0:invtan(p2[0]-p1[0],p2[1]-p1[1]); +function getMidpoint(p1,p2)=[(p1[0]+p2[0])/2,(p1[1]+p2[1])/2]; //returns the midpoint of two points +function pointDist(p1,p2)=sqrt(abs(sq(p1[0]-p2[0])+sq(p1[1]-p2[1]))); //returns the distance between two points +function isColinear(p1,p2,p3)=getGradient(p1,p2)==getGradient(p2,p3)?1:0;//return 1 if 3 points are colinear +module polyline(p, width=0.3) { + for(i=[0:max(0,len(p)-1)]){ + color([i*1/len(p),1-i*1/len(p),0,0.5])line(p[i],p[listWrap(i+1,len(p) )],width); + } +} // polyline plotter +module line(p1, p2 ,width=0.3) { // single line plotter + hull() { + translate(p1){ + circle(width); + } + translate(p2){ + circle(width); + } + } +} + +function getpoints(p)=[for(i=[0:len(p)-1])[p[i].x,p[i].y]];// gets [x,y]list of[x,y,r]list +function listWrap(x,x_max=1,x_min=0) = (((x - x_min) % (x_max - x_min)) + (x_max - x_min)) % (x_max - x_min) + x_min; // wraps numbers inside boundaries +function rnd(a = 1, b = 0, s = []) = + s == [] ? + (rands(min(a, b), max( a, b), 1)[0]):(rands(min(a, b), max(a, b), 1, s)[0]); // nice rands wrapper + +module rounded_square_shape(size, delta, progress, center = true) { + offset(r=$corner_radius, $fa=360/$shape_facets){ + square_shape([size.x - $corner_radius*2, size.y - $corner_radius*2], delta, progress); + } +} + +// for skin +function skin_rounded_square(size, delta, progress, thickness_difference) = + polyRound(add_rounding(rectangle_profile(size - (delta * progress)), $corner_radius), $shape_facets/4); +// a safe theoretical distance between two vertices such that they don't collapse. hard to use +SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; + +// I use functions when I need to compute special variables off of other special variables +// functions need to be explicitly included, unlike special variables, which +// just need to have been set before they are used. hence this file + +function stem_height() = $total_depth - $dish_depth - $stem_inset; + +// cherry stem dimensions +function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; + +// cherry stabilizer stem dimensions +function outer_cherry_stabilizer_stem(slop) = [4.85 - slop * 2, 6.05 - slop * 2]; + +// box (kailh) switches have a bit less to work with +function outer_box_cherry_stem(slop) = [6 - slop, 6 - slop]; + +// .005 purely for aesthetics, to get rid of that ugly crosshatch +function cherry_cross(slop, extra_vertical = 0) = [ + // horizontal tine + [4.03 + slop, 1.25 + slop / 3], + // vertical tine + [1.15 + slop / 3, 4.23 + extra_vertical + slop / 3 + SMALLEST_POSSIBLE], +]; + +// actual mm key width and height +function total_key_width(delta = 0) = $bottom_key_width + $unit * ($key_length - 1) - delta; +function total_key_height(delta = 0) = $bottom_key_height + $unit * ($key_height - 1) - delta; + +// actual mm key width and height at the top +function top_total_key_width() = $bottom_key_width + ($unit * ($key_length - 1)) - $width_difference; +function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1)) - $height_difference; + +function side_tilt(column) = asin($unit * column / $double_sculpt_radius); +// tan of 0 is 0, division by 0 is nan, so we have to guard +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; + +// (I think) extra length of the side of the keycap due to the keytop being tilted. +// necessary for calculating flat sided keycaps +function vertical_inclination_due_to_top_tilt() = sin($top_tilt) * (top_total_key_height() - $corner_radius * 2) * 0.5; +// how much you have to expand the front or back of the keytop to make the side +// of the keycap a flat plane. 1 = front, -1 = back +// I derived this through a bunch of trig reductions I don't really understand. +function extra_keytop_length_for_flat_sides() = ($width_difference * vertical_inclination_due_to_top_tilt()) / ($total_depth); + +// 3d surface functions (still in beta) + +// monotonically increasing function that distributes the points of the surface mesh +// only for polar_3d_surface right now +// if it's linear it's a grid. sin(dim) * size concentrates detail around the edges +function surface_distribution_function(dim, size) = sin(dim) * size; + +// the function that actually determines what the surface is. +// feel free to override, the last one wins + +// debug +function surface_function(x,y) = 1; +// cylindrical +function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); +// spherical +function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ +/* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; + +// we do this weird key_shape_type check here because rounded_square uses +// square_shape, and we want flat sides to work for that too. +// could be refactored, idk +module square_shape(size, delta, progress){ + if ($key_shape_type == "flat_sided_square") { + flat_sided_square_shape(size, delta,progress); + } else { + square(size - delta * progress, center = true); + } +} +/* +[-size.x /2,-size.y / 2], +[size.x / 2,-size.y / 2], +[size.x / 2, size.y / 2], +[-size.x / 2, size.y / 2] */ + +// for side-printed keycaps. Any amount of top tilt (on a keycap with a smaller +// top than bottom) makes the left and right side of the keycap convex. This +// shape makes the sides flat by making the top a trapezoid. +// This obviously doesn't work with rounded sides at all +module flat_sided_square_shape(size, delta, progress) { + polygon(skin_flat_sided_square_shape(size, delta, progress)); +} + +function skin_flat_sided_square_shape(size,delta,progress) = [ + [(-size.x + (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2, (-size.y + delta.y * progress)/2], + [(size.x - (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2,(-size.y + delta.y * progress)/2], + [(size.x - (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2], + [(-size.x + (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2] +]; + +function rectangle_profile(size) = [ + [-size.x/2, -size.y/2], + [size.x/2, -size.y/2], + [size.x/2, size.y/2], + [-size.x/2, size.y/2], +]; + +function skin_square_shape(size, delta, progress, thickness_difference) = + let( + width = size[0], + height = size[1], + + width_difference = delta[0] * progress, + height_difference = delta[1] * progress, + + square_size = [ + width - width_difference - thickness_difference, + height - height_difference - thickness_difference + ] + ) $key_shape_type == "flat_sided_square" ? skin_flat_sided_square_shape(size, delta, progress) : rectangle_profile(square_size); module oblong_shape(size, delta, progress) { // .05 is because of offset. if we set offset to be half the height of the shape, and then subtract height from the shape, the height of the shape will be zero (because the shape would be [width - height, height - height]). that doesn't play well with openSCAD (understandably), so we add this tiny fudge factor to make sure the shape we offset has a positive width height = size[1] - delta[1] * progress - .05; @@ -1325,6 +3182,20 @@ module oblong_shape(size, delta, progress) { } } } +// we do this weird key_shape_type check here because rounded_square uses +// square_shape, and we want flat sides to work for that too. +// could be refactored, idk +module regular_polygon_shape(size, delta, progress, sides=6){ + // https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/undersized_circular_objects + fudge = 1/cos(180/sides); + diameter = (size.x - delta.x * progress - $corner_radius*2) * fudge; + offset(r=$corner_radius) rotate([0,0,360/sides/2]) circle(d = diameter, $fn=sides); +} + + + +// TODO not implemented +function skin_regular_polygon_shape(size, delta, progress, thickness_difference, sides=6) = echo("skin regular polygon not implemented"); // size: at progress 0, the shape is supposed to be this size // delta: at progress 1, the keycap is supposed to be size - delta @@ -1344,6 +3215,10 @@ module key_shape(size, delta, progress = 0) { square_shape(size, delta, progress); } else if ($key_shape_type == "oblong") { oblong_shape(size, delta, progress); + } else if ($key_shape_type == "hexagon") { + regular_polygon_shape(size, delta, progress); + } else if ($key_shape_type == "octagon") { + regular_polygon_shape(size, delta, progress, sides=8); } else { echo("Warning: unsupported $key_shape_type"); } @@ -1359,12 +3234,17 @@ function skin_key_shape(size, delta, progress = 0, thickness_difference) = $key_shape_type == "iso_enter" ? skin_iso_enter_shape(size, delta, progress, thickness_difference) : echo("Warning: unsupported $key_shape_type for skin shape. disable skin_extrude_shape or pick a new shape"); +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; // I use functions when I need to compute special variables off of other special variables // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -1392,7 +3272,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -1418,8 +3298,17 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; // extra length to the vertical tine of the inside cherry cross // splits the stem into halves - allows easier fitment @@ -1444,7 +3333,7 @@ module inside_cherry_cross(slop) { } } -module cherry_stem(depth, slop) { +module cherry_stem(depth, slop, throw) { difference(){ // outside shape linear_extrude(height = depth) { @@ -1456,12 +3345,17 @@ module cherry_stem(depth, slop) { inside_cherry_cross($stem_inner_slop); } } +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; // I use functions when I need to compute special variables off of other special variables // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -1489,7 +3383,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -1515,14 +3409,28 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; // I use functions when I need to compute special variables off of other special variables // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -1550,7 +3458,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -1576,8 +3484,17 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; // extra length to the vertical tine of the inside cherry cross // splits the stem into halves - allows easier fitment @@ -1602,7 +3519,7 @@ module inside_cherry_cross(slop) { } } -module cherry_stem(depth, slop) { +module cherry_stem(depth, slop, throw) { difference(){ // outside shape linear_extrude(height = depth) { @@ -1615,7 +3532,7 @@ module cherry_stem(depth, slop) { } } -module rounded_cherry_stem(depth, slop) { +module rounded_cherry_stem(depth, slop, throw) { difference(){ cylinder(d=$rounded_cherry_stem_d, h=depth); @@ -1624,12 +3541,17 @@ module rounded_cherry_stem(depth, slop) { inside_cherry_cross(slop); } } +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; // I use functions when I need to compute special variables off of other special variables // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -1657,7 +3579,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -1683,14 +3605,28 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; // I use functions when I need to compute special variables off of other special variables // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -1718,7 +3654,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -1744,8 +3680,17 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; // extra length to the vertical tine of the inside cherry cross // splits the stem into halves - allows easier fitment @@ -1770,7 +3715,7 @@ module inside_cherry_cross(slop) { } } -module cherry_stem(depth, slop) { +module cherry_stem(depth, slop, throw) { difference(){ // outside shape linear_extrude(height = depth) { @@ -1783,7 +3728,7 @@ module cherry_stem(depth, slop) { } } -module box_cherry_stem(depth, slop) { +module box_cherry_stem(depth, slop, throw) { difference(){ // outside shape linear_extrude(height = depth) { @@ -1796,12 +3741,12 @@ module box_cherry_stem(depth, slop) { inside_cherry_cross(slop); } } -module alps_stem(depth, has_brim, slop){ +module alps_stem(depth, slop, throw){ linear_extrude(height=depth) { square($alps_stem, center = true); } } -module filled_stem() { +module filled_stem(_depth, _slop, _throw) { // I broke the crap out of this stem type due to the changes I made around how stems are differenced // now that we just take the dish out of stems in order to support stuff like // bare stem keycaps (and buckling spring eventually) we can't just make a @@ -1810,12 +3755,17 @@ module filled_stem() { shape($wall_thickness); } +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; // I use functions when I need to compute special variables off of other special variables // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -1843,7 +3793,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -1869,25 +3819,34 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; // extra length to the vertical tine of the inside cherry cross // splits the stem into halves - allows easier fitment extra_vertical = 0.6; -module inside_cherry_stabilizer_cross(slop) { +module inside_cherry_stabilizer_cross(slop, throw) { // inside cross // translation purely for aesthetic purposes, to get rid of that awful lattice translate([0,0,-SMALLEST_POSSIBLE]) { - linear_extrude(height = $stem_throw) { + linear_extrude(height = throw) { square(cherry_cross(slop, extra_vertical)[0], center=true); square(cherry_cross(slop, extra_vertical)[1], center=true); } } } -module cherry_stabilizer_stem(depth, slop) { +module cherry_stabilizer_stem(depth, slop, throw) { difference(){ // outside shape linear_extrude(height = depth) { @@ -1896,25 +3855,44 @@ module cherry_stabilizer_stem(depth, slop) { } } - inside_cherry_stabilizer_cross(slop); + inside_cherry_stabilizer_cross(slop, throw); } } +separation = 5.7; + +positions = [ + [separation/2, 0], + [-separation/2, 0], +]; + +// TODO throw not used +module choc_stem(depth, slop, throw){ + for (position=positions) { + translate([position.x,position.y, depth/2]) single_choc_stem(depth, slop); + } +} + +module single_choc_stem(depth, slop) { + cube([$choc_stem.x - slop, $choc_stem.y - slop, depth], center=true); +} //whole stem, alps or cherry, trimmed to fit -module stem(stem_type, depth, slop){ +module stem(stem_type, depth, slop, throw){ if (stem_type == "alps") { - alps_stem(depth, slop); + alps_stem(depth, slop, throw); } else if (stem_type == "cherry" || stem_type == "costar_stabilizer") { - cherry_stem(depth, slop); + cherry_stem(depth, slop, throw); } else if (stem_type == "rounded_cherry") { - rounded_cherry_stem(depth, slop); + rounded_cherry_stem(depth, slop, throw); } else if (stem_type == "box_cherry") { - box_cherry_stem(depth, slop); + box_cherry_stem(depth, slop, throw); } else if (stem_type == "filled") { filled_stem(); } else if (stem_type == "cherry_stabilizer") { - cherry_stabilizer_stem(depth, slop); + cherry_stabilizer_stem(depth, slop, throw); + } else if (stem_type == "choc") { + choc_stem(depth, slop, throw); } else if (stem_type == "disable") { children(); } else { @@ -1922,12 +3900,17 @@ module stem(stem_type, depth, slop){ echo(stem_type); } } +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; // I use functions when I need to compute special variables off of other special variables // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -1955,7 +3938,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -1981,14 +3964,28 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; // I use functions when I need to compute special variables off of other special variables // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -2016,7 +4013,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -2042,8 +4039,17 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; // extra length to the vertical tine of the inside cherry cross // splits the stem into halves - allows easier fitment @@ -2068,7 +4074,7 @@ module inside_cherry_cross(slop) { } } -module cherry_stem(depth, slop) { +module cherry_stem(depth, slop, throw) { difference(){ // outside shape linear_extrude(height = depth) { @@ -2123,14 +4129,31 @@ module brim_support(stem_type, stem_support_height, slop) { inside_cherry_cross(slop); } + } else if(stem_type == "choc") { + translate([-5.7/2,0,0]) linear_extrude(height=stem_support_height) { + offset(r=1){ + square($choc_stem + [3,3], center=true); + } + } + + translate([5.7/2,0,0]) linear_extrude(height=stem_support_height) { + offset(r=1){ + square($choc_stem + [3,3], center=true); + } + } } } +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; // I use functions when I need to compute special variables off of other special variables // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -2158,7 +4181,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -2184,14 +4207,28 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; // I use functions when I need to compute special variables off of other special variables // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -2219,7 +4256,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -2245,8 +4282,17 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; // extra length to the vertical tine of the inside cherry cross // splits the stem into halves - allows easier fitment @@ -2271,7 +4317,7 @@ module inside_cherry_cross(slop) { } } -module cherry_stem(depth, slop) { +module cherry_stem(depth, slop, throw) { difference(){ // outside shape linear_extrude(height = depth) { @@ -2360,6 +4406,10 @@ module tines_support(stem_type, stem_support_height, slop) { } } else if (stem_type == "alps"){ centered_tines(stem_support_height); + } else if (stem_type == "choc"){ + if ($key_length < 2) translate([0,0,$stem_support_height / 2]) cube([total_key_width($wall_thickness)+$wall_thickness/4, 0.42, $stem_support_height], center = true); + /* translate([-5.7/2,0,$stem_support_height / 2]) cube([0.5, total_key_height($wall_thickness), $stem_support_height], center = true); */ + /* translate([5.7/2,0,$stem_support_height / 2]) cube([0.5, total_key_height($wall_thickness), $stem_support_height], center = true); */ } } @@ -2574,12 +4624,17 @@ module flat_dish(width, height, depth, inverted){ } // thanks Paul https://github.com/openscad/list-comprehension-demos/ +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; // I use functions when I need to compute special variables off of other special variables // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -2607,7 +4662,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -2633,8 +4688,17 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; module 3d_surface(size=$3d_surface_size, step=$3d_surface_step, bottom=-SMALLEST_POSSIBLE){ function p(x, y) = [ x, y, max(0,surface_function(x, y)) ]; @@ -2720,7 +4784,7 @@ module 3d_surface_dish(width, height, depth, inverted) { // skew and tilt of the top. it's a pain to calculate though scale_factor = 1.1; // the edges on this behave differently than with the previous dish implementations - scale([width*scale_factor/$3d_surface_size/2,height*scale_factor/$3d_surface_size/2,depth]) rotate([inverted ? 0:180,0,90]) polar_3d_surface(bottom=-10); + scale([width*scale_factor/$3d_surface_size/2,height*scale_factor/$3d_surface_size/2,depth]) rotate([inverted ? 0:180,0,180]) polar_3d_surface(bottom=-10); /* %scale([width*scale_factor/$3d_surface_size/2,height*scale_factor/$3d_surface_size/2,depth]) rotate([180,0,0]) polar_3d_surface(bottom=-10); */ } @@ -2750,12 +4814,17 @@ module dish(width, height, depth, inverted) { echo("WARN: $dish_type unsupported"); } } +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; // I use functions when I need to compute special variables off of other special variables // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -2783,7 +4852,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -2809,8 +4878,17 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; // TODO this define doesn't do anything besides tell me I used flat() in this file // is it better than not having it at all? module flat(stem_type, loft, height) { @@ -2856,6 +4934,14 @@ module flared(stem_type, loft, height) { square(outer_cherry_stabilizer_stem($stem_slop) - [2,2], center=true); } } + } else if (stem_type == "choc") { + // single support, just the stem + new_choc_scale = [scale_for_45(height, $choc_stem[0] + 5.7 - $stem_slop), scale_for_45(height, $choc_stem[1])]; + translate([0,0,0]) linear_extrude(height=height, scale = new_choc_scale){ + // TODO make a choc_stem() function so it can build in the slop + square([$choc_stem[0] + 5.7 - $stem_slop, $choc_stem[1] - $stem_slop], center=true); + } + } else { // always render cherry if no stem type. this includes stem_type = false! // this avoids a bug where the keycap is rendered filled when not desired @@ -2893,6 +4979,8 @@ module supports(type, stem_type, loft, height) { echo("Warning: unsupported $support_type"); } } +// features are any premade self-contained objects that go on top or inside + module keybump(depth = 0, edge_inset=0.4) { radius = 0.5; translate([0, -top_total_key_height()/2 + edge_inset, depth]){ @@ -2900,6 +4988,157 @@ module keybump(depth = 0, edge_inset=0.4) { translate([0,0,-radius]) cube([$font_size, radius*2, radius*2], true); } } +// a fake cherry keyswitch, abstracted out to maybe replace with a better one later +module cherry_keyswitch() { + union() { + hull() { + cube([15.6, 15.6, 0.01], center=true); + translate([0,1,5 - 0.01]) cube([10.5,9.5, 0.01], center=true); + } + hull() { + cube([15.6, 15.6, 0.01], center=true); + translate([0,0,-5.5]) cube([13.5,13.5,0.01], center=true); + } + } +} + +//approximate (fully depressed) cherry key to check clearances +module clearance_check() { + if($stem_type == "cherry" || $stem_type == "cherry_rounded"){ + color($warning_color){ + translate([0,0,3.6 + $stem_inset - 5]) { + cherry_keyswitch(); + } + } + } +} +module keytext(text, position, font_size, depth) { + woffset = (top_total_key_width()/3.5) * position[0]; + hoffset = (top_total_key_height()/3.5) * -position[1]; + translate([woffset, hoffset, -depth]){ + color($tertiary_color) linear_extrude(height=$dish_depth + depth){ + text(text=text, font=$font, size=font_size, halign="center", valign="center"); + } + } +} + +module legends(depth=0) { + if (len($front_legends) > 0) { + front_of_key() { + for (i=[0:len($front_legends)-1]) { + rotate([90,0,0]) keytext($front_legends[i][0], $front_legends[i][1], $front_legends[i][2], depth); + } + } + } + if (len($legends) > 0) { + top_of_key() { + for (i=[0:len($legends)-1]) { + keytext($legends[i][0], $legends[i][1], $legends[i][2], depth); + } + } + } +} +// use skin() instead of successive hulls. much more correct, and looks faster +// too, in most cases. successive hull relies on overlapping faces which are +// not good. But, skin works on vertex sets instead of shapes, which makes it +// a lot more difficult to use +module skin_extrude_shape_hull(thickness_difference, depth_difference, extra_slices = 0 ) { + skin([ + for (index = [0:$height_slices + extra_slices]) + let( + progress = (index / $height_slices), + skew_this_slice = $top_skew * progress, + x_skew_this_slice = $top_skew_x * progress, + depth_this_slice = ($total_depth - depth_difference) * progress, + tilt_this_slice = -$top_tilt / $key_height * progress, + y_tilt_this_slice = $double_sculpted ? (-$top_tilt_y / $key_length * progress) : 0 + ) + skin_shape_slice(progress, thickness_difference, skew_this_slice, x_skew_this_slice, depth_this_slice, tilt_this_slice, y_tilt_this_slice) + ]); +} + +function skin_shape_slice(progress, thickness_difference, skew_this_slice, x_skew_this_slice, depth_this_slice, tilt_this_slice, y_tilt_this_slice) = + transform( + translation([x_skew_this_slice,skew_this_slice,depth_this_slice]), + transform( + rotation([tilt_this_slice,y_tilt_this_slice,0]), + skin_key_shape([ + total_key_width(0) - thickness_difference, + total_key_height(0) - thickness_difference, + ], + [$width_difference, $height_difference], + progress, + thickness_difference + ) + ) + ); +// corollary is hull_shape_hull +// extra_slices unused, only to match argument signatures +module linear_extrude_shape_hull(thickness_difference, depth_difference, extra_slices = 0){ + height = $total_depth - depth_difference; + width_scale = top_total_key_width() / total_key_width(); + height_scale = top_total_key_height() / total_key_height(); + + translate([0,$linear_extrude_height_adjustment,0]){ + linear_extrude(height = height, scale = [width_scale, height_scale]) { + translate([0,-$linear_extrude_height_adjustment,0]){ + key_shape( + [total_key_width(), total_key_height()], + [thickness_difference, thickness_difference] + ); + } + } + } +} +module hull_shape_hull(thickness_difference, depth_difference, extra_slices = 0) { + for (index = [0:$height_slices - 1 + extra_slices]) { + hull() { + shape_slice(index / $height_slices, thickness_difference, depth_difference); + shape_slice((index + 1) / $height_slices, thickness_difference, depth_difference); + } + } +} + +module shape_slice(progress, thickness_difference, depth_difference) { + skew_this_slice = $top_skew * progress; + x_skew_this_slice = $top_skew_x * progress; + + depth_this_slice = ($total_depth - depth_difference) * progress; + + tilt_this_slice = -$top_tilt / $key_height * progress; + y_tilt_this_slice = $double_sculpted ? (-$top_tilt_y / $key_length * progress) : 0; + + translate([x_skew_this_slice, skew_this_slice, depth_this_slice]) { + rotate([tilt_this_slice,y_tilt_this_slice,0]){ + linear_extrude(height = SMALLEST_POSSIBLE, scale = 1){ + key_shape( + [ + total_key_width(thickness_difference), + total_key_height(thickness_difference) + ], + [$width_difference, $height_difference], + progress + ); + } + } + } +} + +// basic key shape, no dish, no inside +// which is only used for dishing to cut the dish off correctly +// $height_difference used for keytop thickness +// extra_slices is a hack to make inverted dishes still work +module shape_hull(thickness_difference, depth_difference, extra_slices = 0){ + render() { + if ($hull_shape_type == "skin") { + skin_extrude_shape_hull(thickness_difference, depth_difference, extra_slices); + } else if ($hull_shape_type == "linear extrude") { + linear_extrude_shape_hull(thickness_difference, depth_difference, extra_slices); + } else { + hull_shape_hull(thickness_difference, depth_difference, extra_slices); + } + } +} // from https://www.thingiverse.com/thing:1484333 // public domain license @@ -3844,209 +6083,34 @@ function profile_segment_length(profile,i) = norm(profile[(i+1)%len(profile)] - // Generates an array with n copies of value (default 0) function dup(value=0,n) = [for (i = [1:n]) value]; - -/* [Hidden] */ -SMALLEST_POSSIBLE = 1/128; -$fs = .1; -$unit = 19.05; - // key shape including dish. used as the ouside and inside shape in hollow_key(). allows for itself to be shrunk in depth and width / height module shape(thickness_difference, depth_difference=0){ dished(depth_difference, $inverted_dish) { - color($primary_color) shape_hull(thickness_difference, depth_difference, $inverted_dish ? 2 : 0); + color($primary_color) shape_hull(thickness_difference, depth_difference, $inverted_dish ? 200 : 0); } } -// shape of the key but with soft, rounded edges. no longer includes dish -// randomly doesnt work sometimes -// the dish doesn't _quite_ reach as far as it should +// Not currently used due to CGAL errors. Rounds the shape via minkowski module rounded_shape() { - dished(-$minkowski_radius, $inverted_dish) { - color($primary_color) minkowski(){ - // half minkowski in the z direction - color($primary_color) shape_hull($minkowski_radius * 2, $minkowski_radius/2, $inverted_dish ? 2 : 0); - /* cube($minkowski_radius); */ - sphere(r=$minkowski_radius, $fn=$minkowski_facets); - } - } - /* %envelope(); */ -} - -// this function is more correct, but takes _forever_ -// the main difference is minkowski happens after dishing, meaning the dish is -// also minkowski'd -/* module rounded_shape() { color($primary_color) minkowski(){ // half minkowski in the z direction shape($minkowski_radius * 2, $minkowski_radius/2); - difference(){ - sphere(r=$minkowski_radius, $fn=20); - translate([0,0,-$minkowski_radius]){ - cube($minkowski_radius * 2, center=true); - } + minkowski_object(); + } +} + +// minkowski places this object at every vertex of the other object then mashes +// it all together +module minkowski_object() { + // alternative minkowski shape that needs the bottom of the keycap to be trimmed + /* sphere(1); */ + + difference(){ + sphere(r=$minkowski_radius, $fa=360/$minkowski_facets); + translate([0,0,-$minkowski_radius]){ + cube($minkowski_radius * 2, center=true); } } -} */ - - - -// basic key shape, no dish, no inside -// which is only used for dishing to cut the dish off correctly -// $height_difference used for keytop thickness -// extra_slices is a hack to make inverted dishes still work -module shape_hull(thickness_difference, depth_difference, extra_slices = 0){ - render() { - if ($skin_extrude_shape) { - skin_extrude_shape_hull(thickness_difference, depth_difference, extra_slices); - } else if ($linear_extrude_shape) { - linear_extrude_shape_hull(thickness_difference, depth_difference, extra_slices); - } else { - hull_shape_hull(thickness_difference, depth_difference, extra_slices); - } - } -} - -// use skin() instead of successive hulls. much more correct, and looks faster -// too, in most cases. successive hull relies on overlapping faces which are -// not good. But, skin works on vertex sets instead of shapes, which makes it -// a lot more difficult to use -module skin_extrude_shape_hull(thickness_difference, depth_difference, extra_slices = 0 ) { - skin([ - for (index = [0:$height_slices + extra_slices]) - let( - progress = (index / $height_slices), - skew_this_slice = $top_skew * progress, - x_skew_this_slice = $top_skew_x * progress, - depth_this_slice = ($total_depth - depth_difference) * progress, - tilt_this_slice = -$top_tilt / $key_height * progress, - y_tilt_this_slice = $double_sculpted ? (-$top_tilt_y / $key_length * progress) : 0 - ) - skin_shape_slice(progress, thickness_difference, skew_this_slice, x_skew_this_slice, depth_this_slice, tilt_this_slice, y_tilt_this_slice) - ]); -} - -function skin_shape_slice(progress, thickness_difference, skew_this_slice, x_skew_this_slice, depth_this_slice, tilt_this_slice, y_tilt_this_slice) = - transform( - translation([x_skew_this_slice,skew_this_slice,depth_this_slice]), - transform( - rotation([tilt_this_slice,y_tilt_this_slice,0]), - skin_key_shape([ - total_key_width(0), - total_key_height(0), - ], - [$width_difference, $height_difference], - progress, - thickness_difference - ) - ) - ); - -// corollary is hull_shape_hull -// extra_slices unused, only to match argument signatures -module linear_extrude_shape_hull(thickness_difference, depth_difference, extra_slices = 0){ - height = $total_depth - depth_difference; - width_scale = top_total_key_width() / total_key_width(); - height_scale = top_total_key_height() / total_key_height(); - - translate([0,$linear_extrude_height_adjustment,0]){ - linear_extrude(height = height, scale = [width_scale, height_scale]) { - translate([0,-$linear_extrude_height_adjustment,0]){ - key_shape( - [total_key_width(thickness_difference), total_key_height(thickness_difference)], - [$width_difference, $height_difference] - ); - } - } - } -} - -module hull_shape_hull(thickness_difference, depth_difference, extra_slices = 0) { - for (index = [0:$height_slices - 1 + extra_slices]) { - hull() { - shape_slice(index / $height_slices, thickness_difference, depth_difference); - shape_slice((index + 1) / $height_slices, thickness_difference, depth_difference); - } - } -} - -module shape_slice(progress, thickness_difference, depth_difference) { - skew_this_slice = $top_skew * progress; - x_skew_this_slice = $top_skew_x * progress; - - depth_this_slice = ($total_depth - depth_difference) * progress; - - tilt_this_slice = -$top_tilt / $key_height * progress; - y_tilt_this_slice = $double_sculpted ? (-$top_tilt_y / $key_length * progress) : 0; - - translate([x_skew_this_slice, skew_this_slice, depth_this_slice]) { - rotate([tilt_this_slice,y_tilt_this_slice,0]){ - linear_extrude(height = SMALLEST_POSSIBLE){ - key_shape( - [ - total_key_width(thickness_difference), - total_key_height(thickness_difference) - ], - [$width_difference, $height_difference], - progress - ); - } - } - } -} - -// for when you want something to only exist inside the keycap. -// used for the support structure -module inside() { - intersection() { - shape($wall_thickness, $keytop_thickness); - children(); - } -} - -// for when you want something to only exist outside the keycap -module outside() { - difference() { - children(); - shape($wall_thickness, $keytop_thickness); - } -} - -// put something at the top of the key, with no adjustments for dishing -module top_placement(depth_difference=0) { - top_tilt_by_height = -$top_tilt / $key_height; - top_tilt_y_by_length = $double_sculpted ? (-$top_tilt_y / $key_length) : 0; - - minkowski_height = $rounded_key ? $minkowski_radius : 0; - - translate([$top_skew_x + $dish_skew_x, $top_skew + $dish_skew_y, $total_depth - depth_difference + minkowski_height/2]){ - rotate([top_tilt_by_height, top_tilt_y_by_length,0]){ - children(); - } - } -} - -module front_placement() { - // all this math is to take top skew and tilt into account - // we need to find the new effective height and depth of the top, front lip - // of the keycap to find the angle so we can rotate things correctly into place - total_depth_difference = sin(-$top_tilt) * (top_total_key_height()/2); - total_height_difference = $top_skew + (1 - cos(-$top_tilt)) * (top_total_key_height()/2); - - angle = atan2(($total_depth - total_depth_difference), ($height_difference/2 + total_height_difference)); - hypotenuse = ($total_depth -total_depth_difference) / sin(angle); - - translate([0,-total_key_height()/2,0]) { - rotate([-(90-angle), 0, 0]) { - translate([0,0,hypotenuse/2]){ - children(); - } - } - } -} - -// just to DRY up the code -module _dish() { - color($secondary_color) dish(top_total_key_width() + $dish_overdraw_width, top_total_key_height() + $dish_overdraw_height, $dish_depth, $inverted_dish); } module envelope(depth_difference=0) { @@ -4059,18 +6123,6 @@ module envelope(depth_difference=0) { } } -// I think this is unused -module dished_for_show() { - difference(){ - union() { - envelope(); - if ($inverted_dish) top_placement(0) _dish(); - } - if (!$inverted_dish) top_placement(0) _dish(); - } -} - - // for when you want to take the dish out of things // used for adding the dish to the key shape and making sure stems don't stick out the top // creates a bounding box 1.5 times larger in width and height than the keycap. @@ -4079,37 +6131,24 @@ module dished(depth_difference = 0, inverted = false) { children(); difference(){ union() { + // envelope is needed to "fill in" the rest of the keycap envelope(depth_difference); - if (inverted) top_placement(depth_difference) _dish(); + if (inverted) top_placement(depth_difference) color($secondary_color) _dish(inverted); } - if (!inverted) top_placement(depth_difference) _dish(); + if (!inverted) top_placement(depth_difference) color($secondary_color) _dish(inverted); + /* %top_placement(depth_difference) _dish(); */ } } } -// puts it's children at the center of the dishing on the key, including dish height -// more user-friendly than top_placement -module top_of_key(){ - // if there is a dish, we need to account for how much it digs into the top - dish_depth = ($dish_type == "disable") ? 0 : $dish_depth; - // if the dish is inverted, we need to account for that too. in this case we do half, otherwise the children would be floating on top of the dish - corrected_dish_depth = ($inverted_dish) ? -dish_depth / 2 : dish_depth; - - top_placement(corrected_dish_depth) { - children(); - } -} - -module keytext(text, position, font_size, depth) { - woffset = (top_total_key_width()/3.5) * position[0]; - hoffset = (top_total_key_height()/3.5) * -position[1]; - translate([woffset, hoffset, -depth]){ - color($tertiary_color) linear_extrude(height=$dish_depth){ - text(text=text, font=$font, size=font_size, halign="center", valign="center"); - } - } +// just to DRY up the code +// TODO is putting special vars in function signatures legal +module _dish(inverted=$inverted_dish) { + translate([$dish_offset_x,0,0]) color($secondary_color) + dish(top_total_key_width() + $dish_overdraw_width, top_total_key_height() + $dish_overdraw_height, $dish_depth, inverted); } +// puts its children at each keystem position provided module keystem_positions(positions) { for (connector_pos = positions) { translate(connector_pos) { @@ -4128,131 +6167,156 @@ module support_for(positions, stem_type) { module stems_for(positions, stem_type) { keystem_positions(positions) { - color($tertiary_color) stem(stem_type, $total_depth, $stem_slop); + color($tertiary_color) stem(stem_type, stem_height(), $stem_slop, $stem_throw); if ($stem_support_type != "disable") { color($quaternary_color) stem_support($stem_support_type, stem_type, $stem_support_height, $stem_slop); } } } -// a fake cherry keyswitch, abstracted out to maybe replace with a better one later -module cherry_keyswitch() { - union() { - hull() { - cube([15.6, 15.6, 0.01], center=true); - translate([0,1,5 - 0.01]) cube([10.5,9.5, 0.01], center=true); - } - hull() { - cube([15.6, 15.6, 0.01], center=true); - translate([0,0,-5.5]) cube([13.5,13.5,0.01], center=true); +// put something at the top of the key, with no adjustments for dishing +module top_placement(depth_difference=0) { + top_tilt_by_height = -$top_tilt / $key_height; + top_tilt_y_by_length = $double_sculpted ? (-$top_tilt_y / $key_length) : 0; + + minkowski_height = $rounded_key ? $minkowski_radius : 0; + + translate([$top_skew_x + $dish_skew_x, $top_skew + $dish_skew_y, $total_depth - depth_difference + minkowski_height/2]){ + rotate([top_tilt_by_height, top_tilt_y_by_length,0]){ + children(); } } } -//approximate (fully depressed) cherry key to check clearances -module clearance_check() { - if($stem_type == "cherry" || $stem_type == "cherry_rounded"){ - color($warning_color){ - translate([0,0,3.6 + $stem_inset - 5]) { - cherry_keyswitch(); +// puts its children at the center of the dishing on the key, including dish height +// more user-friendly than top_placement +module top_of_key(){ + // if there is a dish, we need to account for how much it digs into the top + dish_depth = ($dish_type == "disable") ? 0 : $dish_depth; + // if the dish is inverted, we need to account for that too. in this case we do half, otherwise the children would be floating on top of the dish + corrected_dish_depth = ($inverted_dish) ? -dish_depth / 2 : dish_depth; + + top_placement(corrected_dish_depth) { + children(); + } +} + +module front_of_key() { + // all this math is to take top skew and tilt into account + // we need to find the new effective height and depth of the top, front lip + // of the keycap to find the angle so we can rotate things correctly into place + total_depth_difference = sin(-$top_tilt) * (top_total_key_height()/2); + total_height_difference = $top_skew + (1 - cos(-$top_tilt)) * (top_total_key_height()/2); + + angle = atan2(($total_depth - total_depth_difference), ($height_difference/2 + total_height_difference)); + hypotenuse = ($total_depth -total_depth_difference) / sin(angle); + + translate([0,-total_key_height()/2,0]) { + rotate([-(90-angle), 0, 0]) { + translate([0,0,hypotenuse/2]){ + children(); } } } } -module legends(depth=0) { - if (len($front_legends) > 0) { - front_placement() { - if (len($front_legends) > 0) { - for (i=[0:len($front_legends)-1]) { - rotate([90,0,0]) keytext($front_legends[i][0], $front_legends[i][1], $front_legends[i][2], depth); - } - } - } - } - if (len($legends) > 0) { - top_of_key() { - // outset legend - if (len($legends) > 0) { - for (i=[0:len($legends)-1]) { - keytext($legends[i][0], $legends[i][1], $legends[i][2], depth); - } - } - } +module outer_shape() { + if ($rounded_key == true) { + rounded_shape(); + } else { + shape(0, 0); } } -// legends / artisan support -module artisan(depth) { +module inner_shape(extra_wall_thickness = 0, extra_keytop_thickness = 0) { + if ($inner_shape_type == "flat") { + /* $key_shape_type="square"; */ + $height_slices = 1; + // if inner_shape is flat, keytop_thickness will be dish_depth less than it should be, since the dish digs in that far. + // so, we add dish_depth here + color($primary_color) shape_hull($wall_thickness + extra_wall_thickness, $keytop_thickness + extra_keytop_thickness + $dish_depth, 0); + } else { + shape($wall_thickness + extra_wall_thickness, $keytop_thickness + extra_keytop_thickness); + } +} + +// additive objects at the top of the key +module additive_features(inset) { top_of_key() { - // artisan objects / outset shape legends - color($secondary_color) children(); + if($key_bump) keybump($key_bump_depth, $key_bump_edge); + if(!inset && $children > 0) color($secondary_color) children(); + } + if($outset_legends) legends(0); + // render the clearance check if it's enabled, but don't have it intersect with anything + if ($clearance_check) %clearance_check(); +} + +// subtractive objects at the top of the key +module subtractive_features(inset) { + top_of_key() { + if (inset && $children > 0) color($secondary_color) children(); + } + if(!$outset_legends) legends($inset_legend_depth); + // subtract the clearance check if it's enabled, letting the user see the + // parts of the keycap that will hit the cherry switch + // this is a little confusing as it eats the stem too + /* if ($clearance_check) clearance_check(); */ +} + +// features inside the key itself (stem, supports, etc) +module inside_features() { + // Stems and stabilizers are not "inside features" unless they are fully + // contained inside the cap. otherwise they'd be cut off when they are + // differenced with the outside shape. this only matters if $stem_inset + // is negative + if ($stem_inset >= 0) stems_and_stabilizers(); + if ($support_type != "disable") translate([0, 0, $stem_inset]) support_for($stem_positions, $stem_type); + if ($stabilizer_type != "disable") translate([0, 0, $stem_inset]) support_for($stabilizers, $stabilizer_type); +} + +// all stems and stabilizers +module stems_and_stabilizers() { + translate([0, 0, $stem_inset]) { + if ($stabilizer_type != "disable") stems_for($stabilizers, $stabilizer_type); + if ($stem_type != "disable") stems_for($stem_positions, $stem_type); } } -// key with hollowed inside but no stem -module hollow_key() { - difference(){ - if ($rounded_key) { - rounded_shape(); - } else { - shape(0, 0); - } - // translation purely for aesthetic purposes, to get rid of that awful lattice - translate([0,0,-SMALLEST_POSSIBLE]) { - shape($wall_thickness, $keytop_thickness); - } +// helpers for doubleshot keycaps for now +module inner_total_shape() { + difference() { + inner_shape(); + inside_features(); } } +module outer_total_shape(inset=false) { + outer_shape(); + additive_features(inset) { + children(); + }; +} // The final, penultimate key generation function. // takes all the bits and glues them together. requires configuration with special variables. -module key(inset = false) { - difference() { - union(){ - // the shape of the key, inside and out - hollow_key(); - if($key_bump) top_of_key() keybump($key_bump_depth, $key_bump_edge); - // additive objects at the top of the key - // outside() makes them stay out of the inside. it's a bad name - if(!inset && $children > 0) outside() artisan(0) children(); - if($outset_legends) legends(0); - // render the clearance check if it's enabled, but don't have it intersect with anything - if ($clearance_check) %clearance_check(); - } +module key(inset=false) { + difference(){ + outer_total_shape(inset); - // subtractive objects at the top of the key - // no outside() - I can't think of a use for it. will save render time - if (inset && $children > 0) artisan($inset_legend_depth) children(); - if(!$outset_legends) legends($inset_legend_depth); - // subtract the clearance check if it's enabled, letting the user see the - // parts of the keycap that will hit the cherry switch - if ($clearance_check) %clearance_check(); - } - - // both stem and support are optional - if ($stem_type != "disable" || ($stabilizers != [] && $stabilizer_type != "disable")) { - dished($keytop_thickness, $inverted_dish) { - translate([0, 0, $stem_inset]) { - if ($stabilizer_type != "disable") stems_for($stabilizers, $stabilizer_type); - - if ($stem_type != "disable") stems_for($stem_positions, $stem_type); + if ($inner_shape_type != "disable") { + translate([0,0,-SMALLEST_POSSIBLE]) { + inner_total_shape(); } } + + subtractive_features(inset) { + children(); + }; } - if ($support_type != "disable"){ - inside() { - translate([0, 0, $stem_inset]) { - if ($stabilizer_type != "disable") support_for($stabilizers, $stabilizer_type); - - // always render stem support even if there isn't a stem. - // rendering flat support w/no stem is much more common than a hollow keycap - // so if you want a hollow keycap you'll have to turn support off entirely - support_for($stem_positions, $stem_type); - } - } + // if $stem_inset is less than zero, we add the + if ($stem_inset < 0) { + stems_and_stabilizers(); } } @@ -4335,6 +6399,7 @@ $rounded_cherry_stem_d = 5.5; // How much higher the stem is than the bottom of the keycap. // Inset stem requires support but is more accurate in some profiles +// can be negative to make outset stems! $stem_inset = 0; // How many degrees to rotate the stems. useful for sideways keycaps, maybe $stem_rotation = 0; @@ -4363,7 +6428,11 @@ $dish_depth = 1; $dish_skew_x = 0; // How skewed in the y direction (height) the dish is $dish_skew_y = 0; -// If you need the dish to extend further, you can 'overdraw' the rectangle it will hit + + +$dish_offset_x = 0; + +// If you need the dish to extend further, you can 'overdraw' the rectangle it will hit. this was mostly for iso enter and should be deprecated $dish_overdraw_width = 0; // Same as width but for height $dish_overdraw_height = 0; @@ -4379,12 +6448,10 @@ $font="DejaVu Sans Mono:style=Book"; // Whether or not to render fake keyswitches to check clearances $clearance_check = false; // Should be faster, also required for concave shapes -// Use linear_extrude instead of hull slices to make the shape of the key -$linear_extrude_shape = false; -// warns in trajectory.scad but it looks benign -// brand new, more correct, hopefully faster, lots more work -$skin_extrude_shape = false; +// what kind of extrusion we use to create the keycap. "hull" is standard, "linear extrude" is legacy, "skin" is new and not well supported. +$hull_shape_type = "hull"; // ["hull", "linear extrude", "skin"] + // This doesn't work very well, but you can try $rounded_key = false; //minkowski radius. radius of sphere used in minkowski sum for minkowski_key function. 1.75 for G20 @@ -4425,6 +6492,9 @@ $inset_legend_depth = 0.2; // Dimensions of alps stem $alps_stem = [4.45, 2.25]; +// Dimensions of choc stem +$choc_stem = [1.2, 3]; + // Enable stabilizer stems, to hold onto your cherry or costar stabilizers $stabilizer_type = "costar_stabilizer"; // [costar_stabilizer, cherry_stabilizer, disable] @@ -4454,6 +6524,9 @@ $shape_facets =30; $3d_surface_size = 100; // resolution in each axis. 10 = 10 divisions per x/y = 100 points total $3d_surface_step = 10; + +// "flat" / "dished" / "disable" +$inner_shape_type = "flat"; key(); } diff --git a/src/constants.scad b/src/constants.scad index 8e961e0..d005eff 100644 --- a/src/constants.scad +++ b/src/constants.scad @@ -1 +1,4 @@ +// a safe theoretical distance between two vertices such that they don't collapse. hard to use SMALLEST_POSSIBLE = 1/128; +$fs=0.1; +$unit=19.05; diff --git a/src/dishes/3d_surface.scad b/src/dishes/3d_surface.scad index 6a5477a..413c608 100644 --- a/src/dishes/3d_surface.scad +++ b/src/dishes/3d_surface.scad @@ -8,7 +8,7 @@ module 3d_surface_dish(width, height, depth, inverted) { // skew and tilt of the top. it's a pain to calculate though scale_factor = 1.1; // the edges on this behave differently than with the previous dish implementations - scale([width*scale_factor/$3d_surface_size/2,height*scale_factor/$3d_surface_size/2,depth]) rotate([inverted ? 0:180,0,90]) polar_3d_surface(bottom=-10); + scale([width*scale_factor/$3d_surface_size/2,height*scale_factor/$3d_surface_size/2,depth]) rotate([inverted ? 0:180,0,180]) polar_3d_surface(bottom=-10); /* %scale([width*scale_factor/$3d_surface_size/2,height*scale_factor/$3d_surface_size/2,depth]) rotate([180,0,0]) polar_3d_surface(bottom=-10); */ } diff --git a/src/features.scad b/src/features.scad new file mode 100644 index 0000000..b0ae94a --- /dev/null +++ b/src/features.scad @@ -0,0 +1,5 @@ +// features are any premade self-contained objects that go on top or inside + +include +include +include diff --git a/src/features/clearance_check.scad b/src/features/clearance_check.scad new file mode 100644 index 0000000..96c4d70 --- /dev/null +++ b/src/features/clearance_check.scad @@ -0,0 +1,24 @@ +// a fake cherry keyswitch, abstracted out to maybe replace with a better one later +module cherry_keyswitch() { + union() { + hull() { + cube([15.6, 15.6, 0.01], center=true); + translate([0,1,5 - 0.01]) cube([10.5,9.5, 0.01], center=true); + } + hull() { + cube([15.6, 15.6, 0.01], center=true); + translate([0,0,-5.5]) cube([13.5,13.5,0.01], center=true); + } + } +} + +//approximate (fully depressed) cherry key to check clearances +module clearance_check() { + if($stem_type == "cherry" || $stem_type == "cherry_rounded"){ + color($warning_color){ + translate([0,0,3.6 + $stem_inset - 5]) { + cherry_keyswitch(); + } + } + } +} diff --git a/src/features/legends.scad b/src/features/legends.scad new file mode 100644 index 0000000..2f0171a --- /dev/null +++ b/src/features/legends.scad @@ -0,0 +1,26 @@ +module keytext(text, position, font_size, depth) { + woffset = (top_total_key_width()/3.5) * position[0]; + hoffset = (top_total_key_height()/3.5) * -position[1]; + translate([woffset, hoffset, -depth]){ + color($tertiary_color) linear_extrude(height=$dish_depth + depth){ + text(text=text, font=$font, size=font_size, halign="center", valign="center"); + } + } +} + +module legends(depth=0) { + if (len($front_legends) > 0) { + front_of_key() { + for (i=[0:len($front_legends)-1]) { + rotate([90,0,0]) keytext($front_legends[i][0], $front_legends[i][1], $front_legends[i][2], depth); + } + } + } + if (len($legends) > 0) { + top_of_key() { + for (i=[0:len($legends)-1]) { + keytext($legends[i][0], $legends[i][1], $legends[i][2], depth); + } + } + } +} diff --git a/src/functions.scad b/src/functions.scad index 476e73d..77028e8 100644 --- a/src/functions.scad +++ b/src/functions.scad @@ -4,6 +4,8 @@ include // functions need to be explicitly included, unlike special variables, which // just need to have been set before they are used. hence this file +function stem_height() = $total_depth - $dish_depth - $stem_inset; + // cherry stem dimensions function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; @@ -31,7 +33,7 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1 function side_tilt(column) = asin($unit * column / $double_sculpt_radius); // tan of 0 is 0, division by 0 is nan, so we have to guard -function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; +function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; // (I think) extra length of the side of the keycap due to the keytop being tilted. // necessary for calculating flat sided keycaps @@ -57,5 +59,14 @@ function surface_function(x,y) = 1; function surface_function(x,y) = (sin(acos(x/$3d_surface_size))); // spherical function surface_function(x,y) = (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); -// (statically) random! +// ripples +/* function surface_function(x,y) = cos(pow(pow(x,2)+pow(y,2),0.5)*10)/4+0.75; */ +// Rosenbrock's banana +/* function surface_function(x,y) = (pow(1-(x/100), 2) + 100 * pow((y/100)-pow((x/100),2),2))/200 + 0.1; */ +// y=x revolved around the y axis +/* function surface_function(x,y) = 1/(pow(pow(x,2)+pow(y,2),0.5)/100 + .01); */ /* function surface_function(x,y) = sin(rands(0,90,1,x+y)[0]); */ +// adds uniform rounding radius for round-anything polyRound +function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; +// computes millimeter length from unit length +function unit_length(length) = $unit * (length - 1) + 18.16; diff --git a/src/hulls.scad b/src/hulls.scad new file mode 100644 index 0000000..2698011 --- /dev/null +++ b/src/hulls.scad @@ -0,0 +1,19 @@ +include +include +include + +// basic key shape, no dish, no inside +// which is only used for dishing to cut the dish off correctly +// $height_difference used for keytop thickness +// extra_slices is a hack to make inverted dishes still work +module shape_hull(thickness_difference, depth_difference, extra_slices = 0){ + render() { + if ($hull_shape_type == "skin") { + skin_extrude_shape_hull(thickness_difference, depth_difference, extra_slices); + } else if ($hull_shape_type == "linear extrude") { + linear_extrude_shape_hull(thickness_difference, depth_difference, extra_slices); + } else { + hull_shape_hull(thickness_difference, depth_difference, extra_slices); + } + } +} diff --git a/src/hulls/hull.scad b/src/hulls/hull.scad new file mode 100644 index 0000000..af07224 --- /dev/null +++ b/src/hulls/hull.scad @@ -0,0 +1,33 @@ +module hull_shape_hull(thickness_difference, depth_difference, extra_slices = 0) { + for (index = [0:$height_slices - 1 + extra_slices]) { + hull() { + shape_slice(index / $height_slices, thickness_difference, depth_difference); + shape_slice((index + 1) / $height_slices, thickness_difference, depth_difference); + } + } +} + +module shape_slice(progress, thickness_difference, depth_difference) { + skew_this_slice = $top_skew * progress; + x_skew_this_slice = $top_skew_x * progress; + + depth_this_slice = ($total_depth - depth_difference) * progress; + + tilt_this_slice = -$top_tilt / $key_height * progress; + y_tilt_this_slice = $double_sculpted ? (-$top_tilt_y / $key_length * progress) : 0; + + translate([x_skew_this_slice, skew_this_slice, depth_this_slice]) { + rotate([tilt_this_slice,y_tilt_this_slice,0]){ + linear_extrude(height = SMALLEST_POSSIBLE, scale = 1){ + key_shape( + [ + total_key_width(thickness_difference), + total_key_height(thickness_difference) + ], + [$width_difference, $height_difference], + progress + ); + } + } + } +} diff --git a/src/hulls/linear_extrude.scad b/src/hulls/linear_extrude.scad new file mode 100644 index 0000000..dbe6e8b --- /dev/null +++ b/src/hulls/linear_extrude.scad @@ -0,0 +1,18 @@ +// corollary is hull_shape_hull +// extra_slices unused, only to match argument signatures +module linear_extrude_shape_hull(thickness_difference, depth_difference, extra_slices = 0){ + height = $total_depth - depth_difference; + width_scale = top_total_key_width() / total_key_width(); + height_scale = top_total_key_height() / total_key_height(); + + translate([0,$linear_extrude_height_adjustment,0]){ + linear_extrude(height = height, scale = [width_scale, height_scale]) { + translate([0,-$linear_extrude_height_adjustment,0]){ + key_shape( + [total_key_width(), total_key_height()], + [thickness_difference, thickness_difference] + ); + } + } + } +} diff --git a/src/hulls/skin.scad b/src/hulls/skin.scad new file mode 100644 index 0000000..afe98d2 --- /dev/null +++ b/src/hulls/skin.scad @@ -0,0 +1,34 @@ +// use skin() instead of successive hulls. much more correct, and looks faster +// too, in most cases. successive hull relies on overlapping faces which are +// not good. But, skin works on vertex sets instead of shapes, which makes it +// a lot more difficult to use +module skin_extrude_shape_hull(thickness_difference, depth_difference, extra_slices = 0 ) { + skin([ + for (index = [0:$height_slices + extra_slices]) + let( + progress = (index / $height_slices), + skew_this_slice = $top_skew * progress, + x_skew_this_slice = $top_skew_x * progress, + depth_this_slice = ($total_depth - depth_difference) * progress, + tilt_this_slice = -$top_tilt / $key_height * progress, + y_tilt_this_slice = $double_sculpted ? (-$top_tilt_y / $key_length * progress) : 0 + ) + skin_shape_slice(progress, thickness_difference, skew_this_slice, x_skew_this_slice, depth_this_slice, tilt_this_slice, y_tilt_this_slice) + ]); +} + +function skin_shape_slice(progress, thickness_difference, skew_this_slice, x_skew_this_slice, depth_this_slice, tilt_this_slice, y_tilt_this_slice) = + transform( + translation([x_skew_this_slice,skew_this_slice,depth_this_slice]), + transform( + rotation([tilt_this_slice,y_tilt_this_slice,0]), + skin_key_shape([ + total_key_width(0) - thickness_difference, + total_key_height(0) - thickness_difference, + ], + [$width_difference, $height_difference], + progress, + thickness_difference + ) + ) + ); diff --git a/src/key.scad b/src/key.scad index f8ecc95..15768ba 100644 --- a/src/key.scad +++ b/src/key.scad @@ -1,11 +1,13 @@ // files +include include include include include include include -include +include +include include @@ -15,209 +17,34 @@ use use use - -/* [Hidden] */ -SMALLEST_POSSIBLE = 1/128; -$fs = .1; -$unit = 19.05; - // key shape including dish. used as the ouside and inside shape in hollow_key(). allows for itself to be shrunk in depth and width / height module shape(thickness_difference, depth_difference=0){ dished(depth_difference, $inverted_dish) { - color($primary_color) shape_hull(thickness_difference, depth_difference, $inverted_dish ? 2 : 0); + color($primary_color) shape_hull(thickness_difference, depth_difference, $inverted_dish ? 200 : 0); } } -// shape of the key but with soft, rounded edges. no longer includes dish -// randomly doesnt work sometimes -// the dish doesn't _quite_ reach as far as it should +// Not currently used due to CGAL errors. Rounds the shape via minkowski module rounded_shape() { - dished(-$minkowski_radius, $inverted_dish) { - color($primary_color) minkowski(){ - // half minkowski in the z direction - color($primary_color) shape_hull($minkowski_radius * 2, $minkowski_radius/2, $inverted_dish ? 2 : 0); - /* cube($minkowski_radius); */ - sphere(r=$minkowski_radius, $fn=$minkowski_facets); - } - } - /* %envelope(); */ -} - -// this function is more correct, but takes _forever_ -// the main difference is minkowski happens after dishing, meaning the dish is -// also minkowski'd -/* module rounded_shape() { color($primary_color) minkowski(){ // half minkowski in the z direction shape($minkowski_radius * 2, $minkowski_radius/2); - difference(){ - sphere(r=$minkowski_radius, $fn=20); - translate([0,0,-$minkowski_radius]){ - cube($minkowski_radius * 2, center=true); - } + minkowski_object(); + } +} + +// minkowski places this object at every vertex of the other object then mashes +// it all together +module minkowski_object() { + // alternative minkowski shape that needs the bottom of the keycap to be trimmed + /* sphere(1); */ + + difference(){ + sphere(r=$minkowski_radius, $fa=360/$minkowski_facets); + translate([0,0,-$minkowski_radius]){ + cube($minkowski_radius * 2, center=true); } } -} */ - - - -// basic key shape, no dish, no inside -// which is only used for dishing to cut the dish off correctly -// $height_difference used for keytop thickness -// extra_slices is a hack to make inverted dishes still work -module shape_hull(thickness_difference, depth_difference, extra_slices = 0){ - render() { - if ($skin_extrude_shape) { - skin_extrude_shape_hull(thickness_difference, depth_difference, extra_slices); - } else if ($linear_extrude_shape) { - linear_extrude_shape_hull(thickness_difference, depth_difference, extra_slices); - } else { - hull_shape_hull(thickness_difference, depth_difference, extra_slices); - } - } -} - -// use skin() instead of successive hulls. much more correct, and looks faster -// too, in most cases. successive hull relies on overlapping faces which are -// not good. But, skin works on vertex sets instead of shapes, which makes it -// a lot more difficult to use -module skin_extrude_shape_hull(thickness_difference, depth_difference, extra_slices = 0 ) { - skin([ - for (index = [0:$height_slices + extra_slices]) - let( - progress = (index / $height_slices), - skew_this_slice = $top_skew * progress, - x_skew_this_slice = $top_skew_x * progress, - depth_this_slice = ($total_depth - depth_difference) * progress, - tilt_this_slice = -$top_tilt / $key_height * progress, - y_tilt_this_slice = $double_sculpted ? (-$top_tilt_y / $key_length * progress) : 0 - ) - skin_shape_slice(progress, thickness_difference, skew_this_slice, x_skew_this_slice, depth_this_slice, tilt_this_slice, y_tilt_this_slice) - ]); -} - -function skin_shape_slice(progress, thickness_difference, skew_this_slice, x_skew_this_slice, depth_this_slice, tilt_this_slice, y_tilt_this_slice) = - transform( - translation([x_skew_this_slice,skew_this_slice,depth_this_slice]), - transform( - rotation([tilt_this_slice,y_tilt_this_slice,0]), - skin_key_shape([ - total_key_width(0), - total_key_height(0), - ], - [$width_difference, $height_difference], - progress, - thickness_difference - ) - ) - ); - -// corollary is hull_shape_hull -// extra_slices unused, only to match argument signatures -module linear_extrude_shape_hull(thickness_difference, depth_difference, extra_slices = 0){ - height = $total_depth - depth_difference; - width_scale = top_total_key_width() / total_key_width(); - height_scale = top_total_key_height() / total_key_height(); - - translate([0,$linear_extrude_height_adjustment,0]){ - linear_extrude(height = height, scale = [width_scale, height_scale]) { - translate([0,-$linear_extrude_height_adjustment,0]){ - key_shape( - [total_key_width(thickness_difference), total_key_height(thickness_difference)], - [$width_difference, $height_difference] - ); - } - } - } -} - -module hull_shape_hull(thickness_difference, depth_difference, extra_slices = 0) { - for (index = [0:$height_slices - 1 + extra_slices]) { - hull() { - shape_slice(index / $height_slices, thickness_difference, depth_difference); - shape_slice((index + 1) / $height_slices, thickness_difference, depth_difference); - } - } -} - -module shape_slice(progress, thickness_difference, depth_difference) { - skew_this_slice = $top_skew * progress; - x_skew_this_slice = $top_skew_x * progress; - - depth_this_slice = ($total_depth - depth_difference) * progress; - - tilt_this_slice = -$top_tilt / $key_height * progress; - y_tilt_this_slice = $double_sculpted ? (-$top_tilt_y / $key_length * progress) : 0; - - translate([x_skew_this_slice, skew_this_slice, depth_this_slice]) { - rotate([tilt_this_slice,y_tilt_this_slice,0]){ - linear_extrude(height = SMALLEST_POSSIBLE){ - key_shape( - [ - total_key_width(thickness_difference), - total_key_height(thickness_difference) - ], - [$width_difference, $height_difference], - progress - ); - } - } - } -} - -// for when you want something to only exist inside the keycap. -// used for the support structure -module inside() { - intersection() { - shape($wall_thickness, $keytop_thickness); - children(); - } -} - -// for when you want something to only exist outside the keycap -module outside() { - difference() { - children(); - shape($wall_thickness, $keytop_thickness); - } -} - -// put something at the top of the key, with no adjustments for dishing -module top_placement(depth_difference=0) { - top_tilt_by_height = -$top_tilt / $key_height; - top_tilt_y_by_length = $double_sculpted ? (-$top_tilt_y / $key_length) : 0; - - minkowski_height = $rounded_key ? $minkowski_radius : 0; - - translate([$top_skew_x + $dish_skew_x, $top_skew + $dish_skew_y, $total_depth - depth_difference + minkowski_height/2]){ - rotate([top_tilt_by_height, top_tilt_y_by_length,0]){ - children(); - } - } -} - -module front_placement() { - // all this math is to take top skew and tilt into account - // we need to find the new effective height and depth of the top, front lip - // of the keycap to find the angle so we can rotate things correctly into place - total_depth_difference = sin(-$top_tilt) * (top_total_key_height()/2); - total_height_difference = $top_skew + (1 - cos(-$top_tilt)) * (top_total_key_height()/2); - - angle = atan2(($total_depth - total_depth_difference), ($height_difference/2 + total_height_difference)); - hypotenuse = ($total_depth -total_depth_difference) / sin(angle); - - translate([0,-total_key_height()/2,0]) { - rotate([-(90-angle), 0, 0]) { - translate([0,0,hypotenuse/2]){ - children(); - } - } - } -} - -// just to DRY up the code -module _dish() { - color($secondary_color) dish(top_total_key_width() + $dish_overdraw_width, top_total_key_height() + $dish_overdraw_height, $dish_depth, $inverted_dish); } module envelope(depth_difference=0) { @@ -230,18 +57,6 @@ module envelope(depth_difference=0) { } } -// I think this is unused -module dished_for_show() { - difference(){ - union() { - envelope(); - if ($inverted_dish) top_placement(0) _dish(); - } - if (!$inverted_dish) top_placement(0) _dish(); - } -} - - // for when you want to take the dish out of things // used for adding the dish to the key shape and making sure stems don't stick out the top // creates a bounding box 1.5 times larger in width and height than the keycap. @@ -250,37 +65,24 @@ module dished(depth_difference = 0, inverted = false) { children(); difference(){ union() { + // envelope is needed to "fill in" the rest of the keycap envelope(depth_difference); - if (inverted) top_placement(depth_difference) _dish(); + if (inverted) top_placement(depth_difference) color($secondary_color) _dish(inverted); } - if (!inverted) top_placement(depth_difference) _dish(); + if (!inverted) top_placement(depth_difference) color($secondary_color) _dish(inverted); + /* %top_placement(depth_difference) _dish(); */ } } } -// puts it's children at the center of the dishing on the key, including dish height -// more user-friendly than top_placement -module top_of_key(){ - // if there is a dish, we need to account for how much it digs into the top - dish_depth = ($dish_type == "disable") ? 0 : $dish_depth; - // if the dish is inverted, we need to account for that too. in this case we do half, otherwise the children would be floating on top of the dish - corrected_dish_depth = ($inverted_dish) ? -dish_depth / 2 : dish_depth; - - top_placement(corrected_dish_depth) { - children(); - } -} - -module keytext(text, position, font_size, depth) { - woffset = (top_total_key_width()/3.5) * position[0]; - hoffset = (top_total_key_height()/3.5) * -position[1]; - translate([woffset, hoffset, -depth]){ - color($tertiary_color) linear_extrude(height=$dish_depth){ - text(text=text, font=$font, size=font_size, halign="center", valign="center"); - } - } +// just to DRY up the code +// TODO is putting special vars in function signatures legal +module _dish(inverted=$inverted_dish) { + translate([$dish_offset_x,0,0]) color($secondary_color) + dish(top_total_key_width() + $dish_overdraw_width, top_total_key_height() + $dish_overdraw_height, $dish_depth, inverted); } +// puts its children at each keystem position provided module keystem_positions(positions) { for (connector_pos = positions) { translate(connector_pos) { @@ -299,131 +101,156 @@ module support_for(positions, stem_type) { module stems_for(positions, stem_type) { keystem_positions(positions) { - color($tertiary_color) stem(stem_type, $total_depth, $stem_slop); + color($tertiary_color) stem(stem_type, stem_height(), $stem_slop, $stem_throw); if ($stem_support_type != "disable") { color($quaternary_color) stem_support($stem_support_type, stem_type, $stem_support_height, $stem_slop); } } } -// a fake cherry keyswitch, abstracted out to maybe replace with a better one later -module cherry_keyswitch() { - union() { - hull() { - cube([15.6, 15.6, 0.01], center=true); - translate([0,1,5 - 0.01]) cube([10.5,9.5, 0.01], center=true); - } - hull() { - cube([15.6, 15.6, 0.01], center=true); - translate([0,0,-5.5]) cube([13.5,13.5,0.01], center=true); +// put something at the top of the key, with no adjustments for dishing +module top_placement(depth_difference=0) { + top_tilt_by_height = -$top_tilt / $key_height; + top_tilt_y_by_length = $double_sculpted ? (-$top_tilt_y / $key_length) : 0; + + minkowski_height = $rounded_key ? $minkowski_radius : 0; + + translate([$top_skew_x + $dish_skew_x, $top_skew + $dish_skew_y, $total_depth - depth_difference + minkowski_height/2]){ + rotate([top_tilt_by_height, top_tilt_y_by_length,0]){ + children(); } } } -//approximate (fully depressed) cherry key to check clearances -module clearance_check() { - if($stem_type == "cherry" || $stem_type == "cherry_rounded"){ - color($warning_color){ - translate([0,0,3.6 + $stem_inset - 5]) { - cherry_keyswitch(); +// puts its children at the center of the dishing on the key, including dish height +// more user-friendly than top_placement +module top_of_key(){ + // if there is a dish, we need to account for how much it digs into the top + dish_depth = ($dish_type == "disable") ? 0 : $dish_depth; + // if the dish is inverted, we need to account for that too. in this case we do half, otherwise the children would be floating on top of the dish + corrected_dish_depth = ($inverted_dish) ? -dish_depth / 2 : dish_depth; + + top_placement(corrected_dish_depth) { + children(); + } +} + +module front_of_key() { + // all this math is to take top skew and tilt into account + // we need to find the new effective height and depth of the top, front lip + // of the keycap to find the angle so we can rotate things correctly into place + total_depth_difference = sin(-$top_tilt) * (top_total_key_height()/2); + total_height_difference = $top_skew + (1 - cos(-$top_tilt)) * (top_total_key_height()/2); + + angle = atan2(($total_depth - total_depth_difference), ($height_difference/2 + total_height_difference)); + hypotenuse = ($total_depth -total_depth_difference) / sin(angle); + + translate([0,-total_key_height()/2,0]) { + rotate([-(90-angle), 0, 0]) { + translate([0,0,hypotenuse/2]){ + children(); } } } } -module legends(depth=0) { - if (len($front_legends) > 0) { - front_placement() { - if (len($front_legends) > 0) { - for (i=[0:len($front_legends)-1]) { - rotate([90,0,0]) keytext($front_legends[i][0], $front_legends[i][1], $front_legends[i][2], depth); - } - } - } - } - if (len($legends) > 0) { - top_of_key() { - // outset legend - if (len($legends) > 0) { - for (i=[0:len($legends)-1]) { - keytext($legends[i][0], $legends[i][1], $legends[i][2], depth); - } - } - } +module outer_shape() { + if ($rounded_key == true) { + rounded_shape(); + } else { + shape(0, 0); } } -// legends / artisan support -module artisan(depth) { +module inner_shape(extra_wall_thickness = 0, extra_keytop_thickness = 0) { + if ($inner_shape_type == "flat") { + /* $key_shape_type="square"; */ + $height_slices = 1; + // if inner_shape is flat, keytop_thickness will be dish_depth less than it should be, since the dish digs in that far. + // so, we add dish_depth here + color($primary_color) shape_hull($wall_thickness + extra_wall_thickness, $keytop_thickness + extra_keytop_thickness + $dish_depth, 0); + } else { + shape($wall_thickness + extra_wall_thickness, $keytop_thickness + extra_keytop_thickness); + } +} + +// additive objects at the top of the key +module additive_features(inset) { top_of_key() { - // artisan objects / outset shape legends - color($secondary_color) children(); + if($key_bump) keybump($key_bump_depth, $key_bump_edge); + if(!inset && $children > 0) color($secondary_color) children(); + } + if($outset_legends) legends(0); + // render the clearance check if it's enabled, but don't have it intersect with anything + if ($clearance_check) %clearance_check(); +} + +// subtractive objects at the top of the key +module subtractive_features(inset) { + top_of_key() { + if (inset && $children > 0) color($secondary_color) children(); + } + if(!$outset_legends) legends($inset_legend_depth); + // subtract the clearance check if it's enabled, letting the user see the + // parts of the keycap that will hit the cherry switch + // this is a little confusing as it eats the stem too + /* if ($clearance_check) clearance_check(); */ +} + +// features inside the key itself (stem, supports, etc) +module inside_features() { + // Stems and stabilizers are not "inside features" unless they are fully + // contained inside the cap. otherwise they'd be cut off when they are + // differenced with the outside shape. this only matters if $stem_inset + // is negative + if ($stem_inset >= 0) stems_and_stabilizers(); + if ($support_type != "disable") translate([0, 0, $stem_inset]) support_for($stem_positions, $stem_type); + if ($stabilizer_type != "disable") translate([0, 0, $stem_inset]) support_for($stabilizers, $stabilizer_type); +} + +// all stems and stabilizers +module stems_and_stabilizers() { + translate([0, 0, $stem_inset]) { + if ($stabilizer_type != "disable") stems_for($stabilizers, $stabilizer_type); + if ($stem_type != "disable") stems_for($stem_positions, $stem_type); } } -// key with hollowed inside but no stem -module hollow_key() { - difference(){ - if ($rounded_key) { - rounded_shape(); - } else { - shape(0, 0); - } - // translation purely for aesthetic purposes, to get rid of that awful lattice - translate([0,0,-SMALLEST_POSSIBLE]) { - shape($wall_thickness, $keytop_thickness); - } +// helpers for doubleshot keycaps for now +module inner_total_shape() { + difference() { + inner_shape(); + inside_features(); } } +module outer_total_shape(inset=false) { + outer_shape(); + additive_features(inset) { + children(); + }; +} // The final, penultimate key generation function. // takes all the bits and glues them together. requires configuration with special variables. -module key(inset = false) { - difference() { - union(){ - // the shape of the key, inside and out - hollow_key(); - if($key_bump) top_of_key() keybump($key_bump_depth, $key_bump_edge); - // additive objects at the top of the key - // outside() makes them stay out of the inside. it's a bad name - if(!inset && $children > 0) outside() artisan(0) children(); - if($outset_legends) legends(0); - // render the clearance check if it's enabled, but don't have it intersect with anything - if ($clearance_check) %clearance_check(); - } +module key(inset=false) { + difference(){ + outer_total_shape(inset); - // subtractive objects at the top of the key - // no outside() - I can't think of a use for it. will save render time - if (inset && $children > 0) artisan($inset_legend_depth) children(); - if(!$outset_legends) legends($inset_legend_depth); - // subtract the clearance check if it's enabled, letting the user see the - // parts of the keycap that will hit the cherry switch - if ($clearance_check) %clearance_check(); - } - - // both stem and support are optional - if ($stem_type != "disable" || ($stabilizers != [] && $stabilizer_type != "disable")) { - dished($keytop_thickness, $inverted_dish) { - translate([0, 0, $stem_inset]) { - if ($stabilizer_type != "disable") stems_for($stabilizers, $stabilizer_type); - - if ($stem_type != "disable") stems_for($stem_positions, $stem_type); + if ($inner_shape_type != "disable") { + translate([0,0,-SMALLEST_POSSIBLE]) { + inner_total_shape(); } } + + subtractive_features(inset) { + children(); + }; } - if ($support_type != "disable"){ - inside() { - translate([0, 0, $stem_inset]) { - if ($stabilizer_type != "disable") support_for($stabilizers, $stabilizer_type); - - // always render stem support even if there isn't a stem. - // rendering flat support w/no stem is much more common than a hollow keycap - // so if you want a hollow keycap you'll have to turn support off entirely - support_for($stem_positions, $stem_type); - } - } + // if $stem_inset is less than zero, we add the + if ($stem_inset < 0) { + stems_and_stabilizers(); } } diff --git a/src/key_profiles.scad b/src/key_profiles.scad index e6b49b6..83ff5e1 100644 --- a/src/key_profiles.scad +++ b/src/key_profiles.scad @@ -9,6 +9,9 @@ include include include include +include +include +include // man, wouldn't it be so cool if functions were first order module key_profile(key_profile_type, row, column=0) { @@ -18,6 +21,8 @@ module key_profile(key_profile_type, row, column=0) { oem_row(row, column) children(); } else if (key_profile_type == "dsa") { dsa_row(row, column) children(); + } else if (key_profile_type == "dss") { + dss_row(row, column) children(); } else if (key_profile_type == "sa") { sa_row(row, column) children(); } else if (key_profile_type == "g20") { @@ -26,6 +31,12 @@ module key_profile(key_profile_type, row, column=0) { hipro_row(row, column) children(); } else if (key_profile_type == "grid") { grid_row(row, column) children(); + } else if (key_profile_type == "hexagon") { + hexagonal_row(row, column) children(); + } else if (key_profile_type == "octagon") { + octagonal_row(row, column) children(); + } else if (key_profile_type == "cherry") { + cherry_row(row, column) children(); } else if (key_profile_type == "disable") { children(); } else { diff --git a/src/key_profiles/cherry.scad b/src/key_profiles/cherry.scad new file mode 100644 index 0000000..fb5950f --- /dev/null +++ b/src/key_profiles/cherry.scad @@ -0,0 +1,48 @@ +// based off GMK keycap set + +module cherry_row(row=3, column=0) { + $bottom_key_width = 18.16; + $bottom_key_height = 18.16; + $width_difference = $bottom_key_width - 11.85; + $height_difference = $bottom_key_height - 14.64; + $dish_type = "cylindrical"; + $dish_depth = 0.65; + $dish_skew_x = 0; + $dish_skew_y = 0; + $top_skew = 2; + + $top_tilt_y = side_tilt(column); + extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; + + // NOTE: cherry keycaps have this stem inset, but I'm reticent to turn it on + // since it'll be surprising to folks. the height has been adjusted accordingly + // $stem_inset = 0.6; + extra_stem_inset_height = max(0.6 - $stem_inset, 0); + + // <= is a hack so you can do these in a for loop. function row = 0 + if (row <= 1) { + $total_depth = 9.8 - extra_stem_inset_height + extra_height; + $top_tilt = 0; + + children(); + } else if (row == 2) { + $total_depth = 7.45 - extra_stem_inset_height + extra_height; + $top_tilt = 2.5; + + children(); + } else if (row == 3) { + $total_depth = 6.55 - extra_stem_inset_height + extra_height; + $top_tilt = 5; + children(); + } else if (row == 3) { + $total_depth = 6.7 + 0.65 - extra_stem_inset_height + extra_height; + $top_tilt = 11.5; + children(); + } else if (row >= 4) { + $total_depth = 6.7 + 0.65 - extra_stem_inset_height + extra_height; + $top_tilt = 11.5; + children(); + } else { + children(); + } +} diff --git a/src/key_profiles/dsa.scad b/src/key_profiles/dsa.scad index a440fa9..766084b 100644 --- a/src/key_profiles/dsa.scad +++ b/src/key_profiles/dsa.scad @@ -12,7 +12,7 @@ module dsa_row(row=3, column = 0) { $dish_skew_y = 0; $height_slices = 10; $enable_side_sculpting = true; - $corner_radius = 0.25; + $corner_radius = 1; $top_tilt_y = side_tilt(column); extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; diff --git a/src/key_profiles/dss.scad b/src/key_profiles/dss.scad new file mode 100644 index 0000000..0e501ac --- /dev/null +++ b/src/key_profiles/dss.scad @@ -0,0 +1,49 @@ +module dss_row(n=3, column=0) { + $key_shape_type = "sculpted_square"; + $bottom_key_width = 18.24; + $bottom_key_height = 18.24; + $width_difference = 6; + $height_difference = 6; + $dish_type = "spherical"; + $dish_depth = 1.2; + $dish_skew_x = 0; + $dish_skew_y = 0; + $top_skew = 0; + $height_slices = 10; + $enable_side_sculpting = true; + // might wanna change this if you don't minkowski + // do you even minkowski bro + $corner_radius = 1; + + // this is _incredibly_ intensive + /* $rounded_key = true; */ + + $top_tilt_y = side_tilt(column); + extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; + + // 5th row is usually unsculpted or the same as the row below it + // making a super-sculpted top row (or bottom row!) would be real easy + // bottom row would just be 13 tilt and 14.89 total depth + // top row would be something new entirely - 18 tilt maybe? + if (n <= 1){ + $total_depth = 10.5 + extra_height; + $top_tilt = -1; + children(); + } else if (n == 2) { + $total_depth = 8.6 + extra_height; + $top_tilt = 3; + children(); + } else if (n == 3) { + $total_depth = 7.9 + extra_height; + $top_tilt = 8; + children(); + } else if (n == 4){ + $total_depth = 9.1 + extra_height; + $top_tilt = 16; + children(); + } else { + $total_depth = 7.9 + extra_height; + $top_tilt = 8; + children(); + } +} \ No newline at end of file diff --git a/src/key_profiles/grid.scad b/src/key_profiles/grid.scad index 2528e11..c81be46 100644 --- a/src/key_profiles/grid.scad +++ b/src/key_profiles/grid.scad @@ -1,8 +1,8 @@ module grid_row(row=3, column = 0) { $bottom_key_width = 18.16; $bottom_key_height = 18.16; - $width_difference = 0.2; - $height_difference = 0.2; + $width_difference = 1; + $height_difference = 1; $top_tilt = 0; $top_skew = 0; $dish_type = "old spherical"; @@ -11,11 +11,11 @@ module grid_row(row=3, column = 0) { $dish_skew_x = 0; $dish_skew_y = 0; - $linear_extrude_shape = true; + $hull_shape_type = "linear extrude"; - $dish_overdraw_width = -8; - $dish_overdraw_height = -8; + $dish_overdraw_width = -6.5; + $dish_overdraw_height = -6.5; $minkowski_radius = 0.5; //also, @@ -24,7 +24,7 @@ module grid_row(row=3, column = 0) { $top_tilt_y = side_tilt(column); extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; - $total_depth = 6 + abs((row-3) * 0.5) + extra_height; + $total_depth = 7 + abs((row-3) * 0.5) + extra_height; if (row == 5 || row == 0) { /* $top_tilt = -18.55; */ diff --git a/src/key_profiles/hipro.scad b/src/key_profiles/hipro.scad index f456b51..0335a1a 100644 --- a/src/key_profiles/hipro.scad +++ b/src/key_profiles/hipro.scad @@ -13,9 +13,7 @@ module hipro_row(row=3, column=0) { $dish_skew_y = 0; $top_skew = 0; $height_slices = 10; - // might wanna change this if you don't minkowski - // do you even minkowski bro - $corner_radius = 0.25; + $corner_radius = 1; $top_tilt_y = side_tilt(column); extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; diff --git a/src/key_profiles/regular_polygon.scad b/src/key_profiles/regular_polygon.scad new file mode 100644 index 0000000..2f93ca9 --- /dev/null +++ b/src/key_profiles/regular_polygon.scad @@ -0,0 +1,66 @@ +include <../constants.scad> +// Regular polygon shapes CIRCUMSCRIBE the sphere of diameter $bottom_key_width +// This is to make tiling them easier, like in the case of hexagonal keycaps etc + +// this function doesn't set the key shape, so you can't use it directly without some fiddling +module regular_polygon_row(n=3, column=0) { + $bottom_key_width = $unit - 0.5; + $bottom_key_height = $unit - 0.5; + $width_difference = 0; + $height_difference = 0; + $dish_type = "spherical"; + $dish_depth = 0.85; + $dish_skew_x = 0; + $dish_skew_y = 0; + $top_skew = 0; + $height_slices = 1; + $corner_radius = 1; + + // this is _incredibly_ intensive + /* $rounded_key = true; */ + + $top_tilt_y = side_tilt(column); + extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; + + base_depth = 7.5; + if (n <= 1){ + $total_depth = base_depth + 2.5 + extra_height; + $top_tilt = -13; + + children(); + } else if (n == 2) { + $total_depth = base_depth + 0.5 + extra_height; + $top_tilt = -7; + + children(); + } else if (n == 3) { + $total_depth = base_depth + extra_height; + $top_tilt = 0; + + children(); + } else if (n == 4){ + $total_depth = base_depth + 0.5 + extra_height; + $top_tilt = 7; + + children(); + } else { + $total_depth = base_depth + extra_height; + $top_tilt = 0; + + children(); + } +} + +module hexagonal_row(n=3, column=0) { + $key_shape_type = "hexagon"; + regular_polygon_row(n,column) { + children(); + } +} + +module octagonal_row(n=3, column=0) { + $key_shape_type = "octagon"; + regular_polygon_row(n, column) { + children(); + } +} diff --git a/src/key_profiles/sa.scad b/src/key_profiles/sa.scad index ad53a43..3382491 100644 --- a/src/key_profiles/sa.scad +++ b/src/key_profiles/sa.scad @@ -10,9 +10,7 @@ module sa_row(n=3, column=0) { $dish_skew_y = 0; $top_skew = 0; $height_slices = 10; - // might wanna change this if you don't minkowski - // do you even minkowski bro - $corner_radius = 0.25; + $corner_radius = 1; // this is _incredibly_ intensive /* $rounded_key = true; */ diff --git a/src/key_sizes.scad b/src/key_sizes.scad index 6e06fb5..cd04b6e 100644 --- a/src/key_sizes.scad +++ b/src/key_sizes.scad @@ -17,6 +17,10 @@ module 1_5u() { u(1.5) children(); } +module 1_75u(){ + u(1.75) children(); +} + module 2u() { u(2) children(); } @@ -25,6 +29,10 @@ module 2_25u() { u(2.25) children(); } +module 2_50u() { + u(2.5) children(); +} + module 2_75u() { u(2.75) children(); } diff --git a/src/key_transformations.scad b/src/key_transformations.scad index f873a59..4d98cdf 100644 --- a/src/key_transformations.scad +++ b/src/key_transformations.scad @@ -1,10 +1,9 @@ // kind of a catch-all at this point for any directive that doesn't fit in the other files -//TODO duplicate def to not make this a special var. maybe not worth it -unit = 19.05; +include module translate_u(x=0, y=0, z=0){ - translate([x * unit, y*unit, z*unit]) children(); + translate([x * $unit, y*$unit, z*$unit]) children(); } module no_stem_support() { @@ -44,6 +43,12 @@ module rotated() { children(); } +module vertically_stabilized(mm=12, vertical=true, type=undef) { + stabilized(mm,vertical,type) { + children(); + } +} + module stabilized(mm=12, vertical = false, type=undef) { if (vertical) { $stabilizer_type = (type ? type : ($stabilizer_type ? $stabilizer_type : "costar_stabilizer")); @@ -86,30 +91,58 @@ module blank() { children(); } -module cherry(slop) { - $stem_slop = slop ? slop : $stem_slop; +module cherry(slop = undef) { + $stem_slop = slop != undef ? slop : $stem_slop; $stem_type = "cherry"; children(); } -module alps(slop) { - $stem_slop = slop ? slop : $stem_slop; +module alps(slop = undef) { + $stem_slop = slop != undef ? slop : $stem_slop; $stem_type = "alps"; children(); } -module rounded_cherry(slop) { - $stem_slop = slop ? slop : $stem_slop; +module rounded_cherry(slop = undef) { + $stem_slop = slop != undef ? slop : $stem_slop; $stem_type = "rounded_cherry"; children(); } -module box_cherry(slop) { - $stem_slop = slop ? slop : $stem_slop; +module box_cherry(slop = undef) { + $stem_slop = slop != undef ? slop : $stem_slop; $stem_type = "box_cherry"; children(); } +module choc(slop = 0.05) { + echo("WARN:\n\n * choc support is experimental.\n * $stem_slop is overridden.\n * it is also recommended to print them upside down if you can\n\n"); + $stem_throw = 3; + $stem_slop = slop; + + $bottom_key_width = 18; + $bottom_key_height = 17; + + $stem_type = "choc"; + children(); +} + +// a hacky way to make "low profile" keycaps +module low_profile() { + $width_difference = $width_difference / 1.5; + $height_difference = $height_difference / 1.5; + // helps tilted keycaps not have holes if worst comes to worst + $inner_shape_type = "dished"; + + $top_tilt = $top_tilt / 1.25; + + $total_depth = ($total_depth / 2) < 7 ? 7 : $total_depth / 2; + + // just to make sure + $stem_throw = 3; + children(); +} + module flared_support() { $support_type = "flared"; children(); @@ -177,3 +210,16 @@ module debug() { %children(); } + +// auto-place children in a grid. +// For this to work all children have to be single keys, no for loops etc +module auto_place() { + num_children = $children; + row_size = round(pow(num_children, 0.5)); + + for (child_index = [0:num_children-1]) { + x = child_index % row_size; + y = floor(child_index / row_size); + translate_u(x,-y) children(child_index); + } +} diff --git a/src/key_types.scad b/src/key_types.scad index 1b821a1..a6c1ab6 100644 --- a/src/key_types.scad +++ b/src/key_types.scad @@ -1,6 +1,8 @@ +include + module spacebar() { - $inverted_dish = true; - $dish_type = "sideways cylindrical"; + $inverted_dish = $dish_type != "disable"; + $dish_type = $dish_type != "disable" ? "sideways cylindrical" : "disable"; 6_25u() stabilized(mm=50) children(); } @@ -43,16 +45,19 @@ module iso_enter() { $key_length = 1.5; $key_height = 2; - $top_tilt = 0; + $dish_offset_x = -(unit_length(1.5) - unit_length(1.25))/2; + + /* $top_tilt = 0; */ $stem_support_type = "disable"; $key_shape_type = "iso_enter"; - /* $linear_extrude_shape = true; */ + $hull_shape_type = "skin"; $linear_extrude_height_adjustment = 19.05 * 0.5; // this equals (unit_length(1.5) - unit_length(1.25)) / 2 - $dish_overdraw_width = 2.38125; + /* $dish_overdraw_width = 2.38125; */ - - stabilized(vertical=true) { - children(); + render() { + stabilized(vertical=true) { + children(); + } } } diff --git a/src/layouts/lets_split/default.scad b/src/layouts/lets_split/default.scad index e3824de..c236d43 100644 --- a/src/layouts/lets_split/default.scad +++ b/src/layouts/lets_split/default.scad @@ -1,7 +1,7 @@ include <../layout.scad> // negative numbers are used for spacing -lets_split_mapping = [ +lets_split_layout = [ [1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1], @@ -9,5 +9,5 @@ lets_split_mapping = [ ]; module lets_split_default(profile) { - layout(lets_split_mapping, profile, row_sculpting_offset=1) children(); + layout(lets_split_layout, profile, row_sculpting_offset=1) children(); } diff --git a/src/libraries/round-anything/polyround.scad b/src/libraries/round-anything/polyround.scad new file mode 100644 index 0000000..10c3d07 --- /dev/null +++ b/src/libraries/round-anything/polyround.scad @@ -0,0 +1,687 @@ +// Library: round-anything +// Version: 1.0 +// Author: IrevDev +// Contributors: TLC123 +// Copyright: 2020 +// License: MIT + + +function addZcoord(points,displacement)=[for(i=[0:len(points)-1])[points[i].x,points[i].y, displacement]]; +function translate3Dcoords(points,tran=[0,0,0],mult=[1,1,1])=[for(i=[0:len(points)-1])[ + (points[i].x*mult.x)+tran.x, + (points[i].y*mult.y)+tran.y, + (points[i].z*mult.z)+tran.z +]]; +function offsetPolygonPoints(points, offset=0)= +// Work sthe same as the offset does, except for the fact that instead of a 2d shape +// It works directly on polygon points +// It returns the same number of points just offset into or, away from the original shape. +// points= a series of x,y points[[x1,y1],[x2,y2],...] +// offset= amount to offset by, negative numbers go inwards into the shape, positive numbers go out +// return= a series of x,y points[[x1,y1],[x2,y2],...] +let( + isCWorCCW=sign(offset)*CWorCCW(points)*-1, + lp=len(points) +) +[for(i=[0:lp-1]) parallelFollow([ + points[listWrap(i-1,lp)], + points[i], + points[listWrap(i+1,lp)], +],thick=offset,mode=isCWorCCW)]; + +function makeCurvedPartOfPolyHedron(radiiPoints,r,fn,minR=0.01)= +// this is a private function that I'm not expecting library users to use directly +// radiiPoints= serise of x, y, r points +// r= radius of curve that will be put on the end of the extrusion +// fn= amount of subdivisions +// minR= if one of the points in radiiPoints is less than r, it's likely to converge and form a sharp edge, +// the min radius on these converged edges can be controled with minR, though because of legacy reasons it can't be 0, but can be a very small number. +// return= array of [polyhedronPoints, Polyhedronfaces, theLength of a singe layer in the curve] +let( + lp=len(radiiPoints), + radii=[for(i=[0:lp-1])radiiPoints[i].z], + isCWorCCWOverall=CWorCCW(radiiPoints), + dir=sign(r), + absR=abs(r), + fractionOffLp=1-1/fn, + allPoints=[for(fraction=[0:1/fn:1]) + let( + iterationOffset=dir*sqrt(sq(absR)-sq(fraction*absR))-dir*absR, + theOffsetPoints=offsetPolygonPoints(radiiPoints,iterationOffset), + polyRoundOffsetPoints=[for(i=[0:lp-1]) + let( + pointsAboutCurrent=[ + theOffsetPoints[listWrap(i-1,lp)], + theOffsetPoints[i], + theOffsetPoints[listWrap(i+1,lp)] + ], + isCWorCCWLocal=CWorCCW(pointsAboutCurrent), + isInternalRadius=(isCWorCCWLocal*isCWorCCWOverall)==-1, + // the radius names are only true for positive r, + // when are r is negative increasingRadius is actually decreasing and vice-vs + // increasingRadiusWithPositiveR is just to verbose of a variable name for my liking + increasingRadius=max(radii[i]-iterationOffset, minR), + decreasingRadius=max(radii[i]+iterationOffset, minR) + ) + [theOffsetPoints[i].x, theOffsetPoints[i].y, isInternalRadius? increasingRadius: decreasingRadius] + ], + pointsForThisLayer=polyRound(polyRoundOffsetPoints,fn) + ) + addZcoord(pointsForThisLayer,fraction*absR) + ], + polyhedronPoints=flatternArray(allPoints), + allLp=len(allPoints), + layerLength=len(allPoints[0]), + loopToSecondLastLayer=allLp-2, + sideFaces=[for(layerIndex=[0:loopToSecondLastLayer])let( + currentLayeroffset=layerIndex*layerLength, + nextLayeroffset=(layerIndex+1)*layerLength, + layerFaces=[for(subLayerIndex=[0:layerLength-1]) + [ + currentLayeroffset+subLayerIndex, currentLayeroffset + listWrap(subLayerIndex+1,layerLength), nextLayeroffset+listWrap(subLayerIndex+1,layerLength), nextLayeroffset+subLayerIndex] + ] + )layerFaces], + polyhedronFaces=flatternArray(sideFaces) +) +[polyhedronPoints, polyhedronFaces, layerLength]; + +function flatternRecursion(array, init=[], currentIndex)= +// this is a private function, init and currentIndex are for the function's use +// only for when it's calling itself, which is why there is a simplified version flatternArray that just calls this one +// array= array to flattern by one level of nesting +// init= the array used to cancat with the next call, only for when the function calls itself +// currentIndex= so the function can keep track of how far it's progressed through the array, only for when it's calling itself +// returns= flatterned array, by one level of nesting +let( + shouldKickOffRecursion=currentIndex==undef?1:0, + isLastIndex=currentIndex+1==len(array)?1:0, + flatArray=shouldKickOffRecursion?flatternRecursion(array,[],0): + isLastIndex?concat(init,array[currentIndex]): + flatternRecursion(array,concat(init,array[currentIndex]),currentIndex+1) +) +flatArray; + +function flatternArray(array)= +// public version of flatternRecursion, has simplified params to avoid confusion +// array= array to be flatterned +// return= array that been flatterend by one level of nesting +flatternRecursion(array); + +function offsetAllFacesBy(array,offset)=[ + // polyhedron faces are simply a list of indices to points, if your concat points together than you probably need to offset + // your faces array to points to the right place in the new list + // array= array of point indicies + // offset= number to offset all indecies by + // return= array of point indices (i.e. faces) with offset applied + for(faceIndex=[0:len(array)-1])[ + for(pointIndex=[0:len(array[faceIndex])-1])array[faceIndex][pointIndex]+offset + ] +]; + +function extrudePolygonWithRadius(radiiPoints,h=5,r1=1,r2=1,fn=4)= +// this basically calls makeCurvedPartOfPolyHedron twice to get the curved section of the final polyhedron +// and then goes about assmbling them, as the side faces and the top and bottom face caps are missing +// radiiPoints= series of [x,y,r] points, +// h= height of the extrude (total including radius sections) +// r1,r2= define the radius at the top and bottom of the extrud respectively, negative number flange out the extrude +// fn= number of subdivisions +// returns= [polyhedronPoints, polyhedronFaces] +let( + // top is the top curved part of the extrude + top=makeCurvedPartOfPolyHedron(radiiPoints,r1,fn), + topRadiusPoints=translate3Dcoords(top[0],[0,0,h-r1]), + singeLayerLength=top[2], + topRadiusFaces=top[1], + radiusPointsLength=len(topRadiusPoints), // is the same length as bottomRadiusPoints + // bottom is the bottom curved part of the extrude + bottom=makeCurvedPartOfPolyHedron(radiiPoints,r2,fn), + // Z axis needs to be multiplied by -1 to flip it so the radius is going in the right direction [1,1,-1] + bottomRadiusPoints=translate3Dcoords(bottom[0],[0,0,abs(r2)],[1,1,-1]), + // becaues the points will be all concatenated into the same array, and the bottom points come second, than + // the original indices the faces are points towards are wrong and need to have an offset applied to them + bottomRadiusFaces=offsetAllFacesBy(bottom[1],radiusPointsLength), + // all of the side panel of the extrusion, connecting points from the inner layers of each + // of the curved sections + sideFaces=[for(i=[0:singeLayerLength-1])[ + i, + listWrap(i+1,singeLayerLength), + radiusPointsLength + listWrap(i+1,singeLayerLength), + radiusPointsLength + i + ]], + // both of these caps are simple every point from the last layer of the radius points + topCapFace=[for(i=[0:singeLayerLength-1])radiusPointsLength-singeLayerLength+i], + bottomCapFace=[for(i=[0:singeLayerLength-1])radiusPointsLength*2-singeLayerLength+i], + finalPolyhedronPoints=concat(topRadiusPoints,bottomRadiusPoints), + finalPolyhedronFaces=concat(topRadiusFaces,bottomRadiusFaces, sideFaces, [topCapFace], [bottomCapFace]) +) +[ + finalPolyhedronPoints, + finalPolyhedronFaces +]; + +module polyRoundExtrude(radiiPoints,length=5,r1=1,r2=1,fn=10,convexity=10) { + polyhedronPointsNFaces=extrudePolygonWithRadius(radiiPoints,length,r1,r2,fn); + polyhedron(points=polyhedronPointsNFaces[0], faces=polyhedronPointsNFaces[1], convexity=convexity); +} + + +// testingInternals(); +module testingInternals(){ + //example of rounding random points, this has no current use but is a good demonstration + random=[for(i=[0:20])[rnd(0,50),rnd(0,50),/*rnd(0,30)*/1000]]; + R =polyRound(random,7); + translate([-25,25,0]){ + polyline(R); + } + + //example of different modes of the CentreN2PointsArc() function 0=shortest arc, 1=longest arc, 2=CW, 3=CCW + p1=[0,5];p2=[10,5];centre=[5,0]; + translate([60,0,0]){ + color("green"){ + polygon(CentreN2PointsArc(p1,p2,centre,0,20));//draws the shortest arc + } + color("cyan"){ + polygon(CentreN2PointsArc(p1,p2,centre,1,20));//draws the longest arc + } + } + translate([75,0,0]){ + color("purple"){ + polygon(CentreN2PointsArc(p1,p2,centre,2,20));//draws the arc CW (which happens to be the short arc) + } + color("red"){ + polygon(CentreN2PointsArc(p2,p1,centre,2,20));//draws the arc CW but p1 and p2 swapped order resulting in the long arc being drawn + } + } + + radius=6; + radiipoints=[[0,0,0],[10,20,radius],[20,0,0]]; + tangentsNcen=round3points(radiipoints); + translate([10,0,0]){ + for(i=[0:2]){ + color("red")translate(getpoints(radiipoints)[i])circle(1);//plots the 3 input points + color("cyan")translate(tangentsNcen[i])circle(1);//plots the two tangent poins and the circle centre + } + translate([tangentsNcen[2][0],tangentsNcen[2][1],-0.2])circle(r=radius,$fn=25);//draws the cirle + %polygon(getpoints(radiipoints));//draws a polygon + } +} + +function polyRound(radiipoints,fn=5,mode=0)= + /*Takes a list of radii points of the format [x,y,radius] and rounds each point + with fn resolution + mode=0 - automatic radius limiting - DEFAULT + mode=1 - Debug, output radius reduction for automatic radius limiting + mode=2 - No radius limiting*/ + let( + p=getpoints(radiipoints), //make list of coordinates without radii + Lp=len(p), + //remove the middle point of any three colinear points, otherwise adding a radius to the middle of a straigh line causes problems + radiiPointsWithoutTrippleColinear=[ + for(i=[0:len(p)-1]) if( + // keep point if it isn't colinear or if the radius is 0 + !isColinear( + p[listWrap(i-1,Lp)], + p[listWrap(i+0,Lp)], + p[listWrap(i+1,Lp)] + )|| + p[listWrap(i+0,Lp)].z!=0 + ) radiipoints[listWrap(i+0,Lp)] + ], + newrp2=processRadiiPoints(radiiPointsWithoutTrippleColinear), + plusMinusPointRange=mode==2?1:2, + temp=[ + for(i=[0:len(newrp2)-1]) //for each point in the radii array + let( + thepoints=[for(j=[-plusMinusPointRange:plusMinusPointRange])newrp2[listWrap(i+j,len(newrp2))]],//collect 5 radii points + temp2=mode==2?round3points(thepoints,fn):round5points(thepoints,fn,mode) + ) + mode==1?temp2:newrp2[i][2]==0? + [[newrp2[i][0],newrp2[i][1]]]: //return the original point if the radius is 0 + CentreN2PointsArc(temp2[0],temp2[1],temp2[2],0,fn) //return the arc if everything is normal + ] + ) + [for (a = temp) for (b = a) b];//flattern and return the array + +function round5points(rp,fn,debug=0)= + rp[2][2]==0&&debug==0?[[rp[2][0],rp[2][1]]]://return the middle point if the radius is 0 + rp[2][2]==0&&debug==1?0://if debug is enabled and the radius is 0 return 0 + let( + p=getpoints(rp), //get list of points + r=[for(i=[1:3]) abs(rp[i][2])],//get the centre 3 radii + //start by determining what the radius should be at point 3 + //find angles at points 2 , 3 and 4 + a2=cosineRuleAngle(p[0],p[1],p[2]), + a3=cosineRuleAngle(p[1],p[2],p[3]), + a4=cosineRuleAngle(p[2],p[3],p[4]), + //find the distance between points 2&3 and between points 3&4 + d23=pointDist(p[1],p[2]), + d34=pointDist(p[2],p[3]), + //find the radius factors + F23=(d23*tan(a2/2)*tan(a3/2))/(r[0]*tan(a3/2)+r[1]*tan(a2/2)), + F34=(d34*tan(a3/2)*tan(a4/2))/(r[1]*tan(a4/2)+r[2]*tan(a3/2)), + newR=min(r[1],F23*r[1],F34*r[1]),//use the smallest radius + //now that the radius has been determined, find tangent points and circle centre + tangD=newR/tan(a3/2),//distance to the tangent point from p3 + circD=newR/sin(a3/2),//distance to the circle centre from p3 + //find the angle from the p3 + an23=getAngle(p[1],p[2]),//angle from point 3 to 2 + an34=getAngle(p[3],p[2]),//angle from point 3 to 4 + //find tangent points + t23=[p[2][0]-cos(an23)*tangD,p[2][1]-sin(an23)*tangD],//tangent point between points 2&3 + t34=[p[2][0]-cos(an34)*tangD,p[2][1]-sin(an34)*tangD],//tangent point between points 3&4 + //find circle centre + tmid=getMidpoint(t23,t34),//midpoint between the two tangent points + anCen=getAngle(tmid,p[2]),//angle from point 3 to circle centre + cen=[p[2][0]-cos(anCen)*circD,p[2][1]-sin(anCen)*circD] + ) + //circle center by offseting from point 3 + //determine the direction of rotation + debug==1?//if debug in disabled return arc (default) + (newR-r[1]): + [t23,t34,cen]; + +function round3points(rp,fn)= + rp[1][2]==0?[[rp[1][0],rp[1][1]]]://return the middle point if the radius is 0 + let( + p=getpoints(rp), //get list of points + r=rp[1][2],//get the centre 3 radii + ang=cosineRuleAngle(p[0],p[1],p[2]),//angle between the lines + //now that the radius has been determined, find tangent points and circle centre + tangD=r/tan(ang/2),//distance to the tangent point from p2 + circD=r/sin(ang/2),//distance to the circle centre from p2 + //find the angles from the p2 with respect to the postitive x axis + angleFromPoint1ToPoint2=getAngle(p[0],p[1]), + angleFromPoint2ToPoint3=getAngle(p[2],p[1]), + //find tangent points + t12=[p[1][0]-cos(angleFromPoint1ToPoint2)*tangD,p[1][1]-sin(angleFromPoint1ToPoint2)*tangD],//tangent point between points 1&2 + t23=[p[1][0]-cos(angleFromPoint2ToPoint3)*tangD,p[1][1]-sin(angleFromPoint2ToPoint3)*tangD],//tangent point between points 2&3 + //find circle centre + tmid=getMidpoint(t12,t23),//midpoint between the two tangent points + angCen=getAngle(tmid,p[1]),//angle from point 2 to circle centre + cen=[p[1][0]-cos(angCen)*circD,p[1][1]-sin(angCen)*circD] //circle center by offseting from point 2 + ) + [t12,t23,cen]; + +function parallelFollow(rp,thick=4,minR=1,mode=1)= + //rp[1][2]==0?[rp[1][0],rp[1][1],0]://return the middle point if the radius is 0 + thick==0?[rp[1][0],rp[1][1],0]://return the middle point if the radius is 0 + let( + p=getpoints(rp), //get list of points + r=thick,//get the centre 3 radii + ang=cosineRuleAngle(p[0],p[1],p[2]),//angle between the lines + //now that the radius has been determined, find tangent points and circle centre + tangD=r/tan(ang/2),//distance to the tangent point from p2 + sgn=CWorCCW(rp),//rotation of the three points cw or ccw?let(sgn=mode==0?1:-1) + circD=mode*sgn*r/sin(ang/2),//distance to the circle centre from p2 + //find the angles from the p2 with respect to the postitive x axis + angleFromPoint1ToPoint2=getAngle(p[0],p[1]), + angleFromPoint2ToPoint3=getAngle(p[2],p[1]), + //find tangent points + t12=[p[1][0]-cos(angleFromPoint1ToPoint2)*tangD,p[1][1]-sin(angleFromPoint1ToPoint2)*tangD],//tangent point between points 1&2 + t23=[p[1][0]-cos(angleFromPoint2ToPoint3)*tangD,p[1][1]-sin(angleFromPoint2ToPoint3)*tangD],//tangent point between points 2&3 + //find circle centre + tmid=getMidpoint(t12,t23),//midpoint between the two tangent points + angCen=getAngle(tmid,p[1]),//angle from point 2 to circle centre + cen=[p[1][0]-cos(angCen)*circD,p[1][1]-sin(angCen)*circD],//circle center by offseting from point 2 + outR=max(minR,rp[1][2]-thick*sgn*mode) //ensures radii are never too small. + ) + concat(cen,outR); + +function findPoint(ang1,refpoint1,ang2,refpoint2,r=0)= + let( + m1=tan(ang1), + c1=refpoint1.y-m1*refpoint1.x, + m2=tan(ang2), + c2=refpoint2.y-m2*refpoint2.x, + outputX=(c2-c1)/(m1-m2), + outputY=m1*outputX+c1 + ) + [outputX,outputY,r]; + +function beamChain(radiiPoints,offset1=0,offset2,mode=0,minR=0,startAngle,endAngle)= + /*This function takes a series of radii points and plots points to run along side at a consistant distance, think of it as offset but for line instead of a polygon + radiiPoints=radii points, + offset1 & offset2= The two offsets that give the beam it's thickness. When using with mode=2 only offset1 is needed as there is no return path for the polygon + minR=min radius, if all of your radii are set properly within the radii points this value can be ignored + startAngle & endAngle= Angle at each end of the beam, different mode determine if this angle is relative to the ending legs of the beam or absolute. + mode=1 - include endpoints startAngle&2 are relative to the angle of the last two points and equal 90deg if not defined + mode=2 - Only the forward path is defined, useful for combining the beam with other radii points, see examples for a use-case. + mode=3 - include endpoints startAngle&2 are absolute from the x axis and are 0 if not defined + negative radiuses only allowed for the first and last radii points + + As it stands this function could probably be tidied a lot, but it works, I'll tidy later*/ + let( + offset2undef=offset2==undef?1:0, + offset2=offset2undef==1?0:offset2, + CWorCCW1=sign(offset1)*CWorCCW(radiiPoints), + CWorCCW2=sign(offset2)*CWorCCW(radiiPoints), + offset1=abs(offset1), + offset2b=abs(offset2), + Lrp3=len(radiiPoints)-3, + Lrp=len(radiiPoints), + startAngle=mode==0&&startAngle==undef? + getAngle(radiiPoints[0],radiiPoints[1])+90: + mode==2&&startAngle==undef? + 0: + mode==0? + getAngle(radiiPoints[0],radiiPoints[1])+startAngle: + startAngle, + endAngle=mode==0&&endAngle==undef? + getAngle(radiiPoints[Lrp-1],radiiPoints[Lrp-2])+90: + mode==2&&endAngle==undef? + 0: + mode==0? + getAngle(radiiPoints[Lrp-1],radiiPoints[Lrp-2])+endAngle: + endAngle, + OffLn1=[for(i=[0:Lrp3]) offset1==0?radiiPoints[i+1]:parallelFollow([radiiPoints[i],radiiPoints[i+1],radiiPoints[i+2]],offset1,minR,mode=CWorCCW1)], + OffLn2=[for(i=[0:Lrp3]) offset2==0?radiiPoints[i+1]:parallelFollow([radiiPoints[i],radiiPoints[i+1],radiiPoints[i+2]],offset2b,minR,mode=CWorCCW2)], + Rp1=abs(radiiPoints[0].z), + Rp2=abs(radiiPoints[Lrp-1].z), + endP1a=findPoint(getAngle(radiiPoints[0],radiiPoints[1]), OffLn1[0], startAngle,radiiPoints[0], Rp1), + endP1b=findPoint(getAngle(radiiPoints[Lrp-1],radiiPoints[Lrp-2]), OffLn1[len(OffLn1)-1], endAngle,radiiPoints[Lrp-1], Rp2), + endP2a=findPoint(getAngle(radiiPoints[0],radiiPoints[1]), OffLn2[0], startAngle,radiiPoints[0], Rp1), + endP2b=findPoint(getAngle(radiiPoints[Lrp-1],radiiPoints[Lrp-2]), OffLn2[len(OffLn1)-1], endAngle,radiiPoints[Lrp-1], Rp2), + absEnda=getAngle(endP1a,endP2a), + absEndb=getAngle(endP1b,endP2b), + negRP1a=[cos(absEnda)*radiiPoints[0].z*10+endP1a.x, sin(absEnda)*radiiPoints[0].z*10+endP1a.y, 0.0], + negRP2a=[cos(absEnda)*-radiiPoints[0].z*10+endP2a.x, sin(absEnda)*-radiiPoints[0].z*10+endP2a.y, 0.0], + negRP1b=[cos(absEndb)*radiiPoints[Lrp-1].z*10+endP1b.x, sin(absEndb)*radiiPoints[Lrp-1].z*10+endP1b.y, 0.0], + negRP2b=[cos(absEndb)*-radiiPoints[Lrp-1].z*10+endP2b.x, sin(absEndb)*-radiiPoints[Lrp-1].z*10+endP2b.y, 0.0], + OffLn1b=(mode==0||mode==2)&&radiiPoints[0].z<0&&radiiPoints[Lrp-1].z<0? + concat([negRP1a],[endP1a],OffLn1,[endP1b],[negRP1b]) + :(mode==0||mode==2)&&radiiPoints[0].z<0? + concat([negRP1a],[endP1a],OffLn1,[endP1b]) + :(mode==0||mode==2)&&radiiPoints[Lrp-1].z<0? + concat([endP1a],OffLn1,[endP1b],[negRP1b]) + :mode==0||mode==2? + concat([endP1a],OffLn1,[endP1b]) + : + OffLn1, + OffLn2b=(mode==0||mode==2)&&radiiPoints[0].z<0&&radiiPoints[Lrp-1].z<0? + concat([negRP2a],[endP2a],OffLn2,[endP2b],[negRP2b]) + :(mode==0||mode==2)&&radiiPoints[0].z<0? + concat([negRP2a],[endP2a],OffLn2,[endP2b]) + :(mode==0||mode==2)&&radiiPoints[Lrp-1].z<0? + concat([endP2a],OffLn2,[endP2b],[negRP2b]) + :mode==0||mode==2? + concat([endP2a],OffLn2,[endP2b]) + : + OffLn2 + )//end of let() + offset2undef==1?OffLn1b:concat(OffLn2b,revList(OffLn1b)); + +function revList(list)=//reverse list + let(Llist=len(list)-1) + [for(i=[0:Llist]) list[Llist-i]]; + +function CWorCCW(p)= + let( + Lp=len(p), + e=[for(i=[0:Lp-1]) + (p[listWrap(i+0,Lp)].x-p[listWrap(i+1,Lp)].x)*(p[listWrap(i+0,Lp)].y+p[listWrap(i+1,Lp)].y) + ] + ) + sign(sum(e)); + +function CentreN2PointsArc(p1,p2,cen,mode=0,fn)= + /* This function plots an arc from p1 to p2 with fn increments using the cen as the centre of the arc. + the mode determines how the arc is plotted + mode==0, shortest arc possible + mode==1, longest arc possible + mode==2, plotted clockwise + mode==3, plotted counter clockwise + */ + let( + isCWorCCW=CWorCCW([cen,p1,p2]),//determine the direction of rotation + //determine the arc angle depending on the mode + p1p2Angle=cosineRuleAngle(p2,cen,p1), + arcAngle= + mode==0?p1p2Angle: + mode==1?p1p2Angle-360: + mode==2&&isCWorCCW==-1?p1p2Angle: + mode==2&&isCWorCCW== 1?p1p2Angle-360: + mode==3&&isCWorCCW== 1?p1p2Angle: + mode==3&&isCWorCCW==-1?p1p2Angle-360: + cosineRuleAngle(p2,cen,p1), + r=pointDist(p1,cen),//determine the radius + p1Angle=getAngle(cen,p1) //angle of line 1 + ) + [for(i=[0:fn]) + let(angleIncrement=(arcAngle/fn)*i*isCWorCCW) + [cos(p1Angle+angleIncrement)*r+cen.x,sin(p1Angle+angleIncrement)*r+cen.y]]; + +function translateRadiiPoints(radiiPoints,tran=[0,0],rot=0)= + [for(i=radiiPoints) + let( + a=getAngle([0,0],[i.x,i.y]),//get the angle of the this point + h=pointDist([0,0],[i.x,i.y]) //get the hypotenuse/radius + ) + [h*cos(a+rot)+tran.x,h*sin(a+rot)+tran.y,i.z]//calculate the point's new position + ]; + +module round2d(OR=3,IR=1){ + offset(OR,$fn=100){ + offset(-IR-OR,$fn=100){ + offset(IR,$fn=100){ + children(); + } + } + } +} + +module shell2d(offset1,offset2=0,minOR=0,minIR=0){ + difference(){ + round2d(minOR,minIR){ + offset(max(offset1,offset2)){ + children(0);//original 1st child forms the outside of the shell + } + } + round2d(minIR,minOR){ + difference(){//round the inside cutout + offset(min(offset1,offset2)){ + children(0);//shrink the 1st child to form the inside of the shell + } + if($children>1){ + for(i=[1:$children-1]){ + children(i);//second child and onwards is used to add material to inside of the shell + } + } + } + } + } +} + +module internalSq(size,r,center=0){ + tran=center==1?[0,0]:size/2; + translate(tran){ + square(size,true); + offs=sin(45)*r; + for(i=[-1,1],j=[-1,1]){ + translate([(size.x/2-offs)*i,(size.y/2-offs)*j])circle(r); + } + } +} + +module extrudeWithRadius(length,r1=0,r2=0,fn=30){ + n1=sign(r1);n2=sign(r2); + r1=abs(r1);r2=abs(r2); + translate([0,0,r1]){ + linear_extrude(length-r1-r2){ + children(); + } + } + for(i=[0:fn-1]){ + translate([0,0,i/fn*r1]){ + linear_extrude(r1/fn+0.01){ + offset(n1*sqrt(sq(r1)-sq(r1-i/fn*r1))-n1*r1){ + children(); + } + } + } + translate([0,0,length-r2+i/fn*r2]){ + linear_extrude(r2/fn+0.01){ + offset(n2*sqrt(sq(r2)-sq(i/fn*r2))-n2*r2){ + children(); + } + } + } + } +} + +function mirrorPoints(radiiPoints,rot=0,endAttenuation=[0,0])= //mirrors a list of points about Y, ignoring the first and last points and returning them in reverse order for use with polygon or polyRound + let( + a=translateRadiiPoints(radiiPoints,[0,0],-rot), + temp3=[for(i=[0+endAttenuation[0]:len(a)-1-endAttenuation[1]]) + [a[i][0],-a[i][1],a[i][2]] + ], + temp=translateRadiiPoints(temp3,[0,0],rot), + temp2=revList(temp3) + ) + concat(radiiPoints,temp2); + +function processRadiiPoints(rp)= + [for(i=[0:len(rp)-1]) + processRadiiPoints2(rp,i) + ]; + +function processRadiiPoints2(list,end=0,idx=0,result=0)= + idx>=end+1?result: + processRadiiPoints2(list,end,idx+1,relationalRadiiPoints(result,list[idx])); + +function cosineRuleBside(a,c,C)=c*cos(C)-sqrt(sq(a)+sq(c)+sq(cos(C))-sq(c)); + +function absArelR(po,pn)= + let( + th2=atan(po[1]/po[0]), + r2=sqrt(sq(po[0])+sq(po[1])), + r3=cosineRuleBside(r2,pn[1],th2-pn[0]) + ) + [cos(pn[0])*r3,sin(pn[0])*r3,pn[2]]; + +function relationalRadiiPoints(po,pi)= + let( + p0=pi[0], + p1=pi[1], + p2=pi[2], + pv0=pi[3][0], + pv1=pi[3][1], + pt0=pi[3][2], + pt1=pi[3][3], + pn= + (pv0=="y"&&pv1=="x")||(pv0=="r"&&pv1=="a")||(pv0=="y"&&pv1=="a")||(pv0=="x"&&pv1=="a")||(pv0=="y"&&pv1=="r")||(pv0=="x"&&pv1=="r")? + [p1,p0,p2,concat(pv1,pv0,pt1,pt0)]: + [p0,p1,p2,concat(pv0,pv1,pt0,pt1)], + n0=pn[0], + n1=pn[1], + n2=pn[2], + nv0=pn[3][0], + nv1=pn[3][1], + nt0=pn[3][2], + nt1=pn[3][3], + temp= + pn[0]=="l"? + [po[0],pn[1],pn[2]] + :pn[1]=="l"? + [pn[0],po[1],pn[2]] + :nv0==undef? + [pn[0],pn[1],pn[2]]//abs x, abs y as default when undefined + :nv0=="a"? + nv1=="r"? + nt0=="a"? + nt1=="a"||nt1==undef? + [cos(n0)*n1,sin(n0)*n1,n2]//abs angle, abs radius + :absArelR(po,pn)//abs angle rel radius + :nt1=="r"||nt1==undef? + [po[0]+cos(pn[0])*pn[1],po[1]+sin(pn[0])*pn[1],pn[2]]//rel angle, rel radius + :[pn[0],pn[1],pn[2]]//rel angle, abs radius + :nv1=="x"? + nt0=="a"? + nt1=="a"||nt1==undef? + [pn[1],pn[1]*tan(pn[0]),pn[2]]//abs angle, abs x + :[po[0]+pn[1],(po[0]+pn[1])*tan(pn[0]),pn[2]]//abs angle rel x + :nt1=="r"||nt1==undef? + [po[0]+pn[1],po[1]+pn[1]*tan(pn[0]),pn[2]]//rel angle, rel x + :[pn[1],po[1]+(pn[1]-po[0])*tan(pn[0]),pn[2]]//rel angle, abs x + :nt0=="a"? + nt1=="a"||nt1==undef? + [pn[1]/tan(pn[0]),pn[1],pn[2]]//abs angle, abs y + :[(po[1]+pn[1])/tan(pn[0]),po[1]+pn[1],pn[2]]//abs angle rel y + :nt1=="r"||nt1==undef? + [po[0]+(pn[1]-po[0])/tan(90-pn[0]),po[1]+pn[1],pn[2]]//rel angle, rel y + :[po[0]+(pn[1]-po[1])/tan(pn[0]),pn[1],pn[2]]//rel angle, abs y + :nv0=="r"? + nv1=="x"? + nt0=="a"? + nt1=="a"||nt1==undef? + [pn[1],sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1])),pn[2]]//abs radius, abs x + :[po[0]+pn[1],sign(pn[0])*sqrt(sq(pn[0])-sq(po[0]+pn[1])),pn[2]]//abs radius rel x + :nt1=="r"||nt1==undef? + [po[0]+pn[1],po[1]+sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1])),pn[2]]//rel radius, rel x + :[pn[1],po[1]+sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1]-po[0])),pn[2]]//rel radius, abs x + :nt0=="a"? + nt1=="a"||nt1==undef? + [sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1])),pn[1],pn[2]]//abs radius, abs y + :[sign(pn[0])*sqrt(sq(pn[0])-sq(po[1]+pn[1])),po[1]+pn[1],pn[2]]//abs radius rel y + :nt1=="r"||nt1==undef? + [po[0]+sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1])),po[1]+pn[1],pn[2]]//rel radius, rel y + :[po[0]+sign(pn[0])*sqrt(sq(pn[0])-sq(pn[1]-po[1])),pn[1],pn[2]]//rel radius, abs y + :nt0=="a"? + nt1=="a"||nt1==undef? + [pn[0],pn[1],pn[2]]//abs x, abs y + :[pn[0],po[1]+pn[1],pn[2]]//abs x rel y + :nt1=="r"||nt1==undef? + [po[0]+pn[0],po[1]+pn[1],pn[2]]//rel x, rel y + :[po[0]+pn[0],pn[1],pn[2]]//rel x, abs y + ) + temp; + +function invtan(run,rise)= + let(a=abs(atan(rise/run))) + rise==0&&run>0? + 0:rise>0&&run>0? + a:rise>0&&run==0? + 90:rise>0&&run<0? + 180-a:rise==0&&run<0? + 180:rise<0&&run<0? + a+180:rise<0&&run==0? + 270:rise<0&&run>0? + 360-a:"error"; + +function cosineRuleAngle(p1,p2,p3)= + let( + p12=abs(pointDist(p1,p2)), + p13=abs(pointDist(p1,p3)), + p23=abs(pointDist(p2,p3)) + ) + acos((sq(p23)+sq(p12)-sq(p13))/(2*p23*p12)); + +function sum(list, idx = 0, result = 0) = + idx >= len(list) ? result : sum(list, idx + 1, result + list[idx]); + +function sq(x)=x*x; +function getGradient(p1,p2)=(p2.y-p1.y)/(p2.x-p1.x); +function getAngle(p1,p2)=p1==p2?0:invtan(p2[0]-p1[0],p2[1]-p1[1]); +function getMidpoint(p1,p2)=[(p1[0]+p2[0])/2,(p1[1]+p2[1])/2]; //returns the midpoint of two points +function pointDist(p1,p2)=sqrt(abs(sq(p1[0]-p2[0])+sq(p1[1]-p2[1]))); //returns the distance between two points +function isColinear(p1,p2,p3)=getGradient(p1,p2)==getGradient(p2,p3)?1:0;//return 1 if 3 points are colinear +module polyline(p, width=0.3) { + for(i=[0:max(0,len(p)-1)]){ + color([i*1/len(p),1-i*1/len(p),0,0.5])line(p[i],p[listWrap(i+1,len(p) )],width); + } +} // polyline plotter +module line(p1, p2 ,width=0.3) { // single line plotter + hull() { + translate(p1){ + circle(width); + } + translate(p2){ + circle(width); + } + } +} + +function getpoints(p)=[for(i=[0:len(p)-1])[p[i].x,p[i].y]];// gets [x,y]list of[x,y,r]list +function listWrap(x,x_max=1,x_min=0) = (((x - x_min) % (x_max - x_min)) + (x_max - x_min)) % (x_max - x_min) + x_min; // wraps numbers inside boundaries +function rnd(a = 1, b = 0, s = []) = + s == [] ? + (rands(min(a, b), max( a, b), 1)[0]):(rands(min(a, b), max(a, b), 1, s)[0]); // nice rands wrapper diff --git a/src/libraries/rounded_rectangle_profile.scad b/src/libraries/rounded_rectangle_profile.scad deleted file mode 100644 index dec7a0c..0000000 --- a/src/libraries/rounded_rectangle_profile.scad +++ /dev/null @@ -1,35 +0,0 @@ -function sign_x(i,n) = - i < n/4 || i > n*3/4 ? 1 : - i > n/4 && i < n*3/4 ? -1 : - 0; - -function sign_y(i,n) = - i > 0 && i < n/2 ? 1 : - i > n/2 ? -1 : - 0; - - -function rectangle_profile(size=[1,1],fn=32) = [ - for (index = [0:fn-1]) - let(a = index/fn*360) - sign_x(index, fn) * [size[0]/2,0] - + sign_y(index, fn) * [0,size[1]/2] -]; - -function rounded_rectangle_profile(size=[1,1],r=1,fn=32) = [ - let(max_fn = max(fn,8)) - for (index = [0:max_fn-1]) - let(a = index/max_fn*360) - r * [cos(a), sin(a)] - + sign_x(index, max_fn) * [size[0]/2-r,0] - + sign_y(index, max_fn) * [0,size[1]/2-r] -]; - -function double_rounded_rectangle_profile(size=[1,1], r=1, fn=32) = [ - let(max_fn = max(fn,8)) - for (index = [0:max_fn-1]) - let(a = index/max_fn*360) - r * [cos(a), sin(a)] - + sign_x(index, max_fn) * [size[0]/2-r,0] - + sign_y(index, max_fn) * [0,size[1]/2-r] -]; diff --git a/src/settings.scad b/src/settings.scad index 0da6e77..29da524 100644 --- a/src/settings.scad +++ b/src/settings.scad @@ -74,6 +74,7 @@ $rounded_cherry_stem_d = 5.5; // How much higher the stem is than the bottom of the keycap. // Inset stem requires support but is more accurate in some profiles +// can be negative to make outset stems! $stem_inset = 0; // How many degrees to rotate the stems. useful for sideways keycaps, maybe $stem_rotation = 0; @@ -102,7 +103,11 @@ $dish_depth = 1; $dish_skew_x = 0; // How skewed in the y direction (height) the dish is $dish_skew_y = 0; -// If you need the dish to extend further, you can 'overdraw' the rectangle it will hit + + +$dish_offset_x = 0; + +// If you need the dish to extend further, you can 'overdraw' the rectangle it will hit. this was mostly for iso enter and should be deprecated $dish_overdraw_width = 0; // Same as width but for height $dish_overdraw_height = 0; @@ -118,12 +123,10 @@ $font="DejaVu Sans Mono:style=Book"; // Whether or not to render fake keyswitches to check clearances $clearance_check = false; // Should be faster, also required for concave shapes -// Use linear_extrude instead of hull slices to make the shape of the key -$linear_extrude_shape = false; -// warns in trajectory.scad but it looks benign -// brand new, more correct, hopefully faster, lots more work -$skin_extrude_shape = false; +// what kind of extrusion we use to create the keycap. "hull" is standard, "linear extrude" is legacy, "skin" is new and not well supported. +$hull_shape_type = "hull"; // ["hull", "linear extrude", "skin"] + // This doesn't work very well, but you can try $rounded_key = false; //minkowski radius. radius of sphere used in minkowski sum for minkowski_key function. 1.75 for G20 @@ -164,6 +167,9 @@ $inset_legend_depth = 0.2; // Dimensions of alps stem $alps_stem = [4.45, 2.25]; +// Dimensions of choc stem +$choc_stem = [1.2, 3]; + // Enable stabilizer stems, to hold onto your cherry or costar stabilizers $stabilizer_type = "costar_stabilizer"; // [costar_stabilizer, cherry_stabilizer, disable] @@ -193,3 +199,6 @@ $shape_facets =30; $3d_surface_size = 100; // resolution in each axis. 10 = 10 divisions per x/y = 100 points total $3d_surface_step = 10; + +// "flat" / "dished" / "disable" +$inner_shape_type = "flat"; diff --git a/src/shapes.scad b/src/shapes.scad index 206727e..ac893c5 100644 --- a/src/shapes.scad +++ b/src/shapes.scad @@ -1,11 +1,10 @@ -$fs=.1; -unit = 19.05; - +include include include include include include +include // size: at progress 0, the shape is supposed to be this size // delta: at progress 1, the keycap is supposed to be size - delta @@ -25,6 +24,10 @@ module key_shape(size, delta, progress = 0) { square_shape(size, delta, progress); } else if ($key_shape_type == "oblong") { oblong_shape(size, delta, progress); + } else if ($key_shape_type == "hexagon") { + regular_polygon_shape(size, delta, progress); + } else if ($key_shape_type == "octagon") { + regular_polygon_shape(size, delta, progress, sides=8); } else { echo("Warning: unsupported $key_shape_type"); } diff --git a/src/shapes/ISO_enter.scad b/src/shapes/ISO_enter.scad index 8c5730f..0202cac 100644 --- a/src/shapes/ISO_enter.scad +++ b/src/shapes/ISO_enter.scad @@ -1,6 +1,10 @@ -// corollary is rounded_square -// NOT 3D -function unit_length(length) = unit * (length - 1) + 18.16; +include <../functions.scad> +include <../libraries/round-anything/polyround.scad> + +width_ratio = unit_length(1.25) / unit_length(1.5); +height_ratio = unit_length(1) / unit_length(2); + + module ISO_enter_shape(size, delta, progress){ width = size[0]; @@ -13,43 +17,53 @@ module ISO_enter_shape(size, delta, progress){ // and wants to pass just width and height, we make these ratios to know where // to put the elbow joint - width_ratio = unit_length(1.25) / unit_length(1.5); - height_ratio = unit_length(1) / unit_length(2); + delta = delta / 2; pointArray = [ - [ 0, 0], // top right - [ 0, -height], // bottom right - [-width * width_ratio, -height], // bottom left - [-width * width_ratio,-height * height_ratio], // inner middle point - [ -width,-height * height_ratio], // outer middle point - [ -width, 0] // top left + [ 0-delta.x, 0-delta.y], // top right + [ 0-delta.x, -height+delta.y], // bottom right + [-width * width_ratio+delta.x, -height+delta.y], // bottom left + [-width * width_ratio + delta.x,-height * height_ratio+delta.y], // inner middle point + [ -width + delta.x,-height * height_ratio + delta.y], // outer middle point + [ -width + delta.x, 0-delta.y] // top left ]; minkowski(){ - circle(r=corner_size); + circle(r=$corner_radius); // gives us rounded inner corner - offset(r=-corner_size*2) { + offset(r=-$corner_radius*2) { translate([(width * width_ratio)/2, height/2]) polygon(points=pointArray); } } } -function iso_enter_vertices(width, height, width_ratio, height_ratio, wd, hd) = [ - [ 0-wd, 0-hd], // top right - [ 0-wd, -height+hd], // bottom right - [-width * width_ratio+wd, -height+hd], // bottom left - [-width * width_ratio+wd,-height * height_ratio+hd], // inner middle point - [ -width+wd,-height * height_ratio+hd], // outer middle point - [ -width+wd, 0-hd] // top left +function iso_enter_vertices(size, delta, progress, thickness_difference) = [ + [ 0-delta.x/2 * progress - thickness_difference/8, 0 - delta.y / 2 * progress - thickness_difference/8], // top right + [ 0-delta.x/2 * progress - thickness_difference/8, -size[1] + delta.y / 2 * progress + thickness_difference/8], // bottom right + [-size[0] * width_ratio + delta.x/2 * progress + thickness_difference/8, -size[1] + delta.y / 2 * progress + thickness_difference/8], // bottom left + [-size[0] * width_ratio + delta.x/2 * progress + thickness_difference/8,-size[1] * height_ratio + delta.y / 2 * progress + thickness_difference/2], // inner middle point + [ -size[0] + delta.x/2 * progress + thickness_difference/8,-size[1] * height_ratio + delta.y / 2 * progress + thickness_difference/2], // outer middle point + [ -size[0] + delta.x/2 * progress + thickness_difference/8, 0 - delta.y / 2 * progress - thickness_difference/8] // top left ] + [ - [(width * width_ratio)/2, height/2 ], - [(width * width_ratio)/2, height/2 ], - [(width * width_ratio)/2, height/2 ], - [(width * width_ratio)/2, height/2 ], - [(width * width_ratio)/2, height/2 ], - [(width * width_ratio)/2, height/2 ] + [(size[0] * width_ratio)/2, size[1]/2 ], + [(size[0] * width_ratio)/2, size[1]/2 ], + [(size[0] * width_ratio)/2, size[1]/2 ], + [(size[0] * width_ratio)/2, size[1]/2 ], + [(size[0] * width_ratio)/2, size[1]/2 ], + [(size[0] * width_ratio)/2, size[1]/2 ] ]; // no rounding on the corners at all function skin_iso_enter_shape(size, delta, progress, thickness_difference) = - iso_enter_vertices(size.x, size.y, unit_length(1.25) / unit_length(1.5), unit_length(1) / unit_length(2), thickness_difference/2 + delta.x * progress/2, thickness_difference/2 + delta.y * progress/2); + polyRound( + add_rounding( + iso_enter_vertices( + size, + delta, + progress, + thickness_difference + ), + $corner_radius + ), + $shape_facets + ); diff --git a/src/shapes/regular_polygon.scad b/src/shapes/regular_polygon.scad new file mode 100644 index 0000000..40781b3 --- /dev/null +++ b/src/shapes/regular_polygon.scad @@ -0,0 +1,14 @@ +// we do this weird key_shape_type check here because rounded_square uses +// square_shape, and we want flat sides to work for that too. +// could be refactored, idk +module regular_polygon_shape(size, delta, progress, sides=6){ + // https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/undersized_circular_objects + fudge = 1/cos(180/sides); + diameter = (size.x - delta.x * progress - $corner_radius*2) * fudge; + offset(r=$corner_radius) rotate([0,0,360/sides/2]) circle(d = diameter, $fn=sides); +} + + + +// TODO not implemented +function skin_regular_polygon_shape(size, delta, progress, thickness_difference, sides=6) = echo("skin regular polygon not implemented"); diff --git a/src/shapes/rounded_square.scad b/src/shapes/rounded_square.scad index e3f5f26..bef7faa 100644 --- a/src/shapes/rounded_square.scad +++ b/src/shapes/rounded_square.scad @@ -1,4 +1,5 @@ -include <../libraries/rounded_rectangle_profile.scad> +include +include <../libraries/round-anything/polyround.scad> module rounded_square_shape(size, delta, progress, center = true) { offset(r=$corner_radius, $fa=360/$shape_facets){ @@ -7,6 +8,5 @@ module rounded_square_shape(size, delta, progress, center = true) { } // for skin - function skin_rounded_square(size, delta, progress, thickness_difference) = - rounded_rectangle_profile(size - (delta * progress), fn=$shape_facets, r=$corner_radius); + polyRound(add_rounding(rectangle_profile(size - (delta * progress)), $corner_radius), $shape_facets/4); diff --git a/src/shapes/sculpted_square.scad b/src/shapes/sculpted_square.scad index 8e73474..07e3fc4 100644 --- a/src/shapes/sculpted_square.scad +++ b/src/shapes/sculpted_square.scad @@ -1,20 +1,18 @@ -include <../libraries/rounded_rectangle_profile.scad> - // rounded square shape with additional sculpting functions to better approximate // When sculpting sides, how much in should the tops come -$side_sculpting_factor = 4.5; +side_sculpting_factor = 4.5; // When sculpting corners, how much extra radius should be added -$corner_sculpting_factor = 1; +corner_sculpting_factor = 1; // When doing more side sculpting corners, how much extra radius should be added -$more_side_sculpting_factor = 0.4; +more_side_sculpting_factor = 0.4; // side sculpting functions // bows the sides out on stuff like SA and DSA keycaps -function side_sculpting(progress) = (1 - progress) * $side_sculpting_factor; +function side_sculpting(progress) = (1 - progress) * side_sculpting_factor; // makes the rounded corners of the keycap grow larger as they move upwards -function corner_sculpting(progress) = pow(progress, 2) * $corner_sculpting_factor; +function corner_sculpting(progress) = pow(progress, 2) * corner_sculpting_factor; module sculpted_square_shape(size, delta, progress) { width = size[0]; @@ -39,13 +37,40 @@ module sculpted_square_shape(size, delta, progress) { offset(r = extra_corner_radius_this_slice, $fa=360/$shape_facets) { offset(r = -extra_corner_radius_this_slice) { - side_rounded_square(square_size, r = $more_side_sculpting_factor * progress); + side_rounded_square(square_size, r = more_side_sculpting_factor * progress); } } } -// fudging the hell out of this, I don't remember what the negative-offset-positive-offset was doing in the module above -// also no 'bowed' square shape for now +function new_side_rounded_square(size, r, cornerRadius=0) = + let( + width = (size.x - r)/2, + height = (size.y - r)/2, + + // fudge numbers! the radius conflict resolution in polyround smooths out + // the entire shape based on the ratios between conflicting radii. bumping + // these up makes the whole shape more fluid + widthRadius = r ? width*8 : 0, + heightRadius = r ? height*8 : 0, + + bow = r/2, + + // close enough :/ + facets = 360 / $shape_facets/2, + + points = [ + [-width,-height,cornerRadius], + [0,-height-bow,widthRadius], + [width,-height,cornerRadius], + [width + bow,0,heightRadius], + [width,height,cornerRadius], + [0,height + bow,widthRadius], + [-width,height,cornerRadius], + [-width-bow,0,heightRadius] + ] + ) polyRound(points,facets); + + function skin_sculpted_square_shape(size, delta, progress, thickness_difference) = let( width = size[0], @@ -67,13 +92,7 @@ function skin_sculpted_square_shape(size, delta, progress, thickness_difference) width - extra_width_this_slice - thickness_difference, height - extra_height_this_slice - thickness_difference ] - ) double_rounded_rectangle_profile(square_size - [extra_corner_radius_this_slice, extra_corner_radius_this_slice]/4, fn=$shape_facets, r=extra_corner_radius_this_slice/1.5 + $more_side_sculpting_factor * progress); - - /* offset(r = extra_corner_radius_this_slice) { - offset(r = -extra_corner_radius_this_slice) { - side_rounded_square(square_size, r = $more_side_sculpting_factor * progress); - } - } */ + ) new_side_rounded_square(square_size, more_side_sculpting_factor * progress, extra_corner_radius_this_slice); module side_rounded_square(size, r) { diff --git a/src/shapes/square.scad b/src/shapes/square.scad index 27a5d03..701e87a 100644 --- a/src/shapes/square.scad +++ b/src/shapes/square.scad @@ -1,6 +1,4 @@ use <../functions.scad> -include <../libraries/rounded_rectangle_profile.scad> - // we do this weird key_shape_type check here because rounded_square uses // square_shape, and we want flat sides to work for that too. @@ -23,14 +21,23 @@ module square_shape(size, delta, progress){ // shape makes the sides flat by making the top a trapezoid. // This obviously doesn't work with rounded sides at all module flat_sided_square_shape(size, delta, progress) { - polygon(points=[ - [(-size.x + (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2, (-size.y + delta.y * progress)/2], - [(size.x - (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2,(-size.y + delta.y * progress)/2], - [(size.x - (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2], - [(-size.x + (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2] - ]); + polygon(skin_flat_sided_square_shape(size, delta, progress)); } +function skin_flat_sided_square_shape(size,delta,progress) = [ + [(-size.x + (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2, (-size.y + delta.y * progress)/2], + [(size.x - (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2,(-size.y + delta.y * progress)/2], + [(size.x - (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2], + [(-size.x + (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2] +]; + +function rectangle_profile(size) = [ + [-size.x/2, -size.y/2], + [size.x/2, -size.y/2], + [size.x/2, size.y/2], + [-size.x/2, size.y/2], +]; + function skin_square_shape(size, delta, progress, thickness_difference) = let( width = size[0], @@ -43,4 +50,4 @@ function skin_square_shape(size, delta, progress, thickness_difference) = width - width_difference - thickness_difference, height - height_difference - thickness_difference ] - ) rectangle_profile(square_size, fn=36); + ) $key_shape_type == "flat_sided_square" ? skin_flat_sided_square_shape(size, delta, progress) : rectangle_profile(square_size); diff --git a/src/stem_supports/brim.scad b/src/stem_supports/brim.scad index 97ae5dc..372fcf3 100644 --- a/src/stem_supports/brim.scad +++ b/src/stem_supports/brim.scad @@ -43,5 +43,17 @@ module brim_support(stem_type, stem_support_height, slop) { inside_cherry_cross(slop); } + } else if(stem_type == "choc") { + translate([-5.7/2,0,0]) linear_extrude(height=stem_support_height) { + offset(r=1){ + square($choc_stem + [3,3], center=true); + } + } + + translate([5.7/2,0,0]) linear_extrude(height=stem_support_height) { + offset(r=1){ + square($choc_stem + [3,3], center=true); + } + } } } diff --git a/src/stem_supports/tines.scad b/src/stem_supports/tines.scad index 56ff739..4eb2d59 100644 --- a/src/stem_supports/tines.scad +++ b/src/stem_supports/tines.scad @@ -77,5 +77,9 @@ module tines_support(stem_type, stem_support_height, slop) { } } else if (stem_type == "alps"){ centered_tines(stem_support_height); + } else if (stem_type == "choc"){ + if ($key_length < 2) translate([0,0,$stem_support_height / 2]) cube([total_key_width($wall_thickness)+$wall_thickness/4, 0.42, $stem_support_height], center = true); + /* translate([-5.7/2,0,$stem_support_height / 2]) cube([0.5, total_key_height($wall_thickness), $stem_support_height], center = true); */ + /* translate([5.7/2,0,$stem_support_height / 2]) cube([0.5, total_key_height($wall_thickness), $stem_support_height], center = true); */ } } diff --git a/src/stems.scad b/src/stems.scad index c53ab91..5f68c95 100644 --- a/src/stems.scad +++ b/src/stems.scad @@ -4,22 +4,25 @@ include include include include +include //whole stem, alps or cherry, trimmed to fit -module stem(stem_type, depth, slop){ +module stem(stem_type, depth, slop, throw){ if (stem_type == "alps") { - alps_stem(depth, slop); + alps_stem(depth, slop, throw); } else if (stem_type == "cherry" || stem_type == "costar_stabilizer") { - cherry_stem(depth, slop); + cherry_stem(depth, slop, throw); } else if (stem_type == "rounded_cherry") { - rounded_cherry_stem(depth, slop); + rounded_cherry_stem(depth, slop, throw); } else if (stem_type == "box_cherry") { - box_cherry_stem(depth, slop); + box_cherry_stem(depth, slop, throw); } else if (stem_type == "filled") { filled_stem(); } else if (stem_type == "cherry_stabilizer") { - cherry_stabilizer_stem(depth, slop); + cherry_stabilizer_stem(depth, slop, throw); + } else if (stem_type == "choc") { + choc_stem(depth, slop, throw); } else if (stem_type == "disable") { children(); } else { diff --git a/src/stems/alps.scad b/src/stems/alps.scad index 404ad0e..b17a163 100644 --- a/src/stems/alps.scad +++ b/src/stems/alps.scad @@ -1,4 +1,4 @@ -module alps_stem(depth, has_brim, slop){ +module alps_stem(depth, slop, throw){ linear_extrude(height=depth) { square($alps_stem, center = true); } diff --git a/src/stems/box_cherry.scad b/src/stems/box_cherry.scad index f7db595..6c74d14 100644 --- a/src/stems/box_cherry.scad +++ b/src/stems/box_cherry.scad @@ -1,7 +1,7 @@ include <../functions.scad> include -module box_cherry_stem(depth, slop) { +module box_cherry_stem(depth, slop, throw) { difference(){ // outside shape linear_extrude(height = depth) { diff --git a/src/stems/cherry.scad b/src/stems/cherry.scad index 06ac6f5..cdeab90 100644 --- a/src/stems/cherry.scad +++ b/src/stems/cherry.scad @@ -23,7 +23,7 @@ module inside_cherry_cross(slop) { } } -module cherry_stem(depth, slop) { +module cherry_stem(depth, slop, throw) { difference(){ // outside shape linear_extrude(height = depth) { diff --git a/src/stems/cherry_stabilizer.scad b/src/stems/cherry_stabilizer.scad index 572b078..56af1c8 100644 --- a/src/stems/cherry_stabilizer.scad +++ b/src/stems/cherry_stabilizer.scad @@ -4,18 +4,18 @@ include <../functions.scad> // splits the stem into halves - allows easier fitment extra_vertical = 0.6; -module inside_cherry_stabilizer_cross(slop) { +module inside_cherry_stabilizer_cross(slop, throw) { // inside cross // translation purely for aesthetic purposes, to get rid of that awful lattice translate([0,0,-SMALLEST_POSSIBLE]) { - linear_extrude(height = $stem_throw) { + linear_extrude(height = throw) { square(cherry_cross(slop, extra_vertical)[0], center=true); square(cherry_cross(slop, extra_vertical)[1], center=true); } } } -module cherry_stabilizer_stem(depth, slop) { +module cherry_stabilizer_stem(depth, slop, throw) { difference(){ // outside shape linear_extrude(height = depth) { @@ -24,6 +24,6 @@ module cherry_stabilizer_stem(depth, slop) { } } - inside_cherry_stabilizer_cross(slop); + inside_cherry_stabilizer_cross(slop, throw); } } diff --git a/src/stems/choc.scad b/src/stems/choc.scad new file mode 100644 index 0000000..b84970f --- /dev/null +++ b/src/stems/choc.scad @@ -0,0 +1,17 @@ +separation = 5.7; + +positions = [ + [separation/2, 0], + [-separation/2, 0], +]; + +// TODO throw not used +module choc_stem(depth, slop, throw){ + for (position=positions) { + translate([position.x,position.y, depth/2]) single_choc_stem(depth, slop); + } +} + +module single_choc_stem(depth, slop) { + cube([$choc_stem.x - slop, $choc_stem.y - slop, depth], center=true); +} diff --git a/src/stems/filled.scad b/src/stems/filled.scad index e12bfde..bff38e2 100644 --- a/src/stems/filled.scad +++ b/src/stems/filled.scad @@ -1,4 +1,4 @@ -module filled_stem() { +module filled_stem(_depth, _slop, _throw) { // I broke the crap out of this stem type due to the changes I made around how stems are differenced // now that we just take the dish out of stems in order to support stuff like // bare stem keycaps (and buckling spring eventually) we can't just make a diff --git a/src/stems/rounded_cherry.scad b/src/stems/rounded_cherry.scad index 3d6aab7..77cd7ec 100644 --- a/src/stems/rounded_cherry.scad +++ b/src/stems/rounded_cherry.scad @@ -1,7 +1,7 @@ include <../functions.scad> include -module rounded_cherry_stem(depth, slop) { +module rounded_cherry_stem(depth, slop, throw) { difference(){ cylinder(d=$rounded_cherry_stem_d, h=depth); diff --git a/src/supports/flared.scad b/src/supports/flared.scad index 50dd5c5..85b8283 100644 --- a/src/supports/flared.scad +++ b/src/supports/flared.scad @@ -40,6 +40,14 @@ module flared(stem_type, loft, height) { square(outer_cherry_stabilizer_stem($stem_slop) - [2,2], center=true); } } + } else if (stem_type == "choc") { + // single support, just the stem + new_choc_scale = [scale_for_45(height, $choc_stem[0] + 5.7 - $stem_slop), scale_for_45(height, $choc_stem[1])]; + translate([0,0,0]) linear_extrude(height=height, scale = new_choc_scale){ + // TODO make a choc_stem() function so it can build in the slop + square([$choc_stem[0] + 5.7 - $stem_slop, $choc_stem[1] - $stem_slop], center=true); + } + } else { // always render cherry if no stem type. this includes stem_type = false! // this avoids a bug where the keycap is rendered filled when not desired diff --git a/yarn.lock b/yarn.lock index 9be7a17..d6be3e7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -45,11 +45,6 @@ ansi-regex@^2.0.0: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" integrity sha1-w7M6te42DYbg5ijwRorn7yfWVN8= -ansi-regex@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" - integrity sha1-7QMXwyIGT3lGbAKWa922Bas32Zg= - ansi-styles@^4.1.0: version "4.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.2.1.tgz#90ae75c424d008d2624c5bf29ead3177ebfcf359" @@ -78,24 +73,11 @@ append-buffer@^1.0.2: dependencies: buffer-equal "^1.0.0" -aproba@^1.0.3: - version "1.2.0" - resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a" - integrity sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw== - archy@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/archy/-/archy-1.0.0.tgz#f9c8c13757cc1dd7bc379ac77b2c62a5c2868c40" integrity sha1-+cjBN1fMHde8N5rHeyxipcKGjEA= -are-we-there-yet@~1.1.2: - version "1.1.5" - resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz#4b35c2944f062a8bfcda66410760350fe9ddfc21" - integrity sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w== - dependencies: - delegates "^1.0.0" - readable-stream "^2.0.6" - arr-diff@^1.0.1: version "1.1.0" resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-1.1.0.tgz#687c32758163588fef7de7b36fabe495eb1a399a" @@ -308,6 +290,14 @@ cache-base@^1.0.1: union-value "^1.0.0" unset-value "^1.0.0" +call-bind@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c" + integrity sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA== + dependencies: + function-bind "^1.1.1" + get-intrinsic "^1.0.2" + camelcase@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-3.0.0.tgz#32fc4b9fcdaf845fcdf7e73bb97cac2261f0ab0a" @@ -340,11 +330,6 @@ chokidar@^2.0.0: optionalDependencies: fsevents "^1.2.7" -chownr@^1.1.1: - version "1.1.4" - resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b" - integrity sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg== - class-utils@^0.3.5: version "0.3.6" resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463" @@ -447,11 +432,6 @@ concat-stream@^1.6.0: readable-stream "^2.2.2" typedarray "^0.0.6" -console-control-strings@^1.0.0, console-control-strings@~1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e" - integrity sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4= - convert-source-map@^1.5.0: version "1.7.0" resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.7.0.tgz#17a2cb882d7f77d3490585e2ce6c524424a3a442" @@ -492,13 +472,6 @@ debug@^2.2.0, debug@^2.3.3: dependencies: ms "2.0.0" -debug@^3.2.6: - version "3.2.6" - resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" - integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ== - dependencies: - ms "^2.1.1" - decamelize@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" @@ -509,11 +482,6 @@ decode-uri-component@^0.2.0: resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU= -deep-extend@^0.6.0: - version "0.6.0" - resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" - integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA== - default-compare@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/default-compare/-/default-compare-1.0.0.tgz#cb61131844ad84d84788fb68fd01681ca7781a2f" @@ -526,7 +494,7 @@ default-resolution@^2.0.0: resolved "https://registry.yarnpkg.com/default-resolution/-/default-resolution-2.0.0.tgz#bcb82baa72ad79b426a76732f1a81ad6df26d684" integrity sha1-vLgrqnKtebQmp2cy8aga1t8m1oQ= -define-properties@^1.1.2: +define-properties@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1" integrity sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ== @@ -555,21 +523,11 @@ define-property@^2.0.2: is-descriptor "^1.0.2" isobject "^3.0.1" -delegates@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a" - integrity sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o= - detect-file@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/detect-file/-/detect-file-1.0.0.tgz#f0d66d03672a825cb1b73bdb3fe62310c8e552b7" integrity sha1-8NZtA2cqglyxtzvbP+YjEMjlUrc= -detect-libc@^1.0.2: - version "1.0.3" - resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b" - integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups= - duplexify@^3.6.0: version "3.7.1" resolved "https://registry.yarnpkg.com/duplexify/-/duplexify-3.7.1.tgz#2a4df5317f6ccfd91f86d6fd25d8d8a103b88309" @@ -802,13 +760,6 @@ fragment-cache@^0.2.1: dependencies: map-cache "^0.2.2" -fs-minipass@^1.2.5: - version "1.2.7" - resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.7.tgz#ccff8570841e7fe4265693da88936c55aed7f7c7" - integrity sha512-GWSSJGFy4e9GUeCcbIkED+bgAoFyj7XF1mV8rma3QW4NIqX9Kyx79N/PF61H5udOV3aY1IaMLs6pGbH71nlCTA== - dependencies: - minipass "^2.6.0" - fs-mkdirp-stream@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs-mkdirp-stream/-/fs-mkdirp-stream-1.0.0.tgz#0b7815fc3201c6a69e14db98ce098c16935259eb" @@ -835,25 +786,20 @@ function-bind@^1.1.1: resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== -gauge@~2.7.3: - version "2.7.4" - resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7" - integrity sha1-LANAXHU4w51+s3sxcCLjJfsBi/c= - dependencies: - aproba "^1.0.3" - console-control-strings "^1.0.0" - has-unicode "^2.0.0" - object-assign "^4.1.0" - signal-exit "^3.0.0" - string-width "^1.0.1" - strip-ansi "^3.0.1" - wide-align "^1.1.0" - get-caller-file@^1.0.1: version "1.0.3" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a" integrity sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w== +get-intrinsic@^1.0.2: + version "1.1.1" + resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.1.1.tgz#15f59f376f855c446963948f0d24cd3637b4abc6" + integrity sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q== + dependencies: + function-bind "^1.1.1" + has "^1.0.3" + has-symbols "^1.0.1" + get-value@^2.0.3, get-value@^2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" @@ -895,7 +841,7 @@ glob-watcher@^5.0.3: just-debounce "^1.0.0" object.defaults "^1.1.0" -glob@^7.1.1, glob@^7.1.3: +glob@^7.1.1: version "7.1.6" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== @@ -1016,15 +962,10 @@ has-flag@^4.0.0: resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== -has-symbols@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.1.tgz#9f5214758a44196c406d9bd76cebf81ec2dd31e8" - integrity sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg== - -has-unicode@^2.0.0: - version "2.0.1" - resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9" - integrity sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk= +has-symbols@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.2.tgz#165d3070c00309752a1236a479331e3ac56f1423" + integrity sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw== has-value@^0.3.1: version "0.3.1" @@ -1057,6 +998,13 @@ has-values@^1.0.0: is-number "^3.0.0" kind-of "^4.0.0" +has@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" + integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== + dependencies: + function-bind "^1.1.1" + homedir-polyfill@^1.0.1: version "1.0.3" resolved "https://registry.yarnpkg.com/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz#743298cef4e5af3e194161fbadcc2151d3a058e8" @@ -1065,23 +1013,9 @@ homedir-polyfill@^1.0.1: parse-passwd "^1.0.0" hosted-git-info@^2.1.4: - version "2.8.8" - resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.8.tgz#7539bd4bc1e0e0a895815a2e0262420b12858488" - integrity sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg== - -iconv-lite@^0.4.4: - version "0.4.24" - resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" - integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== - dependencies: - safer-buffer ">= 2.1.2 < 3" - -ignore-walk@^3.0.1: - version "3.0.3" - resolved "https://registry.yarnpkg.com/ignore-walk/-/ignore-walk-3.0.3.tgz#017e2447184bfeade7c238e4aefdd1e8f95b1e37" - integrity sha512-m7o6xuOaT1aqheYHKf8W6J5pYH85ZI9w077erOzLje3JsB1gkafkAhHHY19dqjulgIZHFm32Cp5uNZgcQqdJKw== - dependencies: - minimatch "^3.0.4" + version "2.8.9" + resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9" + integrity sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw== inflight@^1.0.4: version "1.0.6" @@ -1096,10 +1030,10 @@ inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.3: resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== -ini@^1.3.4, ini@~1.3.0: - version "1.3.5" - resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" - integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw== +ini@^1.3.4: + version "1.3.8" + resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" + integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew== interpret@^1.1.0: version "1.2.0" @@ -1206,11 +1140,6 @@ is-fullwidth-code-point@^1.0.0: dependencies: number-is-nan "^1.0.0" -is-fullwidth-code-point@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" - integrity sha1-o7MKXE8ZkYMWeqq5O+764937ZU8= - is-glob@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-3.1.0.tgz#7ba5ae24217804ac70707b96922567486cc3e84a" @@ -1475,26 +1404,6 @@ minimatch@^3.0.4: dependencies: brace-expansion "^1.1.7" -minimist@^1.2.0, minimist@^1.2.5: - version "1.2.5" - resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" - integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== - -minipass@^2.6.0, minipass@^2.8.6, minipass@^2.9.0: - version "2.9.0" - resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.9.0.tgz#e713762e7d3e32fed803115cf93e04bca9fcc9a6" - integrity sha512-wxfUjg9WebH+CUDX/CdbRlh5SmfZiy/hpkxaRI16Y9W56Pa75sWgd/rvFilSgrauD9NyFymP/+JFV3KwzIsJeg== - dependencies: - safe-buffer "^5.1.2" - yallist "^3.0.0" - -minizlib@^1.2.1: - version "1.3.3" - resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-1.3.3.tgz#2290de96818a34c29551c8a8d301216bd65a861d" - integrity sha512-6ZYMOEnmVsdCeTJVE0W9ZD+pVnE8h9Hma/iOwwRDsdQoePpoX56/8B6z3P9VNwppJuBKNRuFDRNRqRWexT9G9Q== - dependencies: - minipass "^2.9.0" - mixin-deep@^1.2.0: version "1.3.2" resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.2.tgz#1120b43dc359a785dce65b55b82e257ccf479566" @@ -1503,23 +1412,11 @@ mixin-deep@^1.2.0: for-in "^1.0.2" is-extendable "^1.0.1" -mkdirp@^0.5.0, mkdirp@^0.5.1: - version "0.5.5" - resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def" - integrity sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ== - dependencies: - minimist "^1.2.5" - ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g= -ms@^2.1.1: - version "2.1.2" - resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" - integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== - mute-stdout@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/mute-stdout/-/mute-stdout-1.0.1.tgz#acb0300eb4de23a7ddeec014e3e96044b3472331" @@ -1547,44 +1444,11 @@ nanomatch@^1.2.9: snapdragon "^0.8.1" to-regex "^3.0.1" -needle@^2.2.1: - version "2.4.1" - resolved "https://registry.yarnpkg.com/needle/-/needle-2.4.1.tgz#14af48732463d7475696f937626b1b993247a56a" - integrity sha512-x/gi6ijr4B7fwl6WYL9FwlCvRQKGlUNvnceho8wxkwXqN8jvVmmmATTmZPRRG7b/yC1eode26C2HO9jl78Du9g== - dependencies: - debug "^3.2.6" - iconv-lite "^0.4.4" - sax "^1.2.4" - next-tick@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c" integrity sha1-yobR/ogoFpsBICCOPchCS524NCw= -node-pre-gyp@*: - version "0.14.0" - resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.14.0.tgz#9a0596533b877289bcad4e143982ca3d904ddc83" - integrity sha512-+CvDC7ZttU/sSt9rFjix/P05iS43qHCOOGzcr3Ry99bXG7VX953+vFyEuph/tfqoYu8dttBkE86JSKBO2OzcxA== - dependencies: - detect-libc "^1.0.2" - mkdirp "^0.5.1" - needle "^2.2.1" - nopt "^4.0.1" - npm-packlist "^1.1.6" - npmlog "^4.0.2" - rc "^1.2.7" - rimraf "^2.6.1" - semver "^5.3.0" - tar "^4.4.2" - -nopt@^4.0.1: - version "4.0.3" - resolved "https://registry.yarnpkg.com/nopt/-/nopt-4.0.3.tgz#a375cad9d02fd921278d954c2254d5aa57e15e48" - integrity sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg== - dependencies: - abbrev "1" - osenv "^0.1.4" - nopt@~1.0.10: version "1.0.10" resolved "https://registry.yarnpkg.com/nopt/-/nopt-1.0.10.tgz#6ddd21bd2a31417b92727dd585f8a6f37608ebee" @@ -1621,47 +1485,11 @@ now-and-later@^2.0.0: dependencies: once "^1.3.2" -npm-bundled@^1.0.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.1.1.tgz#1edd570865a94cdb1bc8220775e29466c9fb234b" - integrity sha512-gqkfgGePhTpAEgUsGEgcq1rqPXA+tv/aVBlgEzfXwA1yiUJF7xtEt3CtVwOjNYQOVknDk0F20w58Fnm3EtG0fA== - dependencies: - npm-normalize-package-bin "^1.0.1" - -npm-normalize-package-bin@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/npm-normalize-package-bin/-/npm-normalize-package-bin-1.0.1.tgz#6e79a41f23fd235c0623218228da7d9c23b8f6e2" - integrity sha512-EPfafl6JL5/rU+ot6P3gRSCpPDW5VmIzX959Ob1+ySFUuuYHWHekXpwdUZcKP5C+DS4GEtdJluwBjnsNDl+fSA== - -npm-packlist@^1.1.6: - version "1.4.8" - resolved "https://registry.yarnpkg.com/npm-packlist/-/npm-packlist-1.4.8.tgz#56ee6cc135b9f98ad3d51c1c95da22bbb9b2ef3e" - integrity sha512-5+AZgwru5IevF5ZdnFglB5wNlHG1AOOuw28WhUq8/8emhBmLv6jX5by4WJCh7lW0uSYZYS6DXqIsyZVIXRZU9A== - dependencies: - ignore-walk "^3.0.1" - npm-bundled "^1.0.1" - npm-normalize-package-bin "^1.0.1" - -npmlog@^4.0.2: - version "4.1.2" - resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b" - integrity sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg== - dependencies: - are-we-there-yet "~1.1.2" - console-control-strings "~1.1.0" - gauge "~2.7.3" - set-blocking "~2.0.0" - number-is-nan@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" integrity sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0= -object-assign@^4.1.0: - version "4.1.1" - resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" - integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= - object-copy@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/object-copy/-/object-copy-0.1.0.tgz#7e7d858b781bd7c991a41ba975ed3812754e998c" @@ -1671,7 +1499,7 @@ object-copy@^0.1.0: define-property "^0.2.5" kind-of "^3.0.3" -object-keys@^1.0.11, object-keys@^1.0.12: +object-keys@^1.0.12, object-keys@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e" integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA== @@ -1683,15 +1511,15 @@ object-visit@^1.0.0: dependencies: isobject "^3.0.0" -object.assign@^4.0.4: - version "4.1.0" - resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.0.tgz#968bf1100d7956bb3ca086f006f846b3bc4008da" - integrity sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w== +object.assign@^4.0.4, object.assign@^4.1.0: + version "4.1.2" + resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.2.tgz#0ed54a342eceb37b38ff76eb831a0e788cb63940" + integrity sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ== dependencies: - define-properties "^1.1.2" - function-bind "^1.1.1" - has-symbols "^1.0.0" - object-keys "^1.0.11" + call-bind "^1.0.0" + define-properties "^1.1.3" + has-symbols "^1.0.1" + object-keys "^1.1.1" object.defaults@^1.0.0, object.defaults@^1.1.0: version "1.1.0" @@ -1740,11 +1568,6 @@ ordered-read-streams@^1.0.0: dependencies: readable-stream "^2.0.1" -os-homedir@^1.0.0: - version "1.0.2" - resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" - integrity sha1-/7xJiDNuDoM94MFox+8VISGqf7M= - os-locale@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-1.4.0.tgz#20f9f17ae29ed345e8bde583b13d2009803c14d9" @@ -1752,19 +1575,6 @@ os-locale@^1.4.0: dependencies: lcid "^1.0.0" -os-tmpdir@^1.0.0: - version "1.0.2" - resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" - integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ= - -osenv@^0.1.4: - version "0.1.5" - resolved "https://registry.yarnpkg.com/osenv/-/osenv-0.1.5.tgz#85cdfafaeb28e8677f416e287592b5f3f49ea410" - integrity sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g== - dependencies: - os-homedir "^1.0.0" - os-tmpdir "^1.0.0" - parse-filepath@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/parse-filepath/-/parse-filepath-1.0.2.tgz#a632127f53aaf3d15876f5872f3ffac763d6c891" @@ -1814,9 +1624,9 @@ path-is-absolute@^1.0.0: integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= path-parse@^1.0.6: - version "1.0.6" - resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" - integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== + version "1.0.7" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" + integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== path-root-regex@^0.1.0: version "0.1.2" @@ -1914,16 +1724,6 @@ pumpify@^1.3.5: inherits "^2.0.3" pump "^2.0.0" -rc@^1.2.7: - version "1.2.8" - resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed" - integrity sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw== - dependencies: - deep-extend "^0.6.0" - ini "~1.3.0" - minimist "^1.2.0" - strip-json-comments "~2.0.1" - read-pkg-up@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-1.0.1.tgz#9d63c13276c065918d57f002a57f40a1b643fb02" @@ -1950,7 +1750,7 @@ read-pkg@^1.0.0: string_decoder "^1.1.1" util-deprecate "^1.0.1" -readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.5, readable-stream@^2.3.6, readable-stream@~2.3.6: +readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.5, readable-stream@^2.3.6, readable-stream@~2.3.6: version "2.3.7" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57" integrity sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw== @@ -2075,14 +1875,7 @@ ret@~0.1.10: resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" integrity sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg== -rimraf@^2.6.1: - version "2.7.1" - resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec" - integrity sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w== - dependencies: - glob "^7.1.3" - -safe-buffer@^5.1.0, safe-buffer@^5.1.2, safe-buffer@~5.2.0: +safe-buffer@^5.1.0, safe-buffer@~5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.0.tgz#b74daec49b1148f88c64b68d49b1e815c1f2f519" integrity sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg== @@ -2099,16 +1892,6 @@ safe-regex@^1.1.0: dependencies: ret "~0.1.10" -"safer-buffer@>= 2.1.2 < 3": - version "2.1.2" - resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" - integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== - -sax@^1.2.4: - version "1.2.4" - resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" - integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== - semver-greatest-satisfied-range@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/semver-greatest-satisfied-range/-/semver-greatest-satisfied-range-1.1.0.tgz#13e8c2658ab9691cb0cd71093240280d36f77a5b" @@ -2116,12 +1899,12 @@ semver-greatest-satisfied-range@^1.1.0: dependencies: sver-compat "^1.5.0" -"semver@2 || 3 || 4 || 5", semver@^5.3.0: +"semver@2 || 3 || 4 || 5": version "5.7.1" resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== -set-blocking@^2.0.0, set-blocking@~2.0.0: +set-blocking@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc= @@ -2136,11 +1919,6 @@ set-value@^2.0.0, set-value@^2.0.1: is-plain-object "^2.0.3" split-string "^3.0.1" -signal-exit@^3.0.0: - version "3.0.3" - resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c" - integrity sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA== - snapdragon-node@^2.0.1: version "2.1.1" resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b" @@ -2262,14 +2040,6 @@ string-width@^1.0.1, string-width@^1.0.2: is-fullwidth-code-point "^1.0.0" strip-ansi "^3.0.0" -"string-width@^1.0.2 || 2": - version "2.1.1" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e" - integrity sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw== - dependencies: - is-fullwidth-code-point "^2.0.0" - strip-ansi "^4.0.0" - string_decoder@^1.1.1: version "1.3.0" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" @@ -2291,13 +2061,6 @@ strip-ansi@^3.0.0, strip-ansi@^3.0.1: dependencies: ansi-regex "^2.0.0" -strip-ansi@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f" - integrity sha1-qEeQIusaw2iocTibY1JixQXuNo8= - dependencies: - ansi-regex "^3.0.0" - strip-bom@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-2.0.0.tgz#6219a85616520491f35788bdbf1447a99c7e6b0e" @@ -2305,11 +2068,6 @@ strip-bom@^2.0.0: dependencies: is-utf8 "^0.2.0" -strip-json-comments@~2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" - integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo= - supports-color@^7.1.0: version "7.1.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.1.0.tgz#68e32591df73e25ad1c4b49108a2ec507962bfd1" @@ -2325,19 +2083,6 @@ sver-compat@^1.5.0: es6-iterator "^2.0.1" es6-symbol "^3.1.1" -tar@^4.4.2: - version "4.4.13" - resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.13.tgz#43b364bc52888d555298637b10d60790254ab525" - integrity sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA== - dependencies: - chownr "^1.1.1" - fs-minipass "^1.2.5" - minipass "^2.8.6" - minizlib "^1.2.1" - mkdirp "^0.5.0" - safe-buffer "^5.1.2" - yallist "^3.0.3" - through2-filter@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/through2-filter/-/through2-filter-3.0.0.tgz#700e786df2367c2c88cd8aa5be4cf9c1e7831254" @@ -2584,13 +2329,6 @@ which@^1.2.14: dependencies: isexe "^2.0.0" -wide-align@^1.1.0: - version "1.1.3" - resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457" - integrity sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA== - dependencies: - string-width "^1.0.2 || 2" - wrap-ansi@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85" @@ -2610,21 +2348,17 @@ xtend@~4.0.0, xtend@~4.0.1: integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ== y18n@^3.2.1: - version "3.2.1" - resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41" - integrity sha1-bRX7qITAhnnA136I53WegR4H+kE= - -yallist@^3.0.0, yallist@^3.0.3: - version "3.1.1" - resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd" - integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g== + version "3.2.2" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.2.tgz#85c901bd6470ce71fc4bb723ad209b70f7f28696" + integrity sha512-uGZHXkHnhF0XeeAPgnKfPv1bgKAYyVvmNL1xlKsPYZPaIHxGti2hHqvOCQv71XMsLxu1QjergkqogUnms5D3YQ== yargs-parser@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-5.0.0.tgz#275ecf0d7ffe05c77e64e7c86e4cd94bf0e1228a" - integrity sha1-J17PDX/+Bcd+ZOfIbkzZS/DhIoo= + version "5.0.1" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-5.0.1.tgz#7ede329c1d8cdbbe209bd25cdb990e9b1ebbb394" + integrity sha512-wpav5XYiddjXxirPoCTUPbqM0PXvJ9hiBMvuJgInvo4/lAOTZzUprArw17q2O1P2+GHhbBr18/iQwjL5Z9BqfA== dependencies: camelcase "^3.0.0" + object.assign "^4.1.0" yargs@^7.1.0: version "7.1.0"