Examples
Bézier in 3D
A cubic Bézier constructed in space — control points, control polygon, and a turntable camera
The idea: a cubic Bézier curve is a weighted blend of four control
points — and in 3D you can see the blend, because every sampled point
carries its own depth. The control polygon shows the scaffolding, labels
name the points, a wireframe box frames the volume, and the camera
turntables around it with Camera.orbitTo while Camera.lookAt pins the
aim — no orientation math anywhere in the scene.
import * as Camera from "effect-motion/Camera";import * as Color from "effect-motion/Color";import * as Entity from "effect-motion/Entity";import * as Scene from "effect-motion/Scene";// A 3D cubic Bézier drawn with a native C command. The renderer flattens// it deterministically, retaining depth along the curve so it foreshortens// point by point. A wireframe box (12 Line edges) frames the// volume; the camera aims at its center with Camera.lookAt and turntables// around it with Camera.orbitTo — the point of interest pins the aim, so// there is no orientation math in the scene at all.// control points, local to the path anchor — the curve climbs in y while// z spreads it through depthconst P0 = { x: 0, y: 0, z: 0 };const P1 = { x: 0, y: 100, z: 100 };const P2 = { x: 100, y: 200, z: -100 };const P3 = { x: 10, y: 300, z: 0 };type Point3 = { x: number; y: number; z: number };const curveCommands: [Entity.PathCommand, ...Array<Entity.PathCommand>] = [ { _tag: "M", ...P0 }, { _tag: "C", x1: P1.x, y1: P1.y, z1: P1.z, x2: P2.x, y2: P2.y, z2: P2.z, ...P3, },];const ANCHOR = { x: 0, y: 0 };const noFill = Color.rgba(0, 0, 0, 0);// the axes-box volume around the curve, in world coordinatesconst BOX = { x0: 200, y0: 0, z0: 200, x1: -200, y1: 300, z1: -200,};// its 12 edges as Line endpoints: 4 along each axisconst boxEdges = (): Array<[Point3, Point3]> => { const { x0, x1, y0, y1, z0, z1 } = BOX; const edges: Array<[Point3, Point3]> = []; for (const y of [y0, y1]) { for (const z of [z0, z1]) { edges.push([ { x: x0, y, z }, { x: x1, y, z }, ]); } } for (const x of [x0, x1]) { for (const z of [z0, z1]) { edges.push([ { x, y: y0, z }, { x, y: y1, z }, ]); } } for (const x of [x0, x1]) { for (const y of [y0, y1]) { edges.push([ { x, y, z: z0 }, { x, y, z: z1 }, ]); } } return edges;};export const scene = Scene.make( "bezier-3d", function* () { // the wireframe box: each edge is a skeletal Line, both endpoints at // their own depth for (const [a, b] of boxEdges()) { // position stays at the origin; start and end carry the two corners // as offsets from it, so the edge spans a → b directly yield* Scene.instantiate("Line", { start: Entity.vec3({ x: a.x, y: a.y, z: a.z }), end: Entity.vec3({ x: b.x, y: b.y, z: b.z }), strokeColor: Color.hex("#3d4266"), strokeWidth: 2, opacity: 1, }); } // the control polygon: straight rails between the control points yield* Scene.instantiate("Path", { fillColor: noFill, strokeColor: Color.tw("gray", "400"), strokeWidth: 2, commands: [ { _tag: "M", ...P0 }, { _tag: "L", ...P1 }, { _tag: "L", ...P2 }, { _tag: "L", ...P3 }, ], }); // the curve itself — one Path, with depth in both control points yield* Scene.instantiate("Path", { fillColor: noFill, strokeColor: Color.tw("pink", "500"), strokeWidth: 3, commands: curveCommands, }); // markers + labels at the control points (world = anchor + local) const points = [P0, P1, P2, P3]; for (const [i, p] of points.entries()) { yield* Scene.instantiate("Circle", { position: Entity.vec3({ x: ANCHOR.x + p.x, y: ANCHOR.y + p.y, z: p.z }), radius: 5, fillColor: Color.tw("violet", "500"), }); yield* Scene.instantiate("Text", { position: Entity.vec3({ x: ANCHOR.x + p.x + 12, y: ANCHOR.y + p.y + 8, z: p.z, }), text: `P${i}`, fontSize: 14, fillColor: Color.tw("gray", "400"), }); } // aim at the box center, then turntable around it — the point of // interest keeps the camera locked on while only its position moves. // The camera starts raised above and off to the side of the box. const cam = yield* Scene.camera; yield* Scene.update(cam, (props) => ({ ...props, position: Entity.vec3({ ...props.position, x: 960, y: 960 }), focalLength: 5000, })); yield* cam.pipe( Camera.lookAt({ x: (BOX.x0 + BOX.x1) / 2, y: (BOX.y0 + BOX.y1) / 2, z: (BOX.z0 + BOX.z1) / 2, }), Camera.orbitTo(2, "5 seconds", "easeInOutCubic"), Camera.orbitTo(-2, "5 seconds", "easeInOutCubic"), ); }, { compositing: "depth", width: 1920, height: 1080, backgroundColor: Color.tw("gray", "800"), },);The curve uses one native C command with 3D control points. The renderer
flattens it deterministically and projects the resulting points at their
own depth. See Curves, trim paths, and dashes
for the command fields and stroke animation controls.