Models¶
Build scripts create models with a ModelBuilder, and a model stores only part ids, colors and poses.
ModelBuilder
¶
Build a model in agent-friendly coordinates.
Examples:
>>> builder = ModelBuilder("wall")
>>> builder.place("3001", at=(0, 0, 0), color="Red")
'e1'
>>> builder.place("3001", at=(0, 2, 3), color="Red", rotation="R90")
'e2'
>>> builder.build().element_count()
2
Start an empty model, resolved against catalog or the default one.
component
¶
component(name: str) -> ComponentBuilder
Start a reusable component and return the builder that fills it.
A script may fill components in any order, before or after it places their instances.
Raises:
| Type | Description |
|---|---|
ValueError
|
If a component with this name already exists. |
build
¶
build() -> Model
Return the finished model.
Raises:
| Type | Description |
|---|---|
ValueError
|
If an instance places an unknown or empty component, or if components place each other in a cycle. |
provenance
¶
Return where the build script placed every element and instance so far.
ComponentBuilder
¶
Fill one component with elements and instances.
Wrap the scope a component's parts go into.
model
¶
The canonical model format: what a build is, stored once.
A model is a small tree: top-level elements and instances, plus the named components
that instances place. The model refers to catalog parts and colors by id and never
copies their data, so analyses derive everything else, such as world geometry and
connections. Positions are in 0.4 mm base units, and rotations use the grid rotation
names of :mod:bricky.geometry.
files
¶
Reading and writing model files and their source maps.
A model file (name.bricky.json) holds the model alone. Its source map
(name.bricky.map.json) records the build-script lines that placed each element and
the SHA-256 of the model file it describes, so bricky detects a stale map and ignores
it.
load_model
¶
Read a model file.
Raises:
| Type | Description |
|---|---|
BrickyError
|
If the file is missing, cannot be read or is not a valid model. |
save_model
¶
Write a model file as indented JSON.
Raises:
| Type | Description |
|---|---|
BrickyError
|
If the file cannot be written. |
fill
¶
Fill voxels with bricks and plates, the way a builder lays courses.
Many models are easiest to describe as voxels: which color fills each stud square, one
plate tall. :func:plan_fill converts such a plan into parts a script places: bricks
where the three layers of a course share a color, plates everywhere else, each part as
large as fits.
The courses bond. Each layer lays its parts along x or along y, alternating from layer to layer, so joints rarely line up above each other. Every part rests on at least one voxel of the layer below, so an overhang takes a part that reaches back over what holds it. Overhangs, and the squares beside them, take plates, so each layer of an overhang reaches back on its own. A voxel that no part can hold still gets a part; the checks then report it as floating.
BRICKS
module-attribute
¶
BRICKS: Final[dict[tuple[int, int], str]] = {
(1, 1): "3005",
(1, 2): "3004",
(1, 3): "3622",
(1, 4): "3010",
(1, 6): "3009",
(1, 8): "3008",
(2, 2): "3003",
(2, 3): "3002",
(2, 4): "3001",
(2, 6): "2456",
(2, 8): "3007",
(2, 10): "3006",
}
Bricks a fill uses, by footprint: the shorter side first, along x when unrotated.
PLATES
module-attribute
¶
PLATES: Final[dict[tuple[int, int], str]] = {
(1, 1): "3024",
(1, 2): "3023",
(1, 3): "3623",
(1, 4): "3710",
(1, 6): "3666",
(1, 8): "3460",
(2, 2): "3022",
(2, 3): "3021",
(2, 4): "3020",
(2, 6): "3795",
(2, 8): "3034",
(2, 10): "3832",
(4, 4): "3031",
(4, 6): "3032",
(4, 8): "3035",
(6, 6): "3958",
(6, 8): "3036",
}
Plates a fill uses, by footprint: the shorter side first, along x when unrotated.
Placement
dataclass
¶
plan_fill
¶
plan_fill(
voxels: Mapping[tuple[int, int, int], int | str],
*,
made_in: MadeIn | None = None,
) -> list[Placement]
Return the bricks and plates that fill exactly the voxels, bottom layer first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voxels
|
Mapping[tuple[int, int, int], int | str]
|
The color of every voxel to fill, keyed |
required |
made_in
|
MadeIn | None
|
Whether a part comes in a color; the fill then uses only parts that do, and a 1 x 1 part where none does. Every part is allowed when omitted. |
None
|
Examples:
The package exports model_voxels as bricky.voxels, the name the guide uses.
voxels
¶
The model as voxels: which element fills each voxel.
A voxel is one stud wide, one stud deep and one plate tall: the grid that parts are placed on. An element fills a voxel when the voxel's center lies inside its body. Every voxel of a model free of overlaps therefore belongs to at most one element, and a comparison with a target made of voxels is exact. Studs belong to no body and fill no voxel.