diff --git a/koffer.scad b/koffer.scad index 0c4789a..914fb40 100644 --- a/koffer.scad +++ b/koffer.scad @@ -14,20 +14,97 @@ DEPTH = 5; // [1:1:10] DIMENTION = "2d"; // [2d: 2d export view, 3d: 3d render] POSITION = "inplace"; // [inplace: in place, origin: at the origin] -//RENDER = "all"; // [bot: bottom, lid: lid, front: front, back: back, left: left, right: right, all: all] -RENDER = "all"; + +// comma seperated list of what to render. [all, layout, bottom, lid, front, back, left, right] +RENDER = "stadslab_plaat2"; LAYOUT_SEPERATION = 15; // [1:1:50] - /*[lid]*/ LID_ANGLE = 45; // [0:170] -/* -%square([600, 300]); -%square([700, 400]); -%square([400, 700]); -*/ + +%translate([0, -400, -0.15]) + cube([700, 400, 0.1]); +// %translate([0, -850, 0]) +// square([700, 400]); +// %translate([0, -1300, 0]) +// square([700, 400]); + + + +Layouts = [ + ["stadslab_plaat1", + [ "bottom", + [ // translate + LAYOUT_SEPERATION, + -LAYOUT_SEPERATION + ], + -90, // rotate + 0 // extrude + ],[ "lid", + [ // translate + DEPTH*UNIT + 2*MATT_THIKNESS + 2*LAYOUT_SEPERATION, + -LAYOUT_SEPERATION + ], + -90, // rotate + 0 // extrude + ],[ "front", + [ // translate + 2*DEPTH*UNIT + 4*MATT_THIKNESS + 3*LAYOUT_SEPERATION, + -LAYOUT_SEPERATION + ], + -90, // rotate + 0 // extrude + ] + ], + ["stadslab_plaat2", + [ "back", + [ // translate + LAYOUT_SEPERATION, + -LAYOUT_SEPERATION + ], + -90, // rotate + 0 // extrude + ],[ "left", + [ // translate + HIEGHT*UNIT + 1*MATT_THIKNESS + 2*LAYOUT_SEPERATION, + -LAYOUT_SEPERATION + ], + -90, // rotate + 0 // extrude + ],[ "right", + [ // translate + 2*HIEGHT*UNIT + 3*MATT_THIKNESS + 3*LAYOUT_SEPERATION, + -LAYOUT_SEPERATION + ], + -90, // rotate + 0 // extrude + ],[ "back", + [ // translate + 1*HIEGHT*UNIT + 1*MATT_THIKNESS + 2*LAYOUT_SEPERATION, + -(1*HIEGHT*UNIT + 1*DEPTH*UNIT + 3*MATT_THIKNESS + 2*LAYOUT_SEPERATION) + ], + 0, // rotate + 0 // extrude + ],[ "left", + [ // translate + 3*HIEGHT*UNIT + 5*MATT_THIKNESS + 4*LAYOUT_SEPERATION, + -LAYOUT_SEPERATION + ], + -90, // rotate + 0 // extrude + ],[ "right", + [ // translate + 4*HIEGHT*UNIT + 7*MATT_THIKNESS + 5*LAYOUT_SEPERATION, + -LAYOUT_SEPERATION + ], + -90, // rotate + 0 // extrude + ] + ] +]; + function finger(flip=[1,0], dir="y") = [ [ 0, 0 @@ -75,26 +152,83 @@ module fingers(flip=[1,1], dir="y", number=2, nub=true){ ); } -module renderPart(3dPos, 3dRotation, 2dPos){ - if (DIMENTION == "2d"){ - if (POSITION == "inplace") - translate(2dPos) - children(); - if (POSITION == "origin") - children(); - } - if (DIMENTION == "3d"){ - if (POSITION == "inplace") - translate(3dPos) - rotate(3dRotation) - linear_extrude(MATT_THIKNESS) - children(); - if (POSITION == "origin") - linear_extrude(MATT_THIKNESS) - children(); +AllParts = ["bottom", "lid", "front", "back", "left", "right"]; +module GetPart(name){ + echo(str("GetPart: ",name)); + if (name == "bottom"){ + bottom(); + }else if (name == "lid"){ + lid(); + }else if (name == "front"){ + front(); + }else if (name == "back"){ + back(); + }else if (name == "left"){ + side(); + }else if (name == "right"){ + side(); } } +module RenderPart(name, pos=[0,0,0], rot=[0,0,0], extrude=0){ + part = (is_list(name)) ? name[0] : name; + pos = (is_list(name)) ? name[1] : pos; + rot = (is_list(name)) ? name[2] : rot; + extrude = (is_list(name)) ? name[3] : extrude; + + echo(str("render part; part=",part," pos=",pos," rot=",rot," extrude=",extrude)); + + // translate(pos) + // rotate(rot) + if (extrude != 0){ + translate(pos) + rotate(rot) + linear_extrude(extrude) + !GetPart(part); + }else{ + translate(pos) + rotate(rot) + GetPart(part); + } +} + +function GetLayout(name, i=0, result=[]) = + (i == len(Layouts)) ? result : GetLayout(name, i+1, + (Layouts[i][0] == name) ? Layouts[i] : result + ); + +module RenderLayout(name){ + echo(str("search layout ", name)); + layout = GetLayout(name); + echo("layout", layout); + + if (len(layout) == 0){ + echo("ERROR: layout not found", layout); + }else{ + for (i = [1:len(layout)-1]){ + RenderPart(layout[i]); + } + } +} + +module Render(name){ + if (len(search(",", name)) == 0){ + part = false; + for (i = [0:len(AllParts)-1]){ + if (name == AllParts[i]){ + part = true; + } + } + if (part){ + renderPart(name); + }else{ + RenderLayout(name); + } + } else { + } +} +Render(RENDER); + function split(str, sep=" ", i=0, word="", v=[]) = (i == len(str)) ? concat(v, word) : (str[i] == sep) ? split(str, sep, i+1, "", concat(v, word)) : @@ -112,6 +246,7 @@ module render(name, 3dPos, 3dRotation, 2dPos){ } } +/* render( name = "bot", 2dPos = [0, 0], @@ -120,14 +255,14 @@ render( ) bottom(); -/* -render( - name = "front", - 2dPos = [-(WIDTH*UNIT + 2*MATT_THIKNESS + LAYOUT_SEPERATION), 0], - 3dPos = [0, MATT_THIKNESS, 0], - 3dRotation = [90, 0, 0] -) - front();*/ + +// render( +// name = "front", +// 2dPos = [-(WIDTH*UNIT + 2*MATT_THIKNESS + LAYOUT_SEPERATION), 0], +// 3dPos = [0, MATT_THIKNESS, 0], +// 3dRotation = [90, 0, 0] +// ) +// front(); render( name = "front", 2dPos = [ @@ -174,20 +309,20 @@ render( totalDepth = DEPTH*UNIT + MATT_THIKNESS*2; -/*if (RENDER == "lid" || RENDER == "all") -render( - 2dPos = [ - WIDTH*UNIT + 2*MATT_THIKNESS + LAYOUT_SEPERATION, - 0 - ], - 3dPos = [ - MATT_THIKNESS, - totalDepth - totalDepth*cos(LID_ANGLE), - HIEGHT*UNIT + MATT_THIKNESS + totalDepth*sin(LID_ANGLE) - ], - 3dRotation = [-LID_ANGLE, 0, 0] -) - lid();*/ +// if (RENDER == "lid" || RENDER == "all") +// render( +// 2dPos = [ +// WIDTH*UNIT + 2*MATT_THIKNESS + LAYOUT_SEPERATION, +// 0 +// ], +// 3dPos = [ +// MATT_THIKNESS, +// totalDepth - totalDepth*cos(LID_ANGLE), +// HIEGHT*UNIT + MATT_THIKNESS + totalDepth*sin(LID_ANGLE) +// ], +// 3dRotation = [-LID_ANGLE, 0, 0] +// ) +// lid(); render( name = "lid", 2dPos = [ @@ -202,19 +337,20 @@ render( 3dRotation = [-LID_ANGLE, 0, 0] ) lid(); +*/ module bottom(){ translate([MATT_THIKNESS, MATT_THIKNESS]) - union(){ - translate([0.005, 0.005]) - square(size=[WIDTH*UNIT-0.01, DEPTH*UNIT-0.01]); - fingers(flip=[-1,1], dir="y", number=DEPTH, nub=true); - translate([WIDTH*UNIT, 0]) - fingers(flip=[1,1], dir="y", number=DEPTH, nub=true); - fingers(flip=[1,-1], dir="x", number=WIDTH, nub=true); - translate([0, DEPTH*UNIT]) - fingers(flip=[1,1], dir="x", number=WIDTH, nub=true); - } + union(){ + translate([0.005, 0.005]) + square(size=[WIDTH*UNIT-0.01, DEPTH*UNIT-0.01]); + fingers(flip=[-1,1], dir="y", number=DEPTH, nub=true); + translate([WIDTH*UNIT, 0]) + fingers(flip=[1,1], dir="y", number=DEPTH, nub=true); + fingers(flip=[1,-1], dir="x", number=WIDTH, nub=true); + translate([0, DEPTH*UNIT]) + fingers(flip=[1,1], dir="x", number=WIDTH, nub=true); + } } module front(){ @@ -254,6 +390,7 @@ module back(){ module side(){ translate([MATT_THIKNESS, MATT_THIKNESS]) union(){ + // inner square translate([0.005, 0.005]) square(size=[DEPTH*UNIT-0.01, HIEGHT*UNIT-0.005 + MATT_THIKNESS]);