compas_wood.session_scene¤
compas_wood.session_scene
¤
session_py scene backend - the drawing target that replaces compas_viewer.
The viewer is session_viewer <https://github.com/petrasvestartas/session>_: a
browser-only WebGPU renderer compiled to WASM. It does not open a desktop
window, so a "view" here means writing a scene rather than showing one - the
drawing helpers in :mod:compas_wood.viewer build a :class:SessionScene, and
:meth:SessionScene.save serialises it to a .pb the viewer fetches.
:class:SessionScene is a drop-in for the scene argument those helpers
already take: it implements the same two calls they use, add_group and
add, so no drawing code changes. compas geometry is converted on the way in
(:class:compas.datastructures.Mesh -> :class:session_py.Mesh, and so on);
facecolor / linecolor become the session object's own colors, which is
how the layer palette survives the round trip.
show=False objects are still written. Visibility is the viewer's business -
its tree sidebar toggles them - and dropping them here would make the scene
lie about what the solver produced.
Classes¤
SessionScene
¤
SessionScene(name: str = 'compas_wood')
A scene for the :mod:compas_wood.viewer helpers that records into a session.
Implements only what those helpers call - add_group(name=, parent=) and
add(item, parent=, **kwargs) - and returns :class:session_py.tree.TreeNode
handles, usable as parent= exactly like compas_viewer's group handles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the root group everything is nested under. |
'compas_wood'
|
Examples:
>>> from compas_wood.session_scene import SessionScene
>>> scene = SessionScene()
>>> _ = scene.add_group(name="plates")
>>> path = scene.save("plates.pb")
Methods:¤
add
¤
Convert and record one geometry.
Unknown geometry is collected in :attr:skipped and warned about rather
than raised on: one unsupported item should not lose the whole scene.
Functions:¤
merge_coplanar_faces
¤
Merge groups of adjacent coplanar faces into single polygonal faces.
Lofted plates and earclipped joint areas arrive triangulated: a flat plate cap is dozens of triangles whose shared edges are not real edges of the solid. The viewer draws mesh edges from face topology, so those diagonals show up as internal wireframe over what should read as one flat polygon. Merging the coplanar run into one n-gon removes them at the source, which is also what makes each detected outline one face rather than a fan.
A group is emitted as a single face only when its boundary is exactly one closed cycle. A region with a hole, or one pinched so its boundary visits a vertex twice, has no single-loop representation, so those keep their original faces rather than being silently mangled.
Returns:
| Type | Description |
|---|---|
tuple[list, list[list[int]]]
|
The (unchanged) vertices and the rebuilt face list. |
to_session_color
¤
compas :class:~compas.colors.Color (or any rgb triple) -> session Color.
Both sides are 0..1 floats, so this only re-wraps; None yields default.
to_session_mesh
¤
compas :class:~compas.datastructures.Mesh -> session Mesh.
to_vertices_and_faces returns the vertex keys already compacted to
0..n-1 indices, which is exactly what session's constructor wants.