31 lines
1,006 B
OpenSCAD
31 lines
1,006 B
OpenSCAD
use <scaddy/vector.scad>
|
|
|
|
function fill_layer(vec,o=0)=let(n=len(vec)) concat([
|
|
[o+0,o+1,o+n-1]],[ for (i=[1:1:n/2-2]) [i, i+1, n-i-1, n-i ] + [o,o,o,o] ],[[o+n/2-1,o+n/2,o+n/2+1]]);
|
|
|
|
function wall(vec,o=0)=let(n=len(vec))
|
|
[ for (i=[0:1:n-1]) [i, n+i, n+(i+1)%n, (i+1)%n] + [o,o,o,o] ];
|
|
|
|
module polyhedron_layers(layers) {
|
|
lc = len(layers);
|
|
bottom=layers[0];
|
|
top=layers[lc-1];
|
|
points_per_layer=len(bottom);
|
|
points = flatten_vec(layers);
|
|
walls=[for(i = [0:1:lc-2]) wall(bottom,i*points_per_layer) ];
|
|
bottom_f=fill_layer(bottom);
|
|
walls_f=flatten_vec(walls);
|
|
top_f = [for( i = fill_layer(top,(lc-1)*points_per_layer))
|
|
reverse_vector(i)];
|
|
|
|
//echo(bottom_f = bottom_f);
|
|
//echo(top_f = top_f);
|
|
//echo(walls_f=walls_f);
|
|
//print_points(points);
|
|
polyhedron(points,faces=concat(
|
|
bottom_f,
|
|
top_f,
|
|
walls_f
|
|
),convexity = lc);
|
|
|
|
}
|