Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

3.3 KB
Raw Blame

raea/godot

Godot's whole API from TypeScript, through GodotJS (MIT): every class, singleton, enum and builtin of Godot 4.6.1, typed, run in Godot on its own JavaScript engine (JavaScriptCore on the Mac, QuickJS-ng on Windows and Linux).

raea setup godot                 # GodotJS's Godot 4.6.1, pinned by sha256, into ~/.raea/tools/godot
raea godot run drop.ts           # the script's default export gets the SceneTree; Godot quits when it returns
raea godot run drop.ts --window  # with a window (headless otherwise)
raea godot types game/           # a project's own typings: its scenes, resources and input actions
raea godot open game/            # the Godot editor on the project
import { BoxMesh, MeshInstance3D, Vector3, frames, type SceneTree } from "raea/godot";

export default async function (tree: SceneTree, args: string[]) {
  const box = new MeshInstance3D();
  box.mesh = new BoxMesh();
  box.position = new Vector3(0, 1, 0);
  tree.root!.add_child(box);
  await frames(tree, 2);
  console.log(box.global_position.y);
}

A script imports from raea/godot (which also brings the types in) or from godot, as GodotJS's own scripts do. Godot's names are Godot's: get_child_count(), global_position, snake_case as in GDScript.

The script runs in Godot, not on raea's engine: raea godot run bundles it with raea's bundler, GodotJS's modules standing in (src/shim), and Godot loads it beside src/host/main.js, its main loop. The project is --project DIR, else the nearest project.godot above the script, else an empty one.

Things to know:

  • Paths. Godot runs inside the project's folder, so "media/a.glb" is a file in the project. resolve("media/a.glb") is that path where raea ran; cwd() is that folder.
  • An own main loop. A default export that is a SceneTree (or MainLoop) subclass is Godot's main loop as it is: _initialize(), then _process(delta) each frame, before Godot draws it; it quits itself. Code that must run on frame N (a recording) belongs there, not after an await frame(tree).
  • A callback that throws (_process, a signal) stops the run with exit 1: Godot itself would log it and carry on.
  • Movies. --movie out/f.png is Godot's Movie Maker: each frame drawn in a window kept on top (macOS stops drawing a covered window, and Movie Maker would write its last frame again) and written at --fps. It records the project's window size: --size WxH sets it for a run with no project; a project sets display/window/size/viewport_width and _height in its project.godot (raea refuses a --size that differs).

Files

  • src/index.ts: raea/godot, the godot module re-exported, Main, frame, frames, cwd and resolve.
  • src/types/: generated by tools/gen.sh from GodotJS's codegen (--generate-types); resources.d.ts is raea's. LICENSE there credits GodotJS and Godot (both MIT).
  • src/shim/: the bundle's stand-ins for GodotJS's modules; names.gen.js is generated (tools/names.ts).
  • src/host/main.js: the main loop raea godot run gives Godot.
  • test/typing.ts (tsc), test/run.test.ts (bun test, against the installed Godot).

The spec is docs/godot.feature; the pin and the verbs are apps/engines/src/godot.rs and godot_run.rs.