From a537407ccae4bfe0c8817ea16929e7325dfcfe8d Mon Sep 17 00:00:00 2001 From: Bob - Home - Windows Date: Tue, 30 Jan 2018 12:01:38 -0500 Subject: [PATCH] make shapes much more powerful by passing them a progress prop and starting width / height with width / height end delta --- keys.scad | 11 +++++- keysets.scad | 3 ++ src/key.scad | 36 ++++++++------------ src/shapes.scad | 89 ++++++++++++++++++++++++++++++++++--------------- src/stems.scad | 10 ++++-- 5 files changed, 96 insertions(+), 53 deletions(-) diff --git a/keys.scad b/keys.scad index 6a8ede2..8b3f7a2 100644 --- a/keys.scad +++ b/keys.scad @@ -20,4 +20,13 @@ module translate_u(x=0, y=0, z=0){ translate([x * unit, y*unit, z*unit]) children(); } -sa_row(2) u(2) cherry() key(); +dcs_row(2) u(2) dishless() cherry() { + /* $inverted_dish = true; */ + $key_shape_type = "obloid"; + key(); +} + + translate_u(3) u(2) dcs_row(3) dishless() cherry() { + $key_shape_type = "obloid"; + key(); + } diff --git a/keysets.scad b/keysets.scad index a99d7c5..6a5505e 100644 --- a/keysets.scad +++ b/keysets.scad @@ -20,6 +20,9 @@ for (row = [0:len(60_percent)-1]){ columnDist = sum([for (x = [0 : column]) 60_percent[row][x]]); a = 60_percent[row][column]; translate_u(columnDist - (a/2), -row) dishless() dcs_row((row+4) % 5 + 1) u(a) cherry() { + $width_difference = 0; + $height_difference = 0; + $key_shape_type = "obloid"; if (a != 6.25) { key(); } else { diff --git a/src/key.scad b/src/key.scad index 9ddd380..b193b36 100644 --- a/src/key.scad +++ b/src/key.scad @@ -28,19 +28,13 @@ $minkowski_radius = .33; // derived values. can't be variables if we want them to change when the special variables do // actual mm key width and height -function total_key_width() = $bottom_key_width + unit * ($key_length - 1); -function total_key_height() = $bottom_key_height + unit * ($key_height - 1); +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; -// side sculpting functions -// bows the sides out on stuff like SA and DSA keycaps -function side_sculpting(progress) = (1 - progress) * 2.5; -// makes the rounded corners of the keycap grow larger as they move upwards -function corner_sculpting(progress) = pow(progress, 2); - // key shape including dish. used as the ouside and inside shape in key() module shape(thickness_difference, depth_difference){ @@ -84,7 +78,7 @@ module shape_hull(thickness_difference, depth_difference, extra_slices = 0){ } } -//corollary is shape_hull +//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){ @@ -95,7 +89,7 @@ module linear_extrude_shape_hull(thickness_difference, depth_difference, extra_s 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, $corner_radius); + key_shape(total_key_width(thickness_difference), total_key_height(thickness_difference)); } } } @@ -112,14 +106,6 @@ module hull_shape_hull(thickness_difference, depth_difference, extra_slices = 0) } module shape_slice(progress, thickness_difference, depth_difference) { - // makes the sides bow - extra_side_size = $enable_side_sculpting ? side_sculpting(progress) : 0; - // makes the rounded corners of the keycap grow larger as they move upwards - extra_corner_size = $enable_side_sculpting ? corner_sculpting(progress) : 0; - - // computed values for this slice - extra_width_this_slice = ($width_difference - extra_side_size) * progress; - extra_height_this_slice = ($height_difference - extra_side_size) * progress; skew_this_slice = $top_skew * progress; depth_this_slice = ($total_depth - depth_difference) * progress; tilt_this_slice = -$top_tilt / $key_height * progress; @@ -128,11 +114,15 @@ module shape_slice(progress, thickness_difference, depth_difference) { rotate([tilt_this_slice,0,0]){ linear_extrude(height = 0.001){ key_shape( - total_key_width(), - total_key_height(), - thickness_difference+extra_width_this_slice, - thickness_difference+extra_height_this_slice, - $corner_radius + extra_corner_size + [ + total_key_width(thickness_difference), + total_key_height(thickness_difference) + ], + [ + $width_difference, + $height_difference + ], + progress ); } } diff --git a/src/shapes.scad b/src/shapes.scad index 9f0c70c..5bd3924 100644 --- a/src/shapes.scad +++ b/src/shapes.scad @@ -1,34 +1,71 @@ $fs=.1; unit = 19.05; -module key_shape(width, height, width_difference, height_difference, corner_size) { - if ($key_shape_type == "iso_enter") { - ISO_enter(width, height, width_difference, height_difference, corner_size); - } else if ($key_shape_type == "normal") { - roundedSquare([width - width_difference, height - height_difference], corner_size); - } else if ($key_shape_type == "circle") { - circle(d=width - width_difference); - } else if ($key_shape_type == "square") { - square([width - width_difference, height - height_difference], center = true); - } -} +// side sculpting functions +// bows the sides out on stuff like SA and DSA keycaps +function side_sculpting(progress) = (1 - progress) * 2.5; +// makes the rounded corners of the keycap grow larger as they move upwards +function corner_sculpting(progress) = pow(progress, 2); -// centered -module roundedRect(size, radius, center=true) { - linear_extrude(height = size[2]){ - roundedSquare([size[0], size[1]], radius, center=center); +module key_shape(size, delta, progress = 0) { + if ($key_shape_type == "iso_enter") { + ISO_enter(size, delta, progress); + } else if ($key_shape_type == "normal") { + roundedSquare(size, delta, progress); + } else if ($key_shape_type == "circle") { + circle(d=width); + } else if ($key_shape_type == "square") { + square(size - delta, center = true); + } else if ($key_shape_type == "obloid") { + obloid(size, delta, progress); } } -module roundedSquare(size, radius, center = true) { - offset(r=radius){ - square([size[0] - radius * 2, size[1] - radius * 2], center=center); +module obloid(size, delta, progress) { + width = size[0]; + height = size[1] - delta[1] * progress; // TODO if we don't account for the delta somehow 1u keys will not render as the offset margin is greater than the size of the key. this does not work however + + if (progress < .5 && false) { + circle(d=5.5); + } else { + offset(r=height / 2.1) { + square(size - [height / 1.05, height / 1.05] - delta * progress, center=true); + } + } +} + +module roundedSquare(size, delta, progress, center = true) { + width = size[0]; + height = size[1]; + + width_difference = delta[0]; + height_difference = delta[1]; + // makes the sides bow + extra_side_size = $enable_side_sculpting ? side_sculpting(progress) : 0; + // makes the rounded corners of the keycap grow larger as they move upwards + extra_corner_size = $enable_side_sculpting ? corner_sculpting(progress) : 0; + + // computed values for this slice + extra_width_this_slice = (width_difference - extra_side_size) * progress; + extra_height_this_slice = (height_difference - extra_side_size) * progress; + extra_corner_radius_this_slice = ($corner_radius + extra_corner_size); + + offset(r=extra_corner_radius_this_slice){ + square( + [ + width - extra_width_this_slice - extra_corner_radius_this_slice * 2, + height - extra_height_this_slice - extra_corner_radius_this_slice * 2 + ], + center=center + ); } } // corollary is roundedSquare // NOT 3D -module ISO_enter(width, height, width_difference, height_difference, corner_size){ +module ISO_enter(size, delta, progress){ + width = size[0]; + height = size[1]; function unit_length(length) = unit * (length - 1) + 18.16; @@ -41,15 +78,13 @@ module ISO_enter(width, height, width_difference, height_difference, corner_size width_ratio = unit_length(1.25) / unit_length(1.5); height_ratio = unit_length(1) / unit_length(2); - // height and width difference currently don't do anything - but I think I should keep them. they don't do anything because we currently use scaling in the linear_extrude to express the difference in height and width of the top of the keycap - pointArray = [ - [ -width_difference/2, -height_difference/2], // top right - [ -width_difference/2, -height + height_difference/2], // bottom right - [-width * width_ratio + width_difference/2, -height + height_difference/2], // bottom left - [-width * width_ratio + width_difference/2,-height * height_ratio + height_difference/2], // inner middle point - [ -width + width_difference/2,-height * height_ratio + height_difference/2], // outer middle point - [ -width + width_difference/2, -height_difference/2] // top left + [ 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 ]; minkowski(){ diff --git a/src/stems.scad b/src/stems.scad index 402c4a2..d1a9ad3 100644 --- a/src/stems.scad +++ b/src/stems.scad @@ -38,10 +38,16 @@ module cherry_stem(depth, has_brim, slop, stem_inset, support_type) { difference(){ union() { linear_extrude(height = depth) { - roundedSquare(stem, 1, center=true); + offset(r=1){ + square(stem - [2,2], center=true); + } } if(has_brim) { - roundedRect([stem_width*2, stem_height*2,brim_height], 1, 1, center=true); + linear_extrude(height = brim_height){ + offset(r=1){ + square(stem - [2,2], center=true); + } + } } } linear_extrude(height = cross_depth) {