R3F18: agents are taught three.js work. sdk/guides/craft/bevy/r3f.md (the skill's 3d/r3f.md): an R3F scene in <R3F> (useFrame, refs and drei work there, stepped from the frame), a plain three.js page in <Three program> (raea 0.1.5), what draws and what doesn't yet; bevy.md routes three.js work to it, and the lines in bevy.md, bevy/scene.md, bevy/animation.md and bevy/limits.md that said useFrame and drei don't exist now say they don't drive raea's own components. skills pin: raea-skills #81 (89ab557): the same guide as 3d/r3f.md, 3d.md and SKILL.md routing three.js work to it, directory/ rebuilt

This commit is contained in:
shinyobjectz committed 2026-11-15 11:58:23 -08:00
1 parent 1d04a18d54
commit 1f02317e87
6 files changed
+113 -6

No files matched your search

+3 -1
View File
@@ -34,6 +34,7 @@ pieces; then write the file. Each file's example is a complete composition you c
| water: seas, lakes and pools; waves, reflection, refraction, absorption, caustics, foam | `bevy/water` |
| ray-traced light (Solari): what it lights and traces, glowing lamps, rooms that don't leak, cuts, metering | `bevy/solari` |
| bloom, fog, tone mapping, exposure, fisheye and lens distortion, motion blur | `bevy/post` |
| three.js work: an R3F scene (`<R3F>`, useFrame, drei), a plain three.js page (`<Three program>`), TSL, three's shaders | `bevy/r3f` |
| how much the scene can hold, what isn't there yet | `bevy/limits` |
## What exists
@@ -54,7 +55,8 @@ the rest come from `raea`.
1. **Every value from the frame.** Positions, angles, colours and intensities come from `useCurrentFrame()` (through
`interpolate`, `spring` or plain arithmetic) or from a game's state at the frame. No `useState`, `useEffect`,
`useRef` or `useFrame` mutation: there is no render loop to mutate in. `Math.random()` is seeded for each frame, so
`useRef` or `useFrame` mutation on raea's components: there is no render loop to mutate in. (three.js work keeps
its own: an R3F scene inside `<R3F>`, a plain three.js page in `<Three program>`, stepped from the frame: `bevy/r3f`.) `Math.random()` is seeded for each frame, so
it draws new numbers every frame: seed a scatter or anything that holds still from an index. `Date` is the frame's
time.
2. **Radians and quaternions for rotation**: a Transform turns by `Quat.fromRotationY(Math.PI / 4)` or
+2 -1
View File
@@ -20,7 +20,8 @@ posed at the time you give it, not by a clock, so any frame renders alone and pl
## Common mistakes
- `useFrame((_, dt) => ref.current.rotation.y += dt)`: there's no render loop. `Quat.fromEuler("XYZ", 0, f * speed, 0)`.
- `useFrame((_, dt) => ref.current.rotation.y += dt)` in raea's own 3D: there's no render loop there. Write
`Quat.fromEuler("XYZ", 0, f * speed, 0)`. (Inside `<R3F>`, an R3F scene, useFrame works: `bevy/r3f`.)
- Changing a shape's size or `shape` to animate size: animate the transform's scale.
- A `spring` without `fps`, or an `interpolate` without clamping, overshooting into nonsense values.
- A part shown with `{f > 30 && <Mesh3d ...>}` among others of the same shape, without a `name`: give it one so it
+3 -2
View File
@@ -62,8 +62,9 @@ The router's eight, plus:
- Bevy's own AnimationEvent (use `clipEvents(events, prev, now, duration)` from `raea/3d`).
- A looked model (`look="pixel"`/`"site"`) is drawn over the scene: parts in front of it don't hide it. At most 30.
- A shader of your own on a standard material or a Model (the looks are the engine's own; a shader you write draws
its own shape, as `<ShaderMesh>`, below); react-three-fiber's `useFrame`, refs, `<primitive>` and drei helpers: none
of them exist here.
its own shape, as `<ShaderMesh>`, below). react-three-fiber's `useFrame`, refs, `<primitive>` and drei helpers
don't drive raea's own components; inside `<R3F>` they work, and a plain three.js page runs in `<Three program>`
(`bevy/r3f`, with what three.js work doesn't draw yet).
Since 2026-10-22: `emissive_texture`, `alpha_mode`, `cull_mode`, real glass (`specular_transmission ior thickness`
on StandardMaterial), `receiveShadow={false}`, `<Capsule3d>`, and any of Bevy's own reflected components inside a
+102
View File
@@ -0,0 +1,102 @@
# three.js and React Three Fiber, drawn by raea
raea draws three.js work as it's written: a React Three Fiber scene inside `<R3F>`, or a plain three.js page's script
inside `<Three program>`. Each frame its three.js scene becomes raea's 3D parts, and raea's engine (Bevy) draws them in a
render, a live play and the web export alike. Use these when the work starts as three.js: a demo or tutorial to bring
in, an R3F scene, drei helpers, a TSL node material, a shader written for three. A new scene made from nothing is
plainer in raea's own components (`bevy/scene`).
Both need the project's own three (and React Three Fiber for `<R3F>`):
```bash
raea add [email protected] @react-three/[email protected] # and @react-three/drei, @react-three/postprocessing when used
```
## An R3F scene: `<R3F>`
R3F's JSX goes inside, as it would inside `<Canvas>`, and `<R3F>` takes `<Canvas>`'s settings (`camera`,
`orthographic`, `shadows`, `flat`, `linear`, `scene`).
```tsx
import { R3F } from "raea/r3f";
import { useFrame } from "@react-three/fiber";
import { useRef } from "react";
import * as THREE from "three";
function Spinner() {
const ref = useRef<THREE.Mesh>(null!);
useFrame((_s, dt) => void (ref.current.rotation.y += dt));
return (
<mesh ref={ref} castShadow>
<boxGeometry />
<meshStandardMaterial color="#e05a2b" />
</mesh>
);
}
export const Scene = () => (
<R3F camera={{ position: [0, 1.5, 4], fov: 45 }} shadows>
<ambientLight intensity={0.3} />
<directionalLight position={[3, 5, 2]} intensity={2.5} castShadow />
<Spinner />
</R3F>
);
```
Inside `<R3F>`, `useFrame`, refs and mutation are fine, unlike the rest of a composition: raea steps R3F's clock 1/fps
a frame from the composition's frame, never the wall clock, and a seek back starts the scene again from frame 0, so
a render still equals its play. `Math.random()` is seeded for the scene. raea's hooks (`useCurrentFrame`) work inside
too. Two scenes in one composition that come and go each take a `name`.
## A plain three.js page: `<Three program>` (raea 0.1.5)
A single-file demo's script, wrapped in a function, is the program. It makes its renderer as it always did
(`new THREE.WebGLRenderer({ canvas })` with the canvas it's given, or `document.body.appendChild(renderer.domElement)`,
or three/webgpu's `WebGPURenderer` with `await renderer.init()`), its scene and camera, and renders from
`renderer.setAnimationLoop` or `requestAnimationFrame`. raea's bundler gives it a renderer that draws nothing and
records what it renders; the scene it last rendered is what raea draws.
```tsx
import * as THREE from "three";
import { Three } from "raea/r3f";
function demo(canvas: HTMLCanvasElement) {
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
renderer.shadowMap.enabled = true;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(45, innerWidth / innerHeight, 0.1, 100);
camera.position.set(0, 2, 6);
// ... lights and meshes, as the page had them
renderer.setAnimationLoop((time) => {
knot.rotation.y = time / 1000;
renderer.render(scene, camera);
});
}
export const Scene = () => <Three program={demo} />;
```
Its loop runs once a frame at that frame's time (`time` is frame × 1000 / fps ms), `performance.now()` and three's
`Clock` read the same time, and `Math.random()` is seeded, so frame 40 is the same played to or rendered alone; a seek
back runs the program again from the start. Code at a module's top level can't start again: it must be inside the
function. A program may return a function that undoes it. `<Three>` needs three alone.
## What draws, and what doesn't yet
Drawn: meshes, groups, instanced and batched meshes, points, lines, sprites; standard, physical, basic, Lambert,
normal, matcap, shadow, points and line materials; ShaderMaterial and RawShaderMaterial (their GLSL translated and run
by raea); TSL node materials, unlit and lit (0.1.5); textures, environment maps, fog, the background, shadows; drei's
`<Text>`, `<Sky>`, `<Stars>`, `<Clouds>`, `<ContactShadows>`, `<Environment>`; @react-three/postprocessing's effects
that raea has (bloom, vignette, depth of field and bokeh, chromatic aberration, lens distortion, SSAO,
anti-aliasing, pixelation, tone mapping, brightness, contrast, hue and saturation). Close, not exact:
hemisphere lights, light probes, Phong and toon materials.
What raea can't draw is named once in the render's output (`raea/r3f: ...`), and the frame draws without it:
- a TSL compute (`renderer.compute(node)`): not run yet; the scene is drawn without what it computes
- a pass drawn into a render target other than drei's contact shadows' (an FBO, a portal): the target stays empty
- three's EffectComposer in a plain program: the scene is drawn without its passes
- pointer events and OrbitControls in a live play: not wired yet
- `onBeforeCompile` edits to a built-in material: drawn as the material without them
Look at the render (`raea render scene.tsx --frame 24 -o f.png`) and read its warnings: each says what was left out.
+2 -1
View File
@@ -60,7 +60,8 @@ title's slide. Entities are composed into world space before the engine sees the
`Transform.fromXyz(0, 1, 6).lookingAt([0, 0, 0])` and adjust.
- `.lookingAt` a point straight above or below the camera: there's no up to turn by. Look a little off vertical.
- Two cameras to cut between angles. Use one camera whose transform jumps at the cut frame.
- `useFrame` or refs from react-three-fiber. There's no render loop: write the frame's values as props.
- `useFrame` or refs from react-three-fiber on raea's own components: there's no render loop for them. Write the
frame's values as props. An R3F scene goes inside `<R3F>`, where they work (`bevy/r3f`).
- 2D meant to pass behind a 3D part, without a `<Canvas3D layered>`: otherwise the whole page is over the 3D.
- An unpositioned element after a layered Canvas3D: it paints under the 3D (CSS paints positioned boxes last). Make
it `position: absolute`.
+1 -1
Submodule skills updated: 0247f25f51...89ab557802.