3-D shapes and Bosl2Solid¶
Pure-Python port of the 3-D shape generators from BOSL2’s shapes3d.scad. Each returns a
Bosl2Solid wrapping native geometry, with BOSL2-style anchor/spin/orient
support and bbox-backed attachment methods.
Coverage of BOSL2 shapes3d.scad¶
BOSL2 shape |
Status |
Notes |
|---|---|---|
|
ported |
with chamfer / rounding / edge selection |
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported (height-field form) |
|
Bosl2Solid & attachment¶
Every 3-D shape is a Bosl2Solid, which carries the transform methods
(translate/move, rotate/rot, right/left/back/forward/up/down,
mirror, scale, color) and the BOSL2 attachment methods —
bounds, anchor_point, reanchor, reorient, orient, position, attach,
align, plus the edge/corner/face masking (edge_mask, edge_profile, corner_profile,
face_profile). All of these read the object’s native bounding box, so a size never needs to
be threaded through the calls — e.g. cuboid([40,30,20]).attach(TOP, sphere(radius=6)) or
cyl(height=20, radius=5).orient(RIGHT) just work on the built object.
The BOSL2 attachment framework internals (attachable, attach_geom, named anchors, the
tag/diff/intersect tagged-CSG operations, and the show_anchors/description helpers)
are not ported — the methods above cover positioning/masking directly on the object.
API reference¶
- class bosl2.shapes3d.Bosl2Solid(shape, size=None, anchor=None)[source]¶
Bases:
Distributable,Colorable,Partitionable,MiscellaneousWraps a PyOpenSCAD solid together with the geometry metadata (nominal size and anchor) that BOSL2’s $parent_geom attachment system would otherwise track, so that edge/corner/face masking (bosl2/masking.py) work as plain chained methods instead of needing size=/anchor= threaded through by hand at every call site. Every function in this file returns an instance of this class (or a subclass).
Every geometry method (translate/rotate/mirror/multmatrix/scale/color, the union/intersection/ difference CSG operators) delegates to the wrapped native shape and returns a new Bosl2Solid carrying the same size/anchor metadata forward. Any other method not explicitly listed here (e.g. resize(), offset()) falls through via __getattr__ to the native shape and returns its raw, unwrapped result, since we can’t know whether the size/anchor metadata still applies.
Only cuboid()-shaped objects (cube(), cuboid() – the only ones in this file with a genuine axis-aligned box size) support the masking methods; every other shape (prismoid, wedge, octahedron, the cylinder family, the sphere family) carries size=None and will assert if a masking method is called on it, since bosl2/masking.py’s edge/corner positioning math only supports cuboid parents.
CAVEAT: this is a plain Python wrapper (composition), not a subclass of the real native PyOpenSCAD C-extension type – there was no way to verify from this environment whether that type even supports subclassing. Calling a method on a Bosl2Solid (shape.translate(…), shape.edge_profile(…)) is safe. But if a Bosl2Solid is ever passed directly as a bare argument into a function that expects a native geometry object – hull(a, b), minkowski(a, b) – rather than having a method called on it, the receiving function needs the raw native object: use .shape to unwrap explicitly.
- Parameters:
shape (PyOpenSCAD)
size (Sequence[float] | None)
anchor (Sequence[float] | str | None)
- backend = 'csg'¶
which realize backend produced this solid – see bosl2/_backend.py. Bosl2Solid is the exact-CSG (PythonSCAD) backend’s Solid; the libfive/SDF backend uses its own wrapper.
- move(v)¶
- Parameters:
v (Sequence[float])
- Return type:
- rot(*a, **k)¶
- Return type:
- fwd(y)¶
- Parameters:
y (float)
- Return type:
- repair()[source]¶
Force the mesh watertight, healing gaps/non-manifold edges (native
repair()).- Return type:
- wrap(radius, fn=None)[source]¶
Wrap this solid around a cylinder of radius radius, bending +X into the cylinder’s circumference (native
wrap()). fn sets the facet count of the bend.- Parameters:
radius (float)
fn (int | None)
- Return type:
- pull(direction, distance)[source]¶
Pull the part of the solid on the +*direction* side apart by distance, stretching the material between (native
pull()).- Parameters:
direction (Sequence[float] | ndarray)
distance (float)
- Return type:
- oversample(sides)[source]¶
Subdivide every mesh facet sides-fold, e.g. before
wrap()so the bend is smooth (nativeoversample()).- Parameters:
sides (int)
- Return type:
- separate()[source]¶
Split a solid made of disconnected lumps into a list of its connected components (native
separate()).- Return type:
list[Bosl2Solid]
- inside(point)[source]¶
True if point lies inside the solid (native
inside()).- Parameters:
point (Sequence[float] | ndarray)
- Return type:
bool
- hull(*others)[source]¶
The convex hull of this solid (OpenSCAD
hull()).With arguments, the hull of this solid together with each of others – the shrink-wrap around them all, which is how BOSL2 builds a rounded box from spheres at its corners. Each of others may be a
Bosl2Solid, a raw native solid, or aVNF/point list, which is meshed as a polyhedron first.See
chain_hull()to hull consecutive pairs instead of everything at once.Examples
capsule = s3.sphere(radius=8).hull(s3.sphere(radius=8).up(30)) capsule.show()
- Return type:
- projection(cut=False)[source]¶
The 2-D shadow of this solid on the XY plane (OpenSCAD
projection()).With
cut=Trueyou get the cross-section where the solid crosses the z=0 plane instead of the full outline – slice the solid at the height you want first.- Returns:
A
Bosl2Shape2D, so the result chains straight back into the 2-D operators (.offset(),.fill(),.hull()) and the extruders.- Parameters:
cut (bool)
- Return type:
Note
CSG only. The SDF backend’s
projection()raisesUnsupportedByBackend– a distance field has no closed-form 2-D shadow, and 2-D geometry is a CSG-backend notion.Examples
A footprint outline, grown 2mm, extruded into a base plate:
part = s3.cuboid([30, 20, 10], rounding=3) part.projection().offset(radius=2).linear_extrude(height=2).show()
- to_csg()[source]¶
This solid is already on the CSG backend – returns self (the converter no-op).
- Return type:
- to_sdf(voxel_size=None)[source]¶
CSG -> SDF conversion is not supported (would require lossy voxel-sampling).
- Parameters:
voxel_size (float | None)
- Return type:
- bounds()[source]¶
This object’s axis-aligned bounding box as (center, size) – both plain [x, y, z] float lists in the object’s CURRENT coordinate frame (after any translate/rotate/CSG).
Prefers the native bbox, which always reflects the actual current geometry – this is what lets anchoring/attachment/masking work without the caller tracking a size, and stays correct after the object has been moved or combined (tracked size/anchor metadata would be stale there). Falls back to the tracked cuboid size/anchor metadata only when the native accessors aren’t available (the numeric test mock), where it assumes the box is still at its construction position. Raises if neither is available.
- Return type:
tuple[list[float], list[float]]
- anchor_point(anchor, bbox=None)[source]¶
The [x, y, z] point on this object’s bounding box for the given anchor vector, in the object’s current coordinate frame: center + anchor * size / 2. Works on any object.
Pass bbox to anchor against a supplied box instead of the object’s own (see
_resolve_bounds()).- Parameters:
anchor (Sequence[float])
- Return type:
list[float]
- reanchor(anchor, bbox=None)[source]¶
Return this object translated so its bounding-box anchor point sits at the origin. Re-anchors any object by its bbox after the fact (cube()/cuboid() only do this at construction, and only for cuboids). Pass bbox to use a supplied box.
- Parameters:
anchor (Sequence[float])
- Return type:
- position(anchor, child, bbox=None)[source]¶
BOSL2 position(): place child so its local origin lands on this object’s bounding-box anchor point, keeping the child’s own orientation, and return self unioned with the placed child. child may be a Bosl2Solid or a raw native solid.
- Parameters:
anchor (Sequence[float])
- Return type:
- align(anchor, child, align=None, inside=False, overlap=0.0, bbox=None)[source]¶
BOSL2 align(): place child on this object’s anchor face and return self unioned with it. Like attach() it mates a child face to a parent face, but WITHOUT reorienting the child – the child keeps its own axes and is merely translated.
With align omitted the child is centered on the face, sitting OUTSIDE the parent (inside=False, the default) or tucked inside (inside=True). Pass align (an edge/corner direction within the face, e.g. RIGHT for the +x edge) to sit the child flush against that edge/corner instead – matching BOSL2 align()’s anchor+align pair. Both anchor points come from the native bounding boxes, so no size needs to be passed.
- Parameters:
anchor (Sequence[float]) – the parent face to place the child on (e.g. TOP)
child – the solid to place (Bosl2Solid or raw native solid)
align (Sequence[float] | None) – edge/corner within the face to sit flush against (default: centered)
inside (bool) – place the child inside the parent instead of outside (default False)
overlap (float) – pull the child toward the parent along the face normal by this much
- Return type:
- attach(parent_anchor, child, child_anchor=None, overlap=0.0, spin=0.0, bbox=None)[source]¶
BOSL2 attach(): orient and place child so its child_anchor face mates flush against this object’s parent_anchor face, then return self unioned with the placed child. Both anchor points come from the native bounding boxes, so neither object needs its size passed explicitly.
- Parameters:
parent_anchor (Sequence[float]) – which face of self to attach to (e.g. TOP)
child – the solid to attach (Bosl2Solid or raw native solid)
child_anchor (Sequence[float] | None) – which face of the child mates against it (default: the child’s face OPPOSITE parent_anchor, so the two mate naturally)
overlap (float) – pull the child in by this much along the mating axis (default 0)
spin (float) – spin the child about the mating axis, in degrees (default 0)
- Return type:
- reorient(anchor=[0, 0, 0], spin=0, orient=[0, 0, 1], bbox=None)[source]¶
Reorient this already-built object by its bounding box (BOSL2 reorient()).
Moves the bounding-box anchor point to the origin, spins spin degrees about Z, then rotates the object’s UP toward orient. The size comes from the native bbox, so – unlike BOSL2’s function form – you never pass it. cube()/cuboid()/etc. take anchor/spin/orient at construction; this applies the same transform to any object after the fact. Pass bbox to reorient against a supplied box instead of the object’s own.
- Parameters:
anchor (Sequence[float])
spin (float)
orient (Sequence[float])
- Return type:
- orient(direction=[0, 0, 1], spin=0, bbox=None)[source]¶
Rotate this object so its top (UP) faces direction (BOSL2 orient()); uses the bbox.
- Parameters:
direction (Sequence[float])
spin (float)
- Return type:
- edge_mask(edges='ALL', except_edges=None, children=None, bbox=None)[source]¶
- Parameters:
edges (str | list)
except_edges (list | None)
children (PyOpenSCAD | None)
- Return type:
- edge_profile(edges='ALL', except_edges=None, children=None, convexity=10, bbox=None)[source]¶
- Parameters:
edges (str | list)
except_edges (list | None)
children (Sequence[Sequence[float]] | None)
convexity (int)
- Return type:
- edge_profile_asym(edges='ALL', except_edges=None, children=None, convexity=10)[source]¶
- Parameters:
edges (str | list)
except_edges (list | None)
children (Sequence[Sequence[float]] | None)
convexity (int)
- Return type:
- corner_profile(corners='ALL', except_corners=None, radius=None, diameter=None, children=None, convexity=10, fn=None, fa=None, fs=None, bbox=None)[source]¶
- Parameters:
corners (str | list)
except_corners (list | None)
radius (float | None)
diameter (float | None)
children (Sequence[Sequence[float]] | None)
convexity (int)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
- face_profile(faces='ALL', radius=None, diameter=None, children=None, convexity=10, fn=None, fa=None, fs=None, bbox=None)[source]¶
- Parameters:
faces (str | list)
radius (float | None)
diameter (float | None)
children (Sequence[Sequence[float]] | None)
convexity (int)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
- bosl2.shapes3d.roof(shape, method='straight')[source]¶
Raise a hip roof over a 2-D shape via its straight skeleton (native
roof()).Like
linear_sweep(), this turns a 2-D outline into a 3-D solid, but the top is a peaked roof (each edge slopes inward at 45 degrees to the skeleton) rather than a flat extrusion. shape is any 2-D object – a nativesquare/circle/polygon, aPath.polygon(), or aBosl2Solidwrapping one. method selects the skeleton algorithm. PythonSCAD-only (no BOSL2 counterpart); covered by the STL render tests.- Parameters:
method (str)
- Return type:
- bosl2.shapes3d.cube(size=1, center=None, anchor=[0, 0, 0], spin=0, orient=[0, 0, 1])[source]¶
A cube, built with the builtin cube(), with BOSL2-style anchor/spin/orient support.
- Parameters:
size (float | Sequence[float]) – size of the cube, a number or length-3 vector
center (bool | None) – if given, overrides anchor (True -> CENTER, False -> FRONT+LEFT+BOTTOM)
anchor (Sequence[float]) – anchor point (default CENTER)
spin (float) – Z-axis rotation in degrees after anchor (default 0)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
- Return type:
- bosl2.shapes3d.cuboid(size=[1, 1, 1], p1=None, p2=None, chamfer=None, rounding=None, edges='ALL', except_edges=None, trimcorners=True, teardrop=False, anchor=[0, 0, 0], spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
A cube/cuboid with optional chamfering or rounding of edges and corners.
Built directly from cube()/cylinder()/sphere()/hull()/minkowski(), mirroring BOSL2’s own cuboid() algorithm (which is itself CSG composition of primitive shapes at each corner, not raw polyhedron mesh math).
You cannot mix chamfering and rounding on the same call. Negative chamfers/roundings create external fillets, but only apply to edges around the top or bottom face.
Note: teardrop= is not supported by this pure-Python port.
- Parameters:
size (float | Sequence[float]) – size of the cuboid, a number or length-3 vector
p1 (Sequence[float] | None) – align the cuboid’s corner at p1, if given (forces anchor=FRONT+LEFT+BOTTOM)
p2 (Sequence[float] | None) – if given with p1, defines the cuboid’s opposing cornerpoint
chamfer (float | None) – chamfer size, inset from sides (default: no chamfer)
rounding (float | None) – edge rounding radius (default: no rounding)
edges (str | list) – edges to mask (default “ALL”)
except_edges (list | None) – edges to explicitly not mask (BOSL2’s except= synonym; except is a Python keyword)
trimcorners (bool) – round/chamfer corners where three treated edges meet (default True)
anchor (Sequence[float]) – anchor point (default CENTER)
spin (float) – Z-axis rotation in degrees (default 0)
orient (Sequence[float]) – direction to rotate the top towards (default UP)
fn/fa/fs – arc smoothness overrides for rounded edges/corners
teardrop (bool | float)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
Examples
shape = bosl2.shapes3d.cuboid([40, 30, 20]) shape.show()
shape = bosl2.shapes3d.cuboid([40, 30, 20], rounding=5) shape.show()
- bosl2.shapes3d.prismoid(size1, size2, height=None, shift=[0, 0], rounding=0, rounding1=None, rounding2=None, chamfer=0, chamfer1=None, chamfer2=None, length=None, center=None, anchor=[0, 0, -1], spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
A rectangular prismoid, built as the convex hull() of two (optionally rounded/chamfered) rects.
- Parameters:
size1 (Sequence[float]) – [width, length] of the bottom end
size2 (Sequence[float]) – [width, length] of the top end
height/length – height of the prism
shift (Sequence[float]) – [X,Y] shift of the top center relative to the bottom center
rounding (float | Sequence[float]) – vertical-edge roundover radius, or per-corner list [X+Y+,X-Y+,X-Y-,X+Y-] (default 0)
rounding1 (float | Sequence[float] | None) – roundover radius for the bottom of the vertical-ish edges
rounding2 (float | Sequence[float] | None) – roundover radius for the top of the vertical-ish edges
chamfer (float | Sequence[float]) – vertical-edge chamfer size, or per-corner list (default 0)
chamfer1 (float | Sequence[float] | None) – chamfer size for the bottom of the vertical-ish edges
chamfer2 (float | Sequence[float] | None) – chamfer size for the top of the vertical-ish edges
center (bool | None) – if given, overrides anchor
anchor (Sequence[float]) – anchor point (default BOTTOM)
spin (float) – Z-axis rotation in degrees after anchor (default 0)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
fn/fa/fs – arc smoothness overrides for rounded corners
height (float | None)
length (float | None)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
Examples
shape = bosl2.shapes3d.prismoid([40, 40], [20, 25], height=30) shape.show()
- bosl2.shapes3d.octahedron(size=1, anchor=[0, 0, 0], spin=0, orient=[0, 0, 1])[source]¶
An octahedron with axis-aligned points, built directly with polyhedron().
- Parameters:
size (float) – width of the octahedron, tip to tip
anchor (Sequence[float]) – anchor point (default CENTER)
spin (float) – Z-axis rotation in degrees after anchor (default 0)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
- Return type:
- bosl2.shapes3d.wedge(size=[1, 1, 1], center=None, anchor=[-1, -1, -1], spin=0, orient=[0, 0, 1])[source]¶
A 3-D triangular wedge with the hypotenuse in the X+Z+ quadrant, built directly with polyhedron().
- Parameters:
size (Sequence[float]) – [width, thickness, height]
center (bool | None) – if given, overrides anchor (True -> CENTER, False -> FRONT+LEFT+BOTTOM)
anchor (Sequence[float]) – anchor point (default FRONT+LEFT+BOTTOM)
spin (float) – Z-axis rotation in degrees after anchor (default 0)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
- Return type:
- bosl2.shapes3d.rect_tube(height=None, size=None, isize=None, center=None, shift=[0, 0], wall=None, size1=None, size2=None, isize1=None, isize2=None, rounding=0, rounding1=None, rounding2=None, inner_rounding=0, inner_rounding1=None, inner_rounding2=None, chamfer=0, chamfer1=None, chamfer2=None, inner_chamfer=0, inner_chamfer1=None, inner_chamfer2=None, anchor=[0, 0, -1], spin=0, orient=[0, 0, 1], length=None)[source]¶
BOSL2 rect_tube() – a rectangular tube (a rectangle with a rectangular hole through it).
- Parameters:
height/length – height/length of the tube (default 1)
size (float | Sequence[float] | None) – outer [X,Y] size of the tube
isize (float | Sequence[float] | None) – inner [X,Y] size of the tube
center (bool | None) – if given, overrides anchor
shift (Sequence[float]) – [X,Y] shift of the top center relative to the bottom center
wall (float | None) – wall thickness
size1/size2 – outer [X,Y] size at the bottom/top
isize1/isize2 – inner [X,Y] size at the bottom/top
rounding/rounding1/rounding2 – outer edge rounding radius (overall/bottom/top)
inner_rounding/inner_rounding1/inner_rounding2 – inner edge rounding radius (default: same as rounding)
chamfer/chamfer1/chamfer2 – outer edge chamfer size (overall/bottom/top)
inner_chamfer/inner_chamfer1/inner_chamfer2 – inner edge chamfer size (default: same as chamfer)
anchor (Sequence[float]) – anchor point (default BOTTOM)
spin (float) – Z-axis rotation in degrees after anchor (default 0)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
height (float | None)
size1 (float | Sequence[float] | None)
size2 (float | Sequence[float] | None)
isize1 (float | Sequence[float] | None)
isize2 (float | Sequence[float] | None)
rounding (float | Sequence[float])
rounding1 (float | Sequence[float] | None)
rounding2 (float | Sequence[float] | None)
inner_rounding (float | Sequence[float])
inner_rounding1 (float | Sequence[float] | None)
inner_rounding2 (float | Sequence[float] | None)
chamfer (float | Sequence[float])
chamfer1 (float | Sequence[float] | None)
chamfer2 (float | Sequence[float] | None)
inner_chamfer (float | Sequence[float])
inner_chamfer1 (float | Sequence[float] | None)
inner_chamfer2 (float | Sequence[float] | None)
length (float | None)
- Return type:
- bosl2.shapes3d.cylinder(height=None, radius1=None, radius2=None, center=None, length=None, radius=None, diameter=None, diameter1=None, diameter2=None, anchor=[0, 0, 0], spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
A cylinder/cone, built with the builtin cylinder(), with BOSL2-style anchor/spin/orient support.
- Parameters:
length/height – height of the cylinder
radius1 (float | None) – bottom radius (before orientation)
radius2 (float | None) – top radius (before orientation)
center (bool | None) – if given, overrides anchor (True -> CENTER, False -> BOTTOM)
diameter1 (float | None) – bottom diameter (before orientation)
diameter2 (float | None) – top diameter (before orientation)
radius (float | None) – radius of the cylinder
diameter (float | None) – diameter of the cylinder
anchor (Sequence[float]) – anchor point (default CENTER)
spin (float) – Z-axis rotation in degrees after anchor (default 0)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
fn/fa/fs – arc smoothness overrides
height (float | None)
length (float | None)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
- bosl2.shapes3d.cyl(height=None, radius=None, center=None, length=None, radius1=None, radius2=None, diameter=None, diameter1=None, diameter2=None, chamfer=None, chamfer1=None, chamfer2=None, chamfer_angle=None, chamfer_angle1=None, chamfer_angle2=None, rounding=None, rounding1=None, rounding2=None, circum=False, realign=False, shift=[0, 0], from_end=None, from_end1=None, from_end2=None, texture=None, tex_size=[5, 5], tex_counts=None, tex_inset=False, tex_rot=False, tex_scale=1, tex_samples=None, tex_taper=None, tex_style='min_edge', anchor=None, spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
A cylinder with optional chamfering/rounding of its end rims, built with cube()/cylinder()/sphere()/rotate_extrude().
Positive rounding is built as a minkowski() of a shorter cylinder with a sphere at each rounded end (an inset fillet, not an outward bulge), matching BOSL2’s own rounded-end geometry. Chamfering builds the exact half-profile (with the requested bevel at each end) and revolves it with rotate_extrude().
Note: texture= (VNF surface texturing) is not supported by this pure-Python port.
- Parameters:
length/height – length of the cylinder along its axis (default 1)
radius (float | None) – radius of the cylinder (default 1)
center (bool | None) – if given, overrides anchor (True -> CENTER, False -> BOTTOM)
radius1/radius2 – radius of the negative/positive end of the cylinder
diameter/diameter1/diameter2 – diameter of the cylinder / negative end / positive end
chamfer/chamfer1/chamfer2 – chamfer size on the ends (overall/bottom/top)
rounding/rounding1/rounding2 – rounding radius on the ends (overall/bottom/top)
circum (bool) – circumscribe rather than inscribe the given radius (default False)
realign (bool) – rotate by half the angle of one face (default False)
shift (Sequence[float]) – [X,Y] shift of the top center relative to the bottom center
anchor (Sequence[float] | None) – anchor point (default CENTER, or BOTTOM if center=False)
spin (float) – Z-axis rotation in degrees after anchor (default 0)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
fn/fa/fs – arc smoothness overrides
height (float | None)
length (float | None)
radius1 (float | None)
radius2 (float | None)
diameter (float | None)
diameter1 (float | None)
diameter2 (float | None)
chamfer (float | None)
chamfer1 (float | None)
chamfer2 (float | None)
chamfer_angle (float | None)
chamfer_angle1 (float | None)
chamfer_angle2 (float | None)
rounding (float | None)
rounding1 (float | None)
rounding2 (float | None)
from_end (bool | None)
from_end1 (bool | None)
from_end2 (bool | None)
texture (str | list | None)
tex_size (Sequence[float])
tex_counts (Sequence[float] | None)
tex_inset (bool | float)
tex_rot (bool)
tex_scale (float)
tex_samples (int | None)
tex_taper (float | list | None)
tex_style (str)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
Examples
shape = bosl2.shapes3d.cyl(height=30, radius=10) shape.show()
shape = bosl2.shapes3d.cyl(height=30, radius=10, rounding=3) shape.show()
- bosl2.shapes3d.regular_prism(sides, height=None, radius=None, diameter=None, radius1=None, radius2=None, inner_radius=None, inner_diameter=None, side=None, length=None, chamfer=None, chamfer1=None, chamfer2=None, rounding=None, rounding1=None, rounding2=None, circum=False, realign=False, shift=[0, 0], center=None, anchor=None, spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
A regular sides-sided prism (or frustum) – the sides-gon analogue of cyl(): a regular polygon cross-section extruded along Z, with optional per-end chamfer or rounding. Built the same way cyl() is (native cylinder with fn=sides for the plain case; a revolved half-profile with fn=sides for chamfered/rounded ends), so it shares cyl()’s exact rim geometry.
Sizing gives the CIRCUMradius (vertex distance) unless noted – exactly one of
radius/diameter(radius/diameter to the vertices),inner_radius/inner_diameter(inradius/apothem to the face centers, converted via/cos(180/sides)), orside(edge length, converted via/(2 sin(180/sides))).radius1/radius2(or the corresponding taper) set the bottom/top radius independently for a frustum.Note: BOSL2 regular_prism()’s texture=/teardrop= options are not ported (they need the VNF texturing machinery this pure-Python port doesn’t implement).
- Parameters:
sides (int) – number of sides (integer >= 3)
height/length/height/length – prism height (default 1)
radius/diameter/inner_radius/inner_diameter/side – overall size (see above)
radius1/radius2 – bottom/top circumradius for a tapered prism
chamfer/chamfer1/chamfer2 – end chamfer size (overall/bottom/top)
rounding/rounding1/rounding2 – end rounding radius (overall/bottom/top)
circum (bool) – circumscribe the nominal radius (scale by 1/cos(180/sides)) (default False)
realign (bool) – rotate by half a facet so a face, not a vertex, faces +X (default False)
shift (Sequence[float]) – [X,Y] shift of the top center relative to the bottom center
center (bool | None) – if given, overrides anchor (True -> CENTER, False -> BOTTOM)
anchor (Sequence[float] | None) – anchor point (default CENTER)
spin (float) – Z-axis rotation in degrees after anchor (default 0)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
height (float | None)
radius (float | None)
diameter (float | None)
radius1 (float | None)
radius2 (float | None)
inner_radius (float | None)
inner_diameter (float | None)
side (float | None)
length (float | None)
chamfer (float | None)
chamfer1 (float | None)
chamfer2 (float | None)
rounding (float | None)
rounding1 (float | None)
rounding2 (float | None)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
Examples
shape = bosl2.shapes3d.regular_prism(6, height=20, radius=15) shape.show()
shape = bosl2.shapes3d.regular_prism(5, height=20, inner_radius=12, rounding=2) shape.show()
- bosl2.shapes3d.xcyl(height=None, radius=None, diameter=None, radius1=None, radius2=None, diameter1=None, diameter2=None, length=None, chamfer=None, chamfer1=None, chamfer2=None, rounding=None, rounding1=None, rounding2=None, circum=False, realign=False, anchor=[0, 0, 0], spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
A cylinder oriented along the X axis. See cyl() for argument details.
- Parameters:
height (float | None)
radius (float | None)
diameter (float | None)
radius1 (float | None)
radius2 (float | None)
diameter1 (float | None)
diameter2 (float | None)
length (float | None)
chamfer (float | None)
chamfer1 (float | None)
chamfer2 (float | None)
rounding (float | None)
rounding1 (float | None)
rounding2 (float | None)
circum (bool)
realign (bool)
anchor (Sequence[float])
spin (float)
orient (Sequence[float])
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
- bosl2.shapes3d.ycyl(height=None, radius=None, diameter=None, radius1=None, radius2=None, diameter1=None, diameter2=None, length=None, chamfer=None, chamfer1=None, chamfer2=None, rounding=None, rounding1=None, rounding2=None, circum=False, realign=False, anchor=[0, 0, 0], spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
A cylinder oriented along the Y axis. See cyl() for argument details.
- Parameters:
height (float | None)
radius (float | None)
diameter (float | None)
radius1 (float | None)
radius2 (float | None)
diameter1 (float | None)
diameter2 (float | None)
length (float | None)
chamfer (float | None)
chamfer1 (float | None)
chamfer2 (float | None)
rounding (float | None)
rounding1 (float | None)
rounding2 (float | None)
circum (bool)
realign (bool)
anchor (Sequence[float])
spin (float)
orient (Sequence[float])
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
- bosl2.shapes3d.zcyl(height=None, radius=None, diameter=None, radius1=None, radius2=None, diameter1=None, diameter2=None, length=None, chamfer=None, chamfer1=None, chamfer2=None, rounding=None, rounding1=None, rounding2=None, circum=False, realign=False, anchor=[0, 0, 0], spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
A cylinder oriented along the Z axis (same as cyl() with default orientation). See cyl() for argument details.
- Parameters:
height (float | None)
radius (float | None)
diameter (float | None)
radius1 (float | None)
radius2 (float | None)
diameter1 (float | None)
diameter2 (float | None)
length (float | None)
chamfer (float | None)
chamfer1 (float | None)
chamfer2 (float | None)
rounding (float | None)
rounding1 (float | None)
rounding2 (float | None)
circum (bool)
realign (bool)
anchor (Sequence[float])
spin (float)
orient (Sequence[float])
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
- bosl2.shapes3d.tube(height=None, outer_radius=None, inner_radius=None, center=None, outer_diameter=None, inner_diameter=None, wall=None, outer_radius1=None, outer_radius2=None, outer_diameter1=None, outer_diameter2=None, inner_radius1=None, inner_radius2=None, inner_diameter1=None, inner_diameter2=None, realign=False, length=None, anchor=[0, 0, 0], spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
BOSL2 tube() – a hollow cylindrical tube.
Note: BOSL2’s outer-radius parameters are named or/or1/or2, which collide with the Python keyword or; they are exposed here as outer_radius/outer_radius1/outer_radius2 instead.
- Parameters:
height/length – height of the tube (default 1)
outer_radius (float | None) – outer radius of the tube (BOSL2 or) (default 1)
inner_radius (float | None) – inner radius of the tube
center (bool | None) – if given, overrides anchor (True -> CENTER, False -> DOWN)
outer_diameter (float | None) – outer diameter of the tube
inner_diameter (float | None) – inner diameter of the tube
wall (float | None) – horizontal wall thickness (default 1)
outer_radius1/outer_radius2 – outer radius of the bottom/top (BOSL2 or1/or2)
outer_diameter1/outer_diameter2 – outer diameter of the bottom/top
inner_radius1/inner_radius2 – inner radius of the bottom/top
inner_diameter1/inner_diameter2 – inner diameter of the bottom/top
realign (bool) – rotate by half the angle of one face (default False)
anchor (Sequence[float]) – anchor point (default CENTER)
spin (float) – Z-axis rotation in degrees after anchor (default 0)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
fn/fa/fs – arc smoothness overrides
height (float | None)
outer_radius1 (float | None)
outer_radius2 (float | None)
outer_diameter1 (float | None)
outer_diameter2 (float | None)
inner_radius1 (float | None)
inner_radius2 (float | None)
inner_diameter1 (float | None)
inner_diameter2 (float | None)
length (float | None)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
Examples
shape = bosl2.shapes3d.tube(height=20, outer_radius=15, inner_radius=10) shape.show()
- bosl2.shapes3d.pie_slice(height=None, radius=None, angle=30, center=None, radius1=None, radius2=None, diameter=None, diameter1=None, diameter2=None, length=None, anchor=[0, 0, 0], spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
BOSL2 pie_slice() – a pie slice, wedge of a cylinder/cone.
- Parameters:
height/length – height of the pie slice
radius (float | None) – radius of the pie slice
angle (float) – pie slice angle in degrees (default 30)
center (bool | None) – if given, overrides anchor
radius1/radius2 – bottom/top radius of the pie slice
diameter/diameter1/diameter2 – diameter of the pie slice / bottom / top
anchor (Sequence[float]) – anchor point (default CENTER)
spin (float) – Z-axis rotation in degrees after anchor (default 0)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
fn/fa/fs – arc smoothness overrides
height (float | None)
radius1 (float | None)
radius2 (float | None)
diameter (float | None)
diameter1 (float | None)
diameter2 (float | None)
length (float | None)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
- bosl2.shapes3d.sphere(radius=None, diameter=None, circum=False, style='orig', anchor=[0, 0, 0], spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
A sphere, built with the builtin sphere(), with BOSL2-style anchor/spin/orient support.
Note: style=/circum= are accepted for signature compatibility but not applied; the builtin sphere() is used directly.
- Parameters:
radius (float | None) – radius of the sphere
diameter (float | None) – diameter of the sphere
anchor (Sequence[float]) – anchor point (default CENTER)
spin (float) – Z-axis rotation in degrees after anchor (default 0)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
fn/fa/fs – arc smoothness overrides
circum (bool)
style (str)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
Examples
shape = bosl2.shapes3d.sphere(radius=15) shape.show()
- bosl2.shapes3d.spheroid(radius=None, style='aligned', diameter=None, circum=False, dual=False, anchor=[0, 0, 0], spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
An approximate sphere; this pure-Python port just builds a plain sphere() (style/dual are ignored).
- Parameters:
radius (float | None) – radius of the spheroid
diameter (float | None) – diameter of the spheroid
anchor (Sequence[float]) – anchor point (default CENTER)
spin (float) – Z-axis rotation in degrees after anchor (default 0)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
fn/fa/fs – arc smoothness overrides
style (str)
circum (bool)
dual (bool)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
- bosl2.shapes3d.torus(major_radius=None, minor_radius=None, center=None, major_diameter=None, minor_diameter=None, outer_radius=None, inner_radius=None, outer_diameter=None, inner_diameter=None, anchor=[0, 0, 0], spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
BOSL2 torus() – a torus (donut) shape.
Note: BOSL2’s outer-radius parameter is named or, which collides with the Python keyword or; it is exposed here as outer_radius instead.
- Parameters:
major_radius (float | None) – major radius of the torus ring (use with minor_radius or minor_diameter)
minor_radius (float | None) – minor radius of the torus ring (use with major_radius or major_diameter)
center (bool | None) – if given, overrides anchor (True -> CENTER, False -> DOWN)
major_diameter (float | None) – major diameter of the torus ring
minor_diameter (float | None) – minor diameter of the torus ring
outer_radius (float | None) – outer radius of the torus (BOSL2 or) (use with inner_radius or inner_diameter)
inner_radius (float | None) – inside radius of the torus (use with outer_radius or outer_diameter)
outer_diameter (float | None) – outer diameter of the torus (use with inner_radius or inner_diameter)
inner_diameter (float | None) – inside diameter of the torus (use with outer_radius or outer_diameter)
anchor (Sequence[float]) – anchor point (default CENTER)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
fn/fa/fs – arc smoothness overrides
spin (float)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
Examples
shape = bosl2.shapes3d.torus(major_radius=25, minor_radius=8) shape.show()
- bosl2.shapes3d.teardrop(height=None, radius=None, angle=45, cap_height=None, circum=False, radius1=None, radius2=None, diameter=None, diameter1=None, diameter2=None, cap_h1=None, cap_h2=None, chamfer=0, chamfer1=0, chamfer2=0, realign=False, anchor=[0, 0, 0], spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
BOSL2 teardrop() – a teardrop shape, useful for 3D-printable horizontal holes.
- Parameters:
height/l – thickness of the teardrop (default 1)
radius (float | None) – radius of the circular part (default 1)
angle (float) – angle of the hat walls from the Z axis in degrees (default 45)
cap_height (float | None) – height above center to truncate the shape (default: no truncation)
circum (bool) – produce a circumscribing teardrop shape (default False)
radius1/radius2 – radius of the circular portion of the front/back end
diameter/diameter1/diameter2 – diameter of the circular portion / front end / back end
cap_h1/cap_h2 – truncation height on the front/back side
chamfer/chamfer1/chamfer2 – chamfer size along the bottom/top faces (overall/bottom/top) (default 0)
realign (bool) – shift face alignment, passed to teardrop2d (default False)
anchor (Sequence[float]) – anchor point (default CENTER)
spin (float) – Z-axis rotation in degrees after anchor (default 0)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
fn/fa/fs – arc smoothness overrides
height (float | None)
radius1 (float | None)
radius2 (float | None)
diameter (float | None)
diameter1 (float | None)
diameter2 (float | None)
cap_h1 (float | None)
cap_h2 (float | None)
chamfer (float)
chamfer1 (float)
chamfer2 (float)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
- bosl2.shapes3d.onion(radius=None, angle=45, cap_height=None, circum=False, realign=False, diameter=None, anchor=[0, 0, 0], spin=0, orient=[0, 0, 1], fn=None, fa=None, fs=None)[source]¶
BOSL2 onion() – an onion-dome shape (a sphere with a conical cap).
- Parameters:
radius (float | None) – radius of the spherical portion of the bottom (default 1)
angle (float) – angle of the cone from vertical in degrees (default 45)
cap_height (float | None) – height above the sphere center to truncate the shape (default: no truncation)
circum (bool) – circumscribe rather than inscribe the given radius/diameter (default False)
realign (bool) – adjust point alignment (flat vs pointy bottom) (default False)
diameter (float | None) – diameter of the spherical portion of the bottom
anchor (Sequence[float]) – anchor point (default CENTER)
spin (float) – Z-axis rotation in degrees after anchor (default 0)
orient (Sequence[float]) – direction to rotate the top towards, after spin (default UP)
fn/fa/fs – arc smoothness overrides
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
- bosl2.shapes3d.text3d(text, height=1, size=10, font='Liberation Sans', halign=None, valign=None, spacing=1.0, direction='ltr', language='em', script='latin', anchor='baseline[-1,0,-1]', spin=0, orient=[0, 0, 1])[source]¶
BOSL2 text3d() – 3-D extruded text, with anchor/spin/orient support.
- Parameters:
text (str) – text to create
height (float) – extrusion height (default 1)
size (float) – font size divided by 0.72 (default 10)
font (str) – font to use (default “Liberation Sans”)
halign (str | None) – horizontal alignment: “left”, “center”, “right” (overrides anchor)
valign (str | None) – vertical alignment: “top”, “center”, “baseline”, “bottom” (overrides anchor)
spacing (float) – relative spacing multiplier between characters (default 1.0)
direction (str) – text direction: “ltr”, “rtl”, “ttb”, “btt” (default “ltr”)
language (str) – language the text is in (default “en”)
script (str) – script the text is in (default “latin”)
anchor (str) – anchor point (default “baseline”)
spin (float) – Z-axis rotation in degrees (default 0)
orient (Sequence[float]) – direction to rotate the top towards (default UP)
- Return type:
- bosl2.shapes3d.path_text(path, text, font='Liberation Sans', size=10, thickness=None, lettersize=None, offset=0, reverse=False, normal=None, top=None, center=False, textmetrics=False, kern=0)[source]¶
BOSL2 path_text() – places text characters along a path.
- Parameters:
path (Sequence[Sequence[float]]) – path to place the text on
text (str) – text to create
font (str) – font to use (default “Liberation Sans”)
size (float) – font size divided by 0.72 (default 10)
thickness (float | None) – thickness of the letters (not allowed for a 2-D path)
lettersize (float | Sequence[float] | None) – scalar or array giving the size of the letters
center (bool) – center text on the path instead of starting at the first point (default False)
offset (float) – distance to shift letters “up” towards the reader (default 0, 3-D paths only)
normal (Sequence[float] | list[list[float]] | None) – direction(s) pointing towards the reader of the text (3-D paths only)
top (Sequence[float] | list[list[float]] | None) – direction(s) pointing towards the top of the text
reverse (bool) – reverse the letters if true (default False, 3-D paths only)
textmetrics (bool) – use the experimental textmetrics feature when lettersize is not given (default False)
kern (float | Sequence[float]) – scalar or array giving per-letter size adjustments (default 0)
- Return type: