Canvas, camera, and interaction#
These modules provide canvases, cameras, lights, and input handling for interactive visualizations.
Canvas and windowing#
- class webgpu.canvas.Canvas(device, canvas, multisample_count=4)#
Bases:
objectCanvas management class, handles “global” state, like webgpu device, canvas, frame and depth buffer
- depth_format: TextureFormat#
- destroy_textures()#
- height: int = 0#
- multisample: MultisampleState = None#
- on_resize(func: Callable)#
- on_update_html_canvas(func: Callable)#
- resize()#
- save_screenshot(filename: str)#
- update_html_canvas(html_canvas)#
Reconfigure the canvas with the current HTML canvas element. This is necessary when the HTML canvas element changes, disappears (e.g. when switching a tab) and appears again.
- width: int = 0#
- webgpu.canvas.debounce(arg=None)#
- webgpu.canvas.init_webgpu(html_canvas)#
Initialize WebGPU, create device and canvas
Camera and lighting#
- class webgpu.camera.Camera#
Bases:
objectInteractive camera that maps a 3D scene to clip space and updates GPU uniforms.
- get_bindings() list[BaseBinding]#
- get_shader_code()#
- register_callbacks(input_handler)#
- reset(pmin, pmax)#
Fit the camera to the axis-aligned box [pmin, pmax] and update uniforms.
- reset_xy(flip: bool = False)#
Reset to a top-down XY view of the current center and update uniforms.
- reset_xz(flip: bool = False)#
Reset to an XZ view of the current center and update uniforms.
- reset_yz(flip: bool = False)#
Reset to a YZ view of the current center and update uniforms.
- set_canvas(canvas)#
Attach the camera to a canvas, register resize handling, and allocate uniforms.
- set_render_functions(redraw_function, get_position_function=None)#
Install callbacks for triggering redraws and mapping screen to world positions.
- unregister_callbacks(input_handler)#
- class webgpu.camera.CameraUniforms(**kwargs)#
Bases:
UniformBaseUniforms class, derived from ctypes.Structure to ensure correct memory layout
- aspect#
Structure/Union member
- height#
Structure/Union member
- model_view#
Structure/Union member
- model_view_projection#
Structure/Union member
- normal_mat#
Structure/Union member
- padding#
Structure/Union member
- rot_mat#
Structure/Union member
- view#
Structure/Union member
- width#
Structure/Union member
- class webgpu.camera.Transform#
Bases:
object3D transform with translation/rotation/scale around a configurable center.
- copy()#
- init(pmin, pmax)#
Initialize the transform to frame the axis-aligned box [pmin, pmax].
- map_point(point)#
- property mat#
- reset_xy(flip: bool = False)#
Reset to a view looking along +Z onto the XY plane, optionally flipped.
- reset_xz(flip: bool = False)#
Reset to a view looking along +Y onto the XZ plane, optionally flipped.
- reset_yz(flip: bool = False)#
Reset to a view looking along +X onto the YZ plane, optionally flipped.
- rotate(ang_x, ang_y=0, center=None)#
- scale(s, center=None)#
- set_center(center)#
- translate(dx=0.0, dy=0.0, dz=0.0)#
- class webgpu.light.LightUniforms(**kwargs)#
Bases:
UniformBaseUniforms class for light settings, derived from ctypes.Structure to ensure correct memory layout
- ambient#
Structure/Union member
- diffuse#
Structure/Union member
- fill#
Structure/Union member
- key#
Structure/Union member
- min_diffuse#
Structure/Union member
- rim_power#
Structure/Union member
- rim_strength#
Structure/Union member
- shininess#
Structure/Union member
- specular#
Structure/Union member
- wrap#
Structure/Union member
Interaction and UI helpers#
- class webgpu.input_handler.InputHandler#
Bases:
object- class Modifiers(
- alt: bool | None = False,
- shift: bool | None = False,
- ctrl: bool | None = False,
Bases:
object- get_set()#
- emit(event: str, ev: dict, *args)#
- on(
- event: str,
- func: Callable,
- alt: bool | None = False,
- shift: bool | None = False,
- ctrl: bool | None = False,
- on_click(
- func,
- alt: bool | None = False,
- shift: bool | None = False,
- ctrl: bool | None = False,
- on_dblclick(
- func,
- alt: bool | None = False,
- shift: bool | None = False,
- ctrl: bool | None = False,
- on_drag(
- func,
- alt: bool | None = False,
- shift: bool | None = False,
- ctrl: bool | None = False,
- on_mousedown(
- func,
- alt: bool | None = False,
- shift: bool | None = False,
- ctrl: bool | None = False,
- on_mousemove(
- func,
- alt: bool | None = False,
- shift: bool | None = False,
- ctrl: bool | None = False,
- on_mouseout(
- func,
- alt: bool | None = False,
- shift: bool | None = False,
- ctrl: bool | None = False,
- on_mouseup(
- func,
- alt: bool | None = False,
- shift: bool | None = False,
- ctrl: bool | None = False,
- on_wheel(
- func,
- alt: bool | None = False,
- shift: bool | None = False,
- ctrl: bool | None = False,
- register_callbacks()#
- set_canvas(html_canvas)#
- unregister(event, func: Callable)#
- unregister_callbacks()#
- class webgpu.lilgui.Folder(label: str | None, container, scene)#
Bases:
object- add(label: str, value, func: Callable, *args)#
- checkbox(label: str, value: bool, func: Callable[[bool], None])#
- dropdown(
- values: dict[str, object],
- func: Callable[[object], None],
- value: str | None = None,
- label='Dropdown',
- folder(label: str, closed=False)#
- slider( )#
- value(label: str, value: object, func: Callable[[object], None])#