mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Revert "Revert "Merge remote-tracking branch 'upstream/revarbat_dev'""
This reverts commit f4a8138b37
.
This commit is contained in:
parent
f4a8138b37
commit
5fab080f8e
5 changed files with 79 additions and 40 deletions
|
@ -458,10 +458,9 @@ function find_anchor(anchor, geom) =
|
|||
eps = 1/2048,
|
||||
points = vnf[0],
|
||||
faces = vnf[1],
|
||||
rpts = rot(from=anchor, to=RIGHT, p=move(point3d(-cp), p=points)),
|
||||
rpts = apply(rot(from=anchor, to=RIGHT) * move(point3d(-cp)), points),
|
||||
hits = [
|
||||
for (i = idx(faces)) let(
|
||||
face = faces[i],
|
||||
for (face = faces) let(
|
||||
verts = select(rpts, face)
|
||||
) if (
|
||||
max(subindex(verts,0)) >= -eps &&
|
||||
|
@ -470,35 +469,40 @@ function find_anchor(anchor, geom) =
|
|||
min(subindex(verts,1)) <= eps &&
|
||||
min(subindex(verts,2)) <= eps
|
||||
) let(
|
||||
pt = polygon_line_intersection(
|
||||
select(points, face),
|
||||
[CENTER,anchor], eps=eps
|
||||
)
|
||||
) if (!is_undef(pt)) [norm(pt), i, pt]
|
||||
poly = select(points, face),
|
||||
pt = polygon_line_intersection(poly, [cp,cp+anchor], bounded=[true,false], eps=eps)
|
||||
) if (!is_undef(pt)) let(
|
||||
plane = plane_from_polygon(poly),
|
||||
n = unit(plane_normal(plane))
|
||||
)
|
||||
[norm(pt-cp), n, pt]
|
||||
]
|
||||
)
|
||||
assert(len(hits)>0, "Anchor vector does not intersect with the shape. Attachment failed.")
|
||||
let(
|
||||
furthest = max_index(subindex(hits,0)),
|
||||
pos = point3d(cp) + hits[furthest][2],
|
||||
dist = hits[furthest][0],
|
||||
nfaces = [for (hit = hits) if(approx(hit[0],dist,eps=eps)) hit[1]],
|
||||
n = unit(
|
||||
sum([
|
||||
for (i = nfaces) let(
|
||||
faceverts = select(points, faces[i]),
|
||||
faceplane = plane_from_points(faceverts),
|
||||
nrm = plane_normal(faceplane)
|
||||
) nrm
|
||||
]) / len(nfaces),
|
||||
UP
|
||||
)
|
||||
pos = hits[furthest][2],
|
||||
hitnorms = [for (hit = hits) if (approx(hit[0],dist,eps=eps)) hit[1]],
|
||||
unorms = len(hitnorms) > 7
|
||||
? unique([for (nn = hitnorms) quant(nn,1e-9)])
|
||||
: [
|
||||
for (i = idx(hitnorms)) let(
|
||||
nn = hitnorms[i],
|
||||
isdup = [
|
||||
for (j = [i+1:1:len(hitnorms)-1])
|
||||
if (approx(nn, hitnorms[j])) 1
|
||||
] != []
|
||||
) if (!isdup) nn
|
||||
],
|
||||
n = unit(sum(unorms)),
|
||||
oang = approx(point2d(n), [0,0])? 0 : atan2(n.y, n.x) + 90
|
||||
)
|
||||
[anchor, pos, n, oang]
|
||||
) : type == "vnf_extent"? ( //vnf
|
||||
let(
|
||||
vnf=geom[1],
|
||||
rpts = rot(from=anchor, to=RIGHT, p=move(point3d(-cp), p=vnf[0])),
|
||||
rpts = apply(rot(from=anchor, to=RIGHT) * move(point3d(-cp)), vnf[0]),
|
||||
maxx = max(subindex(rpts,0)),
|
||||
idxs = [for (i = idx(rpts)) if (approx(rpts[i].x, maxx)) i],
|
||||
mm = pointlist_bounds(select(rpts,idxs)),
|
||||
|
@ -849,7 +853,7 @@ module attachable(
|
|||
|
||||
// Module: position()
|
||||
// Usage:
|
||||
// position(from, [overlap]) ...
|
||||
// position(from) ...
|
||||
// Description:
|
||||
// Attaches children to a parent object at an anchor point.
|
||||
// Arguments:
|
||||
|
|
|
@ -1962,4 +1962,4 @@ module bent_cutout_mask(r, thickness, path, convexity=10)
|
|||
}
|
||||
|
||||
|
||||
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|
||||
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|
|
@ -102,8 +102,8 @@ module cuboid(
|
|||
if (edges == EDGES_ALL && trimcorners) {
|
||||
if (chamfer<0) {
|
||||
cube(size, center=true) {
|
||||
attach(TOP) prismoid([size.x,size.y], [size.x-2*chamfer,size.y-2*chamfer], h=-chamfer, anchor=TOP);
|
||||
attach(BOT) prismoid([size.x,size.y], [size.x-2*chamfer,size.y-2*chamfer], h=-chamfer, anchor=TOP);
|
||||
attach(TOP,overlap=0) prismoid([size.x,size.y], [size.x-2*chamfer,size.y-2*chamfer], h=-chamfer, anchor=TOP);
|
||||
attach(BOT,overlap=0) prismoid([size.x,size.y], [size.x-2*chamfer,size.y-2*chamfer], h=-chamfer, anchor=TOP);
|
||||
}
|
||||
} else {
|
||||
isize = [for (v = size) max(0.001, v-2*chamfer)];
|
||||
|
|
63
skin.scad
63
skin.scad
|
@ -16,7 +16,8 @@ include <vnf.scad>
|
|||
|
||||
// Function&Module: skin()
|
||||
// Usage: As module:
|
||||
// skin(profiles, [slices], [refine], [method], [sampling], [caps], [closed], [z]);
|
||||
// skin(profiles, [slices], [refine], [method], [sampling], [caps], [closed], [z], [convexity],
|
||||
// [anchor],[cp],[spin],[orient],[extent]);
|
||||
// Usage: As function:
|
||||
// vnf = skin(profiles, [slices], [refine], [method], [sampling], [caps], [closed], [z]);
|
||||
// Description:
|
||||
|
@ -117,6 +118,12 @@ include <vnf.scad>
|
|||
// caps = true to create endcap faces when closed is false. Can be a length 2 boolean array. Default is true if closed is false.
|
||||
// method = method for connecting profiles, one of "distance", "tangent", "direct" or "reindex". Default: "direct".
|
||||
// z = array of height values for each profile if the profiles are 2d
|
||||
// convexity = convexity setting for use with polyhedron. (module only) Default: 10
|
||||
// anchor = Translate so anchor point is at the origin. (module only) Default: "origin"
|
||||
// spin = Rotate this many degrees around Z axis after anchor. (module only) Default: 0
|
||||
// orient = Vector to rotate top towards after spin (module only)
|
||||
// extent = use extent method for computing anchors. (module only) Default: false
|
||||
// cp = set centerpoint for anchor computation. (module only) Default: object centroid
|
||||
// Example:
|
||||
// skin([octagon(4), circle($fn=70,r=2)], z=[0,3], slices=10);
|
||||
// Example: Rotating the pentagon place the zero index at different locations, giving a twist
|
||||
|
@ -315,11 +322,15 @@ include <vnf.scad>
|
|||
// stroke(zrot(30, p=yscale(0.5, p=circle(d=120))),width=10,closed=true);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
module skin(profiles, slices, refine=1, method="direct", sampling, caps, closed=false, z, convexity=10)
|
||||
module skin(profiles, slices, refine=1, method="direct", sampling, caps, closed=false, z, convexity=10,
|
||||
anchor="origin",cp,spin=0, orient=UP, extent=false)
|
||||
{
|
||||
vnf_polyhedron(skin(profiles, slices, refine, method, sampling, caps, closed, z), convexity=convexity);
|
||||
vnf = skin(profiles, slices, refine, method, sampling, caps, closed, z);
|
||||
attachable(anchor=anchor, spin=spin, orient=orient, vnf=vnf, extent=extent, cp=is_def(cp) ? cp : vnf_centroid(vnf))
|
||||
{
|
||||
vnf_polyhedron(vnf,convexity=convexity);
|
||||
children();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -803,6 +814,12 @@ function associate_vertices(polygons, split, curpoly=0) =
|
|||
// transformations = list of 4x4 matrices to apply
|
||||
// closed = set to true to form a closed (torus) model. Default: false
|
||||
// caps = true to create endcap faces when closed is false. Can be a singe boolean to specify endcaps at both ends, or a length 2 boolean array. Default is true if closed is false.
|
||||
// convexity = convexity setting for use with polyhedron. (module only) Default: 10
|
||||
// anchor = Translate so anchor point is at the origin. (module only) Default: "origin"
|
||||
// spin = Rotate this many degrees around Z axis after anchor. (module only) Default: 0
|
||||
// orient = Vector to rotate top towards after spin (module only)
|
||||
// extent = use extent method for computing anchors. (module only) Default: false
|
||||
// cp = set centerpoint for anchor computation. (module only) Default: object centroid
|
||||
// Example: This is the "sweep-drop" example from list-comprehension-demos.
|
||||
// function drop(t) = 100 * 0.5 * (1 - cos(180 * t)) * sin(180 * t) + 1;
|
||||
// function path(t) = [0, 0, 80 + 80 * cos(180 * t)];
|
||||
|
@ -839,9 +856,16 @@ function sweep(shape, transformations, closed=false, caps) =
|
|||
assert(!closed || !caps, "Cannot make closed shape with caps")
|
||||
_skin_core([for(i=[0:len(transformations)-(closed?0:1)]) apply(transformations[i%len(transformations)],path3d(shape))],caps=fullcaps);
|
||||
|
||||
module sweep(shape, transformations, closed=false, caps, convexity=10) {
|
||||
vnf_polyhedron(sweep(shape, transformations, closed, caps), convexity=convexity);
|
||||
}
|
||||
module sweep(shape, transformations, closed=false, caps, convexity=10,
|
||||
anchor="origin",cp,spin=0, orient=UP, extent=false)
|
||||
{
|
||||
vnf = sweep(shape, transformations, closed, caps);
|
||||
attachable(anchor=anchor, spin=spin, orient=orient, vnf=vnf, extent=extent, cp=is_def(cp) ? cp : vnf_centroid(vnf))
|
||||
{
|
||||
vnf_polyhedron(vnf,convexity=convexity);
|
||||
children();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Function&Module: path_sweep()
|
||||
|
@ -906,8 +930,13 @@ module sweep(shape, transformations, closed=false, caps, convexity=10) {
|
|||
// tangent = a list of tangent vectors in case you need more accuracy (particularly at the end points of your curve)
|
||||
// relaxed = set to true with the "manual" method to relax the orthogonality requirement of cross sections to the path tangent. Default: false
|
||||
// caps = Can be a boolean or vector of two booleans. Set to false to disable caps at the two ends. Default: true
|
||||
// transforms = set to true to return transforms instead of a VNF. These transforms can be manipulated and passed to sweep(). Default: false.
|
||||
// convexity = convexity parameter for polyhedron(). Only accepted by the module version. Default: 10
|
||||
// transforms = set to true to return transforms instead of a VNF. These transforms can be manipulated and passed to sweep(). Default: false.
|
||||
// anchor = Translate so anchor point is at the origin. (module only) Default: "origin"
|
||||
// spin = Rotate this many degrees around Z axis after anchor. (module only) Default: 0
|
||||
// orient = Vector to rotate top towards after spin (module only)
|
||||
// extent = use extent method for computing anchors. (module only) Default: false
|
||||
// cp = set centerpoint for anchor computation. (module only) Default: object centroid
|
||||
//
|
||||
// Example(2D): We'll use this shape in several examples
|
||||
// ushape = [[-10, 0],[-10, 10],[ -7, 10],[ -7, 2],[ 7, 2],[ 7, 7],[ 10, 7],[ 10, 0]];
|
||||
|
@ -1121,13 +1150,19 @@ module sweep(shape, transformations, closed=false, caps, convexity=10) {
|
|||
// outside = [for(i=[0:len(trans)-1]) trans[i]*scale(lerp(1,1.5,i/(len(trans)-1)))];
|
||||
// inside = [for(i=[len(trans)-1:-1:0]) trans[i]*scale(lerp(1.1,1.4,i/(len(trans)-1)))];
|
||||
// sweep(shape, concat(outside,inside),closed=true);
|
||||
|
||||
module path_sweep(shape, path, method="incremental", normal, closed=false, twist=0, twist_by_length=true,
|
||||
symmetry=1, last_normal, tangent, relaxed=false, caps, convexity=10)
|
||||
symmetry=1, last_normal, tangent, relaxed=false, caps, convexity=10,
|
||||
anchor="origin",cp,spin=0, orient=UP, extent=false)
|
||||
{
|
||||
vnf_polyhedron(path_sweep(shape, path, method, normal, closed, twist, twist_by_length,
|
||||
symmetry, last_normal, tangent, relaxed, caps), convexity=convexity);
|
||||
}
|
||||
vnf = path_sweep(shape, path, method, normal, closed, twist, twist_by_length,
|
||||
symmetry, last_normal, tangent, relaxed, caps);
|
||||
attachable(anchor=anchor, spin=spin, orient=orient, vnf=vnf, extent=extent, cp=is_def(cp) ? cp : vnf_centroid(vnf))
|
||||
{
|
||||
vnf_polyhedron(vnf,convexity=convexity);
|
||||
children();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function path_sweep(shape, path, method="incremental", normal, closed=false, twist=0, twist_by_length=true,
|
||||
symmetry=1, last_normal, tangent, relaxed=false, caps, transforms=false) =
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
BOSL_VERSION = [2,0,402];
|
||||
BOSL_VERSION = [2,0,405];
|
||||
|
||||
|
||||
// Section: BOSL Library Version Functions
|
||||
|
|
Loading…
Reference in a new issue