remove models directory and switch to generating them via script

This commit is contained in:
Robert Sheldon 2018-07-04 21:12:07 -04:00
parent c8b4011fac
commit dc9b2a5aa6
8 changed files with 98 additions and 39 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
node_modules/ node_modules/
*.scad.stl *.scad.stl
models/

View File

@ -617,14 +617,10 @@ module bump(depth=undef) {
children(); children();
} }
module one_single_key(profile, row, unsculpted) { module row_profile(profile, unsculpted = false) {
key_profile(profile, unsculpted ? 3 : row) key();
}
module one_row_profile(profile, unsculpted = false) {
rows = [5, 1, 2, 3, 4]; rows = [5, 1, 2, 3, 4];
for(row = [0:len(rows)-1]) { for(row = [0:len(rows)-1]) {
translate_u(0, -row) one_single_key(profile, rows[row], unsculpted); translate_u(0, -row) key_profile(profile, unsculpted ? 3 : rows[row]);
} }
} }

View File

@ -1,27 +1,3 @@
require './openscad.rb'
def expand(filename) OpenSCAD::expand_openSCAD_file(ARGV[1] || 'customizer_base.scad', 'customizer.scad')
lines = File.readlines(filename)
old_dir = Dir.getwd
Dir.chdir File.dirname(filename)
lines = lines.flat_map do |line|
if line =~ /(include|use)\s*<(.*)>/
# File.readlines("./#{$2}")
expand("./#{$2}")
# in lieu of actually implementing `use`, we can just cull this final line from key.scad
elsif line =~ /example\_key\(\);/
""
else
line
end
end
Dir.chdir old_dir
lines
end
lines = expand(ARGV[1] || 'customizer_base.scad')
f = File.open('customizer.scad', 'w')
f.write lines.join

View File

@ -16,4 +16,9 @@ include <src/key_transformations.scad>
//$has_brim=true; //$has_brim=true;
$inverted_dish = true;
$key_length = 6;
dcs_row(3) {
$dish_type = "sideways cylindrical";
key(); key();
}

21
model_base.scad Normal file
View File

@ -0,0 +1,21 @@
// entry point for customizer script. This probably isn't useful to most people,
// as it's just a wrapper that helps generate customizer.scad for thingiverse.
/* [Basic-Settings] */
// what preset profile do you wish to use? disable if you are going to set paramters below
key_profile = "dcs"; // [dcs, oem, dsa, sa, g20, disable]
// what key profile row is this keycap on? 0 for disable
row = 1; // [5,1,2,3,4,0]
// What does the top of your key say?
legend = "";
include <src/settings.scad>
include <src/key_sizes.scad>
include <src/key_profiles.scad>
include <src/key_types.scad>
include <src/key_transformations.scad>
use <src/key.scad>

34
models.rb Normal file
View File

@ -0,0 +1,34 @@
require './openscad.rb'
require 'tempfile'
ROWS = [5,1,2,3,4].freeze
SIZES = [1].freeze # , 1.25, 1.5, 1.75, 2, 2.25, 2.75, 6.25
PROFILES = ['dcs', 'dsa', 'g20', 'oem', 'sa'].freeze
# can't get include statements to work dynamically so we'll just use a file
def make_file(command)
lines = OpenSCAD::expand('model_base.scad')
lines << command
f = Tempfile.new('models.scad')
f.write lines.join
f.close
f.path
end
# length is not used in the command here to get the automatic stabilizers from the script
def make_command(row, length, profile)
"key_profile(\"#{profile}\", #{row}) { union() { #{length == 6.25 ? '$dish_type = "sideways cylindrical"; $inverted_dish=true;' : ''} key(); } }"
end
ROWS.each do |row|
SIZES.each do |length|
PROFILES.each do |profile|
command = make_command(row, length, profile)
filename = "#{profile}_row-#{row}_length-#{length.to_s.sub('.', '_')}.stl"
puts "rendering #{filename}:"
puts "\tcommand: #{command} \n\n"
path = make_file(command)
`openscad -o ./models/#{filename} -D "\\\$key_length = #{length};" #{path}`
end
end
end

30
openscad.rb Normal file
View File

@ -0,0 +1,30 @@
module OpenSCAD
def self.expand(filename)
lines = File.readlines(filename)
old_dir = Dir.getwd
Dir.chdir File.dirname(filename)
lines = lines.flat_map do |line|
if line =~ /(include|use)\s*<(.*)>/
# File.readlines("./#{$2}")
expand("./#{$2}")
# in lieu of actually implementing `use`, we can just cull this final line from key.scad
elsif line =~ /example\_key\(\);/
""
else
line
end
end
Dir.chdir old_dir
lines
end
def self.expand_openSCAD_file(source, destination)
lines = OpenSCAD::expand(source)
f = File.open(destination, 'w')
f.write lines.join
end
end

View File

@ -125,13 +125,9 @@ module bump(depth=undef) {
children(); children();
} }
module one_single_key(profile, row, unsculpted) { module row_profile(profile, unsculpted = false) {
key_profile(profile, unsculpted ? 3 : row) key();
}
module one_row_profile(profile, unsculpted = false) {
rows = [5, 1, 2, 3, 4]; rows = [5, 1, 2, 3, 4];
for(row = [0:len(rows)-1]) { for(row = [0:len(rows)-1]) {
translate_u(0, -row) one_single_key(profile, rows[row], unsculpted); translate_u(0, -row) key_profile(profile, unsculpted ? 3 : rows[row]) children();
} }
} }