Skip to content
Public template

About

Start here to build a native app on ThreeRT: a live path-traced view in the platform's own UI framework (macOS/SwiftUI first), with Claude Code or Codex in a side panel editing the scene while it runs.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

ThreeRT native app templates

Native apps with a live path-traced 3D view, and a coding agent beside it that edits the scene while it runs.

The macOS template: the color box path-traced live, a room lit by one ceiling panel, its coral and teal walls tinting the white surfaces, a mirror block showing both walls and a glass sphere focusing the light onto the floor

This is the starting point for building an app on ThreeRT, the hardware ray-traced engine with a three.js-style API, in a platform's own UI framework. One repository holds every platform: the engine host, the agent bridge and the sample scene are shared, and each platform adds its native shell.

Platform UI framework Folder Status
macOS SwiftUI macos/ ready
more platforms their native frameworks planned

Fork it, replace the scene, keep the plumbing:

  • A native app around the engine. The window is ThreeRT's live path tracer (every light traced: bounce light, soft shadows, reflections, glass, emissive surfaces that light the room) running on its own thread on the platform's surface (a CAMetalLayer on macOS), behind a C ABI of 14 calls (core/). Your UI goes on top in the platform's framework.
  • A hello-world scene. Color box, the path tracer's classic, in one file of about 140 lines: a room lit by one panel in its ceiling, a coral wall and a teal wall whose colour the light carries onto everything else, a mirror block, a glass sphere that focuses the light onto the floor. Every object is a physics body; click the floor to drop cubes in.
  • Your coding agent, in the app. The Claude Code or Codex already installed on the machine runs in a side panel over the Agent Client Protocol. Ask for a change; the agent edits the scene's TypeScript, and the view hot-reloads it within a second. It checks its own work with scene check (build, types, and the running app's errors) and scene shot (a PNG of the live view it can look at).
  • A code viewer. The scene's files as an editor shows them (syntax highlighting, a line-number gutter, no wrapping); it follows the file the agent is editing, goes to the lines that changed and marks them. A console shows the scene's logs and errors.

The side panel open beside the scene: the agent, with prompts to try

macOS

Requirements

  • macOS 14 or later on Apple silicon. M3 or later traces with the GPU's ray-tracing hardware; M1 and M2 use the engine's software BVH (slower).
  • Xcode 16, xcodegen (brew install xcodegen), Rust (the engine pins its toolchain; rustup fetches it), Bun 1.3 or later.
  • For the agent: Claude Code (claude, logged in) and/or Codex (codex, logged in). The app finds them on your login shell's PATH.

Quick start

git clone --recursive https://github.com/threert/native-app-template my-app
cd my-app
bun tools/macos.ts --run      # builds the engine + core (a few minutes the first time), the app, and opens it

In the view: drag to turn, scroll to zoom, click the floor to drop a cube, R puts everything back. The panel starts hidden: ⌘\ (or the button at the top) shows it, ⌘1–3 open it on Agent, Code or Console, ⇧⌘S saves a snapshot to the Desktop.

Then ask the agent something: "Add a gold torus knot that slowly turns on the floor", or "Turn the right wall into a window with blue daylight coming in".

How it fits together

shared, every platform uses them:
  core/     Rust static library: ThreeRT's LiveCore + the scene's script runtime + physics on a native surface (C ABI)
  sidecar/  Bun: watches and bundles scene/, bridges Claude Code / Codex over ACP, serves the `scene` command line
  scene/    the scene: TypeScript on @threert/scene and @threert/gameplay. The only folder the agent writes
  engine/   ThreeRT, as a git submodule
  tools/    still.ts (an offline render of the scene, no app needed)
one folder per platform:
  macos/    SwiftUI: the window, the Metal view, the agent chat, the code viewer, the console, the scene's HUD
            (tools/macos.ts builds and runs it)

The app starts the sidecar, which builds scene/ on every change and tells the app to reload the new bundle; the core swaps it in on the same view (if the new scene fails to start, the old one keeps running and the console says why). The agent's turn streams into the chat; its edits stream into the code viewer. docs/ARCHITECTURE.md has the details: the C ABI, the messages between the parts, the agent bridge and its permission rules.

What the agent may do without asking: write files in scene/; read the repository and the engine's sources and docs; run scene … and read-only commands such as ls, cat, grep. Anything else (another command, a file elsewhere, the network) appears in the chat as a permission card for you to allow or reject.

Make it yours

To Change
Write your own scene scene/ (entry main.game.ts; see scene/README.md and the engine's docs/RUNTIME.md)
Name, bundle id, icon macos/project.yml (PRODUCT_NAME, PRODUCT_BUNDLE_IDENTIFIER; tools/macos.ts reads the name from it)
The agent panel's title, intro and suggested prompts scene/app.json
Talk between your UI and the scene the scene: host.post({ t: "my.event" }) / host.on("my.command", …); the app: Model.posts(_:) / view.send(_:)
Show your app's pixels on a surface in the scene a StreamTexture in the scene, view.stream(_:width:height:rgba:) in Swift
Tell the agent about your project scene/AGENTS.md (read by Claude Code through scene/CLAUDE.md, and by Codex)
Another ACP agent sidecar/src/agent/adapters.ts
Another engine version cd engine && git checkout <commit>, then bun tools/macos.ts

A fork that keeps to that table (its own scene/, its name in project.yml) takes the template's later fixes with a plain merge:

git remote add template https://github.com/threert/native-app-template
git fetch template && git merge template/main     # conflicts only where you changed the template's own files

Examples (archived, kept as they were): Mochi Party, a cartoon physics party game built on this template (some of its modes and furniture were made from the agent panel), and Pocket Bench, the hardware studio this template was extracted from.

Developing

bun tools/macos.ts --no-core --run             # Swift changed only
cd sidecar && bun test                       # the agent bridge against a fake ACP agent, the permission rules
bun tools/still.ts out.png --time 3          # the scene rendered offline, without the app
.build/bin/scene check                       # with the app running: build, types, runtime errors
.build/bin/scene shot --window out.png       # the window, composed offscreen (works with the display asleep)

.build/bin/scene app '{"t":"app.key","key":"N"}' drives the window as tests do (AGENTS.md lists the requests). RT_APP_ACP_LOG=/tmp/acp.log logs every message between the bridge and the agent.

Shipping

The template is a development setup: the app runs the sidecar from the repository with your Bun. To distribute an app built on it, bundle sidecar/, a writable copy of scene/, engine/presets and a Bun binary into the app, then sign it with a Developer ID and notarize it. It cannot use the App Sandbox, because it starts the user's own coding agents as child processes.

License

MIT, like ThreeRT. See LICENSE.

About

Start here to build a native app on ThreeRT: a live path-traced view in the platform's own UI framework (macOS/SwiftUI first), with Claude Code or Codex in a side panel editing the scene while it runs.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages