mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-03-14 03:39:46 +01:00
Changed vnf_vertex_array() to take a nested 2D array of 3D points.
This commit is contained in:
parent
da1086b71b
commit
4334413781
@ -1795,57 +1795,58 @@ function vnf_triangulate(vnf) =
|
|||||||
// Example(3D):
|
// Example(3D):
|
||||||
// vnf = vnf_vertex_array(
|
// vnf = vnf_vertex_array(
|
||||||
// points=[
|
// points=[
|
||||||
// for (h = [0:5:180-EPSILON], t = [0:5:360-EPSILON])
|
// for (h = [0:5:180-EPSILON]) [
|
||||||
// cylindrical_to_xyz(100 + 12 * cos((h/2 + t)*6), t, h)
|
// for (t = [0:5:360-EPSILON])
|
||||||
|
// cylindrical_to_xyz(100 + 12 * cos((h/2 + t)*6), t, h)
|
||||||
|
// ]
|
||||||
// ],
|
// ],
|
||||||
// cols=360/5, col_wrap=true, caps=true, reverse=true, style="alt"
|
// col_wrap=true, caps=true, reverse=true, style="alt"
|
||||||
// );
|
// );
|
||||||
// vnf_polyhedron(vnf);
|
// vnf_polyhedron(vnf);
|
||||||
// Example(3D): Both `col_wrap` and `row_wrap` are true to make a torus.
|
// Example(3D): Both `col_wrap` and `row_wrap` are true to make a torus.
|
||||||
// profile = circle(d=20);
|
|
||||||
// vnf = vnf_vertex_array(
|
// vnf = vnf_vertex_array(
|
||||||
// points=[
|
// points=[
|
||||||
// for (a=[0:5:360-EPSILON])
|
// for (a=[0:5:360-EPSILON])
|
||||||
// each zrot(a,p=right(30,p=xrot(90,p=path3d(profile))))
|
// affine3d_apply(
|
||||||
|
// circle(d=20),
|
||||||
|
// [xrot(90), right(30), zrot(a)]
|
||||||
|
// )
|
||||||
// ],
|
// ],
|
||||||
// cols=len(profile), col_wrap=true, row_wrap=true, reverse=true
|
// col_wrap=true, row_wrap=true, reverse=true
|
||||||
// );
|
// );
|
||||||
// vnf_polyhedron(vnf);
|
// vnf_polyhedron(vnf);
|
||||||
// Example(3D): Möbius Strip. Note that `row_wrap` is not used, and the first and last profile copies are the same.
|
// Example(3D): Möbius Strip. Note that `row_wrap` is not used, and the first and last profile copies are the same.
|
||||||
// profile = square([1,10],center=true);
|
|
||||||
// vnf = vnf_vertex_array(
|
// vnf = vnf_vertex_array(
|
||||||
// points=[
|
// points=[
|
||||||
// for (a=[0:5:360]) each
|
// for (a=[0:5:360]) affine3d_apply(
|
||||||
// zrot(a,p=right(30,p=xrot(90,p=zrot(a/2+60,p=path3d(profile)))))
|
// square([1,10], center=true),
|
||||||
|
// [zrot(a/2+60), xrot(90), right(30), zrot(a)]
|
||||||
|
// )
|
||||||
// ],
|
// ],
|
||||||
// cols=len(profile), col_wrap=true, reverse=true
|
// col_wrap=true, reverse=true
|
||||||
// );
|
// );
|
||||||
// vnf_polyhedron(vnf);
|
// vnf_polyhedron(vnf);
|
||||||
// Example(3D): Assembling a Polyhedron from Multiple Parts
|
// Example(3D): Assembling a Polyhedron from Multiple Parts
|
||||||
// profile = circle(d=100);
|
// wall_points = [
|
||||||
// wall_points=[
|
// for (a = [-90:2:90]) affine3d_apply(
|
||||||
// for (a=[-90:2:90])
|
// circle(d=100),
|
||||||
// each up(a, p=scale([1-0.1*cos(a*6),1-0.1*cos((a+90)*6),1], p=path3d(profile)))
|
// [scale([1-0.1*cos(a*6), 1-0.1*cos((a+90)*6), 1]), up(a)]
|
||||||
|
// )
|
||||||
// ];
|
// ];
|
||||||
// cap_profile = select(wall_points,0,len(profile)-1);
|
// cap = [
|
||||||
// cap_points=[
|
// for (a = [0:0.01:1+EPSILON]) affine3d_apply(
|
||||||
// for (a=[0:0.01:1.001]) each
|
// wall_points[0],
|
||||||
// up(90-5*sin(a*360*2), p=scale([a,a,1], p=cap_profile))
|
// [scale([a,a,1]), up(90-5*sin(a*360*2))]
|
||||||
|
// )
|
||||||
// ];
|
// ];
|
||||||
// vnf1 = vnf_vertex_array(
|
// cap1 = [for (p=cap) down(90, p=zscale(-1, p=p))];
|
||||||
// points=wall_points, cols=len(profile), col_wrap=true
|
// cap2 = [for (p=cap) up(90, p=p)];
|
||||||
// );
|
// vnf1 = vnf_vertex_array(points=wall_points, col_wrap=true);
|
||||||
// vnf2 = vnf_vertex_array(
|
// vnf2 = vnf_vertex_array(points=cap1, col_wrap=true);
|
||||||
// points=down(90, p=zscale(-1, p=cap_points)),
|
// vnf3 = vnf_vertex_array(points=cap2, col_wrap=true, reverse=true);
|
||||||
// cols=len(profile), col_wrap=true
|
|
||||||
// );
|
|
||||||
// vnf3 = vnf_vertex_array(
|
|
||||||
// points=up(90, p=cap_points),
|
|
||||||
// cols=len(profile), col_wrap=true, reverse=true
|
|
||||||
// );
|
|
||||||
// vnf_polyhedron([vnf1, vnf2, vnf3]);
|
// vnf_polyhedron([vnf1, vnf2, vnf3]);
|
||||||
function vnf_vertex_array(
|
function vnf_vertex_array(
|
||||||
points, cols,
|
points,
|
||||||
caps, cap1, cap2,
|
caps, cap1, cap2,
|
||||||
col_wrap=false,
|
col_wrap=false,
|
||||||
row_wrap=false,
|
row_wrap=false,
|
||||||
@ -1853,12 +1854,13 @@ function vnf_vertex_array(
|
|||||||
style="default",
|
style="default",
|
||||||
vnf=[[],[]]
|
vnf=[[],[]]
|
||||||
) =
|
) =
|
||||||
assert(len(points)%cols==0)
|
|
||||||
assert((!caps)||(caps&&col_wrap))
|
assert((!caps)||(caps&&col_wrap))
|
||||||
assert(in_list(style,["default","alt","quincunx"]))
|
assert(in_list(style,["default","alt","quincunx"]))
|
||||||
let(
|
let(
|
||||||
pcnt = len(points),
|
pts = flatten(points),
|
||||||
rows = pcnt/cols,
|
rows = len(points),
|
||||||
|
cols = len(points[0]),
|
||||||
|
errchk = [for (row=points) assert(len(row)==cols, "All rows much have the same number of columns.") 0],
|
||||||
cap1 = first_defined([cap1,caps,false]),
|
cap1 = first_defined([cap1,caps,false]),
|
||||||
cap2 = first_defined([cap2,caps,false]),
|
cap2 = first_defined([cap2,caps,false]),
|
||||||
colcnt = cols - (col_wrap?0:1),
|
colcnt = cols - (col_wrap?0:1),
|
||||||
@ -1867,7 +1869,7 @@ function vnf_vertex_array(
|
|||||||
vnf_merge([
|
vnf_merge([
|
||||||
vnf, [
|
vnf, [
|
||||||
concat(
|
concat(
|
||||||
points,
|
pts,
|
||||||
style!="quincunx"? [] : [
|
style!="quincunx"? [] : [
|
||||||
for (r = [0:1:rowcnt-1]) (
|
for (r = [0:1:rowcnt-1]) (
|
||||||
for (c = [0:1:colcnt-1]) (
|
for (c = [0:1:colcnt-1]) (
|
||||||
@ -1876,7 +1878,7 @@ function vnf_vertex_array(
|
|||||||
i2 = ((r+1)%rows)*cols + ((c+0)%cols),
|
i2 = ((r+1)%rows)*cols + ((c+0)%cols),
|
||||||
i3 = ((r+1)%rows)*cols + ((c+1)%cols),
|
i3 = ((r+1)%rows)*cols + ((c+1)%cols),
|
||||||
i4 = ((r+0)%rows)*cols + ((c+1)%cols)
|
i4 = ((r+0)%rows)*cols + ((c+1)%cols)
|
||||||
) mean([points[i1], points[i2], points[i3], points[i4]])
|
) mean([pts[i1], pts[i2], pts[i3], pts[i4]])
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user