├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── question---enhancement.md ├── .gitignore ├── .node-version ├── .tool-versions ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── TIPS_AND_TRICKS.md ├── TODO.md ├── assets ├── dual_legends.png ├── example1.JPG ├── example2.JPG ├── example3.JPG ├── example4.JPG ├── example5.JPG ├── layout.png └── welcome.png ├── customizer.scad ├── customizer_base.scad ├── examples ├── legends.scad ├── multimaterial_key_top.scad ├── multimaterial_legend.scad ├── plate_generation.scad ├── print_keycaps_on_their_side.scad ├── sa_ergo.scad └── single_extruder_multimaterial_legends.scad ├── expand.rb ├── gulpfile.js ├── includes.scad ├── key_mold.scad ├── keys.scad ├── model_base.scad ├── models.rb ├── openscad.rb ├── package.json ├── src ├── constants.scad ├── dishes.scad ├── dishes │ ├── 3d_surface.scad │ ├── cylindrical.scad │ ├── flat.scad │ ├── old_spherical.scad │ ├── sideways_cylindrical.scad │ ├── spherical.scad │ ├── squared_scoop.scad │ └── squared_spherical.scad ├── features.scad ├── features │ ├── clearance_check.scad │ ├── key_bump.scad │ └── legends.scad ├── functions.scad ├── hulls.scad ├── hulls │ ├── hull.scad │ ├── linear_extrude.scad │ └── skin.scad ├── key.scad ├── key_features.scad ├── key_helpers.scad ├── key_layouts.scad ├── key_profiles.scad ├── key_profiles │ ├── asa.scad │ ├── cherry.scad │ ├── dcs.scad │ ├── dsa.scad │ ├── dss.scad │ ├── g20.scad │ ├── grid.scad │ ├── hex.scad │ ├── hipro.scad │ ├── mt3.scad │ ├── oem.scad │ ├── regular_polygon.scad │ ├── sa.scad │ └── typewriter.scad ├── key_sizes.scad ├── key_transformations.scad ├── key_types.scad ├── layouts │ ├── 60_percent │ │ └── default.scad │ ├── dactyl_manuform │ │ ├── 4x6.scad │ │ └── 4x6_legends.scad │ ├── gherkin │ │ ├── default.scad │ │ └── gherkin_bump.scad │ ├── hhkb │ │ └── default.scad │ ├── layout.scad │ ├── lets_split │ │ └── default.scad │ ├── planck │ │ ├── default.scad │ │ └── mit.scad │ ├── plate.scad │ ├── preonic │ │ ├── default.scad │ │ └── mit.scad │ └── project_zen │ │ └── default.scad ├── libraries │ ├── 3d_surface.scad │ ├── geodesic_sphere.scad │ ├── polyhedrons.scad │ ├── round-anything │ │ └── polyround.scad │ ├── scad-utils │ │ ├── LICENSE │ │ ├── README.md │ │ ├── hull.scad │ │ ├── linalg.scad │ │ ├── lists.scad │ │ ├── mirror.scad │ │ ├── morphology.scad │ │ ├── se3.scad │ │ ├── shapes.scad │ │ ├── so3.scad │ │ ├── spline.scad │ │ ├── trajectory.scad │ │ ├── trajectory_path.scad │ │ └── transformations.scad │ └── skin.scad ├── settings.scad ├── shapes.scad ├── shapes │ ├── ISO_enter.scad │ ├── oblong.scad │ ├── regular_polygon.scad │ ├── rounded_square.scad │ ├── sculpted_square.scad │ └── square.scad ├── stem_supports.scad ├── stem_supports │ ├── brim.scad │ └── tines.scad ├── stems.scad ├── stems │ ├── alps.scad │ ├── box_cherry.scad │ ├── cherry.scad │ ├── cherry_stabilizer.scad │ ├── choc.scad │ ├── filled.scad │ └── rounded_cherry.scad ├── supports.scad └── supports │ ├── bars.scad │ ├── flared.scad │ └── flat.scad └── yarn.lock /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **What version of OpenSCAD are you on?** 8 | Let me know what version of OpenSCAD you have to better diagnose the issue 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Additional context** 21 | Add any other context about the problem here. 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question---enhancement.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question / Enhancement 3 | about: Do you have a feature request or need help? 4 | 5 | --- 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | *.scad.stl 3 | models/* 4 | -------------------------------------------------------------------------------- /.node-version: -------------------------------------------------------------------------------- 1 | 10.3.0 2 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | nodejs 14.1.0 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | CHANGELOG: 2 | V2.0.0: 3 | * added $fa values for minkowski and shape - so you can customize how much rounding there is 4 | * rejiggered `key.scad` pipeline for more clarity and less shapes 5 | * implemented "3d_surface" dish - still in beta 6 | * super cool though, you can even change the distribution of points on the surface! just make sure you use monotonically increasing functions 7 | * created "hull" folder to house different ways of creating the overall key shape 8 | * promoted "feature" folder to first-class folder with keytext and switch clearance as new residents 9 | * wrote this changelog! 10 | * 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 11 | * side-printed keycaps are first class! you can use the `sideways()` modifier to set up sideways keycaps that have flat sides to print on. 12 | * it's much easier to make quick artisans now that the inside of the keycap is differenced from any additive features placed on top 13 | * `$linear_extrude_shape` and `$skin_extrude_shape` retired in favor of `$hull_shape_type` 14 | * added regular_polygon shape and octagonal and hexagonal key profiles 15 | * added beta kailh choc 16 | * Finally got ISO Enter working correctly! -------------------------------------------------------------------------------- /TIPS_AND_TRICKS.md: -------------------------------------------------------------------------------- 1 | # WIP Tips and Tricks section 2 | 3 | just want to make sure I put this here, I'm going to make this a much better document later 4 | 5 | ## Fully sculpted caps 6 | 7 | Fully sculpted keycaps are caps that also tilt inwards / outwards, cupping your fingers a bit. 8 | 9 | Most profiles should support this now; you pass in a "column" value after the row value, and the cap will calculate how much extra height and tilt for that column. 10 | 11 | the way this works is the program projects a large, imaginary cylinder that it inscribes the top of the keycaps into. Thus, the height and tilt can be tweaked by changing the `$double_sculpt_radius`, which changes the radius of that imaginary cylinder. 12 | 13 | At the end of the day though, all the columnular sculpting is doing is adding extra height and y tilt to the top of the key. if you have some other aim than fitting to a cylinder you can control this directly with appropriate changes to `$top_tilt_y` and `$total_depth`, or perhaps changing the `side_tilt()` and `extra_side_tilt_height()` functions in [`functions.scad`](https://github.com/rsheldiii/KeyV2/blob/master/src/functions.scad) which are what the row profiles use. 14 | 15 | ## skin mode 16 | 17 | 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"`. 18 | 19 | `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. 20 | 21 | One current limitation of `skin()` is that I suck at math and can't translate [rounded_square](https://github.com/rsheldiii/KeyV2/blob/master/src/shapes/rounded_square.scad) into a function, which means that we miss out on the very nice bowing exhibited on these profiles. once we can translate that to math however, we'll be in business. 22 | 23 | ## Printing upside down 24 | 25 | still in beta, but using `upside_down()` in a method chain will rotate keycaps to be upside down. This makes the stem print better and requires no support, but generally the top of the keycap comes out worse - unless it is flat. Worth noting that you can probably set `$stem_inner_slop` to 0 if you print upside down - elephant's foot is the largest contributor to stems not fitting correctly. 26 | 27 | ### "doubleshot" letters with a regular printer 28 | 29 | While printing upside down, you can do yourself a favor and embed some legends! use code like below: 30 | 31 | ``` 32 | legends = ["F1", "1", "q", "a", "z", ""]; 33 | for (x = [0:1:4]) { 34 | translate_u(0,-x) legend(legends[x]) g20_row(3, 0) upside_down() { 35 | $stem_support_type = "disable"; 36 | key(true); 37 | dished() { 38 | legends($inset_legend_depth); 39 | } 40 | } 41 | } 42 | ``` 43 | 44 | and comment out either `key(true)` or the whole `dished` segment. This code generates keycaps with inset legends and the legends that fit inside those insets. 45 | 46 | Run just the legends through your slicer first and make sure to turn off anything like skirts or brims, it should print your legends in a single layer on your print bed. Leave them there, swap filaments, and then print the rest of the keycaps around them in a different color. The result is pretty impressive. They aren't quite doubleshot, since the main benefit of doubleshots is the plastic goes all the way through the keycap, but they look incredibly impressive for what they are. 47 | 48 | ### No stem support 49 | 50 | If you're printing updside down you'll want to disable stem supports. you can change the `$stem_support_type`, or just use the `no_stem_support()` modifier function 51 | 52 | ## front print legends and location / font size 53 | 54 | still in beta, set `$front_print_legends = true` to have legends print on the front instead of the top of the keycaps. 55 | 56 | ## Clearance check 57 | 58 | doing some funky stuff and want to make sure your keycap won't hit the keyswitch? set `$clearance_check = true` and a red-colored depressed switch will show up in preview, cutting away at what contacts the switch. 59 | 60 | ## Envelope 61 | 62 | the 'envelope' of a keycap is used to clip geometry - most notably the dishing at the top of the keycap. if something doesn't look right, you can drop `%envelope()` right next to `key()` to see if it's the envelope cutting things off: 63 | 64 | ``` 65 | g20_row() legend("Q", [0,0], 3) { 66 | key(); 67 | %envelope(); 68 | } 69 | ``` 70 | 71 | ## stem inset 72 | 73 | If you want the more refined top surface that printing upright brings, but you are having a bad time with elephant's foot, you can enable some `$stem_inset` and see if that helps. you'll have to figure out what support works best for you. 74 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | TODO: 2 | * implement key_shape_at_progress which allows you to query for the exact 2d outline of the keycap at a given height 3 | * this makes certain functions easier - building the envelope for instance 4 | * requires breaking out shape_slice, and creating a polygon of the skin_shape_slice slices 5 | * dishes add / remove height from keycaps, particularly spherical dishes 6 | * a bandaid solution would be to allow you to modify where the keytop is along the progression of the keycap 7 | * you can't just set a new total_depth because of how width_difference and height_difference work 8 | * the true solution would be to rewrite how the dishes work to make them very graduated at the edges 9 | * implement regular polygon for skin extrusions 10 | * switch to skin-shaped extrusions by default 11 | * kailh choc has a non-square key unit; should I get that working for layouts etc? 12 | * move everything over to layouts requiring a child key 13 | * 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 14 | -------------------------------------------------------------------------------- /assets/dual_legends.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsheldiii/KeyV2/19f0d2faadd4949634c93f38d1a66869d29e8f43/assets/dual_legends.png -------------------------------------------------------------------------------- /assets/example1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsheldiii/KeyV2/19f0d2faadd4949634c93f38d1a66869d29e8f43/assets/example1.JPG -------------------------------------------------------------------------------- /assets/example2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsheldiii/KeyV2/19f0d2faadd4949634c93f38d1a66869d29e8f43/assets/example2.JPG -------------------------------------------------------------------------------- /assets/example3.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsheldiii/KeyV2/19f0d2faadd4949634c93f38d1a66869d29e8f43/assets/example3.JPG -------------------------------------------------------------------------------- /assets/example4.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsheldiii/KeyV2/19f0d2faadd4949634c93f38d1a66869d29e8f43/assets/example4.JPG -------------------------------------------------------------------------------- /assets/example5.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsheldiii/KeyV2/19f0d2faadd4949634c93f38d1a66869d29e8f43/assets/example5.JPG -------------------------------------------------------------------------------- /assets/layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsheldiii/KeyV2/19f0d2faadd4949634c93f38d1a66869d29e8f43/assets/layout.png -------------------------------------------------------------------------------- /assets/welcome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsheldiii/KeyV2/19f0d2faadd4949634c93f38d1a66869d29e8f43/assets/welcome.png -------------------------------------------------------------------------------- /customizer_base.scad: -------------------------------------------------------------------------------- 1 | // entry point for customizer script. This probably isn't useful to most people, 2 | // as it's just a wrapper that helps generate customizer.scad for thingiverse. 3 | 4 | /* [Basic-Settings] */ 5 | 6 | // what preset profile do you wish to use? disable if you are going to set paramters below 7 | key_profile = "dcs"; // [dcs, oem, dsa, sa, g20, disable] 8 | // what key profile row is this keycap on? 0 for disable 9 | row = 1; // [5,1,2,3,4,0] 10 | 11 | // What does the top of your key say? 12 | legend = ""; 13 | 14 | $using_customizer = true; 15 | 16 | include 17 | 18 | include 19 | include 20 | include 21 | include 22 | include 23 | include 24 | 25 | key_profile(key_profile, row) legend(legend) { 26 | key(); 27 | } 28 | -------------------------------------------------------------------------------- /examples/legends.scad: -------------------------------------------------------------------------------- 1 | include <../includes.scad> 2 | 3 | /* here's how to use the legends() command. 4 | The first argument is the legend itself, which can also be a whole string. 5 | The second argument is the "position" of the legend relative to center. 6 | Legends currently have to all be inset or outset at the same time, but you 7 | can have as many of them as you want. 8 | The numbers used are some magic constant, so just fudge them until it looks good. 9 | */ 10 | 11 | /* $outset_legends = true; */ 12 | legends = [ 13 | ["a", "b", "c", "d"], 14 | ["e", "f", "g", "h"], 15 | ["i", "j", "k", "l"], 16 | ]; 17 | 18 | $font_size = 4; 19 | 20 | for (x=[0:len(legends)-1]) { 21 | translate_u(x,0) { 22 | legend(legends[x][0], [-1,-1]) { 23 | legend(legends[x][1], [-1,1]) { 24 | legend(legends[x][2], [1,-1]) { 25 | front_legend(legends[x][3]) { 26 | key(); 27 | } 28 | } 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /examples/multimaterial_key_top.scad: -------------------------------------------------------------------------------- 1 | include <../includes.scad> 2 | 3 | /* use this file to generate multimaterial models for making keycaps with a 4 | different material for the key top. 5 | 6 | This would be great to use with flexible filament, to make squishy-topped 7 | keys. 8 | 9 | You don't need a multimaterial printer to use these files since it's hard 10 | height cutoff. You could print the bottom, leave the prints on the bed, and 11 | then print the top in a different material. Be careful though! your start 12 | gcode may crash into the prints. 13 | */ 14 | 15 | depth = 1; 16 | // swap the debug()s to render opposite part 17 | /* debug() */ difference() { // intersection() { 18 | key(); 19 | top_of_key() { 20 | translate([-total_key_width(),-total_key_height(),-$total_depth - depth]) cube([total_key_width()*2, total_key_height()*2, $total_depth]); 21 | } 22 | } 23 | 24 | debug() intersection() { 25 | key(); 26 | top_of_key() { 27 | translate([-total_key_width(),-total_key_height(),-$total_depth - depth]) cube([total_key_width()*2, total_key_height()*2, $total_depth]); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/multimaterial_legend.scad: -------------------------------------------------------------------------------- 1 | include <../includes.scad> 2 | 3 | /* in this example we'll use some openSCAD to generate files for printing inset 4 | legends with a multimaterial printer. 5 | */ 6 | 7 | legends = ["F1", "1", "q", "a", "z", ""]; 8 | for (x = [0:1:4]) { 9 | translate_u(0,-x) legend(legends[x]) dcs_row(x, 0) { 10 | // swap the debug()s to render opposite part 11 | debug() key(true); 12 | /* debug() */ dished() { 13 | legends($inset_legend_depth); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/plate_generation.scad: -------------------------------------------------------------------------------- 1 | include <../includes.scad> 2 | 3 | // plates are currently generated via the same layout arrays as layouts are. 4 | // just pass the layout to plate() and it'll do it's job using hull(). 5 | // still in beta 6 | plate(60_percent_default_layout); -------------------------------------------------------------------------------- /examples/print_keycaps_on_their_side.scad: -------------------------------------------------------------------------------- 1 | include <../includes.scad> 2 | 3 | /* Printing keycaps on their side is an easy way to get a nice, smooth top 4 | surface, with some caveats: 5 | 1. one of the sides won't look as good as the other 6 | 2. any amount of top tilt makes the sides of the keycap not flat, so we have 7 | to force them to be flat by making the keytop a trapezoid 8 | 9 | sideways() does the magic for you. 10 | 11 | Note that this won't work at all with side sculpted keycaps, skin_shape_hull, 12 | and double sculpted aka full sculpted keycaps either. Getting it to work with 13 | skin_shape_hull is the easiest, getting it to work with full sculpting is a 14 | lot harder, and side sculpting is obviously impossible by nature 15 | */ 16 | 17 | legends = ["F1", "1", "q", "a", "z"]; 18 | for (x = [0:4]) { 19 | translate_u(0,-x) dcs_row(x) sideways() front_legend(legends[x], size=5) { 20 | $stem_support_type = "disable"; 21 | $dish_type = "disable"; 22 | 23 | /* $top_tilt = 30; */ 24 | union() { 25 | key(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/sa_ergo.scad: -------------------------------------------------------------------------------- 1 | include <../includes.scad> 2 | 3 | /* 4 | In this example, we harness full sculpting and simple_layout to make a set of SA 5 | keys that look a lot like the key wells on a dactyl, dactyl manuform, or kinesis 6 | 7 | SA keys render faster with skin_extrude_shape = true, but then they don't get 8 | the nice flaring on the sides... yet. 9 | */ 10 | 11 | // to turn on full sculpting 12 | $double_sculpted = true; 13 | // to make the font fit 14 | $font_size = 4; 15 | 16 | // change this to make the full sculpting more or less aggressive. 200 is default 17 | $double_sculpt_radius = 200; 18 | 19 | // This is the exact column stagger from the dactyl transposed onto the 20 | // rows of the preonic default layout. the second array is for modifying the 21 | // values up or down - making all the 0's -1's would make each key 1mm lower 22 | // for instance. I'd suggest going as low as you can without cutting off any stems 23 | extra_column_height = [5.64, 5.64, 0, -3, 0, 0, 0, 0, 0, -3, 0, 5.64, 5.64] + [0,0,0,0,0,0,0,0,0,0,0,0,0]; 24 | // required for double_sculpted_column 25 | row_length = len(preonic_default_layout[0]); 26 | 27 | simple_layout(preonic_default_layout) { 28 | // this union is here because, for some reason, you cannot modify special variables 29 | // that are modified in the scope directly above. 30 | union() { 31 | // row declarations treat column 0 as perfectly center, so if we just used 32 | // $column we'd have a ridiculously looking left-leaning keyboard. 33 | // this function transforms the actual column value into a "2hands" column 34 | // value, aka for a board with 2 "keywells", one for each hand 35 | column_value = double_sculpted_column($column, row_length, "2hands"); 36 | /* echo("column value", column_value); */ 37 | sa_row($row+1, column_value){ 38 | // uh oh, now I need two of them... 39 | union() { 40 | // uncomment when prototyping for faster prototypes! 41 | /* $dish_type = "disable"; */ 42 | /* $stem_support_type = "disable"; */ 43 | 44 | // here's where the magic happens and we actually add the extra column height 45 | $total_depth = $total_depth + extra_column_height[$column]; 46 | key(); 47 | 48 | // this generates separate legends for the keys 49 | /* legend(preonic_default_legends[$row][$column]) legends(); */ 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /examples/single_extruder_multimaterial_legends.scad: -------------------------------------------------------------------------------- 1 | include <../includes.scad> 2 | 3 | /* Don't have a multimaterial printer but still want cool "doubleshot" legends? 4 | with a couple tricks, you can! We just have to print upside down with no 5 | dish. 6 | 7 | Here's how to use this file: 8 | 9 | 1. modify it as you see fit 10 | 2. render the legends and the keycaps separately 11 | 3. run the legends through your 3d printer. make sure they are a single layer 12 | 4. LEAVE THEM on the bed 13 | 5. change filaments 14 | 6. run the keycaps over the legends. MAKE SURE they line up! PrusaSlicer 15 | centers models on the bed 16 | 7. voila! 17 | 8. use a powder-coated bed for extra points 18 | */ 19 | 20 | legends = ["F1", "1", "q", "a", "z", ""]; 21 | for (x = [0:1:4]) { 22 | translate_u(0,-x) dcs_row(x, 0) upside_down() legend(legends[x]) { 23 | $dish_type = "disable"; 24 | $inset_legend_depth = 0.2; // whatever layer height you use 25 | 26 | union() { 27 | // swap the debug()s to render opposite part 28 | debug() key(true); 29 | /* debug() */ dished() { 30 | legends($inset_legend_depth); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /expand.rb: -------------------------------------------------------------------------------- 1 | require './openscad.rb' 2 | 3 | OpenSCAD::expand_openSCAD_file(ARGV[1] || 'customizer_base.scad', 'customizer.scad') 4 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | const shell = require('gulp-shell'); 3 | const changedInPlace = require('gulp-changed-in-place'); 4 | const changed = require('gulp-changed'); 5 | // var del = require('del'); 6 | 7 | var paths = { 8 | compile: ['*.scad'], // '**/*.scad', 9 | }; 10 | 11 | gulp.task('compile', function() { 12 | // recompile any changed openscad files 13 | return gulp.src(paths.compile) 14 | .pipe(changedInPlace({howToDetermineDifference: "modification-time"})) // TODO doesnt work for literally no reason 15 | .pipe(shell([ 16 | // 'openscad compile/compile.scad -o compile/out.stl > 1' 17 | 'openscad <%= file.relative %> -o <%= file.relative %>.stl' 18 | ], { ignoreErrors: true })) 19 | }); 20 | 21 | gulp.task('default', function() { 22 | gulp.watch(paths.compile, gulp.series('compile')); 23 | }); 24 | -------------------------------------------------------------------------------- /includes.scad: -------------------------------------------------------------------------------- 1 | use 2 | 3 | include 4 | include 5 | include 6 | include 7 | include 8 | include 9 | include 10 | -------------------------------------------------------------------------------- /key_mold.scad: -------------------------------------------------------------------------------- 1 | 2 | include 3 | 4 | platform_width = 30; 5 | platform_height = 4; 6 | // height difference between bottom and top of platform 7 | platform_slant = 3; 8 | 9 | minimum_height = 12; 10 | 11 | //minimum mold thickness 12 | extra = 9; 13 | 14 | //thicknesses of the mold 15 | side_thickness = 2; 16 | bottom_thickness = 2; 17 | 18 | 19 | // computed variables 20 | inner_side = platform_width + extra * 2; 21 | total_side = inner_side + side_thickness * 2; 22 | 23 | 24 | // minimum_height of bottom, non-flared box 25 | bottom_box_height = 5 + bottom_thickness; 26 | 27 | function hypo(num) = sqrt(pow(num,2) / 2); 28 | 29 | 30 | module bottom_box() { 31 | difference(){ 32 | //outer box 33 | cube([total_side, total_side, bottom_box_height]); 34 | 35 | //inner box 36 | translate([ side_thickness, side_thickness, bottom_thickness]) { 37 | cube([inner_side, inner_side, bottom_box_height - bottom_thickness + .02]); 38 | } 39 | } 40 | } 41 | 42 | module slanted_box() { 43 | translate([total_side / 2, total_side / 2, bottom_box_height]) rotate([0,0,45]) difference(){ 44 | //outer box 45 | cylinder( 46 | h = minimum_height + extra - bottom_box_height + platform_height, 47 | r1 = hypo(total_side), 48 | r2 = hypo(total_side + 3), 49 | $fn=4 50 | ); 51 | 52 | //inner box 53 | translate([0,0,-0.01]) cylinder( 54 | minimum_height + extra - bottom_box_height + .02 + platform_height, 55 | hypo(inner_side), 56 | hypo(inner_side + 3), 57 | $fn=4 58 | ); 59 | } 60 | } 61 | 62 | module platform() { 63 | //platform 64 | /* translate([ 65 | side_thickness + extra, 66 | side_thickness + extra, 67 | bottom_thickness 68 | ]) cube([platform_width, platform_width, platform_height]); */ 69 | 70 | translate([ 71 | side_thickness + extra + platform_width/2, 72 | side_thickness + extra + platform_width/2, 73 | bottom_thickness 74 | ]) rotate([0,0,45]) cylinder(r1=hypo(platform_width), r2=hypo(platform_width) - platform_slant, h=platform_height, $fn=4); 75 | } 76 | 77 | module registration() { 78 | positions = [ 79 | [// bottom left 80 | side_thickness + extra / 2 + 1, 81 | side_thickness + extra / 2 + 1, 82 | bottom_thickness 83 | ], 84 | [// top left 85 | side_thickness + extra / 2 + 1, 86 | side_thickness + platform_width + extra * 1.5 - 1, 87 | bottom_thickness 88 | ], 89 | [// bottom right 90 | side_thickness + platform_width + extra * 1.5 - 1, 91 | side_thickness + extra / 2 + 1, 92 | bottom_thickness 93 | ], 94 | [// top right 95 | side_thickness + platform_width + extra * 1.5 - 1, 96 | side_thickness + platform_width + extra * 1.5 - 1, 97 | bottom_thickness 98 | ] 99 | ]; 100 | 101 | for (index = [0:len(positions)-1]) { 102 | position = positions[index]; 103 | translate(position) { 104 | // dont mind the math 105 | rotate([0,0,45 / (index % 2 * 0.5 + 1)]) { 106 | cylinder(platform_height / 2,extra/3, 2, $fn=(index % 2 * 2 + 4)); 107 | } 108 | } 109 | } 110 | } 111 | 112 | module key_for_mold(wall_thickness = 20) { 113 | translate([ 114 | total_side / 2, 115 | total_side / 2, 116 | platform_height + bottom_thickness 117 | ]) { 118 | $wall_thickness = wall_thickness; 119 | $support_type = false; 120 | sa_row(1) key(); 121 | } 122 | } 123 | 124 | module bottom_mold(){ 125 | bottom_box(); 126 | slanted_box(); 127 | platform(); 128 | registration(); 129 | /* key_for_mold(); */ 130 | } 131 | 132 | module top_mold(){ 133 | difference(){ 134 | //outer box 135 | cube([ 136 | total_side, 137 | total_side, 138 | minimum_height + extra + bottom_thickness, 139 | ]); 140 | 141 | //inner box 142 | translate([ 143 | side_thickness, 144 | side_thickness, 145 | 0 146 | ]) { 147 | cube([ 148 | inner_side, 149 | inner_side, 150 | minimum_height + extra + bottom_thickness, 151 | ]); 152 | } 153 | } 154 | } 155 | 156 | // for calculating how much mold material to use! 157 | module difference_box() { 158 | scale(.99) union() { 159 | cube([total_side, total_side, bottom_box_height + bottom_thickness]); 160 | translate([total_side / 2, total_side / 2, bottom_box_height + bottom_thickness]) rotate([0,0,45]){ 161 | //outer box 162 | cylinder( 163 | minimum_height + extra - bottom_box_height, 164 | hypo(total_side), 165 | hypo(total_side + 3), 166 | $fn=4 167 | ); 168 | } 169 | } 170 | } 171 | 172 | difference() { 173 | /* difference_box(); */ 174 | 175 | /* bottom_mold(); */ 176 | } 177 | 178 | /* key_for_mold(0); */ 179 | 180 | translate([0,0,0]) top_mold(); 181 | -------------------------------------------------------------------------------- /keys.scad: -------------------------------------------------------------------------------- 1 | // the point of this file is to be a sort of DSL for constructing keycaps. 2 | // when you create a method chain you are just changing the parameters 3 | // key.scad uses, it doesn't generate anything itself until the end. This 4 | // lets it remain easy to use key.scad like before (except without key profiles) 5 | // without having to rely on this file. Unfortunately that means setting tons of 6 | // special variables, but that's a limitation of SCAD we have to work around 7 | 8 | include <./includes.scad> 9 | 10 | 11 | // example key 12 | dcs_row(5) legend("⇪", size=9) key(); 13 | 14 | // example row 15 | /* for (x = [0:1:4]) { 16 | translate_u(0,-x) dcs_row(x) key(); 17 | } */ 18 | 19 | // example layout 20 | /* preonic_default("dcs") key(); */ 21 | -------------------------------------------------------------------------------- /model_base.scad: -------------------------------------------------------------------------------- 1 | // entry point for customizer script. This probably isn't useful to most people, 2 | // as it's just a wrapper that helps generate customizer.scad for thingiverse. 3 | 4 | /* [Basic-Settings] */ 5 | 6 | // what preset profile do you wish to use? disable if you are going to set paramters below 7 | key_profile = "dcs"; // [dcs, oem, dsa, sa, g20, disable] 8 | // what key profile row is this keycap on? 0 for disable 9 | row = 1; // [5,1,2,3,4,0] 10 | 11 | // What does the top of your key say? 12 | legend = ""; 13 | 14 | include 15 | 16 | include 17 | include 18 | include 19 | include 20 | 21 | use 22 | -------------------------------------------------------------------------------- /models.rb: -------------------------------------------------------------------------------- 1 | require './openscad.rb' 2 | require 'tempfile' 3 | 4 | ROWS = [5,1,2,3,4].freeze # [5,1,2,3,4] 5 | SIZES = [1, 1.25, 1.5, 1.75, 2, 2.25, 2.75, 6.25].freeze 6 | PROFILES = ['dcs', 'dsa', 'g20', 'oem', 'sa'].freeze 7 | 8 | # can't get include statements to work dynamically so we'll just use a file 9 | def make_file(command) 10 | lines = OpenSCAD::expand('model_base.scad') 11 | lines << command 12 | f = Tempfile.new('models.scad') 13 | f.write lines.join 14 | f.close 15 | f.path 16 | end 17 | 18 | # length is not used in the command here to get the automatic stabilizers from the script 19 | def make_command(row, length, profile) 20 | "key_profile(\"#{profile}\", #{row}) { union() { #{length == 6.25 ? '$dish_type = "sideways cylindrical"; $inverted_dish=true;' : ''} key(); } }" 21 | end 22 | 23 | ROWS.each do |row| 24 | SIZES.each do |length| 25 | PROFILES.each do |profile| 26 | command = make_command(row, length, profile) 27 | filename = "#{profile}_row-#{row}_length-#{length.to_s.sub('.', '_')}.stl" 28 | puts "rendering #{filename}:" 29 | puts "\tcommand: #{command} \n\n" 30 | path = make_file(command) 31 | `openscad -o ./models/#{filename} -D "\\\$key_length = #{length};" #{path}` 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /openscad.rb: -------------------------------------------------------------------------------- 1 | module OpenSCAD 2 | def self.expand(filename) 3 | lines = File.readlines(filename) 4 | old_dir = Dir.getwd 5 | 6 | Dir.chdir File.dirname(filename) 7 | lines = lines.flat_map do |line| 8 | # please note we do not implement `use` at all 9 | if line =~ /(include|use)\s*<(.*)>/ 10 | # File.readlines("./#{$2}") 11 | expand("./#{$2}") 12 | else 13 | line 14 | end 15 | end 16 | 17 | Dir.chdir old_dir 18 | 19 | lines 20 | end 21 | 22 | def self.expand_openSCAD_file(source, destination) 23 | lines = OpenSCAD::expand(source) 24 | 25 | f = File.open(destination, 'w') 26 | f.write lines.join 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "keyv2", 3 | "version": "1.0.0", 4 | "description": "automated stl build platform for KeyV2", 5 | "main": "gulpfile.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/rsheldiii/openSCAD-projects.git" 12 | }, 13 | "keywords": [ 14 | "mechanical", 15 | "keyboard" 16 | ], 17 | "author": "rsheldiii", 18 | "license": "GPL-3.0", 19 | "bugs": { 20 | "url": "https://github.com/rsheldiii/openSCAD-projects/issues" 21 | }, 22 | "homepage": "https://github.com/rsheldiii/openSCAD-projects#readme", 23 | "dependencies": { 24 | "gulp-changed": "^3.2.0", 25 | "gulp-changed-in-place": "^2.3.0", 26 | "gulp-shell": "^0.8.0" 27 | }, 28 | "devDependencies": { 29 | "gulp": "4.0.2" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/constants.scad: -------------------------------------------------------------------------------- 1 | // a safe theoretical distance between two vertices such that they don't collapse. hard to use 2 | SMALLEST_POSSIBLE = 1/128; 3 | $fs=0.1; 4 | $unit=19.05; 5 | -------------------------------------------------------------------------------- /src/dishes.scad: -------------------------------------------------------------------------------- 1 | include 2 | 3 | include 4 | include 5 | include 6 | include 7 | include 8 | include 9 | include 10 | include 11 | 12 | //geodesic looks much better, but runs very slow for anything above a 2u 13 | geodesic=false; 14 | 15 | //dish selector 16 | module dish(width, height, depth, inverted) { 17 | if($dish_type == "cylindrical"){ 18 | cylindrical_dish(width, height, depth, inverted); 19 | } else if ($dish_type == "spherical") { 20 | spherical_dish(width, height, depth, inverted); 21 | } else if ($dish_type == "sideways cylindrical"){ 22 | sideways_cylindrical_dish(width, height, depth, inverted); 23 | } else if ($dish_type == "old spherical") { 24 | old_spherical_dish(width, height, depth, inverted); 25 | } else if ($dish_type == "3d surface") { 26 | 3d_surface_dish(width, height, depth, inverted); 27 | } else if ($dish_type == "flat") { 28 | flat_dish(width, height, depth, inverted); 29 | } else if ($dish_type == "disable") { 30 | // else no dish 31 | } else if ($dish_type == "squared spherical") { 32 | squared_spherical_dish(width, height, depth, inverted=inverted); 33 | } else if ($dish_type == "squared scoop") { 34 | squared_scoop_dish(width, height, depth, inverted=inverted); 35 | } else { 36 | echo("WARN: $dish_type unsupported"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/dishes/3d_surface.scad: -------------------------------------------------------------------------------- 1 | include <../libraries/3d_surface.scad> 2 | 3 | module 3d_surface_dish(width, height, depth, inverted) { 4 | echo(inverted ? "inverted" : "not inverted"); 5 | // scale_factor is dead reckoning 6 | // it doesn't have to be dead reckoning for anything but sculpted sides 7 | // we know the angle of the sides from the width difference, height difference, 8 | // skew and tilt of the top. it's a pain to calculate though 9 | scale_factor = 1.05; 10 | // the edges on this behave differently than with the previous dish implementations 11 | scale([width*scale_factor/$3d_surface_size/2,height*scale_factor/$3d_surface_size/2,depth]) 12 | rotate([inverted ? 0:180,0,180]) 13 | polar_3d_surface(size=$3d_surface_size, step=$3d_surface_step, bottom=-10); 14 | /* %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); */ 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/dishes/cylindrical.scad: -------------------------------------------------------------------------------- 1 | module cylindrical_dish(width, height, depth, inverted){ 2 | // .5 has problems starting around 3u 3 | $fa=.25; 4 | /* we do some funky math here 5 | * basically you want to have the dish "dig in" to the keycap x millimeters 6 | * in order to do that you have to solve a small (2d) system of equations 7 | * where the chord of the spherical cross section of the dish is 8 | * the width of the keycap. 9 | */ 10 | // the distance you have to move the dish so it digs in depth millimeters 11 | chord_length = (pow(width, 2) - 4 * pow(depth, 2)) / (8 * depth); 12 | //the radius of the dish 13 | rad = (pow(width, 2) + 4 * pow(depth, 2)) / (8 * depth); 14 | direction = inverted ? -1 : 1; 15 | 16 | translate([0,0, chord_length * direction]){ 17 | rotate([90, 0, 0]) cylinder(h=height + 20, r=rad, center=true); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/dishes/flat.scad: -------------------------------------------------------------------------------- 1 | module flat_dish(width, height, depth, inverted){ 2 | cube([width + 100,height + 100, depth], center=true); 3 | } 4 | -------------------------------------------------------------------------------- /src/dishes/old_spherical.scad: -------------------------------------------------------------------------------- 1 | //the older, 'more accurate', and MUCH slower spherical dish. 2 | // generates the largest sphere possible that still contains the chord we are looking for 3 | // much more graduated curvature at an immense cost 4 | module old_spherical_dish(width, height, depth, inverted){ 5 | 6 | //same thing as the cylindrical dish here, but we need the corners to just touch - so we have to find the hypotenuse of the top 7 | chord = pow((pow(width,2) + pow(height, 2)),0.5); //getting diagonal of the top 8 | 9 | // the distance you have to move the dish up so it digs in depth millimeters 10 | chord_length = (pow(chord, 2) - 4 * pow(depth, 2)) / (8 * depth); 11 | //the radius of the dish 12 | rad = (pow(chord, 2) + 4 * pow(depth, 2)) / (8 * depth); 13 | direction = inverted ? -1 : 1; 14 | 15 | translate([0,0,chord_length * direction]){ 16 | if (geodesic){ 17 | $fa=7; 18 | geodesic_sphere(r=rad); 19 | } else { 20 | $fa=1; 21 | // rotate 1 because the bottom of the sphere looks like trash 22 | sphere(r=rad); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/dishes/sideways_cylindrical.scad: -------------------------------------------------------------------------------- 1 | module sideways_cylindrical_dish(width, height, depth, inverted){ 2 | $fa=1; 3 | chord_length = (pow(height, 2) - 4 * pow(depth, 2)) / (8 * depth); 4 | rad = (pow(height, 2) + 4 * pow(depth, 2)) / (8 * depth); 5 | 6 | direction = inverted ? -1 : 1; 7 | 8 | translate([0,0, chord_length * direction]){ 9 | // cylinder is rendered facing up, so we rotate it on the y axis first 10 | rotate([0,90,0]) cylinder(h = width + 20,r=rad, center=true); // +20 for fudge factor 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/dishes/spherical.scad: -------------------------------------------------------------------------------- 1 | module spherical_dish(width, height, depth, inverted){ 2 | // these variables take into account corner_radius and corner_sculpting, resulting in a more correct dish 3 | // they don't fix the core issue though (dishes adding / subtracting height on the edges of the keycap), so I've disabled them 4 | // new_width = $key_shape_type == "sculpted_square" ? width - distance_between_circumscribed_and_inscribed($corner_radius + $corner_sculpting(1)) : width; 5 | // new_height = $key_shape_type == "sculpted_square" ? height - distance_between_circumscribed_and_inscribed($corner_radius + $corner_sculpting(1)) : height; 6 | 7 | //same thing as the cylindrical dish here, but we need the corners to just touch - so we have to find the hypotenuse of the top 8 | chord = pow((pow(width,2) + pow(height, 2)),0.5); //getting diagonal of the top 9 | 10 | // the distance you have to move the dish up so it digs in depth millimeters 11 | chord_length = (pow(chord, 2) - 4 * pow(depth, 2)) / (8 * depth); 12 | //the radius of the dish 13 | rad = (pow(chord, 2) + 4 * pow(depth, 2)) / (8 * depth); 14 | direction = inverted ? -1 : 1; 15 | 16 | translate([0,0,0 * direction]){ 17 | if (geodesic){ 18 | $fa=20; 19 | scale([chord/2/depth, chord/2/depth]) { 20 | geodesic_sphere(r=depth); 21 | } 22 | } else { 23 | $fa=6.5; 24 | // rotate 1 because the bottom of the sphere looks like trash. 25 | scale([chord/2/depth, chord/2/depth]) { 26 | sphere(r=depth); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/dishes/squared_scoop.scad: -------------------------------------------------------------------------------- 1 | module squared_scoop_dish(height, width, depth, r=0.5, inverted=false, num=4, den=5){ 2 | // changable numerator/denoninator on where to place the square's corners 3 | // for example, num=2, den=3 means the dish will happen at 1/3 and 2/3 the 4 | // width and the height. Defaults to 4/5. Customizable when calling 5 | // this module 6 | // 7 | // This was initially intended for the scoop on the HiPro, since that's what 8 | // it uses. Use "hipro_row()" if that's what you'd like. However, I do NOT 9 | // know how close the inner square is for the HiPro keycaps. In fact, it could 10 | // just be a sphere, in which the "squared spherical" scoop is more appropriate. 11 | // If, however, it the "squared scoop" makes sense, you can adjust where the square 12 | // lands with the num (numerator) and den (denominator) variables. For instance, 13 | // "3" and "4" mean 3/4 of the width/height is where the flat part starts. 14 | 15 | chord = pow(pow(height/2, 2) + pow(width/2, 2),0.5); 16 | direction = inverted ? -1 : 1; 17 | 18 | //This is the set of points to hull around for the scoop 19 | points=[ 20 | [height/den - height/2, width/den - width/2, -chord], 21 | [num*height/den - height/2, width/den - width/2, -chord], 22 | [height/den - height/2, num*width/den - width/2, -chord], 23 | [num*height/den - height/2, num*width/den - width/2, -chord] 24 | ]; 25 | 26 | resize([height,width,depth]) 27 | hull() { 28 | shape_slice(1,0,0); 29 | for(i=[0:len(points)-1]) { 30 | translate(points[i]) 31 | sphere(r=r,$fn=64); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/dishes/squared_spherical.scad: -------------------------------------------------------------------------------- 1 | module squared_spherical_dish(width, height, depth, inverted=false) { 2 | chord = pow(pow(height / 2, 2) + pow(width / 2, 2),0.5); 3 | direction = inverted ? -1 : 1; 4 | r=max(height,width,chord) / 5; 5 | // ^^^^^ Nothing special about this code to figure out r. 6 | // I just modeled up 1u, 1.25u, 1.5u, 2u, 2.25u, and 2.75u 7 | // keys and messed around until I came up with something that 8 | // looked reasonable for all key sizes. This just seems to work 9 | // well for all sizes 10 | 11 | translate([-width / 2, -height / 2, 0 * direction]) { 12 | resize([width, height, depth]) 13 | hull() { 14 | cube([chord,chord,0.001]); 15 | // Use something larger in this translate than -depth 16 | // (like -chord) if you want more of a defined circle 17 | // in the keywell 18 | translate([chord/2, chord/2, -depth]) 19 | sphere(r=r, $fn=128); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/features.scad: -------------------------------------------------------------------------------- 1 | // features are any premade self-contained objects that go on top or inside 2 | 3 | include 4 | include 5 | include 6 | -------------------------------------------------------------------------------- /src/features/clearance_check.scad: -------------------------------------------------------------------------------- 1 | // a fake cherry keyswitch, abstracted out to maybe replace with a better one later 2 | module cherry_keyswitch() { 3 | union() { 4 | hull() { 5 | cube([15.6, 15.6, 0.01], center=true); 6 | translate([0,1,5 - 0.01]) cube([10.5,9.5, 0.01], center=true); 7 | } 8 | hull() { 9 | cube([15.6, 15.6, 0.01], center=true); 10 | translate([0,0,-5.5]) cube([13.5,13.5,0.01], center=true); 11 | } 12 | } 13 | } 14 | 15 | //approximate (fully depressed) cherry key to check clearances 16 | module clearance_check() { 17 | if($stem_type == "cherry" || $stem_type == "cherry_rounded"){ 18 | color($warning_color){ 19 | translate([0,0,3.6 + $stem_inset - 5]) { 20 | cherry_keyswitch(); 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/features/key_bump.scad: -------------------------------------------------------------------------------- 1 | module keybump(depth = 0, edge_inset=0.4) { 2 | radius = 0.5; 3 | translate([0, -top_total_key_height()/2 + edge_inset, depth]){ 4 | rotate([90,0,90]) cylinder($font_size, radius, radius, true); 5 | translate([0,0,-radius]) cube([$font_size, radius*2, radius*2], true); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/features/legends.scad: -------------------------------------------------------------------------------- 1 | module keytext(text, position, font_size, font_face, depth) { 2 | woffset = (top_total_key_width()/3.5) * position[0]; 3 | hoffset = (top_total_key_height()/3.5) * -position[1]; 4 | translate([woffset, hoffset, -depth]){ 5 | color($tertiary_color) linear_extrude(height=$dish_depth + depth){ 6 | text(text=text, font=font_face, size=font_size, halign="center", valign="center"); 7 | } 8 | } 9 | } 10 | 11 | module legends(depth=0) { 12 | if (len($front_legends) > 0) { 13 | front_of_key() { 14 | for (i=[0:len($front_legends)-1]) { 15 | rotate([90,0,0]) keytext($front_legends[i][0], $front_legends[i][1], $front_legends[i][2], $front_legends[i][3], depth); 16 | } 17 | } 18 | } 19 | if (len($legends) > 0) { 20 | top_of_key() { 21 | for (i=[0:len($legends)-1]) { 22 | keytext($legends[i][0], $legends[i][1], $legends[i][2], $legends[i][3], depth); 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/functions.scad: -------------------------------------------------------------------------------- 1 | include 2 | include 3 | 4 | // I use functions when I need to compute special variables off of other special variables 5 | // functions need to be explicitly included, unlike special variables, which 6 | // just need to have been set before they are used. hence this file 7 | 8 | function stem_height() = $total_depth - ($dish_depth * ($inverted_dish ? -1 : 1)) - $stem_inset; 9 | 10 | // cherry stem dimensions 11 | function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2]; 12 | 13 | // cherry stabilizer stem dimensions 14 | function outer_cherry_stabilizer_stem(slop) = [4.85 - slop * 2, 6.05 - slop * 2]; 15 | 16 | // box (kailh) switches have a bit less to work with 17 | function outer_box_cherry_stem(slop) = [6 - slop, 6 - slop]; 18 | 19 | // .005 purely for aesthetics, to get rid of that ugly crosshatch 20 | function cherry_cross(slop, extra_vertical = 0) = [ 21 | // horizontal tine 22 | [4.03 + slop, 1.25 + slop / 3], 23 | // vertical tine 24 | [1.15 + slop / 3, 4.23 + extra_vertical + slop / 3 + SMALLEST_POSSIBLE], 25 | ]; 26 | 27 | // TODO add side_sculpting 28 | function key_width_at_progress(progress = 0) = $bottom_key_width + ($unit * ($key_length - 1)) - $width_difference; 29 | function key_height_at_progress(progress = 0) = $bottom_key_height + ($unit * ($key_height - 1)) - $height_difference + $side_sculpting(progress); 30 | 31 | // actual mm key width and height 32 | function total_key_width(delta = 0) = $bottom_key_width + $unit * ($key_length - 1) - delta; 33 | function total_key_height(delta = 0) = $bottom_key_height + $unit * ($key_height - 1) - delta; 34 | 35 | // actual mm key width and height at the top 36 | function top_total_key_width() = $bottom_key_width + ($unit * ($key_length - 1)) - $width_difference; 37 | function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1)) - $height_difference; 38 | 39 | function side_tilt(column) = asin($unit * column / $double_sculpt_radius); 40 | // tan of 0 is 0, division by 0 is nan, so we have to guard 41 | function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - ($unit * abs(column)) / tan(abs(side_tilt(column)))) : 0; 42 | 43 | // (I think) extra length of the side of the keycap due to the keytop being tilted. 44 | // necessary for calculating flat sided keycaps 45 | function vertical_inclination_due_to_top_tilt() = sin($top_tilt) * (top_total_key_height() - $corner_radius * 2) * 0.5; 46 | // how much you have to expand the front or back of the keytop to make the side 47 | // of the keycap a flat plane. 1 = front, -1 = back 48 | // I derived this through a bunch of trig reductions I don't really understand. 49 | function extra_keytop_length_for_flat_sides() = ($width_difference * vertical_inclination_due_to_top_tilt()) / ($total_depth); 50 | 51 | // adds uniform rounding radius for round-anything polyRound 52 | function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]]; 53 | // computes millimeter length from unit length 54 | function unit_length(length) = $unit * (length - 1) + 18.16; 55 | 56 | // if you have a radius of an inscribed circle, this function gives you the extra length for the radius of the circumscribed circle 57 | // and vice versa. used to find the edge of a rounded_square 58 | function distance_between_circumscribed_and_inscribed(radius) = (pow(2, 0.5) - 1) * radius; -------------------------------------------------------------------------------- /src/hulls.scad: -------------------------------------------------------------------------------- 1 | include 2 | include 3 | include 4 | 5 | // basic key shape, no dish, no inside 6 | // which is only used for dishing to cut the dish off correctly 7 | // $height_difference used for keytop thickness 8 | // extra_slices is a hack to make inverted dishes still work 9 | module shape_hull(thickness_difference, depth_difference, extra_slices = 0){ 10 | render() { 11 | if ($hull_shape_type == "skin") { 12 | skin_extrude_shape_hull(thickness_difference, depth_difference, extra_slices); 13 | } else if ($hull_shape_type == "linear extrude") { 14 | linear_extrude_shape_hull(thickness_difference, depth_difference, extra_slices); 15 | } else { 16 | hull_shape_hull(thickness_difference, depth_difference, extra_slices); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/hulls/hull.scad: -------------------------------------------------------------------------------- 1 | module hull_shape_hull(thickness_difference, depth_difference, extra_slices = 0) { 2 | for (index = [0:$height_slices - 1 + extra_slices]) { 3 | hull() { 4 | placed_shape_slice(index / $height_slices, thickness_difference, depth_difference); 5 | placed_shape_slice((index + 1) / $height_slices, thickness_difference, depth_difference); 6 | } 7 | } 8 | } 9 | 10 | module placed_shape_slice(progress, thickness_difference, depth_difference) { 11 | skew_this_slice = $top_skew * progress; 12 | x_skew_this_slice = $top_skew_x * progress; 13 | 14 | depth_this_slice = ($total_depth - depth_difference) * progress; 15 | 16 | tilt_this_slice = -$top_tilt / $key_height * progress; 17 | y_tilt_this_slice = $double_sculpted ? (-$top_tilt_y / $key_length * progress) : 0; 18 | 19 | translate([x_skew_this_slice, skew_this_slice, depth_this_slice]) { 20 | rotate([tilt_this_slice,y_tilt_this_slice,0]){ 21 | shape_slice(progress, thickness_difference, depth_difference); 22 | } 23 | } 24 | } 25 | 26 | module shape_slice(progress, thickness_difference, depth_difference) { 27 | linear_extrude(height = SMALLEST_POSSIBLE, scale = 1){ 28 | key_shape( 29 | [ 30 | total_key_width(thickness_difference), 31 | total_key_height(thickness_difference) 32 | ], 33 | [$width_difference, $height_difference], 34 | progress 35 | ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/hulls/linear_extrude.scad: -------------------------------------------------------------------------------- 1 | // corollary is hull_shape_hull 2 | // extra_slices unused, only to match argument signatures 3 | module linear_extrude_shape_hull(thickness_difference, depth_difference, extra_slices = 0){ 4 | height = $total_depth - depth_difference; 5 | width_scale = top_total_key_width() / total_key_width(); 6 | height_scale = top_total_key_height() / total_key_height(); 7 | 8 | translate([0,$linear_extrude_height_adjustment,0]){ 9 | linear_extrude(height = height, scale = [width_scale, height_scale]) { 10 | translate([0,-$linear_extrude_height_adjustment,0]){ 11 | key_shape( 12 | [total_key_width(), total_key_height()], 13 | [thickness_difference, thickness_difference] 14 | ); 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/hulls/skin.scad: -------------------------------------------------------------------------------- 1 | // use skin() instead of successive hulls. much more correct, and looks faster 2 | // too, in most cases. successive hull relies on overlapping faces which are 3 | // not good. But, skin works on vertex sets instead of shapes, which makes it 4 | // a lot more difficult to use 5 | module skin_extrude_shape_hull(thickness_difference, depth_difference, extra_slices = 0 ) { 6 | skin([ 7 | for (index = [0:$height_slices + extra_slices]) 8 | let( 9 | progress = (index / $height_slices), 10 | skew_this_slice = $top_skew * progress, 11 | x_skew_this_slice = $top_skew_x * progress, 12 | depth_this_slice = ($total_depth - depth_difference) * progress, 13 | tilt_this_slice = -$top_tilt / $key_height * progress, 14 | y_tilt_this_slice = $double_sculpted ? (-$top_tilt_y / $key_length * progress) : 0 15 | ) 16 | skin_shape_slice(progress, thickness_difference, skew_this_slice, x_skew_this_slice, depth_this_slice, tilt_this_slice, y_tilt_this_slice) 17 | ]); 18 | } 19 | 20 | function skin_shape_slice(progress, thickness_difference, skew_this_slice, x_skew_this_slice, depth_this_slice, tilt_this_slice, y_tilt_this_slice) = 21 | transform( 22 | translation([x_skew_this_slice,skew_this_slice,depth_this_slice]), 23 | transform( 24 | rotation([tilt_this_slice,y_tilt_this_slice,0]), 25 | skin_key_shape([ 26 | total_key_width(0) - thickness_difference, 27 | total_key_height(0) - thickness_difference, 28 | ], 29 | [$width_difference, $height_difference], 30 | progress, 31 | thickness_difference 32 | ) 33 | ) 34 | ); 35 | -------------------------------------------------------------------------------- /src/key.scad: -------------------------------------------------------------------------------- 1 | // files 2 | include 3 | include 4 | include 5 | include 6 | include 7 | include 8 | include 9 | include 10 | include 11 | 12 | include 13 | 14 | // for skin hulls 15 | use 16 | use 17 | use 18 | use 19 | 20 | // key shape including dish. used as the outside and inside shape in hollow_key(). allows for itself to be shrunk in depth and width / height 21 | module shape(thickness_difference, depth_difference=0){ 22 | dished(depth_difference, $inverted_dish) { 23 | color($primary_color) shape_hull(thickness_difference, depth_difference, $inverted_dish ? 200 : 0); 24 | } 25 | } 26 | 27 | module rounded_shape() { 28 | color($primary_color) minkowski(){ 29 | // half minkowski in the z direction 30 | shape($minkowski_radius * 2, $minkowski_radius/2); 31 | minkowski_object(); 32 | } 33 | } 34 | 35 | // minkowski places this object at every vertex of the other object then mashes 36 | // it all together 37 | module minkowski_object() { 38 | // alternative minkowski shape that needs the bottom of the keycap to be trimmed 39 | /* sphere(1); */ 40 | 41 | difference(){ 42 | sphere(r=$minkowski_radius, $fa=360/$minkowski_facets); 43 | translate([0,0,-$minkowski_radius]){ 44 | cube($minkowski_radius * 2, center=true); 45 | } 46 | } 47 | } 48 | 49 | module envelope(depth_difference=0, extra_floor_depth=0) { 50 | size = 1.5; 51 | 52 | hull(){ 53 | translate([0,0,extra_floor_depth]) cube([key_width_at_progress(extra_floor_depth / $total_depth) * size, key_height_at_progress(extra_floor_depth / $total_depth) * size, 0.01], center = true); 54 | top_placement(SMALLEST_POSSIBLE + depth_difference){ 55 | cube([top_total_key_width() * size, top_total_key_height() * size, 0.01], center = true); 56 | } 57 | } 58 | } 59 | 60 | // for when you want to take the dish out of things 61 | // used for adding the dish to the key shape and making sure stems don't stick out the top 62 | // creates a bounding box 1.5 times larger in width and height than the keycap. 63 | module dished(depth_difference = 0, inverted = false) { 64 | intersection() { 65 | children(); 66 | difference(){ 67 | union() { 68 | // envelope is needed to "fill in" the rest of the keycap. intersections with small objects are much faster than differences with large objects 69 | envelope(depth_difference, $stem_inset); 70 | if (inverted) top_placement(depth_difference) color($secondary_color) _dish(inverted); 71 | } 72 | if (!inverted) top_placement(depth_difference) color($secondary_color) _dish(inverted); 73 | // %top_placement(depth_difference) _dish(); 74 | } 75 | } 76 | } 77 | 78 | // just to DRY up the code 79 | // TODO is putting special vars in function signatures legal 80 | module _dish(inverted=$inverted_dish) { 81 | translate([$dish_offset_x,0,0]) color($secondary_color) 82 | dish(top_total_key_width() + $dish_overdraw_width, top_total_key_height() + $dish_overdraw_height, $dish_depth, inverted); 83 | // %dish(top_total_key_width() + $dish_overdraw_width, top_total_key_height() + $dish_overdraw_height, $dish_depth, inverted); 84 | } 85 | 86 | // puts its children at each keystem position provided 87 | module keystem_positions(positions) { 88 | for (connector_pos = positions) { 89 | translate(connector_pos) { 90 | rotate([0, 0, $stem_rotation]){ 91 | children(); 92 | } 93 | } 94 | } 95 | } 96 | 97 | module support_for(positions, stem_type) { 98 | keystem_positions(positions) { 99 | color($tertiary_color) supports($support_type, stem_type, $stem_throw, $total_depth - $stem_throw); 100 | } 101 | } 102 | 103 | module stems_for(positions, stem_type) { 104 | keystem_positions(positions) { 105 | color($tertiary_color) stem(stem_type, stem_height(), $stem_slop, $stem_throw); 106 | if ($stem_support_type != "disable") { 107 | color($quaternary_color) stem_support($stem_support_type, stem_type, $stem_support_height, $stem_slop); 108 | } 109 | } 110 | } 111 | 112 | // put something at the top of the key, with no adjustments for dishing 113 | module top_placement(depth_difference=0) { 114 | top_tilt_by_height = -$top_tilt / $key_height; 115 | top_tilt_y_by_length = $double_sculpted ? (-$top_tilt_y / $key_length) : 0; 116 | 117 | // minkowski_height = $rounded_key ? $minkowski_radius : 0; 118 | 119 | translate([$top_skew_x + $dish_skew_x, $top_skew + $dish_skew_y, $total_depth - depth_difference]){ 120 | rotate([top_tilt_by_height, top_tilt_y_by_length,0]){ 121 | children(); 122 | } 123 | } 124 | } 125 | 126 | // puts its children at the center of the dishing on the key, including dish height 127 | // more user-friendly than top_placement 128 | module top_of_key(){ 129 | // if there is a dish, we need to account for how much it digs into the top 130 | dish_depth = ($dish_type == "disable") ? 0 : $dish_depth; 131 | // 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 132 | corrected_dish_depth = ($inverted_dish) ? -dish_depth / 2 : dish_depth; 133 | 134 | top_placement(corrected_dish_depth) { 135 | children(); 136 | } 137 | } 138 | 139 | module front_of_key() { 140 | // all this math is to take top skew and tilt into account 141 | // we need to find the new effective height and depth of the top, front lip 142 | // of the keycap to find the angle so we can rotate things correctly into place 143 | total_depth_difference = sin(-$top_tilt) * (top_total_key_height()/2); 144 | total_height_difference = $top_skew + (1 - cos(-$top_tilt)) * (top_total_key_height()/2); 145 | 146 | angle = atan2(($total_depth - total_depth_difference), ($height_difference/2 + total_height_difference)); 147 | hypotenuse = ($total_depth -total_depth_difference) / sin(angle); 148 | 149 | translate([0,-total_key_height()/2,0]) { 150 | rotate([-(90-angle), 0, 0]) { 151 | translate([0,0,hypotenuse/2]){ 152 | children(); 153 | } 154 | } 155 | } 156 | } 157 | 158 | module outer_shape() { 159 | if ($rounded_key == true) { 160 | rounded_shape(); 161 | } else { 162 | shape(0, 0); 163 | } 164 | } 165 | 166 | module inner_shape(extra_wall_thickness = 0, extra_keytop_thickness = 0) { 167 | if ($inner_shape_type == "flat") { 168 | /* $key_shape_type="square"; */ 169 | $height_slices = 1; 170 | // if inner_shape is flat, keytop_thickness will be dish_depth less than it should be, since the dish digs in that far. 171 | // so, we add dish_depth here 172 | color($primary_color) shape_hull($wall_thickness + extra_wall_thickness, $keytop_thickness + extra_keytop_thickness + $dish_depth, 0); 173 | } else { 174 | shape($wall_thickness + extra_wall_thickness, $keytop_thickness + extra_keytop_thickness); 175 | } 176 | } 177 | 178 | // additive objects at the top of the key 179 | module additive_features(inset) { 180 | top_of_key() { 181 | if($key_bump) keybump($key_bump_depth, $key_bump_edge); 182 | if(!inset && $children > 0) color($secondary_color) children(); 183 | } 184 | if($outset_legends) legends(0); 185 | // render the clearance check if it's enabled, but don't have it intersect with anything 186 | if ($clearance_check) %clearance_check(); 187 | } 188 | 189 | // subtractive objects at the top of the key 190 | module subtractive_features(inset) { 191 | top_of_key() { 192 | if (inset && $children > 0) color($secondary_color) children(); 193 | } 194 | if(!$outset_legends) legends($inset_legend_depth); 195 | // subtract the clearance check if it's enabled, letting the user see the 196 | // parts of the keycap that will hit the cherry switch 197 | // this is a little confusing as it eats the stem too 198 | /* if ($clearance_check) clearance_check(); */ 199 | } 200 | 201 | // features inside the key itself (stem, supports, etc) 202 | module inside_features() { 203 | // Stems and stabilizers are not "inside features" unless they are fully 204 | // contained inside the cap. otherwise they'd be cut off when they are 205 | // differenced with the outside shape. this only matters if $stem_inset 206 | // is negative 207 | if ($stem_inset >= 0) stems_and_stabilizers(); 208 | if ($support_type != "disable") translate([0, 0, $stem_inset]) support_for($stem_positions, $stem_type); 209 | if ($stabilizer_type != "disable") translate([0, 0, $stem_inset]) support_for($stabilizers, $stabilizer_type); 210 | } 211 | 212 | // all stems and stabilizers 213 | module stems_and_stabilizers() { 214 | translate([0, 0, $stem_inset]) { 215 | if ($stabilizer_type != "disable") stems_for($stabilizers, $stabilizer_type); 216 | if ($stem_type != "disable") stems_for($stem_positions, $stem_type); 217 | } 218 | } 219 | 220 | // helpers for doubleshot keycaps for now 221 | module inner_total_shape() { 222 | difference() { 223 | inner_shape(); 224 | inside_features(); 225 | } 226 | } 227 | 228 | module outer_total_shape(inset=false) { 229 | outer_shape(); 230 | additive_features(inset) { 231 | children(); 232 | }; 233 | } 234 | 235 | // The final, penultimate key generation function. 236 | // takes all the bits and glues them together. requires configuration with special variables. 237 | module key(inset=false) { 238 | difference(){ 239 | outer_total_shape(inset) { 240 | children(); 241 | }; 242 | 243 | if ($inner_shape_type != "disable") { 244 | translate([0,0,-SMALLEST_POSSIBLE]) { // avoids moire 245 | inner_total_shape(); 246 | } 247 | } 248 | 249 | subtractive_features(inset) { 250 | children(); 251 | }; 252 | } 253 | 254 | // semi-hack to make sure negative inset stems don't poke through the top of the keycap 255 | if ($stem_inset < 0) { 256 | dished(0, $inverted_dish) { 257 | stems_and_stabilizers(); 258 | } 259 | } 260 | } 261 | 262 | // actual full key with space carved out and keystem/stabilizer connectors 263 | // this is an example key with all the fixins from settings.scad 264 | module example_key(){ 265 | include 266 | key(); 267 | } 268 | 269 | if (!$using_customizer) { 270 | example_key(); 271 | } 272 | -------------------------------------------------------------------------------- /src/key_features.scad: -------------------------------------------------------------------------------- 1 | include 2 | -------------------------------------------------------------------------------- /src/key_helpers.scad: -------------------------------------------------------------------------------- 1 | module arrows(profile, rows = [4,4,4,3]) { 2 | positions = [[0, 0], [1, 0], [2, 0], [1, 1]]; 3 | legends = ["←", "↓", "→", "↑"]; 4 | 5 | for (i = [0:3]) { 6 | translate_u(positions[i].x, positions[i].y) key_profile(profile, rows[i]) legend(legends[i]) cherry() key(true); 7 | } 8 | } 9 | 10 | module f_cluster(profile, row=5) { 11 | legends = ["F1", "F2", "F3", "F4"]; 12 | for (i =[0:len(legends)-1]) { 13 | translate_u(i) key_profile(profile, row) cherry() legend(legends[i]) key(true); 14 | } 15 | } 16 | 17 | module wasd(profile, rows = [2,2,2,1]) { 18 | positions = [[0, 0], [1, 0], [2, 0], [1, 1]]; 19 | legends = ["A", "S", "D", "W"]; 20 | 21 | for (i = [0:3]) { 22 | translate_u(positions[i].x, positions[i].y) key_profile(profile, rows[i]) legend(legends[i]) cherry() key(true); 23 | } 24 | } 25 | 26 | module row_profile(profile, unsculpted = false) { 27 | rows = [5, 1, 2, 3, 4]; 28 | for(row = [0:len(rows)-1]) { 29 | translate_u(0, -row) key_profile(profile, unsculpted ? 3 : rows[row]) children(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/key_layouts.scad: -------------------------------------------------------------------------------- 1 | include 2 | 3 | include 4 | include 5 | 6 | include 7 | include 8 | 9 | include 10 | 11 | include 12 | 13 | include 14 | include 15 | include 16 | 17 | include 18 | include 19 | 20 | include 21 | -------------------------------------------------------------------------------- /src/key_profiles.scad: -------------------------------------------------------------------------------- 1 | // key profile definitions 2 | 3 | // unlike the other files with their own dedicated folders, this one doesn't 4 | // need a selector. I wrote one anyways for customizer support though 5 | include 6 | include 7 | include 8 | include 9 | include 10 | include 11 | include 12 | include 13 | include 14 | include 15 | include 16 | include 17 | include 18 | include 19 | 20 | // man, wouldn't it be so cool if functions were first order 21 | module key_profile(key_profile_type, row, column=0) { 22 | if (key_profile_type == "dcs") { 23 | dcs_row(row, column) children(); 24 | } else if (key_profile_type == "oem") { 25 | oem_row(row, column) children(); 26 | } else if (key_profile_type == "dsa") { 27 | dsa_row(row, column) children(); 28 | } else if (key_profile_type == "dss") { 29 | dss_row(row, column) children(); 30 | } else if (key_profile_type == "sa") { 31 | sa_row(row, column) children(); 32 | } else if (key_profile_type == "asa") { 33 | asa_row(row, column) children(); 34 | } else if (key_profile_type == "g20") { 35 | g20_row(row, column) children(); 36 | } else if (key_profile_type == "hipro") { 37 | hipro_row(row, column) children(); 38 | } else if (key_profile_type == "grid") { 39 | grid_row(row, column) children(); 40 | } else if (key_profile_type == "typewriter") { 41 | typewriter_row(row, column) children(); 42 | } else if (key_profile_type == "hex") { // reddit.com/r/MechanicalKeyboards/comments/kza7ji 43 | hex_row(row, column) children(); 44 | } else if (key_profile_type == "hexagon") { 45 | hexagonal_row(row, column) children(); 46 | } else if (key_profile_type == "octagon") { 47 | octagonal_row(row, column) children(); 48 | } else if (key_profile_type == "cherry") { 49 | cherry_row(row, column) children(); 50 | } else if (key_profile_type == "mt3") { 51 | mt3_row(row, column) children(); 52 | } else if (key_profile_type == "disable") { 53 | children(); 54 | } else { 55 | echo("Warning: unsupported key_profile_type"); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/key_profiles/asa.scad: -------------------------------------------------------------------------------- 1 | use <../functions.scad> 2 | include <../settings.scad> 3 | 4 | module asa_row(row=3, column = 0) { 5 | $key_shape_type = "sculpted_square"; 6 | $bottom_key_height = 18.15; 7 | $bottom_key_width = 18.10; // Default (R3) 8 | $total_depth = 10.75; // Default (R3) 9 | $top_tilt = 1.5; // Default (R3) 10 | $width_difference = 6.20; 11 | $height_difference = 6.55; 12 | $dish_type = "spherical"; 13 | $dish_depth = 1.3; 14 | $dish_skew_x = 0; 15 | $dish_skew_y = 0; 16 | $top_skew = 1.75; 17 | $stem_inset = 1.2; 18 | $height_slices = 10; 19 | 20 | $corner_radius = 1; 21 | $more_side_sculpting_factor = 0.4; 22 | 23 | $side_sculpting = function(progress) (1 - progress) * 4.5; 24 | $corner_sculpting = function(progress) pow(progress, 2); 25 | 26 | // this is _incredibly_ intensive 27 | //$rounded_key = true; 28 | 29 | if (row == 1){ 30 | $total_depth = 10.5; 31 | $top_tilt = 9.33; 32 | children(); 33 | } else if (row == 2) { 34 | $total_depth = 9.95; 35 | $top_tilt = 4; 36 | children(); 37 | } else if (row == 4){ 38 | $total_depth = 12.55; 39 | $top_tilt = 0.43; 40 | children(); 41 | }else{ 42 | children(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/key_profiles/cherry.scad: -------------------------------------------------------------------------------- 1 | use <../functions.scad> 2 | include <../settings.scad> 3 | 4 | // based off GMK keycap set 5 | 6 | module cherry_row(row=3, column=0) { 7 | $bottom_key_width = 18.16; 8 | $bottom_key_height = 18.16; 9 | $width_difference = $bottom_key_width - 11.85; 10 | $height_difference = $bottom_key_height - 14.64; 11 | $dish_type = "cylindrical"; 12 | $dish_depth = 0.65; 13 | $dish_skew_x = 0; 14 | $dish_skew_y = 0; 15 | $top_skew = 2; 16 | 17 | $top_tilt_y = side_tilt(column); 18 | extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; 19 | 20 | // NOTE: cherry keycaps have this stem inset, but I'm reticent to turn it on 21 | // since it'll be surprising to folks. the height has been adjusted accordingly 22 | // $stem_inset = 0.6; 23 | extra_stem_inset_height = max(0.6 - $stem_inset, 0); 24 | 25 | // <= is a hack so you can do these in a for loop. function row = 0 26 | if (row <= 1) { 27 | $total_depth = 9.8 - extra_stem_inset_height + extra_height; 28 | $top_tilt = 0; 29 | 30 | children(); 31 | } else if (row == 2) { 32 | $total_depth = 7.45 - extra_stem_inset_height + extra_height; 33 | $top_tilt = 2.5; 34 | 35 | children(); 36 | } else if (row == 3) { 37 | $total_depth = 6.55 - extra_stem_inset_height + extra_height; 38 | $top_tilt = 5; 39 | children(); 40 | } else if (row == 3) { 41 | $total_depth = 6.7 + 0.65 - extra_stem_inset_height + extra_height; 42 | $top_tilt = 11.5; 43 | children(); 44 | } else if (row >= 4) { 45 | $total_depth = 6.7 + 0.65 - extra_stem_inset_height + extra_height; 46 | $top_tilt = 11.5; 47 | children(); 48 | } else { 49 | children(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/key_profiles/dcs.scad: -------------------------------------------------------------------------------- 1 | use <../functions.scad> 2 | include <../settings.scad> 3 | 4 | module dcs_row(row=3, column=0) { 5 | $bottom_key_width = 18.16; 6 | $bottom_key_height = 18.16; 7 | $width_difference = 6; 8 | $height_difference = 4; 9 | $dish_type = "cylindrical"; 10 | $dish_depth = 0.5; 11 | $dish_skew_x = 0; 12 | $dish_skew_y = 0; 13 | $top_skew = 1.75; 14 | 15 | $top_tilt_y = side_tilt(column); 16 | extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; 17 | 18 | // this dish depth should match the depth of the uberdishing in fully sculpted mode 19 | // but it doesn't, and it's very slight for any reasonable double sculpting 20 | /* $dish_depth = $double_sculpt_radius - sin(acos(top_total_key_width()/2 /$double_sculpt_radius)) * $double_sculpt_radius; */ 21 | 22 | /* echo("DISH DEPTH", $dish_depth, "column", column); */ 23 | 24 | // 5/0 is a hack so you can do these in a for loop 25 | if (row == 5 || row == 0) { 26 | $total_depth = 11.5 + extra_height; 27 | $top_tilt = -6; 28 | 29 | children(); 30 | } else if (row == 1) { 31 | $total_depth = 8.5 + extra_height; 32 | $top_tilt = -1; 33 | 34 | children(); 35 | } else if (row == 2) { 36 | $total_depth = 7.5 + extra_height; 37 | $top_tilt = 3; 38 | children(); 39 | } else if (row == 3) { 40 | $total_depth = 6 + extra_height; 41 | $top_tilt = 7; 42 | children(); 43 | } else if (row == 4) { 44 | $total_depth = 6 + extra_height; 45 | $top_tilt = 16; 46 | children(); 47 | } else { 48 | children(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/key_profiles/dsa.scad: -------------------------------------------------------------------------------- 1 | use <../functions.scad> 2 | include <../settings.scad> 3 | 4 | module dsa_row(row=3, column = 0) { 5 | $key_shape_type = "sculpted_square"; 6 | $bottom_key_width = 18.24; // 18.4; 7 | $bottom_key_height = 18.24; // 18.4; 8 | $width_difference = 6; // 5.7; 9 | $height_difference = 6; // 5.7; 10 | $top_tilt = row == 5 ? -21 : (row-3) * 7; 11 | $top_skew = 0; 12 | $dish_type = "spherical"; 13 | $dish_depth = 1.2; 14 | $dish_skew_x = 0; 15 | $dish_skew_y = 0; 16 | $height_slices = 10; 17 | 18 | $side_sculpting = function(progress) (1 - progress) * 4.5; 19 | $corner_sculpting = function(progress) pow(progress, 2); 20 | 21 | $corner_radius = 1; 22 | $more_side_sculpting_factor = 0.4; 23 | 24 | $top_tilt_y = side_tilt(column); 25 | extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; 26 | 27 | depth_raisers = [0, 3.5, 1, 0, 1, 3]; 28 | if (row < 1 || row > 4) { 29 | $total_depth = 8.1 + depth_raisers[row] + extra_height; 30 | children(); 31 | } else if (row == 1) { 32 | $total_depth = 8.1 + depth_raisers[row] + extra_height; 33 | children(); 34 | } else if (row == 2) { 35 | $total_depth = 8.1 + depth_raisers[row] + extra_height; 36 | children(); 37 | } else if (row == 3) { 38 | $total_depth = 8.1 + depth_raisers[row] + extra_height; 39 | children(); 40 | } else if (row == 4) { 41 | $total_depth = 8.1 + depth_raisers[row] + extra_height; 42 | children(); 43 | } else { 44 | children(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/key_profiles/dss.scad: -------------------------------------------------------------------------------- 1 | use <../functions.scad> 2 | include <../settings.scad> 3 | 4 | module dss_row(n=3, column=0) { 5 | $key_shape_type = "sculpted_square"; 6 | $bottom_key_width = 18.24; 7 | $bottom_key_height = 18.24; 8 | $width_difference = 6; 9 | $height_difference = 6; 10 | $dish_type = "spherical"; 11 | $dish_depth = 1.2; 12 | $dish_skew_x = 0; 13 | $dish_skew_y = 0; 14 | $top_skew = 0; 15 | $height_slices = 10; 16 | // might wanna change this if you don't minkowski 17 | // do you even minkowski bro 18 | $corner_radius = 1; 19 | $more_side_sculpting_factor = 0.4; 20 | 21 | $side_sculpting = function(progress) (1 - progress) * 4.5; 22 | $corner_sculpting = function(progress) pow(progress, 2); 23 | 24 | // this is _incredibly_ intensive 25 | /* $rounded_key = true; */ 26 | 27 | $top_tilt_y = side_tilt(column); 28 | extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; 29 | 30 | // 5th row is usually unsculpted or the same as the row below it 31 | // making a super-sculpted top row (or bottom row!) would be real easy 32 | // bottom row would just be 13 tilt and 14.89 total depth 33 | // top row would be something new entirely - 18 tilt maybe? 34 | if (n <= 1){ 35 | $total_depth = 10.5 + extra_height; 36 | $top_tilt = -1; 37 | children(); 38 | } else if (n == 2) { 39 | $total_depth = 8.6 + extra_height; 40 | $top_tilt = 3; 41 | children(); 42 | } else if (n == 3) { 43 | $total_depth = 7.9 + extra_height; 44 | $top_tilt = 8; 45 | children(); 46 | } else if (n == 4){ 47 | $total_depth = 9.1 + extra_height; 48 | $top_tilt = 16; 49 | children(); 50 | } else { 51 | $total_depth = 7.9 + extra_height; 52 | $top_tilt = 8; 53 | children(); 54 | } 55 | } -------------------------------------------------------------------------------- /src/key_profiles/g20.scad: -------------------------------------------------------------------------------- 1 | use <../functions.scad> 2 | include <../settings.scad> 3 | 4 | module g20_row(row=3, column = 0) { 5 | $bottom_key_width = 18.16; 6 | $bottom_key_height = 18.16; 7 | $width_difference = 2; 8 | $height_difference = 2; 9 | $top_tilt = 2.5; 10 | $top_skew = 0.75; 11 | $dish_type = "disable"; 12 | // something weird is going on with this and legends - can't put it below 1.2 or they won't show 13 | $dish_depth = 1.2; 14 | $dish_skew_x = 0; 15 | $dish_skew_y = 0; 16 | $minkowski_radius = 1.75; 17 | $key_bump_depth = 0.6; 18 | $key_bump_edge = 2; 19 | //also, 20 | $rounded_key = true; 21 | 22 | $top_tilt_y = side_tilt(column); 23 | extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; 24 | 25 | $total_depth = 6 + abs((row-3) * 0.5) + extra_height; 26 | 27 | if (row == 5 || row == 0) { 28 | 29 | $top_tilt = -18.55; 30 | children(); 31 | } else if (row == 1) { 32 | $top_tilt = (row-3) * 7 + 2.5; 33 | children(); 34 | } else if (row == 2) { 35 | $top_tilt = (row-3) * 7 + 2.5; 36 | children(); 37 | } else if (row == 3) { 38 | $top_tilt = (row-3) * 7 + 2.5; 39 | children(); 40 | } else if (row == 4) { 41 | $top_tilt = (row-3) * 7 + 2.5; 42 | children(); 43 | } else { 44 | children(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/key_profiles/grid.scad: -------------------------------------------------------------------------------- 1 | use <../functions.scad> 2 | include <../settings.scad> 3 | 4 | module grid_row(row=3, column = 0) { 5 | $bottom_key_width = 18.16; 6 | $bottom_key_height = 18.16; 7 | $width_difference = 1; 8 | $height_difference = 1; 9 | $top_tilt = 0; 10 | $top_skew = 0; 11 | $dish_type = "old spherical"; 12 | // something weird is going on with this and legends - can't put it below 1.2 or they won't show 13 | $dish_depth = 1; 14 | $dish_skew_x = 0; 15 | $dish_skew_y = 0; 16 | 17 | $hull_shape_type = "linear extrude"; 18 | 19 | 20 | $dish_overdraw_width = -6.5; 21 | $dish_overdraw_height = -6.5; 22 | 23 | $minkowski_radius = 0.5; 24 | //also, 25 | /* $rounded_key = true; */ 26 | 27 | $top_tilt_y = side_tilt(column); 28 | extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; 29 | 30 | $total_depth = 7 + abs((row-3) * 0.5) + extra_height; 31 | 32 | if (row == 5 || row == 0) { 33 | /* $top_tilt = -18.55; */ 34 | children(); 35 | } else if (row == 1) { 36 | /* $top_tilt = (row-3) * 7 + 2.5; */ 37 | children(); 38 | } else if (row == 2) { 39 | /* $top_tilt = (row-3) * 7 + 2.5; */ 40 | children(); 41 | } else if (row == 3) { 42 | /* $top_tilt = (row-3) * 7 + 2.5; */ 43 | children(); 44 | } else if (row == 4) { 45 | /* $top_tilt = (row-3) * 7 + 2.5; */ 46 | children(); 47 | } else { 48 | children(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/key_profiles/hex.scad: -------------------------------------------------------------------------------- 1 | include <../constants.scad> 2 | // Regular polygon shapes CIRCUMSCRIBE the sphere of diameter $bottom_key_width 3 | // This is to make tiling them easier, like in the case of hexagonal keycaps etc 4 | 5 | // this function doesn't set the key shape, so you can't use it directly without some fiddling 6 | module hex_row(n=3, column=0) { 7 | $bottom_key_width = $unit - 0.5; 8 | $bottom_key_height = $unit - 0.5; 9 | 10 | $width_difference = 0; 11 | $height_difference = 0; 12 | 13 | $dish_type = "spherical"; 14 | $key_shape_type = "hexagon"; 15 | 16 | $stem_inset = -2.5; 17 | $stem_throw = 3; 18 | 19 | // $dish_depth = 1; 20 | 21 | $top_skew = 0; 22 | $height_slices = 1; 23 | $stem_support_type = "disable"; 24 | 25 | $dish_overdraw_width = -8.25; 26 | $dish_overdraw_height = -8.25; 27 | // $corner_radius = 1; 28 | 29 | // this is _incredibly_ intensive 30 | /* $rounded_key = true; */ 31 | 32 | $top_tilt_y = side_tilt(column); 33 | extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; 34 | 35 | base_depth = 4; 36 | if (n <= 1){ 37 | $total_depth = base_depth + 2.5 + extra_height; 38 | $top_tilt = -13; 39 | 40 | children(); 41 | } else if (n == 2) { 42 | $total_depth = base_depth + 0.5 + extra_height; 43 | $top_tilt = -7; 44 | 45 | children(); 46 | } else if (n == 3) { 47 | $total_depth = base_depth + extra_height; 48 | $top_tilt = 0; 49 | 50 | children(); 51 | } else if (n == 4){ 52 | $total_depth = base_depth + 0.5 + extra_height; 53 | $top_tilt = 7; 54 | 55 | children(); 56 | } else { 57 | $total_depth = base_depth + extra_height; 58 | $top_tilt = 0; 59 | 60 | children(); 61 | } 62 | } -------------------------------------------------------------------------------- /src/key_profiles/hipro.scad: -------------------------------------------------------------------------------- 1 | use <../functions.scad> 2 | include <../settings.scad> 3 | 4 | module hipro_row(row=3, column=0) { 5 | $key_shape_type = "sculpted_square"; 6 | 7 | $bottom_key_width = 18.35; 8 | $bottom_key_height = 18.17; 9 | 10 | $width_difference = ($bottom_key_width - 12.3); 11 | $height_difference = ($bottom_key_height - 12.65); 12 | $dish_type = "squared scoop"; 13 | $dish_depth = 0.75; 14 | $dish_skew_x = 0; 15 | $dish_skew_y = 0; 16 | $top_skew = 0; 17 | $height_slices = 10; 18 | 19 | $corner_radius = 1; 20 | $more_side_sculpting_factor = 0.4; 21 | 22 | $side_sculpting = function(progress) (1 - progress) * 4.5; 23 | $corner_sculpting = function(progress) pow(progress, 2); 24 | 25 | $top_tilt_y = side_tilt(column); 26 | extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; 27 | 28 | if (row <= 1){ 29 | $total_depth = 13.7 + extra_height; 30 | // TODO I didn't change these yet 31 | $top_tilt = -13; 32 | children(); 33 | } else if (row == 2) { 34 | $total_depth = 11.1 + extra_height; 35 | $top_tilt = -7; 36 | children(); 37 | } else if (row == 3) { 38 | $total_depth = 11.1 + extra_height; 39 | $top_tilt = 7; 40 | children(); 41 | } else if (row == 4 || row == 5){ 42 | $total_depth = 12.25 + extra_height; 43 | $top_tilt = 13; 44 | children(); 45 | } else { 46 | children(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/key_profiles/mt3.scad: -------------------------------------------------------------------------------- 1 | use <../functions.scad> 2 | include <../settings.scad> 3 | 4 | // This is an imperfect attempt to clone the MT3 profile 5 | module mt3_row(row=3, column=0, deep_dish=false) { 6 | $key_shape_type = "sculpted_square"; 7 | 8 | $bottom_key_width = 18.35; 9 | $bottom_key_height = 18.6; 10 | 11 | $width_difference = ($bottom_key_width - 13.0); 12 | $height_difference = ($bottom_key_height - 13.0); 13 | $dish_type = "squared spherical"; 14 | $dish_depth = deep_dish ? 1.6 : 1.2; 15 | $dish_skew_x = 0; 16 | $dish_skew_y = 0; 17 | $top_skew = 0; 18 | $height_slices = 10; 19 | 20 | $corner_radius = 0.0125; 21 | $more_side_sculpting_factor = 0.75; 22 | 23 | $side_sculpting = function(progress) (1 - progress) * 4.5; 24 | $corner_sculpting = function(progress) pow(progress, 2) * 2; 25 | 26 | 27 | $top_tilt_y = side_tilt(column); 28 | extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; 29 | 30 | if (row == 0){ 31 | // TODO I didn't change these yet 32 | $total_depth = 14.7 + extra_height; 33 | $top_tilt = -12.5; 34 | children(); 35 | } else if (row == 1) { 36 | $total_depth = 13.1 + extra_height; 37 | $top_tilt = -6; 38 | children(); 39 | } else if (row == 2) { 40 | $total_depth = 10.7 + extra_height; 41 | $top_tilt = -6; 42 | children(); 43 | } else if (row == 3) { 44 | $total_depth = 10.7 + extra_height; 45 | $top_tilt = 6; 46 | children(); 47 | } else if (row == 4){ 48 | $total_depth = 11.6 + extra_height; 49 | $top_tilt = 12; 50 | children(); 51 | } else if (row >= 5) { 52 | $total_depth = 11.6 + extra_height; 53 | $top_tilt = 0; 54 | children(); 55 | } else { 56 | children(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/key_profiles/oem.scad: -------------------------------------------------------------------------------- 1 | use <../functions.scad> 2 | include <../settings.scad> 3 | 4 | module oem_row(row=3, column = 0) { 5 | $bottom_key_width = 18.05; 6 | $bottom_key_height = 18.05; 7 | $width_difference = 5.8; 8 | $height_difference = 4; 9 | $dish_type = "cylindrical"; 10 | $dish_depth = 1; 11 | $dish_skew_x = 0; 12 | $dish_skew_y = 0; 13 | $top_skew = 1.75; 14 | $stem_inset = 1.2; 15 | 16 | $top_tilt_y = side_tilt(column); 17 | extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; 18 | 19 | if (row == 5 || row == 0) { 20 | $total_depth = 11.2 + extra_height; 21 | $top_tilt = -3; 22 | children(); 23 | } else if (row == 1) { 24 | $total_depth = 9.45 + extra_height; 25 | $top_tilt = 1; 26 | children(); 27 | } else if (row == 2) { 28 | $total_depth = 9 + extra_height; 29 | $top_tilt = 6; 30 | children(); 31 | } else if (row == 3) { 32 | $total_depth = 9.25 + extra_height; 33 | $top_tilt = 9; 34 | children(); 35 | } else if (row == 4) { 36 | $total_depth = 9.25 + extra_height; 37 | $top_tilt = 10; 38 | children(); 39 | } else { 40 | children(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/key_profiles/regular_polygon.scad: -------------------------------------------------------------------------------- 1 | use <../functions.scad> 2 | include <../settings.scad> 3 | include <../constants.scad> 4 | // Regular polygon shapes CIRCUMSCRIBE the sphere of diameter $bottom_key_width 5 | // This is to make tiling them easier, like in the case of hexagonal keycaps etc 6 | 7 | // this function doesn't set the key shape, so you can't use it directly without some fiddling 8 | module regular_polygon_row(n=3, column=0) { 9 | $bottom_key_width = $unit - 0.5; 10 | $bottom_key_height = $unit - 0.5; 11 | $width_difference = 0; 12 | $height_difference = 0; 13 | $dish_type = "spherical"; 14 | $dish_depth = 0.85; 15 | $dish_skew_x = 0; 16 | $dish_skew_y = 0; 17 | $top_skew = 0; 18 | $height_slices = 1; 19 | $corner_radius = 1; 20 | 21 | // this is _incredibly_ intensive 22 | /* $rounded_key = true; */ 23 | 24 | $top_tilt_y = side_tilt(column); 25 | extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; 26 | 27 | base_depth = 7.5; 28 | if (n <= 1){ 29 | $total_depth = base_depth + 2.5 + extra_height; 30 | $top_tilt = -13; 31 | 32 | children(); 33 | } else if (n == 2) { 34 | $total_depth = base_depth + 0.5 + extra_height; 35 | $top_tilt = -7; 36 | 37 | children(); 38 | } else if (n == 3) { 39 | $total_depth = base_depth + extra_height; 40 | $top_tilt = 0; 41 | 42 | children(); 43 | } else if (n == 4){ 44 | $total_depth = base_depth + 0.5 + extra_height; 45 | $top_tilt = 7; 46 | 47 | children(); 48 | } else { 49 | $total_depth = base_depth + extra_height; 50 | $top_tilt = 0; 51 | 52 | children(); 53 | } 54 | } 55 | 56 | module hexagonal_row(n=3, column=0) { 57 | $key_shape_type = "hexagon"; 58 | regular_polygon_row(n,column) { 59 | children(); 60 | } 61 | } 62 | 63 | module octagonal_row(n=3, column=0) { 64 | $key_shape_type = "octagon"; 65 | regular_polygon_row(n, column) { 66 | children(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/key_profiles/sa.scad: -------------------------------------------------------------------------------- 1 | use <../functions.scad> 2 | include <../settings.scad> 3 | 4 | module sa_row(n=3, column=0) { 5 | $key_shape_type = "sculpted_square"; 6 | $bottom_key_width = 18.4; 7 | $bottom_key_height = 18.4; 8 | $width_difference = 5.7; 9 | $height_difference = 5.7; 10 | $dish_type = "spherical"; 11 | $dish_depth = 0.85; 12 | $dish_skew_x = 0; 13 | $dish_skew_y = 0; 14 | $top_skew = 0; 15 | $height_slices = 10; 16 | 17 | $corner_radius = 1; 18 | $more_side_sculpting_factor = 0.4; 19 | 20 | $side_sculpting = function(progress) (1 - progress) * 4.5; 21 | $corner_sculpting = function(progress) pow(progress, 2); 22 | 23 | // this is _incredibly_ intensive 24 | /* $rounded_key = true; */ 25 | 26 | $top_tilt_y = side_tilt(column); 27 | extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; 28 | 29 | // 5th row is usually unsculpted or the same as the row below it 30 | // making a super-sculpted top row (or bottom row!) would be real easy 31 | // bottom row would just be 13 tilt and 14.89 total depth 32 | // top row would be something new entirely - 18 tilt maybe? 33 | if (n <= 1){ 34 | $total_depth = 14.89 + extra_height; 35 | $top_tilt = -13; 36 | children(); 37 | } else if (n == 2) { 38 | $total_depth = 12.925 + extra_height; 39 | $top_tilt = -7; 40 | children(); 41 | } else if (n == 3) { 42 | $total_depth = 12.5 + extra_height; 43 | $top_tilt = 0; 44 | children(); 45 | } else if (n == 4){ 46 | $total_depth = 12.925 + extra_height; 47 | $top_tilt = 7; 48 | children(); 49 | } else { 50 | $total_depth = 12.5 + extra_height; 51 | $top_tilt = 0; 52 | children(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/key_profiles/typewriter.scad: -------------------------------------------------------------------------------- 1 | use <../functions.scad> 2 | include <../settings.scad> 3 | include <../constants.scad> 4 | // Regular polygon shapes CIRCUMSCRIBE the sphere of diameter $bottom_key_width 5 | // This is to make tiling them easier, like in the case of hexagonal keycaps etc 6 | 7 | // this function doesn't set the key shape, so you can't use it directly without some fiddling 8 | module typewriter_row(n=3, column=0) { 9 | $bottom_key_width = $unit - 0.5; 10 | $bottom_key_height = $unit - 0.5; 11 | $width_difference = 0; 12 | $height_difference = 0; 13 | $dish_type = "spherical"; 14 | $key_shape_type = "circular"; 15 | $inverted_dish = true; 16 | $stem_inset = -4.5; 17 | $stem_throw = 5; 18 | $dish_depth = 4; 19 | $dish_skew_x = 0; 20 | $dish_skew_y = 0; 21 | $top_skew = 0; 22 | $height_slices = 1; 23 | $stem_support_type = "disable"; 24 | // $corner_radius = 1; 25 | 26 | // this is _incredibly_ intensive 27 | /* $rounded_key = true; */ 28 | 29 | $top_tilt_y = side_tilt(column); 30 | extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0; 31 | 32 | base_depth = 3.5; 33 | if (n <= 1){ 34 | $total_depth = base_depth + 2.5 + extra_height; 35 | $top_tilt = -13; 36 | 37 | children(); 38 | } else if (n == 2) { 39 | $total_depth = base_depth + 0.5 + extra_height; 40 | $top_tilt = -7; 41 | 42 | children(); 43 | } else if (n == 3) { 44 | $total_depth = base_depth + extra_height; 45 | $top_tilt = 0; 46 | 47 | children(); 48 | } else if (n == 4){ 49 | $total_depth = base_depth + 0.5 + extra_height; 50 | $top_tilt = 7; 51 | 52 | children(); 53 | } else { 54 | $total_depth = base_depth + extra_height; 55 | $top_tilt = 0; 56 | 57 | children(); 58 | } 59 | } -------------------------------------------------------------------------------- /src/key_sizes.scad: -------------------------------------------------------------------------------- 1 | // key width functions 2 | 3 | module u(u=1) { 4 | $key_length = u; 5 | children(); 6 | } 7 | 8 | module 1u() { 9 | u(1) children(); 10 | } 11 | 12 | module 1_25u() { 13 | u(1.25) children(); 14 | } 15 | 16 | module 1_5u() { 17 | u(1.5) children(); 18 | } 19 | 20 | module 1_75u(){ 21 | u(1.75) children(); 22 | } 23 | 24 | module 2u() { 25 | u(2) children(); 26 | } 27 | 28 | module 2_25u() { 29 | u(2.25) children(); 30 | } 31 | 32 | module 2_50u() { 33 | u(2.5) children(); 34 | } 35 | 36 | module 2_75u() { 37 | u(2.75) children(); 38 | } 39 | 40 | module 6_25u() { 41 | u(6.25) children(); 42 | } 43 | 44 | // key height functions 45 | 46 | module uh(u=1) { 47 | $key_height = u; 48 | children(); 49 | } 50 | 51 | module 1uh() { 52 | uh(1) children(); 53 | } 54 | 55 | module 2uh() { 56 | uh(2) children(); 57 | } 58 | 59 | module 1_25uh() { 60 | uh(1.25) children(); 61 | } 62 | 63 | module 1_5uh() { 64 | uh(1.5) children(); 65 | } 66 | 67 | module 2_25uh() { 68 | uh(2.25) children(); 69 | } 70 | 71 | module 2_75uh() { 72 | uh(2.75) children(); 73 | } 74 | 75 | module 6_25uh() { 76 | uh(6.25) children(); 77 | } 78 | -------------------------------------------------------------------------------- /src/key_transformations.scad: -------------------------------------------------------------------------------- 1 | // kind of a catch-all at this point for any directive that doesn't fit in the other files 2 | 3 | include 4 | 5 | module translate_u(x=0, y=0, z=0){ 6 | translate([x * $unit, y*$unit, z*$unit]) children(); 7 | } 8 | 9 | module no_stem_support() { 10 | $stem_support_type = "disable"; 11 | children(); 12 | } 13 | 14 | module brimmed_stem_support(height = 0.4) { 15 | $stem_support_type = "brim"; 16 | $stem_support_height = height; 17 | children(); 18 | } 19 | 20 | module tined_stem_support(height = 0.4) { 21 | $stem_support_type = "tines"; 22 | $stem_support_height = height; 23 | children(); 24 | } 25 | 26 | module unsupported_stem() { 27 | $stem_support_type = "disable"; 28 | children(); 29 | } 30 | 31 | module rounded() { 32 | $rounded_key = true; 33 | children(); 34 | } 35 | 36 | module inverted() { 37 | $inverted_dish = true; 38 | children(); 39 | } 40 | 41 | module rotated() { 42 | $stem_rotation = 90; 43 | children(); 44 | } 45 | 46 | module vertically_stabilized(mm=12, vertical=true, type=undef) { 47 | stabilized(mm,vertical,type) { 48 | children(); 49 | } 50 | } 51 | 52 | module stabilized(mm=12, vertical = false, type=undef) { 53 | if (vertical) { 54 | $stabilizer_type = (type ? type : ($stabilizer_type ? $stabilizer_type : "costar_stabilizer")); 55 | $stabilizers = [ 56 | [0, mm], 57 | [0, -mm] 58 | ]; 59 | 60 | children(); 61 | } else { 62 | $stabilizer_type = (type ? type : ($stabilizer_type ? $stabilizer_type : "costar_stabilizer")); 63 | 64 | 65 | $stabilizers = [ 66 | [mm, 0], 67 | [-mm, 0] 68 | ]; 69 | 70 | children(); 71 | } 72 | } 73 | 74 | module dishless() { 75 | $dish_type = "disable"; 76 | children(); 77 | } 78 | 79 | module inset(val=1) { 80 | $stem_inset = val; 81 | children(); 82 | } 83 | 84 | module filled() { 85 | $stem_type = "filled"; 86 | children(); 87 | } 88 | 89 | module blank() { 90 | $stem_type = "disable"; 91 | children(); 92 | } 93 | 94 | module cherry(slop = undef) { 95 | $stem_slop = slop != undef ? slop : $stem_slop; 96 | $stem_type = "cherry"; 97 | children(); 98 | } 99 | 100 | module alps(slop = undef) { 101 | $stem_slop = slop != undef ? slop : $stem_slop; 102 | $stem_type = "alps"; 103 | children(); 104 | } 105 | 106 | module rounded_cherry(slop = undef) { 107 | $stem_slop = slop != undef ? slop : $stem_slop; 108 | $stem_type = "rounded_cherry"; 109 | children(); 110 | } 111 | 112 | module box_cherry(slop = undef) { 113 | $stem_slop = slop != undef ? slop : $stem_slop; 114 | $stem_type = "box_cherry"; 115 | children(); 116 | } 117 | 118 | module choc(slop = 0.05) { 119 | 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"); 120 | $stem_throw = 3; 121 | $stem_slop = slop; 122 | 123 | $bottom_key_width = 18; 124 | $bottom_key_height = 17; 125 | 126 | $stem_type = "choc"; 127 | children(); 128 | } 129 | 130 | // a hacky way to make "low profile" keycaps 131 | module low_profile() { 132 | $width_difference = $width_difference / 1.5; 133 | $height_difference = $height_difference / 1.5; 134 | // helps tilted keycaps not have holes if worst comes to worst 135 | $inner_shape_type = "dished"; 136 | 137 | $top_tilt = $top_tilt / 1.25; 138 | 139 | $total_depth = ($total_depth / 2) < 7 ? 7 : $total_depth / 2; 140 | 141 | // just to make sure 142 | $stem_throw = 3; 143 | children(); 144 | } 145 | 146 | module flared_support() { 147 | $support_type = "flared"; 148 | children(); 149 | } 150 | 151 | module bar_support() { 152 | $support_type = "bars"; 153 | children(); 154 | } 155 | 156 | module flat_support() { 157 | $support_type = "flat"; 158 | children(); 159 | } 160 | 161 | module legend(text, position=[0,0], size=undef, font=undef) { 162 | font_size = size == undef ? $font_size : size; 163 | font_face = font == undef ? $font : font; 164 | $legends = [for(L=[$legends, [[text, position, font_size, font_face]]], a=L) a]; 165 | children(); 166 | } 167 | 168 | module front_legend(text, position=[0,0], size=undef, font=undef) { 169 | font_size = size == undef ? $font_size : size; 170 | font_face = font == undef ? $font : font; 171 | $front_legends = [for(L=[$front_legends, [[text, position, font_size, font_face]]], a=L) a]; 172 | children(); 173 | } 174 | 175 | module bump(depth=undef) { 176 | $key_bump = true; 177 | $key_bump_depth = depth == undef ? $key_bump_depth : depth; 178 | children(); 179 | } 180 | 181 | // kinda dirty, but it works 182 | // might not work great with fully sculpted profiles yet 183 | // NOTE: this needs to come after row declarations or it won't work 184 | module upside_down() { 185 | if ($stem_inner_slop != 0) { 186 | echo("it is recommended you set inner stem slop to 0 when you use upside_down()"); 187 | } 188 | 189 | $stem_support_type = "disable"; 190 | // $top_tilt*2 because top_placement rotates by top_tilt for us 191 | // first rotate 180 to get the keycaps to face the same direction 192 | rotate([0,0,180]) top_placement() rotate([180+$top_tilt*2,0,0]) { 193 | children(); 194 | } 195 | } 196 | 197 | module sideways() { 198 | $stem_support_type = "disable"; 199 | $key_shape_type = "flat_sided_square"; 200 | $dish_overdraw_width = abs(extra_keytop_length_for_flat_sides()); 201 | extra_y_rotation = atan2($width_difference/2,$total_depth); // TODO assumes centered top 202 | translate([0,0,cos(extra_y_rotation) * total_key_width()/2]) 203 | rotate([0,90 + extra_y_rotation ,0]) children(); 204 | } 205 | 206 | /* this is hard to explain. we want the angle of the back of the keycap. 207 | * first we draw a line at the back of the keycap perpendicular to the ground. 208 | * then we extend the line created by the slope of the keytop to that line 209 | * the angle of the latter line off the ground is $top_tilt, and 210 | * you can create a right triangle with the adjacent edge being $bottom_key_height/2 211 | * raised up $total_depth. this gets you x, the component of the extended 212 | * keytop slope line, and y, a component of the first perpendicular line. 213 | * by a very similar triangle you get r and s, where x is the hypotenuse of that 214 | * right triangle and the right angle is again against the first perpendicular line 215 | * s is the opposite line in the right triangle required to find q, the angle 216 | * of the back. if you subtract r from $total_depth plus y you can now use these 217 | * two values in atan to find the angle of interest. 218 | */ 219 | module backside() { 220 | $stem_support_type = "disable"; 221 | 222 | // $key_shape_type = "flat_sided_square"; 223 | 224 | a = $bottom_key_height; 225 | b = $total_depth; 226 | c = top_total_key_height(); 227 | 228 | x = (a / 2 - $top_skew) / cos(-$top_tilt) - c / 2; 229 | y = sin(-$top_tilt) * (x + c/2); 230 | r = sin(-$top_tilt) * x; 231 | s = cos(-$top_tilt) * x; 232 | 233 | q = atan2(s, (y + b - r)); 234 | 235 | translate([0,0,cos(q) * total_key_height()/2]) 236 | rotate([-90 - q, 0,0]) children(); 237 | } 238 | 239 | // this is just backside with a few signs switched 240 | module frontside() { 241 | $stem_support_type = "disable"; 242 | 243 | // $key_shape_type = "flat_sided_square"; 244 | 245 | a = $bottom_key_height; 246 | b = $total_depth; 247 | c = top_total_key_height(); 248 | 249 | x = (a / 2 + $top_skew) / cos($top_tilt) - c / 2; 250 | y = sin($top_tilt) * (x + c/2); 251 | r = sin($top_tilt) * x; 252 | s = cos($top_tilt) * x; 253 | 254 | q = atan2(s, (y + b - r)); 255 | 256 | translate([0,0,cos(q) * total_key_height()/2]) 257 | rotate([90 + q, 0,0]) children(); 258 | } 259 | 260 | // emulating the % modifier. 261 | // since we use custom colors, just using the % modifier doesn't work 262 | module debug() { 263 | $primary_color = [0.5,0.5,0.5,0.2]; 264 | $secondary_color = [0.5,0.5,0.5,0.2]; 265 | $tertiary_color = [0.5,0.5,0.5,0.2]; 266 | $quaternary_color = [0.5,0.5,0.5,0.2]; 267 | 268 | %children(); 269 | } 270 | 271 | // auto-place children in a grid. 272 | // For this to work all children have to be single keys, no for loops etc 273 | module auto_place() { 274 | num_children = $children; 275 | row_size = round(pow(num_children, 0.5)); 276 | 277 | for (child_index = [0:num_children-1]) { 278 | x = child_index % row_size; 279 | y = floor(child_index / row_size); 280 | translate_u(x,-y) children(child_index); 281 | } 282 | } 283 | 284 | // suggested settings for resin prints 285 | module resin() { 286 | $stem_slop = 0; 287 | $stem_inner_slop = 0; 288 | $stem_support_type = "disable"; 289 | children(); 290 | } 291 | -------------------------------------------------------------------------------- /src/key_types.scad: -------------------------------------------------------------------------------- 1 | include 2 | use 3 | use 4 | 5 | module spacebar() { 6 | $inverted_dish = $dish_type != "disable"; 7 | $dish_type = $dish_type != "disable" ? "sideways cylindrical" : "disable"; 8 | 6_25u() stabilized(mm=50) children(); 9 | } 10 | 11 | module lshift() { 12 | 2_25u() stabilized() children(); 13 | } 14 | 15 | module rshift() { 16 | 2_75u() stabilized() children(); 17 | } 18 | 19 | module backspace() { 20 | 2u() stabilized() children(); 21 | } 22 | 23 | module enter() { 24 | 2_25u() stabilized() children(); 25 | } 26 | 27 | module numpad_enter() { 28 | 2uh() stabilized(vertical=true) children(); 29 | } 30 | 31 | module numpad_plus() { 32 | numpad_enter() children(); 33 | } 34 | 35 | module numpad_0() { 36 | backspace() children(); 37 | } 38 | 39 | module stepped_caps_lock() { 40 | u(1.75) { 41 | $stem_positions = [[-5, 0]]; 42 | children(); 43 | } 44 | } 45 | 46 | module iso_enter() { 47 | $key_length = 1.5; 48 | $key_height = 2; 49 | 50 | $dish_offset_x = -(unit_length(1.5) - unit_length(1.25))/2; 51 | 52 | /* $top_tilt = 0; */ 53 | $stem_support_type = "disable"; 54 | $key_shape_type = "iso_enter"; 55 | $hull_shape_type = "skin"; 56 | $linear_extrude_height_adjustment = 19.05 * 0.5; 57 | // this equals (unit_length(1.5) - unit_length(1.25)) / 2 58 | /* $dish_overdraw_width = 2.38125; */ 59 | 60 | render() { 61 | stabilized(vertical=true) { 62 | children(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/layouts/60_percent/default.scad: -------------------------------------------------------------------------------- 1 | include <../layout.scad> 2 | 3 | 60_percent_default_layout = [ 4 | [1,1,1,1,1,1,1,1,1,1,1,1,1,2], 5 | [1.5,1,1,1,1,1,1,1,1,1,1,1,1,1.5], 6 | [1.75,1,1,1,1,1,1,1,1,1,1,1,2.25], 7 | [2.25,1,1,1,1,1,1,1,1,1,1,2.75], 8 | [1.25,1.25,1.25,6.25,1.25,1.25,1.25,1.25] 9 | ]; 10 | 11 | 60_percent_legends = [ 12 | ["`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "⌫"], 13 | ["tab", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", "\\"], 14 | ["caps", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "enter"], 15 | ["shift", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "shift"], 16 | ["ctl", "win", "alt", "", "mnu", "win", "alt", "ctl"], 17 | ]; 18 | 19 | module 60_percent_default(profile) { 20 | layout(60_percent_default_layout, profile, 60_percent_legends, row_sculpting_offset=1) children(); 21 | } 22 | -------------------------------------------------------------------------------- /src/layouts/dactyl_manuform/4x6.scad: -------------------------------------------------------------------------------- 1 | include <../layout.scad> 2 | 3 | dactyl_manuform_4x6_main = [ 4 | [1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1], 5 | [1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1], 6 | [1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1], 7 | [-1, -1, 1, 1, -1, -1, -1, -1, -1, 1, 1, -1, -1] 8 | ]; 9 | 10 | dactyl_manuform_4x6_thumbs_l = [ 11 | [1.25, 1.25], 12 | [-0.25, 1, 1], 13 | [-0.25, 1, 1] 14 | ]; 15 | 16 | dactyl_manuform_4x6_thumbs_r = [ 17 | [1.25, 1.25], 18 | [-0.25, 1, 1], 19 | [-0.25, 1, 1] 20 | ]; 21 | 22 | module dactyl_manuform_4x6(profile) { 23 | layout(dactyl_manuform_4x6_main, profile) children(); 24 | translate_u(3,-5) rotate([0,0,25])layout(dactyl_manuform_4x6_thumbs_l, profile, row_override=3) children(); 25 | translate_u(7.75,-3.95) rotate([0,0,-25])layout(dactyl_manuform_4x6_thumbs_r, profile, row_override=3) children(); 26 | } 27 | -------------------------------------------------------------------------------- /src/layouts/dactyl_manuform/4x6_legends.scad: -------------------------------------------------------------------------------- 1 | include <../layout.scad> 2 | 3 | dactyl_manuform_4x6_main = [ 4 | [1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1], 5 | [1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1], 6 | [1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1], 7 | [-1, -1, 1, 1, -1, -1, -1, -1, -1, 1, 1, -1, -1] 8 | ]; 9 | 10 | dactyl_manuform_4x6_thumbs_l = [ 11 | [1.25, 1.25], 12 | [-0.25, 1, 1], 13 | [-0.25, 1, 1] 14 | ]; 15 | 16 | dactyl_manuform_4x6_thumbs_r = [ 17 | [1.25, 1.25], 18 | [-0.25, 1, 1], 19 | [-0.25, 1, 1] 20 | ]; 21 | 22 | dactyl_manuform_4x6_main_legends = [ 23 | ["ESC", "Q", "W", "E", "R", "T", "", "Y", "U", "I", "O", "P", "{["], 24 | ["LS", "A", "S", "D", "F", "G", "", "H", "J", "K", "L", ";:", "'\""], 25 | ["TAB", "Z", "X", "C", "V", "B", "", "N", "M", ",<", ".>", "/?", "\\|"], 26 | ["", "", "CAPS", "T(1)", "", "", "", "", "", "T(2)", "]}", "", ""] 27 | ]; 28 | 29 | dactyl_manuform_4x6_main_front_legends = [ 30 | ["F1", "F2", "F3", "F4", "F5", "F6", "", "F7", "F8", "F9", "F10", "F11", "F12"], 31 | ["", "", "", "", "", "PGUP", "", "", "UP", "", "", "", ""], 32 | ["", "", "", "", "", "PGDN", "", "LFT", "DWN", "RHT", "", "", ""], 33 | ["", "", "", "T(0)", "", "", "", "", "", "T(2)", "", "", ""] 34 | ]; 35 | 36 | dactyl_manuform_4x6_thumbs_l_legends = [ 37 | ["~`", "LCTL"], 38 | ["", "RALT", "LCMD"], 39 | ["", "MEH", "T(2)"] 40 | ]; 41 | 42 | dactyl_manuform_4x6_thumbs_l_front_legends = [ 43 | ["", ""], 44 | ["", "PSC", "LCMD"], 45 | ["", "", "TEMP"] 46 | ]; 47 | 48 | dactyl_manuform_4x6_thumbs_r_legends = [ 49 | ["", "BKSP"], 50 | ["", "ENTR", "CP"], 51 | ["", "T(1)", "PST"] 52 | ]; 53 | 54 | dactyl_manuform_4x6_thumbs_r_front_legends = [ 55 | ["", ""], 56 | ["", "", ""], 57 | ["", "TEMP", ""] 58 | ]; 59 | 60 | module dactyl_manuform_4x6_legends(profile, row_sculpting_offset=1, column_override=undef) { 61 | layout(dactyl_manuform_4x6_main, profile, legends=dactyl_manuform_4x6_main_legends, front_legends=dactyl_manuform_4x6_main_front_legends, row_sculpting_offset=row_sculpting_offset, column_override=column_override, column_sculpt_profile="cresting_wave") children(); 62 | translate_u(3,-5) rotate([0,0,25]) layout(dactyl_manuform_4x6_thumbs_l, profile, legends=dactyl_manuform_4x6_thumbs_l_legends, front_legends=dactyl_manuform_4x6_thumbs_l_front_legends, row_sculpting_offset=row_sculpting_offset, column_override=column_override, column_sculpt_profile="cresting_wave") children(); 63 | translate_u(7.75,-3.95) rotate([0,0,-25]) layout(dactyl_manuform_4x6_thumbs_r, profile, legends=dactyl_manuform_4x6_thumbs_r_legends, front_legends=dactyl_manuform_4x6_thumbs_r_front_legends, row_sculpting_offset=row_sculpting_offset, column_override=column_override, column_sculpt_profile="cresting_wave") children(); 64 | } -------------------------------------------------------------------------------- /src/layouts/gherkin/default.scad: -------------------------------------------------------------------------------- 1 | include <../layout.scad> 2 | 3 | // negative numbers are used for spacing 4 | gherkin_default_layout = [ 5 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 6 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 7 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 8 | ]; 9 | 10 | gherkin_default_legends = [ 11 | ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"], 12 | ["a", "s", "d", "f", "g", "h", "j", "k", "l", ";"], 13 | ["z", "x", "c", "v", "b", "n", "m", ",", ".", "/"], 14 | ]; 15 | 16 | module gherkin_default(profile) { 17 | layout(gherkin_default_layout, profile, legends=gherkin_default_legends, row_sculpting_offset=1, row_override=3) children(); 18 | } 19 | -------------------------------------------------------------------------------- /src/layouts/gherkin/gherkin_bump.scad: -------------------------------------------------------------------------------- 1 | include <../layout.scad> 2 | 3 | // negative numbers are used for spacing 4 | gherkin_bump_mapping = [ 5 | [1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1], 6 | [1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1], 7 | [1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1], 8 | [-1, -1, -1, -1, 2, -1, -1, -1, -1], 9 | ]; 10 | 11 | gherkin_bump_legends = [ 12 | ["q", "w", "e", "r", "t", "", "y", "u", "i", "o", "p"], 13 | ["a", "s", "d", "f", "g", "", "h", "j", "k", "l", ";"], 14 | ["z", "x", "c", "v", "b", "", "n", "m", ",", ".", "/"], 15 | ["", "", "", "", "", "", "", "", ""], 16 | ]; 17 | 18 | module gherkin_bump_layout(profile, row_sculpting_offset=1, column_override=undef) { 19 | layout(gherkin_bump_mapping, profile, legends=gherkin_bump_legends, row_sculpting_offset=row_sculpting_offset, column_override=column_override, column_sculpt_profile="cresting_wave") { 20 | children(); 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /src/layouts/hhkb/default.scad: -------------------------------------------------------------------------------- 1 | include <../layout.scad> 2 | 3 | hhkb_layout = [ 4 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], 5 | [1.5,1,1,1,1,1,1,1,1,1,1,1,1,1.5], 6 | [1.75,1,1,1,1,1,1,1,1,1,1,1,2.25], 7 | [2.25,1,1,1,1,1,1,1,1,1,1,1.75,1], 8 | [-1.5,1,1.5,6,1.5,1] 9 | ]; 10 | 11 | hhkb_legends = [ 12 | ["Esc", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "\\", "`"], 13 | ["Tab", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", "Delete"], 14 | ["Ctrl", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "Return"], 15 | ["Shift", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "Shift", "Fn"], 16 | ["", "Alt", "Cmd", "", "Cmd", "Alt"], 17 | ]; 18 | 19 | module hhkb_default(profile) { 20 | layout(hhkb_layout, profile, hhkb_legends) children(); 21 | } 22 | -------------------------------------------------------------------------------- /src/layouts/layout.scad: -------------------------------------------------------------------------------- 1 | use <../key_transformations.scad> 2 | use <../key_profiles.scad> 3 | use <../key_sizes.scad> 4 | use <../key_types.scad> 5 | 6 | // sums all values, unless a value is negative, in which case it makes it positive 7 | // dirty hack to allow for large gaps in keysets 8 | function abs_sum(list, x=0) = 9 | len(list) <= 1 ? 10 | x + abs(list[0]) : 11 | abs_sum([for (x = [1: len(list) - 1]) list[x]], x+abs(list[0])); 12 | 13 | function 2hands(index, total) = ((index+0.5) % (total/2)) - (total/4); 14 | function cresting_wave(index, total, mod=4) = (index < total/2) ? (((index + 0.5) / total)*mod) : -(mod - ((index + 0.5) / total * mod)); 15 | function 1hand(index, total) = (index % (total)) - (total/2); 16 | 17 | 18 | // chooses between all the sculpting options 19 | // checks if column is smack in middle of row - if so, no sculpting 20 | // since we are zero indexed, the 7th row has an index of 6 and is the center of 13. 6*2+1 = 13 21 | function double_sculpted_column(column, row_length, column_sculpt_profile) = 22 | (column*2 + 1 == row_length) ? 23 | 0 : (column_sculpt_profile == "2hands") ? 24 | 2hands(column, row_length) : (column_sculpt_profile == "1hand") ? 25 | 1hand(column, row_length) : (column_sculpt_profile == "cresting_wave") ? 26 | cresting_wave(column, row_length) : 0; 27 | 28 | module layout(list, profile="dcs", legends=undef, front_legends=undef, row_sculpting_offset=0, row_override=undef, column_sculpt_profile="2hands", column_override=undef) { 29 | for (row = [0:len(list)-1]){ 30 | /* echo("**ROW**:", row); */ 31 | row_length = len(list[row]); 32 | 33 | for(column = column_override ? column_override : [0:len(list[row])-1]) { 34 | row_sculpting = (row_override != undef ? row_override : row) + row_sculpting_offset; 35 | key_length = list[row][column]; 36 | column_value = double_sculpted_column(column, row_length, column_sculpt_profile); 37 | column_distance = abs_sum([for (x = [0 : column]) list[row][x]]); 38 | 39 | /* echo("\t**COLUMN**", "column_value", column_value, "column_distance", column_distance); */ 40 | 41 | // supports negative values for nonexistent keys 42 | if (key_length >= 1) { 43 | translate_u(column_distance - (key_length/2), -row) { 44 | 45 | key_profile(profile, row_sculpting, column_value) u(key_length) legend(legends ? legends[row][column] : "") front_legend(front_legends ? front_legends[row][column] : "") cherry() { // (row+4) % 5 + 1 46 | $row = row; 47 | $column = column; 48 | 49 | if (key_length == 6.25) { 50 | spacebar() { 51 | if ($children) { 52 | children(); 53 | } else { 54 | key(); 55 | } 56 | } 57 | } else if (key_length == 2.25) { 58 | lshift() { 59 | if ($children) { 60 | children(); 61 | } else { 62 | key(); 63 | } 64 | } 65 | } else if (key_length == 2) { 66 | backspace() { 67 | if ($children) { 68 | children(); 69 | } else { 70 | key(); 71 | } 72 | } 73 | } else if (key_length == 2.75) { 74 | rshift() { 75 | if ($children) { 76 | children(); 77 | } else { 78 | key(); 79 | } 80 | } 81 | } else { 82 | { 83 | if ($children) { 84 | children(); 85 | } else { 86 | key(); 87 | } 88 | } 89 | } 90 | } 91 | } 92 | } 93 | } 94 | } 95 | } 96 | 97 | // much simpler, decoupled layout function 98 | // requires more setup - it only does what is in the layout array, which is translate 99 | // and key length. you have to do row / column profile yourself and always pass 100 | // children() 101 | // this is probably the way we'll go forward 102 | module simple_layout(list) { 103 | for (row = [0:len(list)-1]){ 104 | /* echo("**ROW**:", row); */ 105 | for(column = [0:len(list[row])-1]) { 106 | key_length = list[row][column]; 107 | column_distance = abs_sum([for (x = [0 : column]) list[row][x]]); 108 | 109 | /* echo("\t**COLUMN**", "column_value", column_value, "column_distance", column_distance); */ 110 | 111 | // supports negative values for nonexistent keys 112 | if (key_length >= 1) { 113 | translate_u(column_distance - (key_length/2), -row) { 114 | u(key_length) { // (row+4) % 5 + 1 115 | $row = row; 116 | $column = column; 117 | 118 | if (key_length == 6.25) { 119 | spacebar() children(); 120 | } else if (key_length == 2.25) { 121 | lshift() children(); 122 | } else if (key_length == 2) { 123 | backspace() children(); 124 | } else if (key_length == 2.75) { 125 | rshift() children(); 126 | } else { 127 | children(); 128 | } 129 | } 130 | } 131 | } 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/layouts/lets_split/default.scad: -------------------------------------------------------------------------------- 1 | include <../layout.scad> 2 | 3 | // negative numbers are used for spacing 4 | lets_split_layout = [ 5 | [1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1], 6 | [1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1], 7 | [1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1], 8 | [1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1] 9 | ]; 10 | 11 | module lets_split_default(profile) { 12 | layout(lets_split_layout, profile, row_sculpting_offset=1) children(); 13 | } 14 | -------------------------------------------------------------------------------- /src/layouts/planck/default.scad: -------------------------------------------------------------------------------- 1 | include <../layout.scad> 2 | 3 | // 0's are to make space for a middle row for just the spacebar so that it 4 | // isn't sculpted with double sculpting. the 0's in the first three rows 5 | // don't _need_ to be there but it's nice to keep track 6 | planck_default_layout = [ 7 | [1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1], 8 | [1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1], 9 | [1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1], 10 | [1, 1, 1, 1, 1, 0, 2, 0, 1, 1, 1, 1, 1] 11 | ]; 12 | 13 | planck_default_legends = [ 14 | [ "⇥", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "⌫"], 15 | ["Esc", "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "⏎"], 16 | [ "⇧", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", "⇧"], 17 | [ "Fn", "Ctl", "Alt", "Cmd", "Lwr", "", "", "RSE", "←", "↓", "↑", "→"], 18 | ]; 19 | 20 | 21 | module planck_default(profile, column_sculpt_profile="2hands") { 22 | layout(planck_default_layout, profile, row_sculpting_offset=1, column_sculpt_profile=column_sculpt_profile) children(); 23 | } 24 | -------------------------------------------------------------------------------- /src/layouts/planck/mit.scad: -------------------------------------------------------------------------------- 1 | include <../layout.scad> 2 | 3 | // 0's are to make space for a middle row for just the spacebar so that it 4 | // isn't sculpted with double sculpting. the 0's in the first three rows 5 | // don't _need_ to be there but it's nice to keep track 6 | planck_layout_mapping = [ 7 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 8 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 9 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 10 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] 11 | ]; 12 | 13 | module planck_mit(profile) { 14 | layout(planck_layout_mapping, profile, row_sculpting_offset=1) children(); 15 | } 16 | -------------------------------------------------------------------------------- /src/layouts/plate.scad: -------------------------------------------------------------------------------- 1 | // No support for stabilizers yet - but should be easy enough 2 | // Won't work well for split layouts. or, it'll work fine - but it'll only be 3 | // one plate. 4 | 5 | // each corner 6 | module unit_corners(height = 3, radius=3, $fn=24) { 7 | positions = [ 8 | [-$key_length/2, -$key_height/2], 9 | [$key_length/2, -$key_height/2], 10 | [$key_length/2, $key_height/2], 11 | [-$key_length/2, $key_height/2], 12 | ]; 13 | for (position = positions) { 14 | translate_u(position.x, position.y) cylinder(h=height, r=radius, $fn=$fn); 15 | } 16 | } 17 | 18 | module switch_hole() { 19 | cube(14, center=true); 20 | } 21 | 22 | module plate(layout_object) { 23 | difference() { 24 | hull() { 25 | simple_layout(layout_object) unit_corners(); 26 | } 27 | simple_layout(layout_object) switch_hole(); 28 | } 29 | } -------------------------------------------------------------------------------- /src/layouts/preonic/default.scad: -------------------------------------------------------------------------------- 1 | include <../layout.scad> 2 | 3 | preonic_default_layout = [ 4 | [1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1], 5 | [1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1], 6 | [1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1], 7 | [1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1], 8 | [1, 1, 1, 1, 1, 0, 2, 0, 1, 1, 1, 1, 1] 9 | ]; 10 | 11 | preonic_default_legends = [ 12 | [ "`", "1", "2", "3", "4", "5", "", "6", "7", "8", "9", "0", "-"], 13 | [ "⇥", "Q", "W", "E", "R", "T", "", "Y", "U", "I", "O", "P", "⌫"], 14 | ["Esc", "A", "S", "D", "F", "G", "", "H", "J", "K", "L", ";", "⏎"], 15 | [ "⇧", "Z", "X", "C", "V", "B", "", "N", "M", ",", ".", "/", "⇧"], 16 | [ "Fn", "Ctl", "Alt", "Cmd", "Lwr", "", "", "", "RSE", "←", "↓", "↑", "→"], 17 | ]; 18 | 19 | module preonic_default(profile, column_sculpt_profile="2hands") { 20 | layout(preonic_default_layout, profile, column_sculpt_profile=column_sculpt_profile) children(); 21 | } 22 | -------------------------------------------------------------------------------- /src/layouts/preonic/mit.scad: -------------------------------------------------------------------------------- 1 | include <../layout.scad> 2 | 3 | preonic_mit_layout = [ 4 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 5 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 6 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 7 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 8 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] 9 | ]; 10 | 11 | preonic_mit_legends = [ 12 | [ "`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-"], 13 | [ "⇥", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "⌫"], 14 | ["Esc", "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "⏎"], 15 | [ "⇧", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", "⇧"], 16 | [ "Fn", "Ctl", "Alt", "Cmd", "Lwr", "", "", "RSE", "←", "↓", "↑", "→"], 17 | ]; 18 | 19 | module planck_mit(profile) { 20 | layout(preonic_mit_layout, profile, legends=preonic_mit_legends, row_sculpting_offset=1) children(); 21 | } 22 | -------------------------------------------------------------------------------- /src/layouts/project_zen/default.scad: -------------------------------------------------------------------------------- 1 | include <../layout.scad> 2 | 3 | project_zen_main = [ 4 | [1.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5], 5 | [1.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5], 6 | [1.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5], 7 | [1.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5], 8 | [1.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5] 9 | ]; 10 | 11 | project_zen_thumbs = [ 12 | [2,2], 13 | [2,2], 14 | ]; 15 | 16 | module project_zen_default(profile) { 17 | layout(project_zen_main, profile) children(); 18 | translate_u(4.5,-5) layout(project_zen_thumbs, profile, row_override=3) children(); 19 | } 20 | -------------------------------------------------------------------------------- /src/libraries/3d_surface.scad: -------------------------------------------------------------------------------- 1 | // thanks Paul https://github.com/openscad/list-comprehension-demos/ 2 | 3 | include <../functions.scad> 4 | 5 | module 3d_surface(size=$3d_surface_size, step=$3d_surface_step, bottom=-SMALLEST_POSSIBLE){ 6 | function p(x, y) = [ x, y, max(0,$surface_function(x, y) * $corner_smoothing_surface_function(x,y)) ]; 7 | function p0(x, y) = [ x, y, bottom ]; 8 | function rev(b, v) = b ? v : [ v[3], v[2], v[1], v[0] ]; 9 | function face(x, y) = [ p(x, y + step), p(x + step, y + step), p(x + step, y), p(x + step, y), p(x, y), p(x, y + step) ]; 10 | function fan(a, i) = 11 | a == 0 ? [ [ 0, 0, bottom ], [ i, -size, bottom ], [ i + step, -size, bottom ] ] 12 | : a == 1 ? [ [ 0, 0, bottom ], [ i + step, size, bottom ], [ i, size, bottom ] ] 13 | : a == 2 ? [ [ 0, 0, bottom ], [ -size, i + step, bottom ], [ -size, i, bottom ] ] 14 | : [ [ 0, 0, bottom ], [ size, i, bottom ], [ size, i + step, bottom ] ]; 15 | function sidex(x, y) = [ p0(x, y), p(x, y), p(x + step, y), p0(x + step, y) ]; 16 | function sidey(x, y) = [ p0(x, y), p(x, y), p(x, y + step), p0(x, y + step) ]; 17 | 18 | points = flatten(concat( 19 | // top surface 20 | [ for (x = [ -size : step : size - step ], y = [ -size : step : size - step ]) face(x, y) ], 21 | // bottom surface as triangle fan 22 | [ for (a = [ 0 : 3 ], i = [ -size : step : size - step ]) fan(a, i) ], 23 | // sides 24 | [ for (x = [ -size : step : size - step ], y = [ -size, size ]) rev(y < 0, sidex(x, y)) ], 25 | [ for (y = [ -size : step : size - step ], x = [ -size, size ]) rev(x > 0, sidey(x, y)) ] 26 | )); 27 | 28 | tcount = 2 * pow(2 * size / step, 2) + 8 * size / step; 29 | scount = 8 * size / step; 30 | 31 | tfaces = [ for (a = [ 0 : 3 : 3 * (tcount - 1) ] ) [ a, a + 1, a + 2 ] ]; 32 | sfaces = [ for (a = [ 3 * tcount : 4 : 3 * tcount + 4 * scount ] ) [ a, a + 1, a + 2, a + 3 ] ]; 33 | faces = concat(tfaces, sfaces); 34 | 35 | polyhedron(points, faces, convexity = 8); 36 | } 37 | 38 | module polar_3d_surface(size, step, bottom=-SMALLEST_POSSIBLE){ 39 | function to_polar(q, size) = q * (90 / size); 40 | 41 | function p(x, y) = [ 42 | $surface_distribution_function(to_polar(x, size), size), 43 | $surface_distribution_function(to_polar(y, size), size), 44 | max(0,$surface_function($surface_distribution_function(to_polar(x, size), size), $surface_distribution_function(to_polar(y, size), size)) * $corner_smoothing_surface_function($surface_distribution_function(to_polar(x, size), size), $surface_distribution_function(to_polar(y, size), size))) 45 | ]; 46 | function p0(x, y) = [ x, y, bottom ]; 47 | function rev(b, v) = b ? v : [ v[3], v[2], v[1], v[0] ]; 48 | function face(x, y) = [ p(x, y + step), p(x + step, y + step), p(x + step, y), p(x + step, y), p(x, y), p(x, y + step) ]; 49 | function fan(a, i) = 50 | a == 0 ? [ [ 0, 0, bottom ], [ i, -size, bottom ], [ i + step, -size, bottom ] ] 51 | : a == 1 ? [ [ 0, 0, bottom ], [ i + step, size, bottom ], [ i, size, bottom ] ] 52 | : a == 2 ? [ [ 0, 0, bottom ], [ -size, i + step, bottom ], [ -size, i, bottom ] ] 53 | : [ [ 0, 0, bottom ], [ size, i, bottom ], [ size, i + step, bottom ] ]; 54 | function sidex(x, y) = [ p0(x, y), p(x, y), p(x + step, y), p0(x + step, y) ]; 55 | function sidey(x, y) = [ p0(x, y), p(x, y), p(x, y + step), p0(x, y + step) ]; 56 | 57 | points = flatten(concat( 58 | // top surface 59 | [ for (x = [ -size : step : size - step ], y = [ -size : step : size - step ]) face(x, y) ], 60 | // bottom surface as triangle fan 61 | [ for (a = [ 0 : 3 ], i = [ -size : step : size - step ]) fan(a, i) ], 62 | // sides 63 | [ for (x = [ -size : step : size - step ], y = [ -size, size ]) rev(y < 0, sidex(x, y)) ], 64 | [ for (y = [ -size : step : size - step ], x = [ -size, size ]) rev(x > 0, sidey(x, y)) ] 65 | )); 66 | 67 | tcount = 2 * pow(2 * size / step, 2) + 8 * size / step; 68 | scount = 8 * size / step; 69 | 70 | tfaces = [ for (a = [ 0 : 3 : 3 * (tcount - 1) ] ) [ a, a + 1, a + 2 ] ]; 71 | sfaces = [ for (a = [ 3 * tcount : 4 : 3 * tcount + 4 * scount ] ) [ a, a + 1, a + 2, a + 3 ] ]; 72 | faces = concat(tfaces, sfaces); 73 | 74 | polyhedron(points, faces, convexity = 8); 75 | } 76 | 77 | // defaults, overridden in functions.scad 78 | // $surface_distribution_function = function(dim, size) sin(dim) * size; 79 | // $surface_function = function(x,y) (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); 80 | -------------------------------------------------------------------------------- /src/libraries/geodesic_sphere.scad: -------------------------------------------------------------------------------- 1 | // from https://www.thingiverse.com/thing:1484333 2 | // public domain license 3 | // same syntax and semantics as built-in sphere, so should be a drop-in replacement 4 | // it's a bit slow for large numbers of facets 5 | module geodesic_sphere(r=-1, d=-1) { 6 | // if neither parameter specified, radius is taken to be 1 7 | rad = r > 0 ? r : d > 0 ? d/2 : 1; 8 | 9 | pentside_pr = 2*sin(36); // side length compared to radius of a pentagon 10 | pentheight_pr = sqrt(pentside_pr*pentside_pr - 1); 11 | // from center of sphere, icosahedron edge subtends this angle 12 | edge_subtend = 2*atan(pentheight_pr); 13 | 14 | // vertical rotation by 72 degrees 15 | c72 = cos(72); 16 | s72 = sin(72); 17 | function zrot(pt) = [ c72*pt[0]-s72*pt[1], s72*pt[0]+c72*pt[1], pt[2] ]; 18 | 19 | // rotation from north to vertex along positive x 20 | ces = cos(edge_subtend); 21 | ses = sin(edge_subtend); 22 | function yrot(pt) = [ ces*pt[0] + ses*pt[2], pt[1], ces*pt[2]-ses*pt[0] ]; 23 | 24 | // 12 icosahedron vertices generated from north, south, yrot and zrot 25 | ic1 = [ 0, 0, 1 ]; // north 26 | ic2 = yrot(ic1); // north and +x 27 | ic3 = zrot(ic2); // north and +x and +y 28 | ic4 = zrot(ic3); // north and -x and +y 29 | ic5 = zrot(ic4); // north and -x and -y 30 | ic6 = zrot(ic5); // north and +x and -y 31 | ic12 = [ 0, 0, -1]; // south 32 | ic10 = yrot(ic12); // south and -x 33 | ic11 = zrot(ic10); // south and -x and -y 34 | ic7 = zrot(ic11); // south and +x and -y 35 | ic8 = zrot(ic7); // south and +x and +y 36 | ic9 = zrot(ic8); // south and -x and +y 37 | 38 | // start with icosahedron, icos[0] is vertices and icos[1] is faces 39 | icos = [ [ic1, ic2, ic3, ic4, ic5, ic6, ic7, ic8, ic9, ic10, ic11, ic12 ], 40 | [ [0, 2, 1], [0, 3, 2], [0, 4, 3], [0, 5, 4], [0, 1, 5], 41 | [1, 2, 7], [2, 3, 8], [3, 4, 9], [4, 5, 10], [5, 1, 6], 42 | [7, 6, 1], [8, 7, 2], [9, 8, 3], [10, 9, 4], [6, 10, 5], 43 | [6, 7, 11], [7, 8, 11], [8, 9, 11], [9, 10, 11], [10, 6, 11]]]; 44 | 45 | // now for polyhedron subdivision functions 46 | 47 | // given two 3D points on the unit sphere, find the half-way point on the great circle 48 | // (euclidean midpoint renormalized to be 1 unit away from origin) 49 | function midpt(p1, p2) = 50 | let (midx = (p1[0] + p2[0])/2, midy = (p1[1] + p2[1])/2, midz = (p1[2] + p2[2])/2) 51 | let (midlen = sqrt(midx*midx + midy*midy + midz*midz)) 52 | [ midx/midlen, midy/midlen, midz/midlen ]; 53 | 54 | // given a "struct" where pf[0] is vertices and pf[1] is faces, subdivide all faces into 55 | // 4 faces by dividing each edge in half along a great circle (midpt function) 56 | // and returns a struct of the same format, i.e. pf[0] is a (larger) list of vertices and 57 | // pf[1] is a larger list of faces. 58 | function subdivpf(pf) = 59 | let (p=pf[0], faces=pf[1]) 60 | [ // for each face, barf out six points 61 | [ for (f=faces) 62 | let (p0 = p[f[0]], p1 = p[f[1]], p2=p[f[2]]) 63 | // "identity" for-loop saves having to flatten 64 | for (outp=[ p0, p1, p2, midpt(p0, p1), midpt(p1, p2), midpt(p0, p2) ]) outp 65 | ], 66 | // now, again for each face, spit out four faces that connect those six points 67 | [ for (i=[0:len(faces)-1]) 68 | let (base = 6*i) // points generated in multiples of 6 69 | for (outf = 70 | [[ base, base+3, base+5], 71 | [base+3, base+1, base+4], 72 | [base+5, base+4, base+2], 73 | [base+3, base+4, base+5]]) outf // "identity" for-loop saves having to flatten 74 | ] 75 | ]; 76 | 77 | // recursive wrapper for subdivpf that subdivides "levels" times 78 | function multi_subdiv_pf(pf, levels) = 79 | levels == 0 ? pf : 80 | multi_subdiv_pf(subdivpf(pf), levels-1); 81 | 82 | // subdivision level based on $fa: 83 | // level 0 has edge angle of edge_subtend so subdivision factor should be edge_subtend/$fa 84 | // must round up to next power of 2. 85 | // Take log base 2 of angle ratio and round up to next integer 86 | ang_levels = ceil(log(edge_subtend/$fa)/log(2)); 87 | 88 | // subdivision level based on $fs: 89 | // icosahedron edge length is rad*2*tan(edge_subtend/2) 90 | // actually a chord and not circumference but let's say it's close enough 91 | // subdivision factor should be rad*2*tan(edge_subtend/2)/$fs 92 | side_levels = ceil(log(rad*2*tan(edge_subtend/2)/$fs)/log(2)); 93 | 94 | // subdivision level based on $fn: (fragments around circumference, not total facets) 95 | // icosahedron circumference around equator is about 5 (level 1 is exactly 10) 96 | // ratio of requested to equatorial segments is $fn/5 97 | // level of subdivison is log base 2 of $fn/5 98 | // round up to the next whole level so we get at least $fn 99 | facet_levels = ceil(log($fn/5)/log(2)); 100 | 101 | // $fn takes precedence, otherwise facet_levels is NaN (-inf) but it's ok 102 | // because it falls back to $fa or $fs, whichever translates to fewer levels 103 | levels = $fn ? facet_levels : min(ang_levels, side_levels); 104 | 105 | // subdivide icosahedron by these levels 106 | subdiv_icos = multi_subdiv_pf(icos, levels); 107 | 108 | scale(rad) 109 | polyhedron(points=subdiv_icos[0], faces=subdiv_icos[1]); 110 | } 111 | -------------------------------------------------------------------------------- /src/libraries/polyhedrons.scad: -------------------------------------------------------------------------------- 1 | function cat(L1, L2) = [for (i=[0:len(L1)+len(L2)-1]) 2 | i < len(L1)? L1[i] : L2[i-len(L1)]] ; 3 | 4 | 5 | module dish(type = "sphere", sides = 10, length = 10){ 6 | 7 | //TODO length scaling 8 | 9 | function pointyDish(x,y) = (x == 0 || y == 0 || x== sides || y == sides ) ? 0 : abs(5-x) + abs(5-y); 10 | 11 | /* 12 | matrix looks like this: 13 | [ 14 | [0, 0, 0], [0, 1, 0], [0, 2, 0], 15 | [1, 0, 0], [1, 1, 0], [1, 2, 0], 16 | [2, 0, 0], [2, 1, 0], [2, 2, 0] 17 | ] 18 | */ 19 | // row is how many verts are actually in a row 20 | row = sides + 1; 21 | 22 | // first make an x-first matrix of points. (0,0), (1,0) etc 23 | matrix = cat([ 24 | for ( y = [0 : sides], x = [ 0 : sides ]) [x, y, pointyDish(x,y)] 25 | ], [[sides / 2, sides / 2, 0]]); 26 | 27 | echo(matrix); 28 | 29 | echo(matrix[121]); 30 | 31 | echo(len(matrix)); 32 | 33 | translate([sides / 2, sides / 2, 0]) sphere(r=1); 34 | 35 | // then make 2 faces for each set of four points: (0,1,4), (0,4,3) 36 | // sides - 1 because we are doing this fromt the bottom left corner and extending up and out 1 vertex 37 | // so the rightmost and topmost vertexes are already covered 38 | f1 = [ 39 | for (y = [0 : sides-1], x = [ 0 : sides-1 ], num = [0, 1]) ( 40 | num == 0 ? 41 | [(x + row * y), (x + row * y + 1), (x + row * y + 1 + row)] : 42 | [(x + row * y), (x + row * y + 1 + row), (x + row * y + row)]) 43 | ]; 44 | 45 | f2 = cat(f1, [for (n = [0: sides-1]) [n, n+1, len(matrix) - 1]]); 46 | 47 | faces = cat(f2, [for (n = [len(matrix) - sides-1 : len(matrix)]) [n-1, n, len(matrix) - 1]]); 48 | // add 49 | 50 | /* 51 | faces needs to start like this: 52 | [ 53 | [0,1,4,3], 54 | [1,2,5,4] 55 | ]*/ 56 | 57 | /*index, index + 1, index + 1 + row, index + row*/ 58 | 59 | polyhedron(points = matrix, faces=faces); 60 | 61 | } 62 | 63 | dish(); 64 | -------------------------------------------------------------------------------- /src/libraries/scad-utils/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2014 Oskar Linde 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/libraries/scad-utils/README.md: -------------------------------------------------------------------------------- 1 | scad-utils 2 | ========== 3 | 4 | Utility libraries for OpenSCAD 5 | 6 | Morphology 7 | ---------- 8 | 9 | contains basic 2D morphology operations 10 | 11 | inset(d=1) - creates a polygon at an offset d inside a 2D shape 12 | outset(d=1) - creates a polygon at an offset d outside a 2D shape 13 | fillet(r=1) - adds fillets of radius r to all concave corners of a 2D shape 14 | rounding(r=1) - adds rounding to all convex corners of a 2D shape 15 | shell(d,center=false) - makes a shell of width d along the edge of a 2D shape 16 | - positive values of d places the shell on the outside 17 | - negative values of d places the shell on the inside 18 | - center=true and positive d places the shell centered on the edge 19 | 20 | 21 | ### Examples 22 | 23 | With a basic sample polygon shape, 24 | 25 | module shape() { 26 | polygon([[0,0],[1,0],[1.5,1],[2.5,1],[2,-1],[0,-1]]); 27 | } 28 | 29 | and `$fn=32;`. 30 | 31 | 32 | * `inset(d=0.3) shape();` 33 | 34 | ![](http://oskarlinde.github.io/scad-utils/img/morph-0.png) 35 | 36 | 37 | * `outset(d=0.3) shape();` 38 | 39 | ![](http://oskarlinde.github.io/scad-utils/img/morph-1.png) 40 | 41 | 42 | * `rounding(r=0.3) shape();` 43 | 44 | ![](http://oskarlinde.github.io/scad-utils/img/morph-2.png) 45 | 46 | 47 | * `fillet(r=0.3) shape();` 48 | 49 | ![](http://oskarlinde.github.io/scad-utils/img/morph-3.png) 50 | 51 | 52 | *`shell(d=0.3) shape();` 53 | 54 | ![](http://oskarlinde.github.io/scad-utils/img/morph-4.png) 55 | 56 | 57 | *`shell(d=-0.3) shape();` 58 | 59 | ![](http://oskarlinde.github.io/scad-utils/img/morph-5.png) 60 | 61 | 62 | *`shell(d=0.3,center=true) shape();` 63 | 64 | ![](http://oskarlinde.github.io/scad-utils/img/morph-6.png) 65 | 66 | 67 | Mirror 68 | ------ 69 | 70 | contains simple mirroring functions 71 | 72 | mirror_x() 73 | mirror_y() 74 | mirror_z() 75 | 76 | example: 77 | 78 | module arrow(l=1,w=.6,t=0.15) { 79 | mirror_y() polygon([[0,0],[l,0],[l-w/2,w/2],[l-w/2-sqrt(2)*t,w/2],[l-t/2-sqrt(2)*t,t/2],[0,t/2]]); 80 | } 81 | -------------------------------------------------------------------------------- /src/libraries/scad-utils/hull.scad: -------------------------------------------------------------------------------- 1 | 2 | // NOTE: this code uses 3 | // * experimental let() syntax 4 | // * experimental list comprehension syntax 5 | // * search() bugfix and feature addition 6 | // * vector min()/max() 7 | 8 | // Calculates the convex hull of a set of points. 9 | // The result is expressed in point indices. 10 | // If the points are collinear (or 2d), the result is a convex 11 | // polygon [i1,i2,i3,...], otherwise a triangular 12 | // polyhedron [[i1,i2,i3],[i2,i3,i4],...] 13 | 14 | function hull(points) = 15 | !(len(points) > 0) ? [] : 16 | len(points[0]) == 2 ? convexhull2d(points) : 17 | len(points[0]) == 3 ? convexhull3d(points) : []; 18 | 19 | epsilon = 1e-9; 20 | 21 | // 2d version 22 | function convexhull2d(points) = 23 | len(points) < 3 ? [] : let( 24 | a=0, b=1, 25 | 26 | c = find_first_noncollinear([a,b], points, 2) 27 | 28 | ) c == len(points) ? convexhull_collinear(points) : let( 29 | 30 | remaining = [ for (i = [2:len(points)-1]) if (i != c) i ], 31 | 32 | polygon = area_2d(points[a], points[b], points[c]) > 0 ? [a,b,c] : [b,a,c] 33 | 34 | ) convex_hull_iterative_2d(points, polygon, remaining); 35 | 36 | 37 | // Adds the remaining points one by one to the convex hull 38 | function convex_hull_iterative_2d(points, polygon, remaining, i_=0) = i_ >= len(remaining) ? polygon : 39 | let ( 40 | // pick a point 41 | i = remaining[i_], 42 | 43 | // find the segments that are in conflict with the point (point not inside) 44 | conflicts = find_conflicting_segments(points, polygon, points[i]) 45 | 46 | // no conflicts, skip point and move on 47 | ) len(conflicts) == 0 ? convex_hull_iterative_2d(points, polygon, remaining, i_+1) : let( 48 | 49 | // find the first conflicting segment and the first not conflicting 50 | // conflict will be sorted, if not wrapping around, do it the easy way 51 | polygon = remove_conflicts_and_insert_point(polygon, conflicts, i) 52 | ) convex_hull_iterative_2d( 53 | points, 54 | polygon, 55 | remaining, 56 | i_+1 57 | ); 58 | 59 | function find_conflicting_segments(points, polygon, point) = [ 60 | for (i = [0:len(polygon)-1]) let(j = (i+1) % len(polygon)) 61 | if (area_2d(points[polygon[i]], points[polygon[j]], point) < 0) 62 | i 63 | ]; 64 | 65 | // remove the conflicting segments from the polygon 66 | function remove_conflicts_and_insert_point(polygon, conflicts, point) = 67 | conflicts[0] == 0 ? let( 68 | nonconflicting = [ for(i = [0:len(polygon)-1]) if (!contains(conflicts, i)) i ], 69 | new_indices = concat(nonconflicting, (nonconflicting[len(nonconflicting)-1]+1) % len(polygon)), 70 | polygon = concat([ for (i = new_indices) polygon[i] ], point) 71 | ) polygon : let( 72 | prior_to_first_conflict = [ for(i = [0:1:min(conflicts)]) polygon[i] ], 73 | after_last_conflict = [ for(i = [max(conflicts)+1:1:len(polygon)-1]) polygon[i] ], 74 | polygon = concat(prior_to_first_conflict, point, after_last_conflict) 75 | ) polygon; 76 | 77 | 78 | // 3d version 79 | function convexhull3d(points) = 80 | len(points) < 3 ? [ for(i = [0:1:len(points)-1]) i ] : let ( 81 | 82 | // start with a single triangle 83 | a=0, b=1, c=2, 84 | plane = plane(points,a,b,c), 85 | 86 | d = find_first_noncoplanar(plane, points, 3) 87 | 88 | ) d == len(points) ? /* all coplanar*/ let ( 89 | 90 | pts2d = [ for (p = points) plane_project(p, points[a], points[b], points[c]) ], 91 | hull2d = convexhull2d(pts2d) 92 | 93 | ) hull2d : let( 94 | 95 | remaining = [for (i = [3:len(points)-1]) if (i != d) i], 96 | 97 | // Build an initial tetrahedron 98 | 99 | // swap b,c if d is in front of triangle t 100 | bc = in_front(plane, points[d]) ? [c,b] : [b,c], 101 | b = bc[0], c = bc[1], 102 | 103 | triangles = [ 104 | [a,b,c], 105 | [d,b,a], 106 | [c,d,a], 107 | [b,d,c], 108 | ], 109 | 110 | // calculate the plane equations 111 | planes = [ for (t = triangles) plane(points, t[0], t[1], t[2]) ] 112 | 113 | ) convex_hull_iterative(points, triangles, planes, remaining); 114 | 115 | // A plane equation (normal, offset) 116 | function plane(points, a, b, c) = let( 117 | normal = unit(cross(points[c]-points[a], points[b]-points[a])) 118 | ) [ 119 | normal, 120 | normal * points[a] 121 | ]; 122 | 123 | // Adds the remaining points one by one to the convex hull 124 | function convex_hull_iterative(points, triangles, planes, remaining, i_=0) = i_ >= len(remaining) ? triangles : 125 | let ( 126 | // pick a point 127 | i = remaining[i_], 128 | 129 | // find the triangles that are in conflict with the point (point not inside) 130 | conflicts = find_conflicts(points[i], planes), 131 | 132 | // for all triangles that are in conflict, collect their halfedges 133 | halfedges = [ 134 | for(c = conflicts) 135 | for(i = [0:2]) let(j = (i+1)%3) 136 | [triangles[c][i], triangles[c][j]] 137 | ], 138 | 139 | // find the outer perimeter of the set of conflicting triangles 140 | horizon = remove_internal_edges(halfedges), 141 | 142 | // generate a new triangle for each horizon halfedge together with the picked point i 143 | new_triangles = [ for (h = horizon) concat(h,i) ], 144 | 145 | // calculate the corresponding plane equations 146 | new_planes = [ for (t = new_triangles) plane(points, t[0], t[1], t[2]) ] 147 | 148 | ) convex_hull_iterative( 149 | points, 150 | // remove the conflicting triangles and add the new ones 151 | concat(remove_elements(triangles, conflicts), new_triangles), 152 | concat(remove_elements(planes, conflicts), new_planes), 153 | remaining, 154 | i_+1 155 | ); 156 | 157 | function convexhull_collinear(points) = let( 158 | n = points[1] - points[0], 159 | a = points[0], 160 | points1d = [ for(p = points) (p-a)*n ], 161 | min_i = min_index(points1d), 162 | max_i = max_index(points1d) 163 | ) [ min_i, max_i ]; 164 | 165 | function min_index(values,min_,min_i_,i_) = 166 | i_ == undef ? min_index(values,values[0],0,1) : 167 | i_ >= len(values) ? min_i_ : 168 | values[i_] < min_ ? min_index(values,values[i_],i_,i_+1) 169 | : min_index(values,min_,min_i_,i_+1); 170 | 171 | function max_index(values,max_,max_i_,i_) = 172 | i_ == undef ? max_index(values,values[0],0,1) : 173 | i_ >= len(values) ? max_i_ : 174 | values[i_] > max_ ? max_index(values,values[i_],i_,i_+1) 175 | : max_index(values,max_,max_i_,i_+1); 176 | 177 | function remove_elements(array, elements) = [ 178 | for (i = [0:len(array)-1]) 179 | if (!search(i, elements)) 180 | array[i] 181 | ]; 182 | 183 | function remove_internal_edges(halfedges) = [ 184 | for (h = halfedges) 185 | if (!contains(halfedges, reverse(h))) 186 | h 187 | ]; 188 | 189 | function plane_project(point, a, b, c) = let( 190 | u = b-a, 191 | v = c-a, 192 | n = cross(u,v), 193 | w = cross(n,u), 194 | relpoint = point-a 195 | ) [relpoint * u, relpoint * w]; 196 | 197 | function plane_unproject(point, a, b, c) = let( 198 | u = b-a, 199 | v = c-a, 200 | n = cross(u,v), 201 | w = cross(n,u) 202 | ) a + point[0] * u + point[1] * w; 203 | 204 | function reverse(arr) = [ for (i = [len(arr)-1:-1:0]) arr[i] ]; 205 | 206 | function contains(arr, element) = search([element],arr)[0] != [] ? true : false; 207 | 208 | function find_conflicts(point, planes) = [ 209 | for (i = [0:len(planes)-1]) 210 | if (in_front(planes[i], point)) 211 | i 212 | ]; 213 | 214 | function find_first_noncollinear(line, points, i) = 215 | i >= len(points) ? len(points) : 216 | collinear(points[line[0]], 217 | points[line[1]], 218 | points[i]) ? find_first_noncollinear(line, points, i+1) 219 | : i; 220 | 221 | function find_first_noncoplanar(plane, points, i) = 222 | i >= len(points) ? len(points) : 223 | coplanar(plane, points[i]) ? find_first_noncoplanar(plane, points, i+1) 224 | : i; 225 | 226 | function distance(plane, point) = plane[0] * point - plane[1]; 227 | 228 | function in_front(plane, point) = distance(plane, point) > epsilon; 229 | 230 | function coplanar(plane, point) = abs(distance(plane,point)) <= epsilon; 231 | 232 | function unit(v) = v/norm(v); 233 | 234 | function area_2d(a,b,c) = ( 235 | a[0] * (b[1] - c[1]) + 236 | b[0] * (c[1] - a[1]) + 237 | c[0] * (a[1] - b[1])) / 2; 238 | 239 | function collinear(a,b,c) = abs(area_2d(a,b,c)) < epsilon; 240 | 241 | function spherical(cartesian) = [ 242 | atan2(cartesian[1], cartesian[0]), 243 | asin(cartesian[2]) 244 | ]; 245 | 246 | function cartesian(spherical) = [ 247 | cos(spherical[1]) * cos(spherical[0]), 248 | cos(spherical[1]) * sin(spherical[0]), 249 | sin(spherical[1]) 250 | ]; 251 | 252 | 253 | /// TESTCODE 254 | 255 | 256 | phi = 1.618033988749895; 257 | 258 | testpoints_on_sphere = [ for(p = 259 | [ 260 | [1,phi,0], [-1,phi,0], [1,-phi,0], [-1,-phi,0], 261 | [0,1,phi], [0,-1,phi], [0,1,-phi], [0,-1,-phi], 262 | [phi,0,1], [-phi,0,1], [phi,0,-1], [-phi,0,-1] 263 | ]) 264 | unit(p) 265 | ]; 266 | 267 | testpoints_spherical = [ for(p = testpoints_on_sphere) spherical(p) ]; 268 | testpoints_circular = [ for(a = [0:15:360-epsilon]) [cos(a),sin(a)] ]; 269 | 270 | testpoints_coplanar = let(u = unit([1,3,7]), v = unit([-2,1,-2])) [ for(i = [1:10]) rands(-1,1,1)[0] * u + rands(-1,1,1)[0] * v ]; 271 | 272 | testpoints_collinear_2d = let(u = unit([5,3])) [ for(i = [1:20]) rands(-1,1,1)[0] * u ]; 273 | testpoints_collinear_3d = let(u = unit([5,3,-5])) [ for(i = [1:20]) rands(-1,1,1)[0] * u ]; 274 | 275 | testpoints2d = 20 * [for (i = [1:10]) concat(rands(-1,1,2))]; 276 | testpoints3d = 20 * [for (i = [1:50]) concat(rands(-1,1,3))]; 277 | 278 | // All points are on the sphere, no point should be red 279 | translate([-50,0]) visualize_hull(20*testpoints_on_sphere); 280 | 281 | // 2D points 282 | translate([50,0]) visualize_hull(testpoints2d); 283 | 284 | // All points on a circle, no point should be red 285 | translate([0,50]) visualize_hull(20*testpoints_circular); 286 | 287 | // All points 3d but collinear 288 | translate([0,-50]) visualize_hull(20*testpoints_coplanar); 289 | 290 | // Collinear 291 | translate([50,50]) visualize_hull(20*testpoints_collinear_2d); 292 | 293 | // Collinear 294 | translate([-50,50]) visualize_hull(20*testpoints_collinear_3d); 295 | 296 | // 3D points 297 | visualize_hull(testpoints3d); 298 | 299 | 300 | module visualize_hull(points) { 301 | 302 | hull = hull(points); 303 | 304 | %if (len(hull) > 0 && len(hull[0]) > 0) 305 | polyhedron(points=points, faces = hull); 306 | else 307 | polyhedron(points=points, faces = [hull]); 308 | 309 | for (i = [0:len(points)-1]) assign(p = points[i], $fn = 16) { 310 | translate(p) { 311 | if (hull_contains_index(hull,i)) { 312 | color("blue") sphere(1); 313 | } else { 314 | color("red") sphere(1); 315 | } 316 | } 317 | } 318 | 319 | function hull_contains_index(hull, index) = 320 | search(index,hull,1,0) || 321 | search(index,hull,1,1) || 322 | search(index,hull,1,2); 323 | 324 | } 325 | -------------------------------------------------------------------------------- /src/libraries/scad-utils/linalg.scad: -------------------------------------------------------------------------------- 1 | // very minimal set of linalg functions needed by so3, se3 etc. 2 | 3 | // cross and norm are builtins 4 | //function cross(x,y) = [x[1]*y[2]-x[2]*y[1], x[2]*y[0]-x[0]*y[2], x[0]*y[1]-x[1]*y[0]]; 5 | //function norm(v) = sqrt(v*v); 6 | 7 | function vec3(p) = len(p) < 3 ? concat(p,0) : p; 8 | function vec4(p) = let (v3=vec3(p)) len(v3) < 4 ? concat(v3,1) : v3; 9 | function unit(v) = v/norm(v); 10 | 11 | function identity3()=[[1,0,0],[0,1,0],[0,0,1]]; 12 | function identity4()=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]; 13 | 14 | 15 | function take3(v) = [v[0],v[1],v[2]]; 16 | function tail3(v) = [v[3],v[4],v[5]]; 17 | function rotation_part(m) = [take3(m[0]),take3(m[1]),take3(m[2])]; 18 | function rot_trace(m) = m[0][0] + m[1][1] + m[2][2]; 19 | function rot_cos_angle(m) = (rot_trace(m)-1)/2; 20 | 21 | function rotation_part(m) = [take3(m[0]),take3(m[1]),take3(m[2])]; 22 | function translation_part(m) = [m[0][3],m[1][3],m[2][3]]; 23 | function transpose_3(m) = [[m[0][0],m[1][0],m[2][0]],[m[0][1],m[1][1],m[2][1]],[m[0][2],m[1][2],m[2][2]]]; 24 | function transpose_4(m) = [[m[0][0],m[1][0],m[2][0],m[3][0]], 25 | [m[0][1],m[1][1],m[2][1],m[3][1]], 26 | [m[0][2],m[1][2],m[2][2],m[3][2]], 27 | [m[0][3],m[1][3],m[2][3],m[3][3]]]; 28 | function invert_rt(m) = construct_Rt(transpose_3(rotation_part(m)), -(transpose_3(rotation_part(m)) * translation_part(m))); 29 | function construct_Rt(R,t) = [concat(R[0],t[0]),concat(R[1],t[1]),concat(R[2],t[2]),[0,0,0,1]]; 30 | 31 | // Hadamard product of n-dimensional arrays 32 | function hadamard(a,b) = !(len(a)>0) ? a*b : [ for(i = [0:len(a)-1]) hadamard(a[i],b[i]) ]; 33 | -------------------------------------------------------------------------------- /src/libraries/scad-utils/lists.scad: -------------------------------------------------------------------------------- 1 | // List helpers 2 | 3 | /*! 4 | Flattens a list one level: 5 | 6 | flatten([[0,1],[2,3]]) => [0,1,2,3] 7 | */ 8 | function flatten(list) = [ for (i = list, v = i) v ]; 9 | 10 | 11 | /*! 12 | Creates a list from a range: 13 | 14 | range([0:2:6]) => [0,2,4,6] 15 | */ 16 | function range(r) = [ for(x=r) x ]; 17 | 18 | /*! 19 | Reverses a list: 20 | 21 | reverse([1,2,3]) => [3,2,1] 22 | */ 23 | function reverse(list) = [for (i = [len(list)-1:-1:0]) list[i]]; 24 | 25 | /*! 26 | Extracts a subarray from index begin (inclusive) to end (exclusive) 27 | FIXME: Change name to use list instead of array? 28 | 29 | subarray([1,2,3,4], 1, 2) => [2,3] 30 | */ 31 | function subarray(list,begin=0,end=-1) = [ 32 | let(end = end < 0 ? len(list) : end) 33 | for (i = [begin : 1 : end-1]) 34 | list[i] 35 | ]; 36 | 37 | /*! 38 | Returns a copy of a list with the element at index i set to x 39 | 40 | set([1,2,3,4], 2, 5) => [1,2,5,4] 41 | */ 42 | function set(list, i, x) = [for (i_=[0:len(list)-1]) i == i_ ? x : list[i_]]; 43 | 44 | /*! 45 | Remove element from the list by index. 46 | remove([4,3,2,1],1) => [4,2,1] 47 | */ 48 | function remove(list, i) = [for (i_=[0:1:len(list)-2]) list[i_ < i ? i_ : i_ + 1]]; 49 | -------------------------------------------------------------------------------- /src/libraries/scad-utils/mirror.scad: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Oskar Linde. All rights reserved. 2 | // License: BSD 3 | // 4 | // This library contains simple mirroring functions 5 | // 6 | // mirror_x() 7 | // mirror_y() 8 | // mirror_z() 9 | 10 | 11 | module mirror_x() { 12 | union() { 13 | child(); 14 | scale([-1,1,1]) child(); 15 | } 16 | } 17 | 18 | module mirror_y() { 19 | union() { 20 | child(); 21 | scale([1,-1,1]) child(); 22 | } 23 | } 24 | 25 | module mirror_z() { 26 | union() { 27 | child(); 28 | scale([1,1,-1]) child(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/libraries/scad-utils/morphology.scad: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Oskar Linde. All rights reserved. 2 | // License: BSD 3 | // 4 | // This library contains basic 2D morphology operations 5 | // 6 | // outset(d=1) - creates a polygon at an offset d outside a 2D shape 7 | // inset(d=1) - creates a polygon at an offset d inside a 2D shape 8 | // fillet(r=1) - adds fillets of radius r to all concave corners of a 2D shape 9 | // rounding(r=1) - adds rounding to all convex corners of a 2D shape 10 | // shell(d,center=false) - makes a shell of width d along the edge of a 2D shape 11 | // - positive values of d places the shell on the outside 12 | // - negative values of d places the shell on the inside 13 | // - center=true and positive d places the shell centered on the edge 14 | 15 | module outset(d=1) { 16 | // Bug workaround for older OpenSCAD versions 17 | if (version_num() < 20130424) render() outset_extruded(d) child(); 18 | else minkowski() { 19 | circle(r=d); 20 | child(); 21 | } 22 | } 23 | 24 | module outset_extruded(d=1) { 25 | projection(cut=true) minkowski() { 26 | cylinder(r=d); 27 | linear_extrude(center=true) child(); 28 | } 29 | } 30 | 31 | module inset(d=1) { 32 | render() inverse() outset(d=d) inverse() child(); 33 | } 34 | 35 | module fillet(r=1) { 36 | inset(d=r) render() outset(d=r) child(); 37 | } 38 | 39 | module rounding(r=1) { 40 | outset(d=r) inset(d=r) child(); 41 | } 42 | 43 | module shell(d,center=false) { 44 | if (center && d > 0) { 45 | difference() { 46 | outset(d=d/2) child(); 47 | inset(d=d/2) child(); 48 | } 49 | } 50 | if (!center && d > 0) { 51 | difference() { 52 | outset(d=d) child(); 53 | child(); 54 | } 55 | } 56 | if (!center && d < 0) { 57 | difference() { 58 | child(); 59 | inset(d=-d) child(); 60 | } 61 | } 62 | if (d == 0) child(); 63 | } 64 | 65 | 66 | // Below are for internal use only 67 | 68 | module inverse() { 69 | difference() { 70 | square(1e5,center=true); 71 | child(); 72 | } 73 | } 74 | 75 | 76 | // TEST CODE 77 | 78 | use 79 | 80 | module arrow(l=1,w=.6,t=0.15) { 81 | mirror_y() polygon([[0,0],[l,0],[l-w/2,w/2],[l-w/2-sqrt(2)*t,w/2],[l-t/2-sqrt(2)*t,t/2],[0,t/2]]); 82 | } 83 | 84 | module shape() { 85 | polygon([[0,0],[1,0],[1.5,1],[2.5,1],[2,-1],[0,-1]]); 86 | } 87 | 88 | if(0) assign($fn=32) { 89 | 90 | for (p = [0:10*3-1]) assign(o=floor(p/3)) { 91 | translate([(p%3)*2.5,-o*3]) { 92 | //%if (p % 3 == 1) translate([0,0,1]) shape(); 93 | if (p % 3 == 0) shape(); 94 | if (p % 3 == 1) translate([0.6,0]) arrow(); 95 | if (p % 3 == 2) { 96 | if (o == 0) inset(d=0.3) shape(); 97 | if (o == 1) outset(d=0.3) shape(); 98 | if (o == 2) rounding(r=0.3) shape(); 99 | if (o == 3) fillet(r=0.3) shape(); 100 | if (o == 4) shell(d=0.3) shape(); 101 | if (o == 5) shell(d=-0.3) shape(); 102 | if (o == 6) shell(d=0.3,center=true) shape(); 103 | if (o == 7) rounding(r=0.3) fillet(r=0.3) shape(); 104 | if (o == 8) shell(d=0.3,center=true) fillet(r=0.3) rounding(r=0.3) shape(); 105 | if (o == 9) shell(d=-0.3) fillet(r=0.3) rounding(r=0.3) shape(); 106 | } 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/libraries/scad-utils/se3.scad: -------------------------------------------------------------------------------- 1 | use 2 | use 3 | 4 | function combine_se3_exp(w, ABt) = construct_Rt(rodrigues_so3_exp(w, ABt[0], ABt[1]), ABt[2]); 5 | 6 | // [A,B,t] 7 | function se3_exp_1(t,w) = concat( 8 | so3_exp_1(w*w), 9 | [t + 0.5 * cross(w,t)] 10 | ); 11 | 12 | function se3_exp_2(t,w) = se3_exp_2_0(t,w,w*w); 13 | function se3_exp_2_0(t,w,theta_sq) = 14 | se3_exp_23( 15 | so3_exp_2(theta_sq), 16 | C = (1.0 - theta_sq/20) / 6, 17 | t=t,w=w); 18 | 19 | function se3_exp_3(t,w) = se3_exp_3_0(t,w,sqrt(w*w)*180/PI,1/sqrt(w*w)); 20 | 21 | function se3_exp_3_0(t,w,theta_deg,inv_theta) = 22 | se3_exp_23( 23 | so3_exp_3_0(theta_deg = theta_deg, inv_theta = inv_theta), 24 | C = (1 - sin(theta_deg) * inv_theta) * (inv_theta * inv_theta), 25 | t=t,w=w); 26 | 27 | function se3_exp_23(AB,C,t,w) = 28 | [AB[0], AB[1], t + AB[1] * cross(w,t) + C * cross(w,cross(w,t)) ]; 29 | 30 | function se3_exp(mu) = se3_exp_0(t=take3(mu),w=tail3(mu)/180*PI); 31 | 32 | function se3_exp_0(t,w) = 33 | combine_se3_exp(w, 34 | // Evaluate by Taylor expansion when near 0 35 | w*w < 1e-8 36 | ? se3_exp_1(t,w) 37 | : w*w < 1e-6 38 | ? se3_exp_2(t,w) 39 | : se3_exp_3(t,w) 40 | ); 41 | 42 | function se3_ln(m) = se3_ln_to_deg(se3_ln_rad(m)); 43 | function se3_ln_to_deg(v) = concat(take3(v),tail3(v)*180/PI); 44 | 45 | function se3_ln_rad(m) = se3_ln_0(m, 46 | rot = so3_ln_rad(rotation_part(m))); 47 | function se3_ln_0(m,rot) = se3_ln_1(m,rot, 48 | theta = sqrt(rot*rot)); 49 | function se3_ln_1(m,rot,theta) = se3_ln_2(m,rot,theta, 50 | shtot = theta > 0.00001 ? sin(theta/2*180/PI)/theta : 0.5, 51 | halfrotator = so3_exp_rad(rot * -.5)); 52 | function se3_ln_2(m,rot,theta,shtot,halfrotator) = 53 | concat( (halfrotator * translation_part(m) - 54 | (theta > 0.001 55 | ? rot * ((translation_part(m) * rot) * (1-2*shtot) / (rot*rot)) 56 | : rot * ((translation_part(m) * rot)/24) 57 | )) / (2 * shtot), rot); 58 | 59 | __se3_test = [20,-40,60,-80,100,-120]; 60 | echo(UNITTEST_se3=norm(__se3_test-se3_ln(se3_exp(__se3_test))) < 1e-8); 61 | -------------------------------------------------------------------------------- /src/libraries/scad-utils/shapes.scad: -------------------------------------------------------------------------------- 1 | function square(size) = [[-size,-size], [-size,size], [size,size], [size,-size]] / 2; 2 | 3 | function circle(r) = [for (i=[0:$fn-1]) let (a=i*360/$fn) r * [cos(a), sin(a)]]; 4 | 5 | function regular(r, n) = circle(r, $fn=n); 6 | 7 | function rectangle_profile(size=[1,1]) = [ 8 | // The first point is the anchor point, put it on the point corresponding to [cos(0),sin(0)] 9 | [ size[0]/2, 0], 10 | [ size[0]/2, size[1]/2], 11 | [-size[0]/2, size[1]/2], 12 | [-size[0]/2, -size[1]/2], 13 | [ size[0]/2, -size[1]/2], 14 | ]; 15 | 16 | // FIXME: Move rectangle and rounded rectangle from extrusion 17 | -------------------------------------------------------------------------------- /src/libraries/scad-utils/so3.scad: -------------------------------------------------------------------------------- 1 | // so3 2 | 3 | use 4 | 5 | function rodrigues_so3_exp(w, A, B) = [ 6 | [1.0 - B*(w[1]*w[1] + w[2]*w[2]), B*(w[0]*w[1]) - A*w[2], B*(w[0]*w[2]) + A*w[1]], 7 | [B*(w[0]*w[1]) + A*w[2], 1.0 - B*(w[0]*w[0] + w[2]*w[2]), B*(w[1]*w[2]) - A*w[0]], 8 | [B*(w[0]*w[2]) - A*w[1], B*(w[1]*w[2]) + A*w[0], 1.0 - B*(w[0]*w[0] + w[1]*w[1])] 9 | ]; 10 | 11 | function so3_exp(w) = so3_exp_rad(w/180*PI); 12 | function so3_exp_rad(w) = 13 | combine_so3_exp(w, 14 | w*w < 1e-8 15 | ? so3_exp_1(w*w) 16 | : w*w < 1e-6 17 | ? so3_exp_2(w*w) 18 | : so3_exp_3(w*w)); 19 | 20 | function combine_so3_exp(w,AB) = rodrigues_so3_exp(w,AB[0],AB[1]); 21 | 22 | // Taylor series expansions close to 0 23 | function so3_exp_1(theta_sq) = [ 24 | 1 - 1/6*theta_sq, 25 | 0.5 26 | ]; 27 | 28 | function so3_exp_2(theta_sq) = [ 29 | 1.0 - theta_sq * (1.0 - theta_sq/20) / 6, 30 | 0.5 - 0.25/6 * theta_sq 31 | ]; 32 | 33 | function so3_exp_3_0(theta_deg, inv_theta) = [ 34 | sin(theta_deg) * inv_theta, 35 | (1 - cos(theta_deg)) * (inv_theta * inv_theta) 36 | ]; 37 | 38 | function so3_exp_3(theta_sq) = so3_exp_3_0(sqrt(theta_sq)*180/PI, 1/sqrt(theta_sq)); 39 | 40 | 41 | function rot_axis_part(m) = [m[2][1] - m[1][2], m[0][2] - m[2][0], m[1][0] - m[0][1]]*0.5; 42 | 43 | function so3_ln(m) = 180/PI*so3_ln_rad(m); 44 | function so3_ln_rad(m) = so3_ln_0(m, 45 | cos_angle = rot_cos_angle(m), 46 | preliminary_result = rot_axis_part(m)); 47 | 48 | function so3_ln_0(m, cos_angle, preliminary_result) = 49 | so3_ln_1(m, cos_angle, preliminary_result, 50 | sin_angle_abs = sqrt(preliminary_result*preliminary_result)); 51 | 52 | function so3_ln_1(m, cos_angle, preliminary_result, sin_angle_abs) = 53 | cos_angle > sqrt(1/2) 54 | ? sin_angle_abs > 0 55 | ? preliminary_result * asin(sin_angle_abs)*PI/180 / sin_angle_abs 56 | : preliminary_result 57 | : cos_angle > -sqrt(1/2) 58 | ? preliminary_result * acos(cos_angle)*PI/180 / sin_angle_abs 59 | : so3_get_symmetric_part_rotation( 60 | preliminary_result, 61 | m, 62 | angle = PI - asin(sin_angle_abs)*PI/180, 63 | d0 = m[0][0] - cos_angle, 64 | d1 = m[1][1] - cos_angle, 65 | d2 = m[2][2] - cos_angle 66 | ); 67 | 68 | function so3_get_symmetric_part_rotation(preliminary_result, m, angle, d0, d1, d2) = 69 | so3_get_symmetric_part_rotation_0(preliminary_result,angle,so3_largest_column(m, d0, d1, d2)); 70 | 71 | function so3_get_symmetric_part_rotation_0(preliminary_result, angle, c_max) = 72 | angle * unit(c_max * preliminary_result < 0 ? -c_max : c_max); 73 | 74 | function so3_largest_column(m, d0, d1, d2) = 75 | d0*d0 > d1*d1 && d0*d0 > d2*d2 76 | ? [d0, (m[1][0]+m[0][1])/2, (m[0][2]+m[2][0])/2] 77 | : d1*d1 > d2*d2 78 | ? [(m[1][0]+m[0][1])/2, d1, (m[2][1]+m[1][2])/2] 79 | : [(m[0][2]+m[2][0])/2, (m[2][1]+m[1][2])/2, d2]; 80 | 81 | __so3_test = [12,-125,110]; 82 | echo(UNITTEST_so3=norm(__so3_test-so3_ln(so3_exp(__so3_test))) < 1e-8); 83 | -------------------------------------------------------------------------------- /src/libraries/scad-utils/spline.scad: -------------------------------------------------------------------------------- 1 | // Spline module for scad-util library 2 | // Author Sergei Kuzmin, 2014. 3 | 4 | // For n+1 given point and hense n intervals returns the spline coefficient matrix. 5 | // param p defines the anchor points. 6 | // File defines two functions: spline_args and spline. 7 | // example usage: 8 | // spl1 = spline_args(point, v1=[0,1,0], closed=false); 9 | // interpolated_points = [for(t=[0:0.1:len(point)-1]) spline(spl1, t)] 10 | 11 | use 12 | use 13 | 14 | q1=[[1,0,0,0],[1,1,1,1],[0,1,2,3],[0,0,1,3]]; 15 | q1inv=[[1,0,0,0],[-3,3,-2,1],[3,-3,3,-2],[-1,1,-1,1]]; 16 | q2=[[0,0,0,0],[0,0,0,0],[0,-1,0,0],[0,0,-1,0]]; 17 | qn1i2=-q1inv*q2; 18 | z3=[0,0,0]; 19 | z4=[0,0,0,0]; 20 | 21 | function matrix_power(m,n)= n==0? (len(m)==3?identity3():identity4()) : 22 | n==1 ? m : (n%2==1) ? matrix_power(m*m,floor(n/2))*m : matrix_power(m*m,n/2); 23 | 24 | function det(m) = let(r=[for(i=[0:1:len(m)-1]) i]) det_help(m, 0, r); 25 | // Construction indices list is inefficient, but currently there is no way to imperatively 26 | // assign to a list element 27 | function det_help(m, i, r) = len(r) == 0 ? 1 : 28 | m[len(m)-len(r)][r[i]]*det_help(m,0,remove(r,i)) - (i+1=n? u : u-q2*q1inv*spline_helper(i+1, n, p); 50 | 51 | // knowing s[j+1], calculate s[j]. Stop when found s[i] 52 | function spline_si(i,n, p, sn) = i == n ? sn : q1inv*(spline_u(i,p)-q2*spline_si(i+1, n, p, sn)); 53 | 54 | // Takes array of (3n+1) points or (2n + 2) points, if tangent segments are symmetric. 55 | // For non-symmetric version input is: point0, normal0, neg_normal1, point1, normal1, ... neg_normal_n, point_n 56 | // For symmetric version: point0, normal0, point1, normal1, ... , normal_n_sub_1, point_n 57 | // In the second case second tangent is constructed from the next tangent by symmetric map. 58 | // I.e. if current points are p0,p1,p2 then anchor points are p0 and p2, first tangent defined by p1-p0, 59 | // second tangent defined by p3-p2. 60 | // Return array of coefficients accepted by spline(), spline_tan() and similar 61 | function bezier3_args(p, symmetric=false) = let(step=symmetric?2:3) 62 | [for(i=[0:step:len(p)-3]) [[1,0,0,0],[-3,3,0,0],[3,-6,3,0],[-1,3,-3,1]]* 63 | (symmetric?[p[i],p[i]+p[i+1],p[i+2]-p[i+3],p[i+2]] : [p[i], p[i]+p[i+1], p[i+3]+p[i+2], p[i+3]])]; 64 | 65 | // s - spline arguments calculated by spline_args 66 | // t - defines point on curve. each segment length is 1. I.e. t= 0..1 is first segment, t=1..2 - second. 67 | function spline(s, t)= let(i=t>=len(s)?len(s)-1: floor(t), t2=t-i) [1,t2,t2*t2,t2*t2*t2]*s[i]; 68 | 69 | function spline_tan(s, t)= let(i=t>=len(s)?len(s)-1: floor(t), t2=t-i) [0,1,2*t2,3*t2*t2]*s[i]; 70 | function spline_tan_unit(s, t)= unit(spline_tan(s,t)); 71 | function spline_d2(s,t)= let(i=t>=len(s)?len(s)-1: floor(t), t2=t-i) [0,0,2,6*t2]*s[i]; 72 | function spline_binormal_unit(s,t)= unit(cross(spline_tan(s, t), spline_d2(s,t))); 73 | function spline_normal_unit(s,t)= unit(cross(spline_tan(s, t), spline_binormal_unit(s,t))); 74 | 75 | function spline_transform(s, t)= 76 | construct_Rt(transpose_3([spline_normal_unit(s,t), spline_binormal_unit(s,t), spline_tan_unit(s,t)]), spline(s,t)); 77 | 78 | // Unit tests 79 | __s = spline_args([[0,10,0], [10,0,0],[0,-5,2]], v1=[0,1,0], v2=[-1,0,0], closed=true); 80 | for(t=[0:0.01:len(__s)]) translate(spline(__s, t)) 81 | cube([0.2,0.2,0.2], center=true); 82 | 83 | __s1=spline_args([[0,0,0],[0,0,15], [26,0,26+15]], /*v1=[0,0,100],*/ v2=[40,0,0]); 84 | for(t=[0:0.01:len(s1)]) translate(spline(__s1, t)) 85 | cube([0.2,0.2,0.2], center=true); 86 | 87 | __s2=bezier3_args([[0,0,0],[0,0,10],[0,0,15],[0,0,26*0.552284],[26,0,41],[26*0.552284,0,0]],symmetric=true); 88 | echo(__s2); 89 | for(t=[0:0.01:len(__s2)]) translate(spline(__s2, t)) 90 | cube([0.2,0.2,0.2], center=true); 91 | 92 | // Rotation methods taken from list-comprehension-demos/sweep.scad to demonstrate normal and binormal 93 | // Normally spline_transform is more convenient 94 | function __rotation_from_axis(x,y,z) = [[x[0],y[0],z[0]],[x[1],y[1],z[1]],[x[2],y[2],z[2]]]; 95 | function __rotate_from_to(a,b,_axis=[]) = 96 | len(_axis) == 0 97 | ? __rotate_from_to(a,b,unit(cross(a,b))) 98 | : _axis*_axis >= 0.99 ? __rotation_from_axis(unit(b),_axis,cross(_axis,unit(b))) * 99 | transpose_3(__rotation_from_axis(unit(a),_axis,cross(_axis,unit(a)))) : identity3(); 100 | 101 | __s3 = spline_args([[0,10,0], [6,6,0], [10,0,0],[0,-5,4]], v1=[0,1,0], v2=[-1,0,0], closed=true); 102 | for(t=[0:0.05:len(__s3)]) translate(spline(__s3, t)) { 103 | translate([0,0,3]) multmatrix(m=__rotate_from_to([0,0,1],spline_normal_unit(__s3,t))) 104 | cylinder(r1=0.1, r2=0, h=1, $fn=3); 105 | translate([0,0,6]) multmatrix(m=__rotate_from_to([0,0,1],spline_binormal_unit(__s3,t))) 106 | cylinder(r1=0.1, r2=0, h=1, $fn=3); 107 | } 108 | 109 | translate([0,0,9]) for(t=[0:0.025:len(__s3)]) 110 | multmatrix(spline_transform(__s3,t)) cube([1,1,0.1],center=true); 111 | -------------------------------------------------------------------------------- /src/libraries/scad-utils/trajectory.scad: -------------------------------------------------------------------------------- 1 | use 2 | 3 | function val(a=undef,default=undef) = a == undef ? default : a; 4 | function vec_is_undef(x,index_=0) = index_ >= len(x) ? true : 5 | is_undef(x[index_]) && vec_is_undef(x,index_+1); 6 | 7 | function is_undef(x) = len(x) > 0 ? vec_is_undef(x) : x == undef; 8 | // Either a or b, but not both 9 | function either(a,b,default=undef) = is_undef(a) ? (is_undef(b) ? default : b) : is_undef(b) ? a : undef; 10 | 11 | function translationv(left=undef,right=undef,up=undef,down=undef,forward=undef,backward=undef,translation=undef) = 12 | translationv_2( 13 | x = either(up,-down), 14 | y = either(right,-left), 15 | z = either(forward,-backward), 16 | translation = translation); 17 | 18 | function translationv_2(x,y,z,translation) = 19 | x == undef && y == undef && z == undef ? translation : 20 | is_undef(translation) ? [val(x,0),val(y,0),val(z,0)] 21 | : undef; 22 | 23 | function rotationv(pitch=undef,yaw=undef,roll=undef,rotation=undef) = 24 | rotation == undef ? [val(yaw,0),val(pitch,0),val(roll,0)] : 25 | pitch == undef && yaw == undef && roll == undef ? rotation : 26 | undef; 27 | 28 | function trajectory( 29 | left=undef, right=undef, 30 | up=undef, down=undef, 31 | forward=undef, backward=undef, 32 | translation=undef, 33 | 34 | pitch=undef, 35 | yaw=undef, 36 | roll=undef, 37 | rotation=undef 38 | ) = concat( 39 | translationv(left=left,right=right,up=up,down=down,forward=forward,backward=backward,translation=translation), 40 | rotationv(pitch=pitch,yaw=yaw,roll=roll,rotation=rotation) 41 | ); 42 | 43 | function rotationm(rotation=undef,pitch=undef,yaw=undef,roll=undef) = so3_exp(rotationv(rotation=rotation,pitch=pitch,yaw=yaw,roll=roll)); 44 | -------------------------------------------------------------------------------- /src/libraries/scad-utils/trajectory_path.scad: -------------------------------------------------------------------------------- 1 | use 2 | use 3 | 4 | function left_multiply(a,bs,i_=0) = i_ >= len(bs) ? [] : 5 | concat([ 6 | a * bs[i_] 7 | ], left_multiply(a,bs,i_+1)); 8 | 9 | 10 | function right_multiply(as,b,i_=0) = i_ >= len(as) ? [] : 11 | concat([ 12 | as[i_] * b 13 | ], right_multiply(as,b,i_+1)); 14 | 15 | function quantize_trajectory(trajectory,step=undef,start_position=0,steps=undef,i_=0,length_=undef) = 16 | length_ == undef ? quantize_trajectory( 17 | trajectory=trajectory, 18 | start_position=(step==undef?norm(take3(trajectory))/steps*start_position:start_position), 19 | length_=norm(take3(trajectory)), 20 | step=step,steps=steps,i_=i_) : 21 | (steps==undef?start_position > length_:i_>=steps) ? [] : 22 | concat([ 23 | // if steps is defined, ignore start_position 24 | se3_exp(trajectory*(steps==undef ? start_position/length_ 25 | : i_/(steps>1?steps-1:1))) 26 | ], quantize_trajectory(trajectory=trajectory,step=step,start_position=(steps==undef?start_position+step:start_position),steps=steps,i_=i_+1,length_=length_)); 27 | 28 | function close_trajectory_loop(trajectories) = concat(trajectories,[se3_ln(invert_rt(trajectories_end_position(trajectories)))]); 29 | 30 | function quantize_trajectories(trajectories,step=undef,start_position=0,steps=undef,loop=false,last_=identity4(),i_=0,current_length_=undef,j_=0) = 31 | // due to quantization differences, the last step may be missed. In that case, add it: 32 | loop==true ? quantize_trajectories( 33 | trajectories=close_trajectory_loop(trajectories), 34 | step=step, 35 | start_position = start_position, 36 | steps=steps, 37 | loop=false, 38 | last_=last_, 39 | i_=i_, 40 | current_length_=current_length_, 41 | j_=j_) : 42 | i_ >= len(trajectories) ? (j_ < steps ? [last_] : []) : 43 | current_length_ == undef ? 44 | quantize_trajectories( 45 | trajectories=trajectories, 46 | step = (step == undef ? trajectories_length(trajectories) / steps : step), 47 | start_position = (step == undef ? start_position * trajectories_length(trajectories) / steps : start_position), 48 | steps=steps, 49 | loop=loop, 50 | last_=last_, 51 | i_=i_, 52 | current_length_=norm(take3(trajectories[i_])), 53 | j_=j_) : 54 | concat( 55 | left_multiply(last_,quantize_trajectory( 56 | trajectory=trajectories[i_], 57 | start_position=start_position, 58 | step=step)), 59 | quantize_trajectories( 60 | trajectories=trajectories, 61 | step=step, 62 | start_position = start_position > current_length_ 63 | ? start_position - current_length_ 64 | : step - ((current_length_-start_position) % step), 65 | steps=steps, 66 | loop=loop, 67 | last_=last_ * se3_exp(trajectories[i_]), 68 | i_=i_+1, 69 | current_length_ = undef, 70 | j_=j_+len( 71 | 72 | quantize_trajectory( 73 | trajectory=trajectories[i_], 74 | start_position=start_position, 75 | step=step 76 | 77 | )) 78 | )) 79 | ; 80 | 81 | 82 | function trajectories_length(trajectories, i_=0) = i_ >= len(trajectories) ? 0 83 | : norm(take3(trajectories[i_])) + trajectories_length(trajectories,i_+1); 84 | 85 | 86 | function trajectories_end_position(rt,i_=0,last_=identity4()) = 87 | i_ >= len(rt) ? last_ : 88 | trajectories_end_position(rt, i_+1, last_ * se3_exp(rt[i_])); 89 | -------------------------------------------------------------------------------- /src/libraries/scad-utils/transformations.scad: -------------------------------------------------------------------------------- 1 | use 2 | use 3 | use 4 | 5 | /*! 6 | Creates a rotation matrix 7 | 8 | xyz = euler angles = rz * ry * rx 9 | axis = rotation_axis * rotation_angle 10 | */ 11 | function rotation(xyz=undef, axis=undef) = 12 | xyz != undef && axis != undef ? undef : 13 | xyz == undef ? se3_exp([0,0,0,axis[0],axis[1],axis[2]]) : 14 | len(xyz) == undef ? rotation(axis=[0,0,xyz]) : 15 | (len(xyz) >= 3 ? rotation(axis=[0,0,xyz[2]]) : identity4()) * 16 | (len(xyz) >= 2 ? rotation(axis=[0,xyz[1],0]) : identity4()) * 17 | (len(xyz) >= 1 ? rotation(axis=[xyz[0],0,0]) : identity4()); 18 | 19 | /*! 20 | Creates a scaling matrix 21 | */ 22 | function scaling(v) = [ 23 | [v[0],0,0,0], 24 | [0,v[1],0,0], 25 | [0,0,v[2],0], 26 | [0,0,0,1], 27 | ]; 28 | 29 | /*! 30 | Creates a translation matrix 31 | */ 32 | function translation(v) = [ 33 | [1,0,0,v[0]], 34 | [0,1,0,v[1]], 35 | [0,0,1,v[2]], 36 | [0,0,0,1], 37 | ]; 38 | 39 | // Convert between cartesian and homogenous coordinates 40 | function project(x) = subarray(x,end=len(x)-1) / x[len(x)-1]; 41 | 42 | function transform(m, list) = [for (p=list) project(m * vec4(p))]; 43 | function to_3d(list) = [ for(v = list) vec3(v) ]; 44 | -------------------------------------------------------------------------------- /src/libraries/skin.scad: -------------------------------------------------------------------------------- 1 | use 2 | use 3 | 4 | // Skin a set of profiles with a polyhedral mesh 5 | module skin(profiles, loop=false /* unimplemented */) { 6 | P = max_len(profiles); 7 | N = len(profiles); 8 | 9 | profiles = [ 10 | for (p = profiles) 11 | for (pp = augment_profile(to_3d(p),P)) 12 | pp 13 | ]; 14 | 15 | function quad(i,P,o) = [[o+i, o+i+P, o+i%P+P+1], [o+i, o+i%P+P+1, o+i%P+1]]; 16 | 17 | function profile_triangles(tindex) = [ 18 | for (index = [0:P-1]) 19 | let (qs = quad(index+1, P, P*(tindex-1)-1)) 20 | for (q = qs) q 21 | ]; 22 | 23 | triangles = [ 24 | for(index = [1:N-1]) 25 | for(t = profile_triangles(index)) 26 | t 27 | ]; 28 | 29 | start_cap = [range([0:P-1])]; 30 | end_cap = [range([P*N-1 : -1 : P*(N-1)])]; 31 | 32 | polyhedron(convexity=2, points=profiles, faces=concat(start_cap, triangles, end_cap)); 33 | } 34 | 35 | // Augments the profile with steiner points making the total number of vertices n 36 | function augment_profile(profile, n) = 37 | subdivide(profile,insert_extra_vertices_0([profile_lengths(profile),dup(0,len(profile))],n-len(profile))[1]); 38 | 39 | function subdivide(profile,subdivisions) = let (N=len(profile)) [ 40 | for (i = [0:N-1]) 41 | let(n = len(subdivisions)>0 ? subdivisions[i] : subdivisions) 42 | for (p = interpolate(profile[i],profile[(i+1)%N],n+1)) 43 | p 44 | ]; 45 | 46 | function interpolate(a,b,subdivisions) = [ 47 | for (index = [0:subdivisions-1]) 48 | let(t = index/subdivisions) 49 | a*(1-t)+b*t 50 | ]; 51 | 52 | function distribute_extra_vertex(lengths_count,ma_=-1) = ma_<0 ? distribute_extra_vertex(lengths_count, max_element(lengths_count[0])) : 53 | concat([set(lengths_count[0],ma_,lengths_count[0][ma_] * (lengths_count[1][ma_]+1) / (lengths_count[1][ma_]+2))], [increment(lengths_count[1],max_element(lengths_count[0]),1)]); 54 | 55 | function insert_extra_vertices_0(lengths_count,n_extra) = n_extra <= 0 ? lengths_count : 56 | insert_extra_vertices_0(distribute_extra_vertex(lengths_count),n_extra-1); 57 | 58 | // Find the index of the maximum element of arr 59 | function max_element(arr,ma_,ma_i_=-1,i_=0) = i_ >= len(arr) ? ma_i_ : 60 | i_ == 0 || arr[i_] > ma_ ? max_element(arr,arr[i_],i_,i_+1) : max_element(arr,ma_,ma_i_,i_+1); 61 | 62 | function max_len(arr) = max([for (i=arr) len(i)]); 63 | 64 | function increment(arr,i,x=1) = set(arr,i,arr[i]+x); 65 | 66 | function profile_lengths(profile) = [ 67 | for (i = [0:len(profile)-1]) 68 | profile_segment_length(profile,i) 69 | ]; 70 | 71 | function profile_segment_length(profile,i) = norm(profile[(i+1)%len(profile)] - profile[i]); 72 | 73 | // Generates an array with n copies of value (default 0) 74 | function dup(value=0,n) = [for (i = [1:n]) value]; 75 | -------------------------------------------------------------------------------- /src/settings.scad: -------------------------------------------------------------------------------- 1 | /* [Basic-Settings] */ 2 | 3 | // Length in units of key. A regular key is 1 unit; spacebar is usually 6.25 4 | $key_length = 1.0; // Range not working in thingiverse customizer atm [1:0.25:16] 5 | 6 | // What type of stem you want. Most people want Cherry. 7 | $stem_type = "cherry"; // [cherry, alps, rounded_cherry, box_cherry, filled, disable] 8 | 9 | // The stem is the hardest part to print, so this variable controls how much 'slop' there is in the stem 10 | // if your keycaps stick in the switch raise this value 11 | $stem_slop = 0.35; // Not working in thingiverse customizer atm [0:0.01:1] 12 | // broke this out. if your keycaps are falling off lower this value. only works for cherry stems rn 13 | $stem_inner_slop = 0.2; 14 | 15 | // Font size used for text 16 | $font_size = 6; 17 | 18 | // Set this to true if you're making a spacebar! 19 | $inverted_dish = false; 20 | 21 | // change aggressiveness of double sculpting 22 | // this is the radius of the cylinder the keytops are placed on 23 | $double_sculpt_radius = 200; 24 | 25 | 26 | // Support type. default is "flared" for easy FDM printing; bars are more realistic, and flat could be for artisans 27 | $support_type = "flared"; // [flared, bars, flat, disable] 28 | 29 | // Supports for the stem, as it often comes off during printing. Reccommended for most machines 30 | $stem_support_type = "tines"; // [tines, brim, disabled] 31 | 32 | // make legends outset instead of inset. 33 | // broken off from artisan support since who wants outset legends? 34 | $outset_legends = false; 35 | 36 | /* [Key] */ 37 | // Height in units of key. should remain 1 for most uses 38 | $key_height = 1.0; 39 | // Keytop thickness, aka how many millimeters between the inside and outside of the top surface of the key 40 | $keytop_thickness = 1; 41 | // Wall thickness, aka the thickness of the sides of the keycap. note this is the total thickness, aka 3 = 1.5mm walls 42 | $wall_thickness = 3; 43 | // Radius of corners of keycap 44 | $corner_radius = 1; 45 | // Width of the very bottom of the key 46 | $bottom_key_width = 18.16; 47 | // Height (from the front) of the very bottom of the key 48 | $bottom_key_height = 18.16; 49 | // How much less width there is on the top. eg top_key_width = bottom_key_width - width_difference 50 | $width_difference = 6; 51 | // How much less height there is on the top 52 | $height_difference = 4; 53 | // How deep the key is, before adding a dish 54 | $total_depth = 11.5; 55 | // The tilt of the dish in degrees. divided by key height 56 | $top_tilt = -6; 57 | // the y tilt of the dish in degrees. divided by key width. 58 | // for double axis sculpted keycaps and probably not much else 59 | $top_tilt_y = 0; 60 | // How skewed towards the back the top is (0 for center) 61 | $top_skew = 1.7; 62 | 63 | // how skewed towards the right the top is. unused, but implemented. 64 | // for double axis sculpted keycaps and probably not much else 65 | $top_skew_x = 0; 66 | 67 | /* [Stem] */ 68 | 69 | // How far the throw distance of the switch is. determines how far the 'cross' in the cherry switch digs into the stem, and how long the keystem needs to be before supports can start. luckily, alps and cherries have a pretty similar throw. can modify to have stouter keycaps for low profile switches, etc 70 | $stem_throw = 4; 71 | // Diameter of the outside of the rounded cherry stem 72 | $rounded_cherry_stem_d = 5.5; 73 | 74 | 75 | // How much higher the stem is than the bottom of the keycap. 76 | // Inset stem requires support but is more accurate in some profiles 77 | // can be negative to make outset stems! 78 | $stem_inset = 0; 79 | // How many degrees to rotate the stems. useful for sideways keycaps 80 | $stem_rotation = 0; 81 | // How many degrees to rotate the keycap, but _not_ inside features (the stem). 82 | $keycap_rotation = 0; 83 | 84 | /* [Shape] */ 85 | 86 | // Key shape type, determines the shape of the key. default is 'rounded square' 87 | $key_shape_type = "rounded_square"; 88 | // ISO enter needs to be linear extruded NOT from the center when not using skin. this tells the program how far up 'not from the center' is 89 | $linear_extrude_height_adjustment = 0; 90 | // How many slices will be made, to approximate curves on corners. Leave at 1 if you are not curving corners 91 | // If you're doing fancy bowed keycap sides, this controls how many slices you take 92 | $height_slices = 1; 93 | 94 | /* [Dish] */ 95 | 96 | // What type of dish the key has. note that unlike stems and supports a dish ALWAYS gets rendered. 97 | $dish_type = "cylindrical"; // [cylindrical, spherical, sideways cylindrical, old spherical, disable] 98 | // How deep the dish 'digs' into the top of the keycap. this is max depth, so you can't find the height from total_depth - dish_depth. besides the top is skewed anyways 99 | $dish_depth = 1; 100 | // How skewed in the x direction the dish is 101 | $dish_skew_x = 0; 102 | // How skewed in the y direction (height) the dish is 103 | $dish_skew_y = 0; 104 | 105 | 106 | $dish_offset_x = 0; 107 | 108 | // 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 109 | $dish_overdraw_width = 0; 110 | // Same as width but for height 111 | $dish_overdraw_height = 0; 112 | 113 | /* [Misc] */ 114 | // There's a bevel on the cherry stems to aid insertion / guard against first layer squishing making a hard-to-fit stem. 115 | $cherry_bevel = true; 116 | 117 | // How tall in mm the stem support is, if there is any. stem support sits around the keystem and helps to secure it while printing. 118 | $stem_support_height = .8; 119 | // Font used for text 120 | $font="DejaVu Sans Mono:style=Book"; 121 | // Whether or not to render fake keyswitches to check clearances 122 | $clearance_check = false; 123 | // Should be faster, also required for concave shapes 124 | 125 | // what kind of extrusion we use to create the keycap. "hull" is standard, "linear extrude" is legacy, "skin" is new and not well supported. 126 | $hull_shape_type = "hull"; // ["hull", "linear extrude", "skin"] 127 | 128 | // This doesn't work very well, but you can try 129 | $rounded_key = false; 130 | //minkowski radius. radius of sphere used in minkowski sum for minkowski_key function. 1.75 for G20 131 | $minkowski_radius = .33; 132 | 133 | /* [Features] */ 134 | 135 | //insert locating bump 136 | $key_bump = false; 137 | //height of the location bump from the top surface of the key 138 | $key_bump_depth = 0.5; 139 | //distance to move the bump from the front edge of the key 140 | $key_bump_edge = 0.4; 141 | 142 | /* [Hidden] */ 143 | 144 | // set this to true if you are making double sculpted keycaps 145 | $double_sculpted = false; 146 | 147 | //list of legends to place on a key format: [text, halign, valign, size] 148 | //halign = "left" or "center" or "right" 149 | //valign = "top" or "center" or "bottom" 150 | // Currently does not work with thingiverse customizer, and actually breaks it 151 | $legends = []; 152 | 153 | //list of front legends to place on a key format: [text, halign, valign, size] 154 | //halign = "left" or "center" or "right" 155 | //valign = "top" or "center" or "bottom" 156 | // Currently does not work with thingiverse customizer, and actually breaks it 157 | $front_legends = []; 158 | 159 | // print legends on the front of the key instead of the top 160 | $front_print_legends = false; 161 | 162 | // how recessed inset legends / artisans are from the top of the key 163 | $inset_legend_depth = 0.2; 164 | 165 | // Dimensions of alps stem 166 | $alps_stem = [4.45, 2.25]; 167 | 168 | // Dimensions of choc stem 169 | $choc_stem = [1.2, 3]; 170 | 171 | // Enable stabilizer stems, to hold onto your cherry or costar stabilizers 172 | $stabilizer_type = "costar_stabilizer"; // [costar_stabilizer, cherry_stabilizer, disable] 173 | 174 | // Ternaries are ONLY for customizer. they will NOT work if you're using this in 175 | // OpenSCAD. you should use stabilized(), openSCAD customizer, 176 | // or set $stabilizers directly 177 | // Array of positions of stabilizers 178 | $stabilizers = $key_length >= 6 ? [[-50, 0], [50, 0]] : $key_length >= 2 ? [[-12,0],[12,0]] : []; 179 | 180 | // Where the stems are in relation to the center of the keycap, in units. default is one in the center 181 | // Shouldn't work in thingiverse customizer, though it has been... 182 | $stem_positions = [[0,0]]; 183 | 184 | // colors 185 | $primary_color = [.2667,.5882,1]; 186 | $secondary_color = [.4412, .7, .3784]; 187 | $tertiary_color = [1, .6941, .2]; 188 | $quaternary_color = [.4078, .3569, .749]; 189 | $warning_color = [1,0,0, 0.15]; 190 | 191 | // how many facets circles will have when used in these features 192 | $minkowski_facets = 30; 193 | $shape_facets =30; 194 | 195 | 196 | 197 | // "flat" / "dished" / "disable" 198 | $inner_shape_type = "flat"; 199 | 200 | // default side_sculpting function, linear 201 | $side_sculpting = function(progress) 0; 202 | $corner_sculpting = function(progress) 0; 203 | 204 | // you probably shouldn't touch this, it's internal to sculpted_square 205 | // modify side sculpting with the $side_sculpting function in the key profile files 206 | $more_side_sculpting_factor = 0; 207 | 208 | // 3d surface functions (still in beta) 209 | 210 | // 3d surface settings 211 | // unused for now 212 | $3d_surface_size = 1; 213 | // 3d surface point resolution. $3d_surface_size / $3d_surface_step = steps per x / y 214 | $3d_surface_step = 1/20; 215 | 216 | // monotonically increasing function that distributes the points of the surface mesh 217 | // only for polar_3d_surface right now 218 | // if it's linear it's a grid. sin(dim) * size concentrates detail around the edges 219 | sinusoidal_surface_distribution = function(dim,size) sin(dim) * size; 220 | linear_surface_distribution = function(dim,size) dim; 221 | 222 | $surface_distribution_function = sinusoidal_surface_distribution; 223 | 224 | // the function that actually determines what the surface is. 225 | // feel free to override, the last one wins 226 | 227 | // debug 228 | // $surface_function = function(x,y) 1; 229 | cylindrical_surface = function(x,y) (sin(acos(x/$3d_surface_size))); 230 | spherical_surface = function(x,y) (1 - (x/$3d_surface_size)^2)^0.5 * (1 - (y/$3d_surface_size)^2)^0.5; 231 | // looks a lot like mt3 232 | quartic_surface = function(x,y) (1 - (x/$3d_surface_size)^4)^0.5 * (1 - (y/$3d_surface_size)^4)^0.5; 233 | ripple_surface = function(x,y) cos((x^2+y^2)^0.5 * 50)/4 + 0.75; 234 | rosenbrocks_banana_surface = function(x,y) (pow(1-(x/$3d_surface_size))^2 + 100 * pow((y/$3d_surface_size)-(x/$3d_surface_size)^2)^2)/200 + 0.1; 235 | spike_surface = function(x,y) 1/(((x/$3d_surface_size)^2+(y/$3d_surface_size)^2)^0.5) + .01; 236 | random_surface = function(x,y) sin(rands(0,90,1,x+y)[0]); 237 | bumps_surface = function(x,y) sin(20*x)*cos(20*y)/3+1; 238 | 239 | $surface_function = bumps_surface; // bumps_surface; 240 | 241 | // can be used to smooth the corners of the 3d surface function, to make the dishes add / subtract less height. can really do anything it's just multiplying, but that's what I use it for 242 | $corner_smoothing_surface_function = function(x,y) 1; 243 | // $corner_smoothing_surface_function = function(x,y) (1 - pow(abs(x), 5)/$3d_surface_size) * (1 - pow(abs(y),5)/$3d_surface_size); 244 | 245 | // ripples 246 | /* 247 | // Rosenbrock's banana 248 | /* $ 249 | // y=x revolved around the y axis 250 | /* $surface_function = */ 251 | /* $surface_function = */ -------------------------------------------------------------------------------- /src/shapes.scad: -------------------------------------------------------------------------------- 1 | include 2 | include 3 | include 4 | include 5 | include 6 | include 7 | include 8 | 9 | // size: at progress 0, the shape is supposed to be this size 10 | // delta: at progress 1, the keycap is supposed to be size - delta 11 | // progress: how far along the transition you are. 12 | // it's not always linear - specifically sculpted_square 13 | module key_shape(size, delta, progress = 0) { 14 | if ($key_shape_type == "iso_enter") { 15 | ISO_enter_shape(size, delta, progress); 16 | } else if ($key_shape_type == "sculpted_square") { 17 | sculpted_square_shape(size, delta, progress); 18 | } else if ($key_shape_type == "rounded_square") { 19 | rounded_square_shape(size, delta, progress); 20 | } else if ($key_shape_type == "flat_sided_square") { 21 | // rounded_square_shape handles this 22 | rounded_square_shape(size, delta, progress); 23 | } else if ($key_shape_type == "square") { 24 | square_shape(size, delta, progress); 25 | } else if ($key_shape_type == "oblong") { 26 | oblong_shape(size, delta, progress); 27 | } else if ($key_shape_type == "hexagon") { 28 | regular_polygon_shape(size, delta, progress); 29 | } else if ($key_shape_type == "octagon") { 30 | regular_polygon_shape(size, delta, progress, sides=8); 31 | } else if ($key_shape_type == "circular") { 32 | regular_polygon_shape(size, delta, progress, sides=36); 33 | } else { 34 | echo("Warning: unsupported $key_shape_type"); 35 | } 36 | } 37 | 38 | function skin_key_shape(size, delta, progress = 0, thickness_difference) = 39 | $key_shape_type == "rounded_square" ? 40 | skin_rounded_square(size, delta, progress, thickness_difference) : 41 | $key_shape_type == "sculpted_square" ? 42 | skin_sculpted_square_shape(size, delta, progress, thickness_difference) : 43 | $key_shape_type == "square" ? 44 | skin_square_shape(size, delta, progress, thickness_difference) : 45 | $key_shape_type == "iso_enter" ? 46 | skin_iso_enter_shape(size, delta, progress, thickness_difference) : 47 | echo("Warning: unsupported $key_shape_type for skin shape. disable skin_extrude_shape or pick a new shape"); 48 | -------------------------------------------------------------------------------- /src/shapes/ISO_enter.scad: -------------------------------------------------------------------------------- 1 | include <../functions.scad> 2 | include <../libraries/round-anything/polyround.scad> 3 | 4 | width_ratio = unit_length(1.25) / unit_length(1.5); 5 | height_ratio = unit_length(1) / unit_length(2); 6 | 7 | 8 | 9 | module ISO_enter_shape(size, delta, progress){ 10 | width = size[0]; 11 | height = size[1]; 12 | 13 | 14 | // in order to make the ISO keycap shape generic, we are going to express the 15 | // 'elbow point' in terms of ratios. an ISO enter is just a 1.5u key stuck on 16 | // top of a 1.25u key, but since our key_shape function doesnt understand that 17 | // and wants to pass just width and height, we make these ratios to know where 18 | // to put the elbow joint 19 | 20 | delta = delta / 2; 21 | 22 | pointArray = [ 23 | [ 0-delta.x, 0-delta.y], // top right 24 | [ 0-delta.x, -height+delta.y], // bottom right 25 | [-width * width_ratio+delta.x, -height+delta.y], // bottom left 26 | [-width * width_ratio + delta.x,-height * height_ratio+delta.y], // inner middle point 27 | [ -width + delta.x,-height * height_ratio + delta.y], // outer middle point 28 | [ -width + delta.x, 0-delta.y] // top left 29 | ]; 30 | 31 | minkowski(){ 32 | circle(r=$corner_radius); 33 | // gives us rounded inner corner 34 | offset(r=-$corner_radius*2) { 35 | translate([(width * width_ratio)/2, height/2]) polygon(points=pointArray); 36 | } 37 | } 38 | } 39 | 40 | function iso_enter_vertices(size, delta, progress, thickness_difference) = [ 41 | [ 0-delta.x/2 * progress - thickness_difference/8, 0 - delta.y / 2 * progress - thickness_difference/8], // top right 42 | [ 0-delta.x/2 * progress - thickness_difference/8, -size[1] + delta.y / 2 * progress + thickness_difference/8], // bottom right 43 | [-size[0] * width_ratio + delta.x/2 * progress + thickness_difference/8, -size[1] + delta.y / 2 * progress + thickness_difference/8], // bottom left 44 | [-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 45 | [ -size[0] + delta.x/2 * progress + thickness_difference/8,-size[1] * height_ratio + delta.y / 2 * progress + thickness_difference/2], // outer middle point 46 | [ -size[0] + delta.x/2 * progress + thickness_difference/8, 0 - delta.y / 2 * progress - thickness_difference/8] // top left 47 | ] + [ 48 | [(size[0] * width_ratio)/2, size[1]/2 ], 49 | [(size[0] * width_ratio)/2, size[1]/2 ], 50 | [(size[0] * width_ratio)/2, size[1]/2 ], 51 | [(size[0] * width_ratio)/2, size[1]/2 ], 52 | [(size[0] * width_ratio)/2, size[1]/2 ], 53 | [(size[0] * width_ratio)/2, size[1]/2 ] 54 | ]; 55 | 56 | // no rounding on the corners at all 57 | function skin_iso_enter_shape(size, delta, progress, thickness_difference) = 58 | polyRound( 59 | add_rounding( 60 | iso_enter_vertices( 61 | size, 62 | [delta.x - $side_sculpting(progress), delta.y - $side_sculpting(progress)], 63 | progress, 64 | thickness_difference 65 | ), 66 | $corner_radius + $corner_sculpting(progress) 67 | ), 68 | $shape_facets 69 | ); 70 | -------------------------------------------------------------------------------- /src/shapes/oblong.scad: -------------------------------------------------------------------------------- 1 | module oblong_shape(size, delta, progress) { 2 | // .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 3 | height = size[1] - delta[1] * progress - .05; 4 | 5 | if (progress < 0.5) { 6 | } else { 7 | offset(r=height / 2) { 8 | square(size - [height, height] - delta * progress, center=true); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/shapes/regular_polygon.scad: -------------------------------------------------------------------------------- 1 | // we do this weird key_shape_type check here because rounded_square uses 2 | // square_shape, and we want flat sides to work for that too. 3 | // could be refactored, idk 4 | module regular_polygon_shape(size, delta, progress, sides=6){ 5 | // https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/undersized_circular_objects 6 | fudge = 1/cos(180/sides); 7 | diameter = (size.x - delta.x * progress - $corner_radius*2) * fudge; 8 | offset(r=$corner_radius) rotate([0,0,360/sides/2]) circle(d = diameter, $fn=sides); 9 | } 10 | 11 | 12 | 13 | // TODO not implemented 14 | function skin_regular_polygon_shape(size, delta, progress, thickness_difference, sides=6) = echo("skin regular polygon not implemented"); 15 | -------------------------------------------------------------------------------- /src/shapes/rounded_square.scad: -------------------------------------------------------------------------------- 1 | include 2 | include <../libraries/round-anything/polyround.scad> 3 | 4 | module rounded_square_shape(size, delta, progress, center = true) { 5 | offset(r=$corner_radius, $fa=360/$shape_facets){ 6 | square_shape([size.x - $corner_radius*2, size.y - $corner_radius*2], delta, progress); 7 | } 8 | } 9 | 10 | // for skin 11 | function skin_rounded_square(size, delta, progress, thickness_difference) = 12 | polyRound(add_rounding(rectangle_profile(size - (delta * progress)), $corner_radius), $shape_facets/4); 13 | -------------------------------------------------------------------------------- /src/shapes/sculpted_square.scad: -------------------------------------------------------------------------------- 1 | // rounded square shape with additional sculpting functions to better approximate 2 | 3 | // side sculpting functions 4 | // bows the sides out on stuff like SA and DSA keycaps 5 | function side_sculpting(progress) = (1 - progress) * $side_sculpting_factor; 6 | // makes the rounded corners of the keycap grow larger as they move upwards 7 | function corner_sculpting(progress) = pow(progress, 2) * $corner_sculpting_factor; 8 | 9 | module sculpted_square_shape(size, delta, progress) { 10 | width = size[0]; 11 | height = size[1]; 12 | 13 | width_difference = delta[0]; 14 | height_difference = delta[1]; 15 | // makes the sides bow 16 | extra_side_size = $side_sculpting(progress); 17 | // makes the rounded corners of the keycap grow larger as they move upwards 18 | extra_corner_size = $corner_sculpting(progress); 19 | 20 | // computed values for this slice 21 | extra_width_this_slice = (width_difference - extra_side_size) * progress; 22 | extra_height_this_slice = (height_difference - extra_side_size) * progress; 23 | extra_corner_radius_this_slice = ($corner_radius + extra_corner_size); 24 | 25 | square_size = [ 26 | width - extra_width_this_slice, 27 | height - extra_height_this_slice 28 | ]; 29 | 30 | offset(r = extra_corner_radius_this_slice, $fa=360/$shape_facets) { 31 | offset(r = -extra_corner_radius_this_slice) { 32 | side_rounded_square(square_size, r = $more_side_sculpting_factor * progress); 33 | } 34 | } 35 | } 36 | 37 | function new_side_rounded_square(size, r, cornerRadius=0) = 38 | let( 39 | width = (size.x - r)/2, 40 | height = (size.y - r)/2, 41 | 42 | // fudge numbers! the radius conflict resolution in polyround smooths out 43 | // the entire shape based on the ratios between conflicting radii. bumping 44 | // these up makes the whole shape more fluid 45 | widthRadius = r ? width*8 : 0, 46 | heightRadius = r ? height*8 : 0, 47 | 48 | bow = r/2, 49 | 50 | // close enough :/ 51 | facets = 360 / $shape_facets/2, 52 | 53 | points = [ 54 | [-width,-height,cornerRadius], 55 | [0,-height-bow,widthRadius], 56 | [width,-height,cornerRadius], 57 | [width + bow,0,heightRadius], 58 | [width,height,cornerRadius], 59 | [0,height + bow,widthRadius], 60 | [-width,height,cornerRadius], 61 | [-width-bow,0,heightRadius] 62 | ] 63 | ) polyRound(points,facets); 64 | 65 | 66 | function skin_sculpted_square_shape(size, delta, progress, thickness_difference) = 67 | let( 68 | width = size[0], 69 | height = size[1], 70 | 71 | width_difference = delta[0], 72 | height_difference = delta[1], 73 | // makes the sides bow 74 | extra_side_size = $side_sculpting(progress), 75 | // makes the rounded corners of the keycap grow larger as they move upwards 76 | extra_corner_size = $corner_sculpting(progress), 77 | 78 | // computed values for this slice 79 | extra_width_this_slice = (width_difference - extra_side_size) * progress, 80 | extra_height_this_slice = (height_difference - extra_side_size) * progress, 81 | extra_corner_radius_this_slice = ($corner_radius + extra_corner_size), 82 | 83 | square_size = [ 84 | width - extra_width_this_slice - thickness_difference, 85 | height - extra_height_this_slice - thickness_difference 86 | ] 87 | ) new_side_rounded_square(square_size, $more_side_sculpting_factor * progress, extra_corner_radius_this_slice); 88 | 89 | 90 | module side_rounded_square(size, r) { 91 | iw = size.x - 2 * r; 92 | ih = size.y - 2 * r; 93 | resolution = 100; 94 | sr = r / resolution * 2; 95 | sh = ih / resolution; 96 | sw = iw / resolution; 97 | union() { 98 | if (sr > 0) { 99 | translate([-iw/2, 0]) scale([sr, sh]) circle(d = resolution, $fa=360/$shape_facets); 100 | translate([iw/2, 0]) scale([sr, sh]) circle(d = resolution, $fa=360/$shape_facets); 101 | translate([0, -ih/2]) scale([sw, sr]) circle(d = resolution, $fa=360/$shape_facets); 102 | translate([0, ih/2]) scale([sw, sr]) circle(d = resolution, $fa=360/$shape_facets); 103 | } 104 | square([iw, ih], center=true); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/shapes/square.scad: -------------------------------------------------------------------------------- 1 | use <../functions.scad> 2 | 3 | // we do this weird key_shape_type check here because rounded_square uses 4 | // square_shape, and we want flat sides to work for that too. 5 | // could be refactored, idk 6 | module square_shape(size, delta, progress){ 7 | if ($key_shape_type == "flat_sided_square") { 8 | flat_sided_square_shape(size, delta,progress); 9 | } else { 10 | square(size - delta * progress, center = true); 11 | } 12 | } 13 | /* 14 | [-size.x /2,-size.y / 2], 15 | [size.x / 2,-size.y / 2], 16 | [size.x / 2, size.y / 2], 17 | [-size.x / 2, size.y / 2] */ 18 | 19 | // for side-printed keycaps. Any amount of top tilt (on a keycap with a smaller 20 | // top than bottom) makes the left and right side of the keycap convex. This 21 | // shape makes the sides flat by making the top a trapezoid. 22 | // This obviously doesn't work with rounded sides at all 23 | module flat_sided_square_shape(size, delta, progress) { 24 | polygon(skin_flat_sided_square_shape(size, delta, progress)); 25 | } 26 | 27 | function skin_flat_sided_square_shape(size,delta,progress) = [ 28 | [(-size.x + (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2, (-size.y + delta.y * progress)/2], 29 | [(size.x - (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2,(-size.y + delta.y * progress)/2], 30 | [(size.x - (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2], 31 | [(-size.x + (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2] 32 | ]; 33 | 34 | function rectangle_profile(size) = [ 35 | [-size.x/2, -size.y/2], 36 | [size.x/2, -size.y/2], 37 | [size.x/2, size.y/2], 38 | [-size.x/2, size.y/2], 39 | ]; 40 | 41 | function skin_square_shape(size, delta, progress, thickness_difference) = 42 | let( 43 | width = size[0], 44 | height = size[1], 45 | 46 | width_difference = delta[0] * progress, 47 | height_difference = delta[1] * progress, 48 | 49 | square_size = [ 50 | width - width_difference - thickness_difference, 51 | height - height_difference - thickness_difference 52 | ] 53 | ) $key_shape_type == "flat_sided_square" ? skin_flat_sided_square_shape(size, delta, progress) : rectangle_profile(square_size); 54 | -------------------------------------------------------------------------------- /src/stem_supports.scad: -------------------------------------------------------------------------------- 1 | include 2 | include 3 | 4 | 5 | //whole stem, alps or cherry, trimmed to fit 6 | module stem_support(support_type, stem_type, stem_support_height, slop){ 7 | if (support_type == "brim") { 8 | brim_support(stem_type, stem_support_height, slop); 9 | } else if (support_type == "tines") { 10 | tines_support(stem_type, stem_support_height, slop); 11 | } else if (support_type == "disable") { 12 | children(); 13 | } else { 14 | echo("Warning: unsupported $stem_support_type"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/stem_supports/brim.scad: -------------------------------------------------------------------------------- 1 | include <../functions.scad> 2 | include <../stems/cherry.scad> 3 | 4 | module brim_support(stem_type, stem_support_height, slop) { 5 | if(stem_type == "alps") { 6 | linear_extrude(height=stem_support_height) { 7 | offset(r=1){ 8 | square($alps_stem + [2,2], center=true); 9 | } 10 | } 11 | } else if (stem_type == "cherry" || stem_type == "costar_stabilizer") { 12 | difference() { 13 | linear_extrude(height = stem_support_height){ 14 | offset(r=1){ 15 | square(outer_cherry_stem(slop) + [2,2], center=true); 16 | } 17 | } 18 | 19 | inside_cherry_cross($stem_inner_slop); 20 | } 21 | } else if (stem_type == "rounded_cherry") { 22 | difference() { 23 | cylinder(d=$rounded_cherry_stem_d * 2, h=stem_support_height); 24 | inside_cherry_cross($stem_inner_slop); 25 | } 26 | } else if (stem_type == "box_cherry") { 27 | difference() { 28 | linear_extrude(height = stem_support_height){ 29 | offset(r=1){ 30 | square(outer_box_cherry_stem(slop) + [2,2], center=true); 31 | } 32 | } 33 | 34 | inside_cherry_cross($stem_inner_slop); 35 | } 36 | } else if (stem_type == "cherry_stabilizer") { 37 | difference() { 38 | linear_extrude(height = stem_support_height){ 39 | offset(r=1){ 40 | square(outer_cherry_stabilizer_stem(slop) + [2,2], center=true); 41 | } 42 | } 43 | 44 | inside_cherry_cross($stem_inner_slop); 45 | } 46 | } else if(stem_type == "choc") { 47 | translate([-5.7/2,0,0]) linear_extrude(height=stem_support_height) { 48 | offset(r=1){ 49 | square($choc_stem + [3,3], center=true); 50 | } 51 | } 52 | 53 | translate([5.7/2,0,0]) linear_extrude(height=stem_support_height) { 54 | offset(r=1){ 55 | square($choc_stem + [3,3], center=true); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/stem_supports/tines.scad: -------------------------------------------------------------------------------- 1 | include <../functions.scad> 2 | include <../stems/cherry.scad> 3 | 4 | /* NOTE: every reference to total_key_width and total_key_height 5 | * is multiplied by two in order to account for offset stems 6 | */ 7 | module centered_tines(stem_support_height) { 8 | if ($key_length < 2) { 9 | translate([0,0,$stem_support_height / 2]) { 10 | cube([total_key_width()*2, 0.5, $stem_support_height], center = true); 11 | } 12 | } 13 | 14 | translate([0,0,$stem_support_height / 2]) { 15 | cube([ 16 | 1, 17 | total_key_height()*2, 18 | $stem_support_height 19 | ], 20 | center = true); 21 | } 22 | } 23 | 24 | module tines_support(stem_type, stem_support_height, slop) { 25 | if (stem_type == "cherry" || stem_type == "costar_stabilizer") { 26 | difference () { 27 | union() { 28 | if ($key_length < 2) { 29 | translate([0,0,$stem_support_height / 2]) { 30 | cube([ 31 | total_key_width()*2, 32 | 0.5, 33 | $stem_support_height 34 | ], center = true); 35 | } 36 | } 37 | 38 | // 2 vertical tines holding either side of the cruciform 39 | for (x = [2, -2]) { 40 | translate([x,0,$stem_support_height / 2]) { 41 | cube([ 42 | 0.5, 43 | total_key_height()*2, // this is to extend past 44 | $stem_support_height 45 | ], center = true); 46 | } 47 | } 48 | } 49 | 50 | inside_cherry_cross($stem_inner_slop); 51 | } 52 | } else if (stem_type == "cherry_stabilizer") { 53 | difference () { 54 | for (x = [1.15, -1.15]) { 55 | translate([x,0,$stem_support_height / 2]) { 56 | cube([ 57 | 1, 58 | total_key_height()*2, 59 | $stem_support_height 60 | ], center = true); 61 | } 62 | } 63 | 64 | inside_cherry_stabilizer_cross(slop); 65 | } 66 | } else if (stem_type == "box_cherry") { 67 | difference () { 68 | centered_tines(stem_support_height); 69 | 70 | inside_cherry_cross($stem_inner_slop); 71 | } 72 | } else if (stem_type == "rounded_cherry") { 73 | difference () { 74 | centered_tines(stem_support_height); 75 | 76 | inside_cherry_cross($stem_inner_slop); 77 | } 78 | } else if (stem_type == "alps"){ 79 | centered_tines(stem_support_height); 80 | } else if (stem_type == "choc"){ 81 | if ($key_length < 2) translate([0,0,$stem_support_height / 2]) cube([total_key_width(), 0.42, $stem_support_height], center = true); 82 | /* translate([-5.7/2,0,$stem_support_height / 2]) cube([0.5, total_key_height(), $stem_support_height], center = true); */ 83 | /* translate([5.7/2,0,$stem_support_height / 2]) cube([0.5, total_key_height(), $stem_support_height], center = true); */ 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/stems.scad: -------------------------------------------------------------------------------- 1 | include 2 | include 3 | include 4 | include 5 | include 6 | include 7 | include 8 | 9 | 10 | //whole stem, alps or cherry, trimmed to fit 11 | module stem(stem_type, depth, slop, throw){ 12 | if (stem_type == "alps") { 13 | alps_stem(depth, slop, throw); 14 | } else if (stem_type == "cherry" || stem_type == "costar_stabilizer") { 15 | cherry_stem(depth, slop, throw); 16 | } else if (stem_type == "rounded_cherry") { 17 | rounded_cherry_stem(depth, slop, throw); 18 | } else if (stem_type == "box_cherry") { 19 | box_cherry_stem(depth, slop, throw); 20 | } else if (stem_type == "filled") { 21 | filled_stem(); 22 | } else if (stem_type == "cherry_stabilizer") { 23 | cherry_stabilizer_stem(depth, slop, throw); 24 | } else if (stem_type == "choc") { 25 | choc_stem(depth, slop, throw); 26 | } else if (stem_type == "disable") { 27 | children(); 28 | } else { 29 | echo("Warning: unsupported $stem_type: "); 30 | echo(stem_type); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/stems/alps.scad: -------------------------------------------------------------------------------- 1 | module alps_stem(depth, slop, throw){ 2 | linear_extrude(height=depth) { 3 | square($alps_stem, center = true); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/stems/box_cherry.scad: -------------------------------------------------------------------------------- 1 | include <../functions.scad> 2 | include 3 | 4 | module box_cherry_stem(depth, slop, throw) { 5 | difference(){ 6 | // outside shape 7 | linear_extrude(height = depth) { 8 | offset(r=1){ 9 | square(outer_box_cherry_stem(slop) - [2,2], center=true); 10 | } 11 | } 12 | 13 | // inside cross 14 | inside_cherry_cross($stem_inner_slop); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/stems/cherry.scad: -------------------------------------------------------------------------------- 1 | include <../functions.scad> 2 | 3 | // extra length to the vertical tine of the inside cherry cross 4 | // splits the stem into halves - allows easier fitment 5 | extra_vertical = 100; 6 | 7 | module inside_cherry_cross(slop) { 8 | // inside cross 9 | // translation purely for aesthetic purposes, to get rid of that awful lattice 10 | translate([0,0,-SMALLEST_POSSIBLE]) { 11 | linear_extrude(height = $stem_throw) { 12 | square(cherry_cross(slop, extra_vertical)[0], center=true); 13 | square(cherry_cross(slop, extra_vertical)[1], center=true); 14 | } 15 | } 16 | 17 | // Guides to assist insertion and mitigate first layer squishing 18 | if ($cherry_bevel){ 19 | for (i = cherry_cross(slop, extra_vertical)) hull() { 20 | linear_extrude(height = 0.01, center = false) offset(delta = 0.4) square(i, center=true); 21 | translate([0, 0, 0.5]) linear_extrude(height = 0.01, center = false) square(i, center=true); 22 | } 23 | } 24 | } 25 | 26 | module cherry_stem(depth, slop, throw) { 27 | difference(){ 28 | // outside shape 29 | linear_extrude(height = depth) { 30 | offset(r=1){ 31 | square(outer_cherry_stem(slop) - [2,2], center=true); 32 | } 33 | } 34 | 35 | inside_cherry_cross($stem_inner_slop); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/stems/cherry_stabilizer.scad: -------------------------------------------------------------------------------- 1 | include <../functions.scad> 2 | 3 | // extra length to the vertical tine of the inside cherry cross 4 | // splits the stem into halves - allows easier fitment 5 | extra_vertical = 0.6; 6 | 7 | module inside_cherry_stabilizer_cross(slop, throw) { 8 | // inside cross 9 | // translation purely for aesthetic purposes, to get rid of that awful lattice 10 | translate([0,0,-SMALLEST_POSSIBLE]) { 11 | linear_extrude(height = throw) { 12 | square(cherry_cross(slop, extra_vertical)[0], center=true); 13 | square(cherry_cross(slop, extra_vertical)[1], center=true); 14 | } 15 | } 16 | } 17 | 18 | module cherry_stabilizer_stem(depth, slop, throw) { 19 | difference(){ 20 | // outside shape 21 | linear_extrude(height = depth) { 22 | offset(r=1){ 23 | square(outer_cherry_stabilizer_stem(slop) - [2,2], center=true); 24 | } 25 | } 26 | 27 | inside_cherry_stabilizer_cross(slop, throw); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/stems/choc.scad: -------------------------------------------------------------------------------- 1 | separation = 5.7; 2 | 3 | positions = [ 4 | [separation/2, 0], 5 | [-separation/2, 0], 6 | ]; 7 | 8 | // TODO throw not used 9 | module choc_stem(depth, slop, throw){ 10 | for (position=positions) { 11 | translate([position.x,position.y, depth/2]) single_choc_stem(depth, slop); 12 | } 13 | } 14 | 15 | module single_choc_stem(depth, slop) { 16 | cube([$choc_stem.x - slop, $choc_stem.y - slop, depth], center=true); 17 | } 18 | -------------------------------------------------------------------------------- /src/stems/filled.scad: -------------------------------------------------------------------------------- 1 | module filled_stem(_depth, _slop, _throw) { 2 | // I broke the crap out of this stem type due to the changes I made around how stems are differenced 3 | // now that we just take the dish out of stems in order to support stuff like 4 | // bare stem keycaps (and buckling spring eventually) we can't just make a 5 | // cube. shape() works but means that you certainly couldn't render this 6 | // stem without the presence of the entire library 7 | 8 | shape($wall_thickness); 9 | } 10 | -------------------------------------------------------------------------------- /src/stems/rounded_cherry.scad: -------------------------------------------------------------------------------- 1 | include <../functions.scad> 2 | include 3 | 4 | module rounded_cherry_stem(depth, slop, throw) { 5 | difference(){ 6 | cylinder(d=$rounded_cherry_stem_d, h=depth); 7 | 8 | // inside cross 9 | // translation purely for aesthetic purposes, to get rid of that awful lattice 10 | inside_cherry_cross($stem_inner_slop); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/supports.scad: -------------------------------------------------------------------------------- 1 | include 2 | include 3 | include 4 | 5 | module supports(type, stem_type, loft, height) { 6 | if (type == "flared") { 7 | flared(stem_type, loft, height); 8 | } else if (type == "flat") { 9 | flat(stem_type, loft, height); 10 | } else if (type == "bars") { 11 | bars(stem_type, loft, height); 12 | } else if (type == "disable") { 13 | children(); 14 | } else { 15 | echo("Warning: unsupported $support_type"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/supports/bars.scad: -------------------------------------------------------------------------------- 1 | module bars(stem_type, loft, height) { 2 | translate([0,0,loft + height / 2]){ 3 | cube([2, 100, height], center = true); 4 | cube([100, 2, height], center = true); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/supports/flared.scad: -------------------------------------------------------------------------------- 1 | include <../functions.scad> 2 | // TODO this define doesn't do anything besides tell me I used flat() in this file 3 | // is it better than not having it at all? 4 | include <./flat.scad> 5 | 6 | // figures out the scale factor needed to make a 45 degree wall 7 | function scale_for_45(height, starting_size) = (height * 2 + starting_size) / starting_size; 8 | 9 | // complicated since we want the different stems to work well 10 | // also kind of messy... oh well 11 | module flared(stem_type, loft, height) { 12 | // flat support. straight flat support has a tendency to shear off; flared support 13 | // all the way to the top has a tendency to warp the outside of the keycap. 14 | // hopefully the compromise is both 15 | flat(stem_type, loft + height/4, height); 16 | 17 | translate([0,0,loft]){ 18 | if (stem_type == "rounded_cherry") { 19 | linear_extrude(height=height, scale = scale_for_45(height, $rounded_cherry_stem_d)){ 20 | circle(d=$rounded_cherry_stem_d); 21 | } 22 | } else if (stem_type == "alps") { 23 | alps_scale = [scale_for_45(height, $alps_stem[0]), scale_for_45(height, $alps_stem[1])]; 24 | linear_extrude(height=height, scale = alps_scale){ 25 | square($alps_stem, center=true); 26 | } 27 | } else if (stem_type == "box_cherry") { 28 | // always render cherry if no stem type. this includes stem_type = false! 29 | // this avoids a bug where the keycap is rendered filled when not desired 30 | cherry_scale = [scale_for_45(height, outer_box_cherry_stem($stem_slop)[0]), scale_for_45(height, outer_box_cherry_stem($stem_slop)[1])]; 31 | linear_extrude(height=height, scale = cherry_scale){ 32 | offset(r=1){ 33 | square(outer_box_cherry_stem($stem_slop) - [2,2], center=true); 34 | } 35 | } 36 | } else if (stem_type == "cherry_stabilizer") { 37 | cherry_scale = [scale_for_45(height, outer_cherry_stabilizer_stem($stem_slop)[0]), scale_for_45(height, outer_cherry_stabilizer_stem($stem_slop)[1])]; 38 | linear_extrude(height=height, scale = cherry_scale){ 39 | offset(r=1){ 40 | square(outer_cherry_stabilizer_stem($stem_slop) - [2,2], center=true); 41 | } 42 | } 43 | } else if (stem_type == "choc") { 44 | // single support, just the stem 45 | new_choc_scale = [scale_for_45(height, $choc_stem[0] + 5.7 - $stem_slop), scale_for_45(height, $choc_stem[1])]; 46 | translate([0,0,0]) linear_extrude(height=height, scale = new_choc_scale){ 47 | // TODO make a choc_stem() function so it can build in the slop 48 | square([$choc_stem[0] + 5.7 - $stem_slop, $choc_stem[1] - $stem_slop], center=true); 49 | } 50 | 51 | } else { 52 | // always render cherry if no stem type. this includes stem_type = false! 53 | // this avoids a bug where the keycap is rendered filled when not desired 54 | cherry_scale = [scale_for_45(height, outer_cherry_stem($stem_slop)[0]), scale_for_45(height, outer_cherry_stem($stem_slop)[1])]; 55 | linear_extrude(height=height, scale = cherry_scale){ 56 | offset(r=1){ 57 | square(outer_cherry_stem($stem_slop) - [2,2], center=true); 58 | } 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/supports/flat.scad: -------------------------------------------------------------------------------- 1 | module flat(stem_type, loft, height) { 2 | translate([0,0,loft + 500]){ 3 | cube(1000, center=true); 4 | } 5 | } 6 | --------------------------------------------------------------------------------