Rendering¶
The renderer resolves a model into a scene of plain data, then renders that scene in headless Chromium or a standalone viewer.
scene
¶
Scenes: a model resolved into the boxes, meshes, studs, colors and marks to render.
A scene is plain data in base units (0.4 mm), laid out as compact arrays so a large
model crosses into the browser quickly. An element made only of boxes appears as boxes.
An element with other solids, such as a slope or a round part, appears as a mesh: its
corners, its faces and the edges worth outlining. :func:build_scene is pure Python,
and :mod:bricky.render.browser renders its result.
Scene
¶
Everything to render, in base units (0.4 mm).
View
¶
One image of a scene.
SHEET
class-attribute
instance-attribute
¶
The perspective, front, right and top views on one image.
PERSPECTIVE
class-attribute
instance-attribute
¶
In perspective, from above the south-east.
PERSPECTIVE_SOUTH_WEST
class-attribute
instance-attribute
¶
In perspective, from above the south-west.
PERSPECTIVE_NORTH_WEST
class-attribute
instance-attribute
¶
In perspective, from above the north-west.
PERSPECTIVE_NORTH_EAST
class-attribute
instance-attribute
¶
In perspective, from above the north-east.
FRONT
class-attribute
instance-attribute
¶
Orthographic, looking north, with x and z rulers.
BACK
class-attribute
instance-attribute
¶
Orthographic, looking south, with x and z rulers.
LEFT
class-attribute
instance-attribute
¶
Orthographic, looking east, with y and z rulers.
RIGHT
class-attribute
instance-attribute
¶
Orthographic, looking west, with y and z rulers.
TOP
class-attribute
instance-attribute
¶
Orthographic plan, north up, with x and y rulers.
Clip
¶
A plane and the side of it that a render keeps, to look inside a model.
Flag
¶
How the renderer shows an element.
GHOST
class-attribute
instance-attribute
¶
Rendered faintly: outside a highlight, and named by no error or warning.
Label
¶
Text pinned to an element.
Mark
¶
A diagnostic's region: a box outlined over everything else.
Mesh
¶
An element rendered by its faces, for an element with solids other than boxes.
SceneColor
¶
A color the scene uses.
build_scene
¶
build_scene(
model: Model,
catalog: Catalog,
*,
provenance: Provenance | None = None,
report: Report | None = None,
highlight: Sequence[str] = (),
clips: Sequence[Clip] = (),
changed: Sequence[str] = (),
cull: bool = True,
instructions: Instructions | None = None,
) -> Scene
Resolve a model into the scene to render.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The model. |
required |
catalog
|
Catalog
|
The catalog that resolves parts and colors. |
required |
provenance
|
Provenance | None
|
The script lines that placed each element; |
None
|
report
|
Report | None
|
A report whose errors and warnings mark the elements they name. |
None
|
highlight
|
Sequence[str]
|
Selectors of the elements to highlight; the renderer shows the
rest faintly. A selector is a uid pattern such as |
()
|
clips
|
Sequence[Clip]
|
The clips that keep part of the model, to look inside it. |
()
|
changed
|
Sequence[str]
|
The uids of elements new or changed since the last build, to mark. |
()
|
cull
|
bool
|
Whether to leave out faces pressed against opaque neighbors. A viewer that clips the model interactively sets it to false, as clipping can bring buried faces into view. |
True
|
instructions
|
Instructions | None
|
The steps to build the model, for a viewer to show one by one. Each step reveals the studs the next steps cover, so the scene then keeps every stud. |
None
|
Raises:
| Type | Description |
|---|---|
BrickyError
|
If the model has no element to render, a selector matches nothing, or the clips keep nothing. |
Renderer
¶
Renderer(browser: Path | None = None)
Renders scenes with three.js in headless Chromium.
Launching the browser and compiling shaders take the most time, so a renderer keeps
one page open for every render. A renderer starts once and serves many renders, as
an async context manager or through :meth:start and :meth:close. Renders on one
renderer run one at a time.
Create a renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
browser
|
Path | None
|
The Chromium executable to use; Playwright's own browser when
|
None
|
start
async
¶
Launch the browser, unless it is already running.
Raises:
| Type | Description |
|---|---|
BrickyError
|
If Chromium cannot be started. |
write_html
¶
write_html(
scene: Scene,
path: Path,
downloads: Sequence[Download] = (),
*,
heading: str | None = None,
mode: Literal["explore", "instructions"] = "explore",
) -> Path
Write a standalone HTML viewer for a scene and return its path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene
|
Scene
|
The scene to view. |
required |
path
|
Path
|
The file to write. |
required |
downloads
|
Sequence[Download]
|
Files the viewer offers to download, such as the model's exports. |
()
|
heading
|
str | None
|
The model's name as people read it; by default, the model's name with spaces for hyphens and a capital first letter. |
None
|
mode
|
Literal['explore', 'instructions']
|
What the page opens on: the model to explore, or its first building step, which needs a scene with steps. |
'explore'
|
Raises:
| Type | Description |
|---|---|
BrickyError
|
If the file cannot be written. |