mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 08:19:43 +00:00
Optimized bezier_patch()
This commit is contained in:
parent
f65228f0af
commit
9f3cf44f91
3 changed files with 26 additions and 21 deletions
19
beziers.scad
19
beziers.scad
|
@ -809,11 +809,20 @@ function is_patch(x) = is_tripatch(x) || is_rectpatch(x);
|
|||
// ];
|
||||
// vnf_polyhedron(concat(edges,corners,faces));
|
||||
function bezier_patch(patch, splinesteps=16, vnf=EMPTY_VNF) =
|
||||
assert(is_num(splinesteps)||is_list(splinesteps))
|
||||
is_tripatch(patch)? _bezier_triangle(patch, splinesteps=splinesteps, vnf=vnf) :
|
||||
assert(is_num(splinesteps) || is_vector(splinesteps,2))
|
||||
is_tripatch(patch) ? _bezier_triangle(patch, splinesteps=splinesteps, vnf=vnf) :
|
||||
let(
|
||||
splinesteps = is_list(splinesteps)? splinesteps : [splinesteps, splinesteps],
|
||||
pts = [for (v=[0:1:splinesteps.y], u=[0:1:splinesteps.x]) bezier_patch_point(patch, u/splinesteps.x, v/splinesteps.y)],
|
||||
splinesteps = is_list(splinesteps) ? splinesteps : [splinesteps,splinesteps],
|
||||
bpatch = [
|
||||
for(step=[0:1:splinesteps.x]) [
|
||||
for(patchline=patch)
|
||||
bez_point(patchline, step/splinesteps.x)
|
||||
]
|
||||
],
|
||||
pts = [
|
||||
for(step=[0:1:splinesteps.y], bezparm=bpatch)
|
||||
bez_point(bezparm, step/splinesteps.y)
|
||||
],
|
||||
faces = [
|
||||
for (
|
||||
v=[0:1:splinesteps.y-1],
|
||||
|
@ -825,7 +834,7 @@ function bezier_patch(patch, splinesteps=16, vnf=EMPTY_VNF) =
|
|||
v4 = v3 + 1
|
||||
) each [[v1,v3,v2], [v2,v3,v4]]
|
||||
]
|
||||
) vnf_merge([vnf, [pts, faces]]);
|
||||
) vnf_merge([vnf, [pts, faces]]);
|
||||
|
||||
|
||||
function _tri_count(n) = (n*(1+n))/2;
|
||||
|
|
|
@ -54,11 +54,11 @@ function CR_edge(size, spin=0, orient=UP, trans=[0,0,0]) =
|
|||
);
|
||||
|
||||
|
||||
module CR_cube(size=[100,100,100], r=10, splinesteps=8, cheat=false, debug=false)
|
||||
module CR_cube(size=[100,100,100], r=10, splinesteps=8, debug=false)
|
||||
{
|
||||
s = size-2*[r,r,r];
|
||||
h = size/2;
|
||||
corners = [
|
||||
corners = bezier_surface([
|
||||
CR_corner([r,r,r], spin=0, orient=UP, trans=[-size.x/2, -size.y/2, -size.z/2]),
|
||||
CR_corner([r,r,r], spin=90, orient=UP, trans=[ size.x/2, -size.y/2, -size.z/2]),
|
||||
CR_corner([r,r,r], spin=180, orient=UP, trans=[ size.x/2, size.y/2, -size.z/2]),
|
||||
|
@ -68,8 +68,8 @@ module CR_cube(size=[100,100,100], r=10, splinesteps=8, cheat=false, debug=false
|
|||
CR_corner([r,r,r], spin=90, orient=DOWN, trans=[-size.x/2, -size.y/2, size.z/2]),
|
||||
CR_corner([r,r,r], spin=180, orient=DOWN, trans=[-size.x/2, size.y/2, size.z/2]),
|
||||
CR_corner([r,r,r], spin=270, orient=DOWN, trans=[ size.x/2, size.y/2, size.z/2]),
|
||||
];
|
||||
edges = [
|
||||
], splinesteps=splinesteps);
|
||||
edges = bezier_surface([
|
||||
CR_edge([r, r, s.x], spin=0, orient=RIGHT, trans=[ 0, -h.y, h.z]),
|
||||
CR_edge([r, r, s.x], spin=90, orient=RIGHT, trans=[ 0, -h.y, -h.z]),
|
||||
CR_edge([r, r, s.x], spin=180, orient=RIGHT, trans=[ 0, h.y, -h.z]),
|
||||
|
@ -84,8 +84,8 @@ module CR_cube(size=[100,100,100], r=10, splinesteps=8, cheat=false, debug=false
|
|||
CR_edge([r, r, s.z], spin=90, orient=UP, trans=[ h.x, -h.y, 0]),
|
||||
CR_edge([r, r, s.z], spin=180, orient=UP, trans=[ h.x, h.y, 0]),
|
||||
CR_edge([r, r, s.z], spin=270, orient=UP, trans=[-h.x, h.y, 0])
|
||||
];
|
||||
faces = [
|
||||
], splinesteps=[1,splinesteps]);
|
||||
faces = bezier_surface([
|
||||
// Yes, these are degree 1 bezier patches. That means just the four corner points.
|
||||
// Since these are flat, it doesn't matter what degree they are, and this will reduce calculation overhead.
|
||||
bezier_patch_flat([s.y, s.z], N=1, orient=RIGHT, trans=[ h.x, 0, 0]),
|
||||
|
@ -96,21 +96,17 @@ module CR_cube(size=[100,100,100], r=10, splinesteps=8, cheat=false, debug=false
|
|||
|
||||
bezier_patch_flat([s.x, s.y], N=1, orient=UP, trans=[ 0, 0, h.z]),
|
||||
bezier_patch_flat([s.x, s.y], N=1, orient=DOWN, trans=[ 0, 0, -h.z])
|
||||
];
|
||||
], splinesteps=1);
|
||||
|
||||
if (cheat) {
|
||||
hull() bezier_polyhedron(patches=corners, splinesteps=splinesteps);
|
||||
if (debug) {
|
||||
vnf_validate([edges, faces, corners], convexity=4);
|
||||
} else {
|
||||
if (debug) {
|
||||
trace_bezier_patches(patches=concat(edges, faces, corners), showcps=true, splinesteps=splinesteps);
|
||||
} else {
|
||||
bezier_polyhedron(patches=concat(edges, faces, corners), splinesteps=splinesteps);
|
||||
}
|
||||
vnf_polyhedron([edges, faces, corners], convexity=4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CR_cube(size=[100,100,100], r=20, splinesteps=16, cheat=false, debug=false);
|
||||
CR_cube(size=[100,100,100], r=20, splinesteps=16, debug=false);
|
||||
cube(1);
|
||||
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
BOSL_VERSION = [2,0,207];
|
||||
BOSL_VERSION = [2,0,208];
|
||||
|
||||
|
||||
// Section: BOSL Library Version Functions
|
||||
|
|
Loading…
Reference in a new issue