-
Notifications
You must be signed in to change notification settings - Fork 1
Home
This is an OpenSCAD module for creating blocks of 3D text that are attachable with BOSL2.
OpenSCAD provides a rudimentary text()
built-in function,
but only for 2D models. BOSL2 takes that a step further, and provides
a text3d()
module, and those models may be
attached to other BOSL2 attachable primatives. This attachability limitation is because
post hoc dimension information of models within OpenSCAD is not available, and BOSL2 leverages the built-in text()
to create
text3d()
models.
So, while you can attach text to a shape, you cannot attach a shape to text, nor can you attach text to text. BOSL2 doesn't have the dimensioning information to know how to position objects onto text models which, you know, that's fair: OpenSCAD itself doesn't really know itself what the dimensions of text models are.
You can only attach text to other shapes with a known geometry, like this:
cube([20, 20, 5])
attach(TOP, BOTTOM)
text3d("x");
Figure 1:
You can't reverse that order; and, you can't attach models created with text3d()
to other text models created
similarly.
Circa 2018, Alexander Pruss took a subset of the available
fonts within OpenSCAD and measured their output, then
consolidated those measurements into a library called fontmetrics. This
library provides fairly accurate per-character dimensions for a variety of font faces and styles, and at various sizes,
with the intention of providing decent word-wrapping text modules. A side effect of those modules is the availability
of a measureTextBounds()
function, which does precisely what it's named: given some text and optionally a font
and a sizing, return a bounding dimension.
The attachable_text3d.scad
library - this file - marries BOSL2 bi-directional attachability and fontmetrics.scad
-measured text
dimensions into a set of modules that produce attachable 3D text: that is, modeled 3D objects that can use BOSL2's
attachments functionality to join text to other text, arbitrary
shapes, or existing attachment-aware models.
Figure 2: anchorable, attachable text:
attachable_text3d()
and its ilk create an attachable rectangle around the output of text3d()
, by measuring the size of the
text being fed into text3d()
and then wrapping that model with attachable()
using that boundary sizing.
This means you can reverse the above operation that attaches text to things, and instead attach things to text, like so:
attachable_text3d("x")
attach(BOTTOM, TOP)
cube([20, 20, 5]);
Figure 3:
It also means you can join blocks of text with other blocks, as though they were simple BOSL2 rectangles:
attachable_text3d("z", font="Webdings")
attach(RIGHT, LEFT, overlap=-2)
attachable_text3d("No Smoking");
Figure 4:
Details on installation of this library can be found here, including notes on dependencies.
attachable_text3d("Hello");
attachable_text3d("Hello")
show_anchors();
attachable_text3d("Block 1")
attach(RIGHT, LEFT)
attachable_text3d(", and of couse, ")
attach(RIGHT, LEFT)
attachable_text3d("Block 2");