Skip to main content

Realtime terminal 3D STL renderer for kitty/ghostty and Textual

Project description

TermRenderer

Realtime STL rendering for kitty-graphics-compatible terminals.

TermRenderer rasterizes binary or ASCII STL meshes into RGBA frames in Rust, then streams them through the kitty graphics protocol so Ghostty and kitty can display actual pixels instead of character art.

It ships with two Python-facing integration styles:

  • a viewport-level API for direct rendering into any terminal rectangle
  • a reusable Textual PreviewWidget that renders inside its own widget region

Demo

GitHub can render .mov attachments in repository views, but inline playback reliability depends on the browser and GitHub surface. The repository includes two recordings in media/raw_render.mov and media/textual_components.mov.

Raw terminal renderer

Raw terminal renderer demo

Fallback video: media/raw_render.mov

Textual component embedding

Textual component embedding demo

Fallback video: media/textual_components.mov

Features

  • binary and ASCII STL loading
  • CPU software rasterizer with flat shading, backface culling, projection, and z-buffering
  • kitty graphics protocol presenter with tile-based dirty updates and per-tile double buffering
  • viewport abstraction for rendering into bounded terminal regions
  • direct Rust CLI for quick local viewing
  • Python bindings via PyO3
  • official Textual integration through a reusable PreviewWidget

Python package

  • PyPI package name: termrenderer
  • import package name: termrender

Install from PyPI:

pip install termrenderer

For local development from this repository:

python3 -m pip install maturin
maturin develop

Build a wheel:

maturin build

Python API

Import surface-level and viewport-level APIs:

from termrender import Camera, Mesh, Surface, TerminalRenderer, Viewport

Render into an explicit viewport:

from termrender import Camera, Mesh, TerminalRenderer, Viewport

mesh = Mesh.from_stl("model.stl")
camera = Camera.default()
renderer = TerminalRenderer("medium")
viewport = Viewport(10, 4, 80, 24)

renderer.render_viewport(mesh, camera, viewport)

Textual integration

The package exposes a reusable widget that renders into its own content_region.

from termrender import Mesh, PreviewWidget
from textual.app import App, ComposeResult


class Demo(App):
    CSS = """
    Screen { background: #020617; }
    PreviewWidget { width: 1fr; height: 1fr; }
    """

    def compose(self) -> ComposeResult:
        yield PreviewWidget(Mesh.demo(), quality="medium")

The widget provides host-control methods such as:

  • set_mesh(...)
  • set_camera(...)
  • set_quality(...)
  • adjust_pitch(...)
  • adjust_yaw(...)
  • adjust_zoom(...)
  • toggle_spin()
  • reset_camera()
  • clear_surface()

It also emits a PreviewWidget.FrameRendered message with FPS, framebuffer size, viewport size, and camera state.

The widget ships its own default component styling through PreviewWidget.DEFAULT_CSS; the host app only needs to decide layout and sizing.

The demo Textual app is included as a versioned example module:

maturin develop
termrender-preview path/to/model.stl --quality low

If you want a managed Textual demo environment during development:

python3 -m venv .venv
source .venv/bin/activate
pip install -U pip maturin textual==8.2.0
maturin develop
python -m termrender.examples.textual_preview path/to/model.stl --quality low

CLI

Run the Rust viewer directly:

cargo run --
cargo run -- path/to/model.stl
cargo run -- path/to/model.stl --quality high

Controls:

  • w a s d or arrow keys: rotate
  • + / -: zoom
  • space: toggle auto spin
  • r: reset camera
  • q or esc: quit

Demo controls

The packaged Textual demo uses these controls:

  • arrow keys: orbit
  • =: zoom in
  • -: zoom out
  • space: toggle auto spin
  • r: reset camera
  • q: quit

Terminal support

This project currently targets terminals that support the kitty graphics protocol, especially Ghostty and kitty.

Notes:

  • the renderer uploads compressed RGBA tiles through kitty APC graphics commands
  • the presenter only re-uploads changed tiles when possible
  • framebuffer dimensions stay aligned to terminal cell geometry
  • performance is best with low or medium quality on larger terminal windows

Development

Rust verification:

cargo test
cargo build
cargo build --features python-module

Python verification:

python3 -m compileall python
python3 -m py_compile termrender/examples/textual_preview.py

Repository layout

  • src/ Rust renderer, presenter, viewport, CLI, and bindings
  • pyproject.toml Python packaging metadata for the mixed Rust/Python project
  • python/termrender/ Python package code layered over the PyO3 module
  • python/termrender/examples/ versioned demo apps
  • media/ demo recordings used by the README

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

termrenderer-0.0.1.tar.gz (22.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

termrenderer-0.0.1-cp39-abi3-macosx_11_0_arm64.whl (339.1 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file termrenderer-0.0.1.tar.gz.

File metadata

  • Download URL: termrenderer-0.0.1.tar.gz
  • Upload date:
  • Size: 22.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.3 Darwin/25.3.0

File hashes

Hashes for termrenderer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 232c2eef51957291ce5eabdce916d014daa244c53648c64423b9dccc613b170c
MD5 3a00ede7c357ad185430d8f38fa55735
BLAKE2b-256 1acb5b4edbed7eb9c6ad74b057e327031d50207bb2880e699917caf0ad143b47

See more details on using hashes here.

File details

Details for the file termrenderer-0.0.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for termrenderer-0.0.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9022ad4609c8071187d851b1e9861fffe6902551c9499f01d802210292ff55f5
MD5 d766c42c279c164879c835a4fa18db82
BLAKE2b-256 3dd513962bdda180bb149be8aa2881c9bb7155a1061c83c316987895bf396f7a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page