shore.gui.viewport.pygfx_backend
pygfx/wgpu implementation of the GUI viewport (ADR 0006, 0037, 0038).
The only module of SHORE that imports pygfx, wgpu or rendercanvas.
Float precision: positions are kept in float64 on the CPU and uploaded as float32(p - origin); the origin follows the orbit target and moves (re-uploading everything, "rebase") when the target drifts more than rebase_factor view widths from it, or on look_at_point. Coordinates reported by pick come from the float64 arrays (ADR 0006, spike item 3).
Drawn objects: per block its six boundary faces (quads) and twelve edges; per slice plane its quads; per geometry its triangles, curves and points.
create_canvas function
create_canvas(
parent: Any = None,
*,
offscreen: bool = False,
size: tuple[int, int] = (800, 600),
) -> AnyA rendercanvas canvas: a Qt widget, or an offscreen canvas for tests.
PygfxViewport class
PygfxViewport(canvas: Any, *, rebase_factor: float = 100.0)pygfx/wgpu implementation of Viewport.
PygfxViewport.set_blocks method
set_blocks(blocks: Sequence[tuple[Any, np.ndarray]]) -> NonePygfxViewport.set_slices method
set_slices(slices: Sequence[tuple[SliceKey, np.ndarray]]) -> NoneReplace the slice planes: (SliceKey, the block's nodes).
PygfxViewport.set_geometries method
set_geometries(geometries: Sequence[tuple[str, Any]]) -> NoneReplace the geometries: (name, shore.geometry.base.Display).
PygfxViewport.set_skeleton method
set_skeleton(edges: Sequence[tuple[Any, np.ndarray]]) -> NoneReplace the blocking skeleton (ADR 0042): (key, edge nodes (n, 3)), drawn over the blocks so it stays pickable.
PygfxViewport.set_markers method
set_markers(markers: Sequence[tuple[Any, np.ndarray]]) -> NoneReplace the blocking face or block markers (ADR 0044): (key, xyz), points drawn over everything so each stays pickable.
PygfxViewport.marker_keys property
marker_keys: list[Any]PygfxViewport.skeleton_keys property
skeleton_keys: list[Any]PygfxViewport.show method
show(kind: str, visible: bool) -> NoneShow or hide every "block", "slice", "geometry" or "skeleton" object.
PygfxViewport.visible method
visible(kind: str) -> boolPygfxViewport.set_face_scalars method
set_face_scalars(
values: dict[Any, np.ndarray] | None,
clim: tuple[float, float] = (0.0, 1.0),
) -> NoneColour block and slice quads by value (keys: block keys, SliceKey), or clear.
PygfxViewport.face_colours method
face_colours(key: Any) -> np.ndarrayThe uploaded per-quad RGBA of a block or slice (for tests).
PygfxViewport.keys property
keys: list[Any]PygfxViewport.slice_keys property
slice_keys: list[SliceKey]PygfxViewport.geometry_names property
geometry_names: list[str]PygfxViewport.uploaded_vertices method
uploaded_vertices(key: Any) -> intPygfxViewport.uploaded_positions method
uploaded_positions(key: Any) -> np.ndarrayfloat64 world positions of what was uploaded for key's first object.
PygfxViewport.view_width method
view_width() -> floatPygfxViewport.maybe_rebase method
maybe_rebase() -> boolPygfxViewport.show_all method
show_all() -> NonePygfxViewport.look_at_point method
look_at_point(
xyz: np.ndarray,
distance: float,
view_dir: np.ndarray | None = None,
) -> NonePygfxViewport.camera_position method
camera_position() -> np.ndarrayThe camera's float64 world position.
PygfxViewport.project method
project(xyz: np.ndarray) -> tuple[float, float]PygfxViewport.pixel_size method
pixel_size(xyz: np.ndarray) -> floatWorld size of one pixel at xyz (perspective).
PygfxViewport.pick method
pick(x: float, y: float) -> PickResult | GeometryPick | SkeletonPick | MarkerPick | NonePygfxViewport.highlight_polyline method
highlight_polyline(points: np.ndarray) -> NoneOutline points (float64, (n, 3)): a selected edge or vertex.
PygfxViewport.on_pick method
on_pick(callback: Any) -> NoneCall callback(pick result or None, shift) on a double click in the view.
PygfxViewport.request_draw method
request_draw() -> NonePygfxViewport.draw_now method
draw_now() -> np.ndarrayRender synchronously and return the image (offscreen canvases).