R3 for programmers: main loop, interrupts and components
For programmers new to the web: where main() went, what a component, an entityRef and an asset are, which language you write, and that AI is optional.
You can program, but the web and 3D engines are new to you. This page maps R3's words to things you already know. To try them out, follow How to write hello world in R3, by hand: ten minutes, no AI.
The language: JavaScript
You write JavaScript, in a code editor inside the browser. There is nothing to install, compile or link: press Save, and the code runs. The same code runs in the editor and on any link you share.
Where is main.c?
There is no main(). R3 owns the program's entry point and its loop, and calls your code:
| You know | In R3 |
|---|---|
| your program | a project |
the body of while (1) { … } | a Code component on the event RENDER_BEFORE, called once per frame with data.delta, the seconds since the last frame |
| an interrupt handler | a Code component on KEY_DOWN, KEY_UP, MOUSE_CLICK, SWIPE or PHYSICS_COLLISION: it runs only when that happens |
setup() / init code | the script's start function: it runs once, when the code starts |
| drivers | systems: graphics, physics, audio, music, input, code |
| a struct with live fields | a component |
| a variable name | an entityRef |
| a file on disk (image, sound, model) | an asset |
Each script picks exactly one event in the Inspector. Two behaviours on two events are two scripts.
Components: structs with live fields
Everything in a project is a component: a mesh, a material, a light, the camera, a physics body, a sound, a script. Each has typed fields, which you see and edit in the Inspector on the right.
The fields are live. When your code writes this.mesh_cube_1.position.y = 2, the cube moves on screen in the next frame drawn. There is no "commit" call: the systems watch the fields and do the work.
entityRef: the variable name
Every component has an entityRef, a unique snake_case name such as mesh_cube_1 or code_1. Inside a script, every component of the project is on this under that name: this.mesh_cube_1. Rename a component in the Inspector and its entityRef changes with it. The Inspector shows each one, so you never have to guess.
Systems: the drivers
A system watches components and talks to the hardware and libraries underneath: graphics draws the meshes with WebGL (three.js), physics steps the bodies (Rapier), audio plays the sounds, input reads the keyboard, mouse and touch. Systems are also what fire the events your scripts run on: graphics fires RENDER_BEFORE each frame, input fires KEY_DOWN, physics fires PHYSICS_COLLISION.
The top bar has a start and stop button for Physics, Code, Audio and Music, so you can run one part without the others. Your scripts run only while Code is started.
Assets: the files you uploaded
An asset is a file you uploaded: an image, a sound, a Blender model. They live in your account, in the menu under Images, Audio and Models, and any of your projects can use them. Components point at assets: a texture at an image, an audio component at a sound, a mesh at the model data you imported. Your scripts are not files you manage: they are stored with the project.
Where output goes
console.log prints to the browser's developer console (F12, then Console), as in any web page. A script that throws is stopped, and its error shows in the console, in the editor's status line and on the script in the Inspector; it runs again once you fix it and Save.
Sharing: preview link or going live
- A preview link is private: anyone you send it to can open the project, for 7 days, and you can make one as often as you like. It is free.
- Going live gives the project a public address that stays. Going live needs a plan.
See Publishing and going live.
AI is optional
You can build everything by hand: the editor, the Inspector and your own JavaScript. That is free.
If you want an AI to do the typing, connect your own Claude to your account: it signs in to R3, and R3 charges nothing for it (how to connect Claude). R3 Builder, where R3 runs the AI on its own servers to build 3D models, is the only part that uses R3 credits (why R3 isn't completely free).
Next
- How to write hello world in R3, by hand: spin a cube, print a message, react to a key, share a link.
- Make something happen on a key press or click: more events and their
data. - Code Components:
start,updateand the rest of a script. - Understanding ECS: the architecture behind components and systems.
- The API reference lists every component, system and event: open it.