Skip to main content

Overview

OpenTUI provides a complete 3D rendering system powered by WebGPU and Three.js, allowing you to render 3D scenes directly in terminal applications. The API includes support for textures, sprites, animations, and physics.

ThreeRenderable

The main component for rendering 3D scenes in your terminal UI.

Constructor

RenderContext
required
The render context (typically a CliRenderer instance)
ThreeRenderableOptions
required
Configuration options

Properties

ThreeCliRenderer
Access to the underlying renderer
number
Current aspect ratio of the render area

Methods

getScene()

Gets the current scene.
Scene | null
The current Three.js scene

setScene()

Sets a new scene to render.
Scene | null
required
The new scene to render

getActiveCamera()

Gets the active camera.
PerspectiveCamera | OrthographicCamera
The active camera

setActiveCamera()

Sets a new active camera.
PerspectiveCamera | OrthographicCamera
required
The new camera to use

setAutoAspect()

Enables or disables automatic aspect ratio adjustment.
boolean
required
Whether to automatically adjust aspect ratio

ThreeCliRenderer

Low-level renderer for Three.js scenes.

Constructor

CliRenderer
required
The CLI renderer instance
ThreeCliRendererOptions
required
Renderer options (same as ThreeRenderable’s renderer options, plus width/height/autoResize)

Methods

init()

Initializes the WebGPU renderer. Must be called before rendering.

drawScene()

Renders a scene to a buffer.
Scene
required
Scene to render
OptimizedBuffer
required
Target buffer to render into
number
required
Time elapsed since last frame in seconds

setSize()

Resizes the renderer.
number
required
New width in cells
number
required
New height in cells
boolean
default:"false"
Force resize even if dimensions haven’t changed

setBackgroundColor()

Changes the background color.
RGBA
required
New background color

saveToFile()

Saves the current frame to an image file.
string
required
Path where the image should be saved

toggleSuperSampling()

Cycles through super sampling modes.

destroy()

Cleans up renderer resources.

TextureUtils

Utility class for loading and generating textures.

TextureUtils.loadTextureFromFile()

Loads a texture from an image file.
string
required
Path to the image file
DataTexture | null
Loaded texture, or null if loading failed

TextureUtils.fromFile()

Alias for loadTextureFromFile().

TextureUtils.createCheckerboard()

Creates a procedural checkerboard texture.
number
default:"256"
Texture size in pixels (width and height)
Color
default:"white"
First checker color
Color
default:"black"
Second checker color
number
default:"32"
Size of each checker square in pixels
Texture
Generated checkerboard texture

TextureUtils.createGradient()

Creates a procedural gradient texture.
number
default:"256"
Texture size in pixels
Color
default:"red"
Gradient start color
Color
default:"blue"
Gradient end color
'horizontal' | 'vertical' | 'radial'
default:"vertical"
Gradient direction
Texture
Generated gradient texture

TextureUtils.createNoise()

Creates a procedural noise texture.
number
default:"256"
Texture size in pixels
number
default:"1"
Noise scale factor
number
default:"1"
Number of noise octaves
Color
default:"white"
High noise value color
Color
default:"black"
Low noise value color
Texture
Generated noise texture

SpriteUtils

Utility class for creating sprite objects.

SpriteUtils.fromFile()

Creates a sprite from an image file.
string
required
Path to the sprite image
object
Sprite
Three.js Sprite with loaded texture

SpriteUtils.sheetFromFile()

Creates an animated sprite from a sprite sheet.
string
required
Path to the sprite sheet image
number
required
Number of frames in the sprite sheet
SheetSprite
Sprite with frame selection capability

SpriteAnimator

Advanced sprite animation system with instancing support.

Constructor

Scene
required
Three.js scene to add sprite meshes to

createSprite()

Creates a new animated sprite instance.
SpriteDefinition
required
Sprite configuration
() => NodeMaterial
Optional factory function for custom materials
TiledSprite
Animated sprite instance

update()

Updates all sprite animations.
number
required
Time elapsed since last update in milliseconds

removeSprite()

Removes a sprite by ID.
string
required
ID of the sprite to remove

removeAllSprites()

Removes all sprites.

TiledSprite

Animated sprite instance created by SpriteAnimator.

Properties

string
Unique identifier
boolean
Visibility state (get/set)

Methods

setAnimation()

Switches to a different animation.
string
required
Name of the animation to switch to

setPosition()

Sets the sprite’s position.
Vector3
required
New position

setRotation()

Sets the sprite’s rotation.
Quaternion
required
New rotation

setScale()

Sets the sprite’s scale.
Vector3
required
New scale

play() / stop()

Controls animation playback.

goToFrame()

Jumps to a specific frame.
number
required
Frame index to jump to

setFrameDuration()

Changes the frame duration for the current animation.
number
required
New frame duration in milliseconds

Example: 3D Scene