Use polyRound for all skin shapes

slightly faster it seems!
This commit is contained in:
Bob 2020-08-28 10:10:30 -04:00
parent 2b341af540
commit 3e76968a03
4 changed files with 49 additions and 58 deletions

View File

@ -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]
];

View File

@ -1,4 +1,5 @@
include <../libraries/rounded_rectangle_profile.scad> include <square.scad>
include <../libraries/round-anything/polyround.scad>
module rounded_square_shape(size, delta, progress, center = true) { module rounded_square_shape(size, delta, progress, center = true) {
offset(r=$corner_radius, $fa=360/$shape_facets){ offset(r=$corner_radius, $fa=360/$shape_facets){
@ -7,6 +8,5 @@ module rounded_square_shape(size, delta, progress, center = true) {
} }
// for skin // for skin
function skin_rounded_square(size, delta, progress, thickness_difference) = 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);

View File

@ -1,5 +1,3 @@
include <../libraries/rounded_rectangle_profile.scad>
// rounded square shape with additional sculpting functions to better approximate // rounded square shape with additional sculpting functions to better approximate
// When sculpting sides, how much in should the tops come // When sculpting sides, how much in should the tops come
@ -44,8 +42,35 @@ module sculpted_square_shape(size, delta, progress) {
} }
} }
// fudging the hell out of this, I don't remember what the negative-offset-positive-offset was doing in the module above function new_side_rounded_square(size, r, cornerRadius=0) =
// also no 'bowed' square shape for now 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) = function skin_sculpted_square_shape(size, delta, progress, thickness_difference) =
let( let(
width = size[0], width = size[0],
@ -67,13 +92,7 @@ function skin_sculpted_square_shape(size, delta, progress, thickness_difference)
width - extra_width_this_slice - thickness_difference, width - extra_width_this_slice - thickness_difference,
height - extra_height_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); ) new_side_rounded_square(square_size, $more_side_sculpting_factor * progress, extra_corner_radius_this_slice);
/* 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);
}
} */
module side_rounded_square(size, r) { module side_rounded_square(size, r) {

View File

@ -1,6 +1,4 @@
use <../functions.scad> use <../functions.scad>
include <../libraries/rounded_rectangle_profile.scad>
// we do this weird key_shape_type check here because rounded_square uses // 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. // 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. // shape makes the sides flat by making the top a trapezoid.
// This obviously doesn't work with rounded sides at all // This obviously doesn't work with rounded sides at all
module flat_sided_square_shape(size, delta, progress) { module flat_sided_square_shape(size, delta, progress) {
polygon(points=[ polygon(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 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) = function skin_square_shape(size, delta, progress, thickness_difference) =
let( let(
width = size[0], width = size[0],
@ -43,4 +50,4 @@ function skin_square_shape(size, delta, progress, thickness_difference) =
width - width_difference - thickness_difference, width - width_difference - thickness_difference,
height - height_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);