Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
include <module_item_holder.scad>
include <module_pattern_voronoi.scad>
include <module_pattern_brick.scad>
include <thridparty/kumikoPatterns/kumiko.scad>
include <module_pattern_kumiko.scad>
include <module_pattern_slat.scad>
iPatternEnabled=0;
iPatternStyle=1;
iPatternRotate=2;
iPatternFill=3;
iPatternBorder=4;
iPatternDepth=5;
iPatternCellSize=6;
iPatternHoleSides=7;
iPatternStrength=8;
iPatternHoleRadius=9;
iPatternFs=10;
iPatternGridChamfer=11;
iPatternVoronoiNoise=12;
iPatternBrickWeight=13;
iPatternColored=14;
iPatternKumikoFillRatio=15;
PatternStyle_grid = "grid";
PatternStyle_hexgrid = "hexgrid";
PatternStyle_voronoi = "voronoi";
PatternStyle_voronoigrid = "voronoigrid";
PatternStyle_voronoihexgrid = "voronoihexgrid";
PatternStyle_brick = "brick";
PatternStyle_brickoffset = "brickoffset";
PatternStyle_slat = "slats";
PatternStyle_tobiAsanoha = "kumiko_tobi_asanoha";
PatternStyle_asanoha = "kumiko_asanoha";
PatternStyle_goma = "kumiko_goma";
PatternStyle_tsumiishiKikko = "kumiko_tsumiishi_kikko";
PatternStyle_bishamonKikkou = "kumiko_bishamon_kikkou";
PatternStyle_mikado = "kumiko_mikado";
PatternStyle_values = [
PatternStyle_grid, PatternStyle_hexgrid,
PatternStyle_voronoi, PatternStyle_voronoigrid, PatternStyle_voronoihexgrid,
PatternStyle_slat,
PatternStyle_tobiAsanoha, PatternStyle_asanoha, PatternStyle_goma, PatternStyle_tsumiishiKikko, PatternStyle_bishamonKikkou, PatternStyle_mikado,
PatternStyle_brick, PatternStyle_brickoffset
];
function validatePatternStyle(value, name = "PatternStyle") =
assert(list_contains(PatternStyle_values, value), typeerror(name, value))
value;
PatternFill_none = "none";
PatternFill_space = "space";
PatternFill_crop = "crop";
PatternFill_crophorizontal = "crophorizontal";
PatternFill_cropvertical = "cropvertical";
PatternFill_crophorizontal_spacevertical = "crophorizontal_spacevertical";
PatternFill_cropvertical_spacehorizontal = "cropvertical_spacehorizontal";
PatternFill_spacevertical = "spacevertical";
PatternFill_spacehorizontal = "spacehorizontal";
PatternFill_values = [PatternFill_none, PatternFill_space, PatternFill_crop, PatternFill_crophorizontal, PatternFill_cropvertical, PatternFill_crophorizontal_spacevertical, PatternFill_cropvertical_spacehorizontal, PatternFill_spacevertical, PatternFill_spacehorizontal];
function validatePatternFill(value, name = "PatternFill") =
assert(list_contains(PatternFill_values, value), typeerror(name, value))
value;
function PatternSettings(
patternEnabled,
patternStyle,
patternRotate = false,
patternFill,
patternBorder = -1,
patternDepth = 0,
patternCellSize,
patternHoleSides,
patternStrength,
patternHoleRadius=0.5,
patternFs = 0,
patternGridChamfer=0,
patternVoronoiNoise=0,
patternBrickWeight=0,
patternColored="disabled"
,patternKumikoFillRatio=[0,0]
) =
let(
result = [
patternEnabled,
patternStyle,
patternRotate,
patternFill,
patternBorder,
patternDepth,
is_num(patternCellSize) ? [patternCellSize, patternCellSize] : patternCellSize,
patternHoleSides,
is_num(patternStrength) ? [patternStrength, patternStrength] : patternStrength,
patternHoleRadius,
patternFs,
patternGridChamfer,
patternVoronoiNoise,
patternBrickWeight,
patternColored
, is_num(patternKumikoFillRatio) ? [patternKumikoFillRatio, patternKumikoFillRatio] : patternKumikoFillRatio,
],
validatedResult = ValidatePatternSettings(result)
) validatedResult;
function ValidatePatternSettings(settings, num_x, num_y) =
assert(is_list(settings), "Settings must be a list")
assert(len(settings)==16, "Settings must length 16")
assert(is_bool(settings[iPatternEnabled]), "settings[iPatternEnabled] must be a boolean")
assert(is_string(settings[iPatternStyle]), "settings[iPatternStyle] must be a string")
assert(is_bool(settings[iPatternRotate]), "settings[iPatternRotate] must be a boolean")
assert(is_string(settings[iPatternFill]), "settings[iPatternFill] must be a string")
assert(is_num(settings[iPatternBorder]), "settings[iPatternBorder] must be a non-negative number or -1")
assert(is_num(settings[iPatternDepth]), "settings[iPatternDepth] must be a number")
assert(is_list(settings[iPatternCellSize]) && len(settings[iPatternCellSize])==2, "settings[iPatternCellSize] must be a list two positive numbers")
assert(is_num(settings[iPatternHoleSides]) && settings[iPatternHoleSides] >= 3, "settings[iPatternHoleSides] must be a number >= 3")
assert(is_list(settings[iPatternStrength]) && len(settings[iPatternStrength])==2 &&
is_num(settings[iPatternStrength].x) && settings[iPatternStrength].x > 0 &&
is_num(settings[iPatternStrength].y) && settings[iPatternStrength].y > 0, "settings[iPatternStrength] must be a list of two positive numbers")
assert(is_num(settings[iPatternHoleRadius]) && settings[iPatternHoleRadius] >= 0, "settings[iPatternHoleRadius] must be a non-negative number")
assert(is_num(settings[iPatternFs]) && settings[iPatternFs] >= 0, "settings[iPatternFs] must be a non-negative number")
assert(is_num(settings[iPatternGridChamfer]), "settings[iPatternGridChamfer] must be a number")
assert(is_num(settings[iPatternVoronoiNoise]) && settings[iPatternVoronoiNoise] >= 0 && settings[iPatternVoronoiNoise] <= 1, "settings[iPatternVoronoiNoise] must be between 0 and 1")
assert(is_list(settings[iPatternKumikoFillRatio]), "settings[iPatternKumikoFillRatio] must be a list")
assert(is_list(settings[iPatternKumikoFillRatio]), "settings[iPatternKumikoFillRatio] must be a list")
assert(is_num(settings[iPatternBrickWeight]) && settings[iPatternBrickWeight] >= 0, "settings[iPatternBrickWeight] must be a non-negative number")
[settings[iPatternEnabled],
validatePatternStyle(settings[iPatternStyle]),
settings[iPatternRotate],
validatePatternFill(settings[iPatternFill]),
settings[iPatternBorder],
settings[iPatternDepth],
settings[iPatternCellSize],
settings[iPatternHoleSides],
settings[iPatternStrength],
settings[iPatternHoleRadius],
settings[iPatternFs],
settings[iPatternGridChamfer],
settings[iPatternVoronoiNoise],
settings[iPatternBrickWeight],
settings[iPatternColored]
,settings[iPatternKumikoFillRatio]
];
function get_wallpattern_positions(
border,
heightz,
positionz,
wall_thickness,
wallpattern_thickness,
wallpattern_walls= [0,0,0,0],
label_walls = [0,0,0,0],
label_sizez=0) =
let(
fudgeFactor= 0.01,
bin_size=[env_numx()*env_pitch().x-env_clearance().x, env_numy()*env_pitch().y-env_clearance().y],
x_width = bin_size.x-env_corner_radius()*2-border,
y_width = bin_size.y-env_corner_radius()*2-border,
wallpattern_thickness=wallpattern_thickness+fudgeFactor,
front = [
//width, height, depth
[x_width, heightz - (label_walls[0] != 0 ? label_sizez : 0), wallpattern_thickness],
//Position
[bin_size.x/2+env_clearance().x/2,
env_clearance().y/2+wall_thickness/2-(wall_thickness-wallpattern_thickness)/2,
positionz - (label_walls[0] != 0 ? label_sizez : 0)/2],
//rotation, mirror
[90,0,0], [0,0,0],
//enabled
wallpattern_walls[0]],
back = [
//width, height, depth
[x_width, heightz - (label_walls[1] != 0 ? label_sizez : 0), wallpattern_thickness],
//Position
[bin_size.x/2+env_clearance().x/2,
bin_size.y+env_clearance().y/2-wall_thickness/2+(wall_thickness-wallpattern_thickness)/2,
positionz - (label_walls[1] != 0 ? label_sizez : 0)/2],
//rotation, mirror
[90,0,0], [0,1,0],
//enabled
wallpattern_walls[1]],
left = [
//width, height, depth
[y_width, heightz - (label_walls[2] != 0 ? label_sizez : 0), wallpattern_thickness],
//Position
[env_clearance().x/2+wall_thickness/2-(wall_thickness-wallpattern_thickness)/2,
bin_size.y/2+env_clearance().y/2,
positionz - (label_walls[2] != 0 ? label_sizez : 0)/2],
//rotation, mirror (for chamfer)
[90,0,90], [1,0,0],
//enabled
wallpattern_walls[2]],
right = [
//width, height, depth
[y_width, heightz - (label_walls[3] != 0 ? label_sizez : 0), wallpattern_thickness],
//Position
[bin_size.x+env_clearance().x/2-wall_thickness/2+(wall_thickness-wallpattern_thickness)/2,
bin_size.y/2+env_clearance().y/2,
positionz - (label_walls[3] != 0 ? label_sizez : 0)/2],
//rotation, mirror (for chamfer)
[90,0,90], [0,1,0],
//enabled
wallpattern_walls[3]],
ylocations = [left, right],
xlocations = [front, back])
[xlocations, ylocations];
// cuts the wall pattern section from the bin walls and replaces them with coloured sections
module coloured_wall_pattern(
wall_pattern_settings=[],
wallpattern_walls=[],
wall_thickness=1,
pattern_floor,
pattern_height,
border = 0,
colored_pattern = false,
){
colored_pattern = is_string(colored_pattern) ? colored_pattern : (colored_pattern ? "enabled" : "disabled");
fudgeFactor = 0.001;
wallpattern_thickness = get_related_value(wall_pattern_settings[iPatternDepth], wall_thickness);
positions = get_wallpattern_positions(
border = border,
heightz = pattern_height,
positionz = pattern_floor,
wall_thickness = wall_thickness,
wallpattern_thickness = wallpattern_thickness,
wallpattern_walls = wall_pattern_settings[iPatternEnabled] ? wallpattern_walls : [0,0,0,0]);
locations = [positions.x[0], positions.x[1], positions.y[0], positions.y[1]];
assert($children == 3, "coloured_wall_pattern expects three children");
difference(){
colored_block(colored_pattern){
children(0);
split_clearance = 0.25;
split_lip = 2;
back_lip = 1;
//subtracted block
wall_pattern_canvas_negative(
locations,
colored_pattern,
clearance = 0,
back_lip = back_lip,
lip_size = split_lip);
//added blockblock
wall_pattern_canvas_positive(
locations,
colored_pattern,
clearance = split_clearance,
back_lip = back_lip,
lip_size = split_lip/2);
if($children >=3) children(2);
}
// Child 1 is bin cavities and negatives
if($children >=2) children(1);
}
}
module wall_pattern_canvas_negative(locations, colored_pattern, clearance = 0, back_lip, lip_size = 1){
//subtracted block
for(i = [0:1:len(locations)-1])
if(locations[i][4] > 0)
translate(locations[i][1])
mirror(locations[i][3])
rotate(locations[i][2])
if(colored_pattern == "split") {
thickness = locations[i][0].z+fudgeFactor;
difference(){
//block cavity, with side clips and clearance added
translate([0,thickness/2,0])
split_block(
[locations[i][0].x,locations[i][0].y+thickness],
thickness,
clearance = clearance,
back_lip = back_lip,
lip_size = lip_size,
hook_thickness_ratio=0.2);
//Top taper, for easy printability
translate([-locations[i][0].x/2-thickness*2,locations[i][0].y/2+thickness,thickness/2])
rotate([180+45,0,0])
cube([locations[i][0].x+thickness*4,thickness*2,thickness*2], center=false);
}
} else {
cube([locations[i][0].x,locations[i][0].y,locations[i][0].z+fudgeFactor], center=true);
}
}
module wall_pattern_canvas_positive(locations, colored_pattern, clearance = 0, back_lip, lip_size = 1){
//add block
for(i = [0:1:len(locations)-1])
if(locations[i][4] > 0)
translate(locations[i][1])
mirror(locations[i][3])
rotate(locations[i][2]) {
thickness = locations[i][0].z;
if(colored_pattern == "split"){
//block cavity, with side clips and clearance subtracted
split_block(
locations[i][0],
thickness,
clearance = clearance*-1,
back_lip = back_lip,
lip_size = lip_size);
} else {
cube([locations[i][0].x,locations[i][0].y,thickness], center=true);
}
}
}
module split_block(
size,
thickness,
clearance,
back_lip,
lip_size,
bottom_thickness_ratio = 0.25,
top_thickness_ratio = 0.5,
hook_thickness_ratio = 0){
bottom_thickness = thickness*bottom_thickness_ratio;
top_thickness = thickness*top_thickness_ratio;
middle_thickness = thickness-top_thickness;
hook_thickness = thickness*hook_thickness_ratio;
fudge_factor = 0.01;
block_clearance = clearance;
lip_clearance = 0;
lip_ramp_clearance = 0;//clearance/5;
echo("split_block: ", thickness=thickness, lip_size=lip_size, back_lip=back_lip, bottom_thickness=bottom_thickness, top_thickness=top_thickness, middle_thickness=middle_thickness, hook_thickness=hook_thickness);
inner_block = [size.x-back_lip+block_clearance, size.y, thickness];
middle_block = [inner_block.x, inner_block.y, middle_thickness+lip_ramp_clearance];
outer_block = [size.x+lip_size+lip_clearance, size.y, bottom_thickness+hook_thickness];
echo("split_block: ", inner_block=inner_block, middle_block=middle_block, outer_block=outer_block);
difference(){
union(){
cube(inner_block, center=true);
hull(){
translate(-[middle_block.x, middle_block.y, thickness]/2)
cube(middle_block);
translate(-[outer_block.x, outer_block.y, thickness+hook_thickness*2]/2)
cube(outer_block);
}
}
if(hook_thickness_ratio > 0 && hook_thickness > 0){
hook_width = lip_size;
hook_middle_block = [middle_block.x+fudge_factor*2-hook_width*2, middle_block.y+fudge_factor*2, outer_block.z];
hook_outer_block = [outer_block.x+fudge_factor*2-hook_width*2, outer_block.y+fudge_factor*2, bottom_thickness];
translate([0, -fudge_factor, -hook_outer_block.z-hook_thickness])
hull(){
translate(-[hook_middle_block.x, hook_middle_block.y, thickness]/2)
cube(hook_middle_block);
translate(-[hook_outer_block.x, hook_outer_block.y, thickness]/2)
cube(hook_outer_block);
}
}
}
}
module colored_block(coloured_pattern = "enabled"){
union(){
if(coloured_pattern == "enabled" || coloured_pattern == "split"){
difference(){
// Child 0 is bin block
children(0);
//Subtract the wall pattern block so it can be coloured.
color(env_colour(color_cup))
children(1);
}
translate(coloured_pattern == "split" ? [env_numx()*env_pitch().x+10, 0, 0] : [0,0,0])
color(env_colour(color_wallcutout, isLip=true))
//render_conditional(true)
difference(){
children(2);
// Child 3 is wall pattern
color(env_colour(color_wallcutout, isLip=true))
children(3);
}
} else {
difference(){
// Child 0 is bin block
children(0);
// Child 3 is wall pattern
color(env_colour(color_wallcutout, isLip=true))
children(3);
}
}
}
}
module cutout_pattern(
patternStyle,
canvasSize,
customShape = false,
circleFn,
cellSize = [],
strength,
holeHeight,
holeRadius,
center = true,
centerz = false,
fill,
patternGridChamfer=0,
patternVoronoiNoise=0,
patternKumikoFillRatio=[0,0],
patternBrickWeight=0,
partialDepth = false,
border = 0,
patternFs = 0,
rotateGrid = false,
source = ""){
// validate inputs
assert(is_list(canvasSize) && len(canvasSize) == 2, "canvasSize must be a list of two numbers");
assert(is_num(canvasSize.x) && canvasSize.x > 0, "canvasSize.x must be a positive number");
assert(is_num(canvasSize.y) && canvasSize.y > 0, "canvasSize.y must be a positive number");
assert(is_num(holeHeight) && holeHeight > 0, "holeHeight must be a positive number");
assert(is_num(holeRadius) && holeRadius >= 0, "holeRadius must be a non-negative number");
assert(is_num(border) && border >= 0, "border must be a non-negative number");
assert(is_num(patternFs) && patternFs >= 0, "patternFs must be a non-negative number");
assert(is_num(patternGridChamfer), "patternGridChamfer must be a number");
assert(is_num(patternVoronoiNoise) && patternVoronoiNoise >= 0 && patternVoronoiNoise <= 1, "patternVoronoiNoise must be between 0 and 1");
assert(is_num(patternBrickWeight) && patternBrickWeight >= 0, "patternBrick Weight must be a non-negative number");
assert(is_list(patternKumikoFillRatio), "patternKumikoFillRatio must be a list");
assert(is_list(strength) && len(strength) == 2 && is_num(strength.x) && strength.x > 0 && is_num(strength.y) && strength.y > 0, "strength must be a list of two positive numbers");
canvasSize =
let(cs = rotateGrid ? [canvasSize.y,canvasSize.x] : canvasSize)
border > 0
? [cs.x-border*2, cs.y-border*2]
: cs;
if(env_help_enabled("trace")) echo("cutout_pattern", patternStyle=patternStyle, source=source, canvasSize=canvasSize, patternFs=patternFs, border=border);
function calculate_chamfer(chamfer, thickness, partialDepth) =
let(
_chamfer = is_num(chamfer) ? (partialDepth ? [0, chamfer] : [chamfer, chamfer]) : chamfer,
dual_chamfer = (_chamfer[0] != 0 && _chamfer[1] != 0) ? 2 : 1)
[get_related_value(_chamfer.x, thickness/dual_chamfer, 0),get_related_value(_chamfer.y, thickness/dual_chamfer, 0)];
chamfer = calculate_chamfer(chamfer = patternGridChamfer, thickness=holeHeight, partialDepth=partialDepth);
//override the FS for the pattern, if required
$fs = patternFs > 0 ? patternFs : $fs;
//translate(border>0 ? [border,border,0] : [0,0,0])
translate(center ? [0,0,0] : [border,border,0])
translate(centerz ? [0,0,-holeHeight/2] : [0,0,0])
rotate(rotateGrid ? [0,0,90] : [0,0,0])
union(){
if(patternStyle == PatternStyle_grid || patternStyle == PatternStyle_hexgrid) {
GridItemHolder(
canvasSize = canvasSize,
hexGrid = patternStyle == PatternStyle_hexgrid,
customShape = customShape,
circleFn = circleFn,
holeSize = cellSize,
holeSpacing = strength,
holeHeight = holeHeight,
center=center,
fill=fill, //"none", "space", "crop"
rotateGrid = true,
//border = border,
holeChamfer = chamfer);
}
else if(patternStyle == PatternStyle_voronoi || patternStyle == PatternStyle_voronoigrid || patternStyle == PatternStyle_voronoihexgrid){
if(env_help_enabled("trace")) echo("cutout_pattern", canvasSize = [canvasSize.x,canvasSize.y,holeHeight], thickness = holeSpacing.x, round=1);
rectangle_voronoi(
canvasSize = [canvasSize.x,canvasSize.y,holeHeight],
spacing = strength.x,
cellsize = cellSize.x,
grid = (patternStyle == PatternStyle_voronoigrid || patternStyle == PatternStyle_voronoihexgrid),
gridOffset = (patternStyle == PatternStyle_voronoihexgrid),
noise=patternVoronoiNoise,
radius = holeRadius,
center=center,
seed=env_random_seed());
}
else if(patternStyle == PatternStyle_brick || patternStyle == PatternStyle_brickoffset){
if(env_help_enabled("trace")) echo("cutout_pattern", canvasSize = [canvasSize.x,canvasSize.y,holeHeight], thickness = holeSpacing.x, round=1);
brick_pattern(
canvis_size=[canvasSize.x,canvasSize.y],
thickness = holeHeight,
spacing=strength.x,
center=center,
cell_size = cellSize,
corner_radius = holeRadius,
center_weight = patternBrickWeight,
rotateGrid = true,
offset_layers = patternStyle == PatternStyle_brickoffset
);
} else if(patternStyle == PatternStyle_slat){
slat_pattern(
canvis_size=[canvasSize.x,canvasSize.y],
thickness = holeHeight,
spacing = strength.x,
slat_width = cellSize.x,
slat_chamfer = chamfer,
center = center,
rotateGrid = false);
}
else if(patternStyle == PatternStyle_tobiAsanoha){
rectangle_tobiAsanoha(
canvasSize = [canvasSize.x,canvasSize.y,holeHeight],
height = holeHeight,
cell_size = cellSize.x,
strength = strength.x,
fillRatio = patternKumikoFillRatio[0],
fillHeight = patternKumikoFillRatio[1],
center=center);
} else if(patternStyle == PatternStyle_asanoha){
rectangle_asanoha(
canvasSize = [canvasSize.x,canvasSize.y,holeHeight],
height = holeHeight,
cell_size = cellSize.x,
strength = strength.x,
fillRatio = patternKumikoFillRatio[0],
fillHeight = patternKumikoFillRatio[1],
center=center);
} else if(patternStyle == PatternStyle_goma){
rectangle_goma(
canvasSize = [canvasSize.x,canvasSize.y,holeHeight],
height = holeHeight,
cell_size = cellSize.x,
strength = strength.x,
fillRatio = patternKumikoFillRatio[0],
fillHeight = patternKumikoFillRatio[1],
center=center);
} else if(patternStyle == PatternStyle_tsumiishiKikko){
rectangle_tsumiishiKikko(
canvasSize = [canvasSize.x,canvasSize.y,holeHeight],
height = holeHeight,
cell_size = cellSize.x,
strength = strength.x,
fillRatio = patternKumikoFillRatio[0],
fillHeight = patternKumikoFillRatio[1],
center=center);
} else if(patternStyle == PatternStyle_bishamonKikkou){
rectangle_bishamonKikkou(
canvasSize = [canvasSize.x,canvasSize.y,holeHeight],
height = holeHeight,
cell_size = cellSize.x,
strength = strength.x,
fillRatio = patternKumikoFillRatio[0],
fillHeight = patternKumikoFillRatio[1],
center=center);
} else if(patternStyle == PatternStyle_mikado){
rectangle_mikado(
canvasSize = [canvasSize.x,canvasSize.y,holeHeight],
height = holeHeight,
cell_size = cellSize.x,
strength = strength.x,
fillRatio = patternKumikoFillRatio[0],
fillHeight = patternKumikoFillRatio[1],
center=center);
}
else {
echo("cutout_pattern: Unknown patternStyle", patternStyle=patternStyle);
}
}
}94d5a3e2dThis file is pinned to the selected release. Download the original to open it in your design tool.