/* * Copyright 2022 Thomas Buck - thomas@xythobuz.de * Philipp Schönberger - mail@phschoen.de * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * See . */ include ; include ; use ; use ; use ; use ; function switch_rc_point(switch_r,switch_t, row,colum,a,h,offset=[0,0,0]) = v_rot(switch_r[row][colum]) * (switch_point(a,h) + offset) + switch_t[row][colum]; function switch_bz(switch_r,switch_t, row,colum,a,h,offset=[0,-10,0]) = [ [ switch_rc_point(switch_r,switch_t, row,colum,a[0],h,[0,0,0]), switch_rc_point(switch_r,switch_t, row,colum,a[1],h,[0,0,0]), ], [ switch_rc_point(switch_r,switch_t, row,colum,a[0],h,offset), switch_rc_point(switch_r,switch_t, row,colum,a[1],h,offset), ], [ zero_axis("z", switch_rc_point(switch_r,switch_t, row,colum,a[0],h,offset), -20), zero_axis("z", switch_rc_point(switch_r,switch_t, row,colum,a[1],h,offset), -20) ], ]; function switch_bz_edge(switch_r,switch_t, row,colum,a,h,offset1=[0,-10,0],offset2=[0,-10,0]) = [ [ switch_rc_point(switch_r,switch_t, row,colum,a,h,$e*offset1), switch_rc_point(switch_r,switch_t, row,colum,a,h, 0*offset1), switch_rc_point(switch_r,switch_t, row,colum,a,h,$e*offset2), ], [ switch_rc_point(switch_r,switch_t, row,colum,a,h,offset1), switch_rc_point(switch_r,switch_t, row,colum,a,h,offset1+offset2), switch_rc_point(switch_r,switch_t, row,colum,a,h,offset2), ], [ zero_axis("z", switch_rc_point(switch_r,switch_t, row,colum,a,h,offset1), -20), zero_axis("z", switch_rc_point(switch_r,switch_t, row,colum,a,h,offset1+offset2), -20), zero_axis("z", switch_rc_point(switch_r,switch_t, row,colum,a,h,offset2), -20) ], ]; function switch_bz_between(switch_r,switch_t,rows,colums,a,h,offset_bz=[2,0,0],offset_out=[0,-10,0]) = [ [ switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0],h,[0,0,0]), switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0],h,[0,0,0]+offset_bz), switch_rc_point(switch_r,switch_t,rows[len(rows) == 1 ? 0 : 1],colums[len(colums) == 1 ? 0 : 1],a[1],h,[0,0,0]-offset_bz), switch_rc_point(switch_r,switch_t,rows[len(rows) == 1 ? 0 : 1],colums[len(colums) == 1 ? 0 : 1],a[1],h,[0,0,0]), ], [ switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0],h,[0,0,0]+offset_out), switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0],h,[0,0,0]+offset_bz+offset_out), switch_rc_point(switch_r,switch_t,rows[len(rows) == 1 ? 0 : 1],colums[len(colums) == 1 ? 0 : 1],a[1],h,[0,0,0]-offset_bz+offset_out), switch_rc_point(switch_r,switch_t,rows[len(rows) == 1 ? 0 : 1],colums[len(colums) == 1 ? 0 : 1],a[1],h,[0,0,0]+offset_out), ], [ zero_axis("z", switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0],h,[0,0,0]+offset_out), -20), zero_axis("z", switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0],h,[0,0,0]+offset_bz+offset_out), -20), zero_axis("z", switch_rc_point(switch_r,switch_t,rows[len(rows) == 1 ? 0 : 1],colums[len(colums) == 1 ? 0 : 1],a[1],h,[0,0,0]-offset_bz+offset_out), -20), zero_axis("z", switch_rc_point(switch_r,switch_t,rows[len(rows) == 1 ? 0 : 1],colums[len(colums) == 1 ? 0 : 1],a[1],h,[0,0,0]+offset_out), -20), ], ]; function switch_bz_connection(switch_r,switch_t,rows,colums,a,h,offset_bz=[2,0,0]) = [ [ switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0][0],h,[0,0,0]-$e*offset_bz), switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0][1],h,[0,0,0]-$e*offset_bz), ], [ switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0][0],h,[0,0,0]), switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0][1],h,[0,0,0]), ], [ switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0][0],h,[0,0,0]+offset_bz), switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0][1],h,[0,0,0]+offset_bz), ], [ switch_rc_point(switch_r,switch_t,rows[len(rows) == 1 ? 0 : 1],colums[len(colums) == 1 ? 0 : 1],a[1][0],h,[0,0,0]-offset_bz), switch_rc_point(switch_r,switch_t,rows[len(rows) == 1 ? 0 : 1],colums[len(colums) == 1 ? 0 : 1],a[1][1],h,[0,0,0]-offset_bz), ], [ switch_rc_point(switch_r,switch_t,rows[len(rows) == 1 ? 0 : 1],colums[len(colums) == 1 ? 0 : 1],a[1][0],h,[0,0,0]), switch_rc_point(switch_r,switch_t,rows[len(rows) == 1 ? 0 : 1],colums[len(colums) == 1 ? 0 : 1],a[1][1],h,[0,0,0]), ], [ switch_rc_point(switch_r,switch_t,rows[len(rows) == 1 ? 0 : 1],colums[len(colums) == 1 ? 0 : 1],a[1][0],h,[0,0,0]+$e*offset_bz), switch_rc_point(switch_r,switch_t,rows[len(rows) == 1 ? 0 : 1],colums[len(colums) == 1 ? 0 : 1],a[1][1],h,[0,0,0]+$e*offset_bz), ], ]; function switch_bz_connection_cross(switch_r,switch_t,rows,colums,a,h,offset_bz=[2,0,0]) = [ [ switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0][0],h,[0,0,0]-$e*offset_bz), switch_rc_point(switch_r,switch_t,rows[1],colums[0],a[0][1],h,[0,0,0]-$e*offset_bz), ], [ switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0][0],h,[0,0,0]), switch_rc_point(switch_r,switch_t,rows[1],colums[0],a[0][1],h,[0,0,0]), ], [ switch_rc_point(switch_r,switch_t,rows[0],colums[0],a[0][0],h,[0,0,0]+offset_bz), switch_rc_point(switch_r,switch_t,rows[1],colums[0],a[0][1],h,[0,0,0]+offset_bz), ], [ switch_rc_point(switch_r,switch_t,rows[0],colums[1],a[1][0],h,[0,0,0]-offset_bz), switch_rc_point(switch_r,switch_t,rows[1],colums[1],a[1][1],h,[0,0,0]-offset_bz), ], [ switch_rc_point(switch_r,switch_t,rows[0],colums[1],a[1][0],h,[0,0,0]), switch_rc_point(switch_r,switch_t,rows[1],colums[1],a[1][1],h,[0,0,0]), ], [ switch_rc_point(switch_r,switch_t,rows[0],colums[1],a[1][0],h,[0,0,0]+$e*offset_bz), switch_rc_point(switch_r,switch_t,rows[1],colums[1],a[1][1],h,[0,0,0]+$e*offset_bz), ], ]; function reverse_bz(points) = [for(i = [len(points)-1:-1:0]) points[i], ]; switch_holder_plate(switch_thumb_r, switch_thumb_t, 10); module switch_holder_plate(switch_r, switch_t, w_extra) { t_step = 0.1; thickness = switch_holder_height+1; // S curve ctrl_pts_S = [ for(r=len(switch_r)-1, c=[0:len(switch_r[r])-1]) switch_bz(switch_r,switch_t,r,c,["SW","SO"],"top",[0,-w_extra,0]), ]; echo("ctrl_pts_S", ctrl_pts_S); // between the s curves ctrl_pts_S_B = [ for(r=len(switch_r)-1, c=[0:len(switch_r[r])-2]) switch_bz_between(switch_r,switch_t,[r], [c,c+1],["SO","SW"],"top",[1,0,0],[0,-w_extra,0]), ]; ctrl_pts_N = [ // N curve for(r=0, c=[0:len(switch_r[r])-1]) switch_bz(switch_r,switch_t,r,c,["NO","NW"],"top",[0,w_extra,0]), ]; ctrl_pts_N_B = [ for(r=0, c=[0:len(switch_r[r])-2]) switch_bz_between(switch_r,switch_t,[r], [c+1,c],["NW","NO"],"top",[-1,0,0],[0,+w_extra,0]), ]; // W curve ctrl_pts_W = [ for(r=[0:len(switch_r)-1], c=0) switch_bz(switch_r,switch_t,r,c,["NW","SW"],"top",[-w_extra,0,0]), ]; ctrl_pts_W_B = [ for(r=[0:len(switch_r)-2], c=0) switch_bz_between(switch_r,switch_t,[r,r+1], [c],["SW","NW"],"top",[1,0,0],[-w_extra,0,0]), ]; // O curve ctrl_pts_O = [ for(r=[0:len(switch_r)-1], c=len(switch_r[r])-1) switch_bz(switch_r,switch_t,r,c,["SO","NO"],"top",[+w_extra,0,0]), ]; ctrl_pts_O_B = [ for(r=[0:len(switch_r)-2], c=len(switch_r[r])-1) switch_bz_between(switch_r,switch_t,[r+1,r], [c],["NO","SO"],"top",[1,0,0],[w_extra,0,0]), ]; // edge ctrl_pts_E = [ switch_bz_edge(switch_r,switch_t,len(switch_r)-1,0,"SW","top",[-w_extra,0,0],[0,-w_extra,0]), switch_bz_edge(switch_r,switch_t,0,len(switch_r[0])-1,"NO","top",[ w_extra,0,0],[0, w_extra,0]), reverse_bz(switch_bz_edge(switch_r,switch_t,len(switch_r)-1,len(switch_r[0])-1,"SO","top",[ w_extra,0,0],[0,-w_extra,0])), reverse_bz(switch_bz_edge(switch_r,switch_t,0,0,"NW","top",[-w_extra,0,0],[0, w_extra,0])), ]; ctrl_pts_NS_IN = [ // within OW for(r=[0:len(switch_r)-1], c=[0:len(switch_r[r])-2]) switch_bz_connection(switch_r,switch_t,[r], [c+1,c],[ ["NW", "SW"],["NO", "SO"] ],"top",[-1,0,0]), ]; ctrl_pts_OW_IN = [ // within NS for(r=[0:len(switch_r)-2], c=[0:len(switch_r[r])-1]) switch_bz_connection(switch_r,switch_t,[r,r+1], [c],[ ["SW", "SO"],["NW", "NO"] ],"top",[0,-1,0]), ]; ctrl_pts_CROSS_IN = [ for(r=[0:len(switch_r)-2], c=[0:len(switch_r[r])-2]) switch_bz_connection_cross(switch_r,switch_t,[r+1,r], [c,c+1],[ [ "NO", "SO"],["NW", "SW"] ],"top",[1,0,0]), ]; ctrl_pts = [ ctrl_pts_S , ctrl_pts_S_B, ctrl_pts_N_B , ctrl_pts_N, ctrl_pts_W_B , ctrl_pts_W, ctrl_pts_O_B , ctrl_pts_O, ctrl_pts_E, ctrl_pts_OW_IN, ctrl_pts_NS_IN, ctrl_pts_CROSS_IN, ]; for(r=[0:len(switch_r)-1], c=[0:len(switch_r[r])-1]) translate(switch_t[r][c]) rotate(switch_r[r][c]) { if($show_switches == true) switch(0, $show_keycaps ? switch_keycap[r][c][0]: "none", switch_keycap[r][c][1] ); if($show_switch_pcb == true) translate([0,0,-switch_holder_height-amoeba_royale_pcb_h-$c]) amoeba_royale_pcb(); switch_holder_with_cutouts(type="B"); } for(j=[0:len(ctrl_pts)-1]) { for(k=[0:len(ctrl_pts[j])-1]) { g_S = bezier_surface(t_step, ctrl_pts[j][k]); // g_S = sf_splines(t_step, ctrl_pts[j][k]); sf_thicken(g_S, thickness,"FORWARD"); //function_grapher(g_S,thickness,"FORWARD"); } } // draw bezier_points color("black") for(k=[0:len(ctrl_pts)-1]) for(i=[0:len(ctrl_pts[k])-1]) for(j=[0:len(ctrl_pts[k][i])-1]) translate(ctrl_pts[k][i][j]) { %sphere(d=0.5); } }