Skip to content

3D

View .mdllms.txt

3D and 2D share one depth buffer. The camera is calibrated so z = 0 maps 1:1 onto canvas pixels: a box at x: 960, y: 540, z: 0 sits in the centre of a 1920×1080 frame. y points down, so “up” is −y.

import { Composition, Layer3D, LayerAnimation, Lighting } from "framefields";
const W = 1920, H = 1080;
const comp = new Composition({ width: W, height: H, fps: 30, durationMs: 4000, backgroundColor: "#0b0b0c" });
comp.add(Lighting.studio({ target: [W / 2, H / 2, 0] })); // environment + key/rim/fill, soft shadow
comp.add(
Layer3D.text({
text: "framefields", fontFamily: "Archivo", fontWeight: 800, fontSize: 280,
extrusionDepth: 26, fill: "#f5e300", bevelColor: "#6b6300", roughness: 0.35,
x: W / 2, y: H / 2, z: 0,
}).animate(LayerAnimation.create().keys("rotateY", [[0, -20], [120, 6, "sine.inOut"]])),
);

Rigs: Lighting.studio, soft, sunset, dramatic. Options: target, distance, rotation, intensity, exposure (stops), toneMapping, shadows (default on), shadowSoftness, fog, bloom. A rig returns an array; comp.add takes it, or spread it into children.

import { CameraAnimation, Layer } from "framefields";
comp.add(
Layer.camera({ x: 960, y: 540, z: -1000, targetX: 960, targetY: 540, targetZ: 0 }).animate(
CameraAnimation.camera()
.orbit({ azimuth: { from: -30, to: 30 }, elevation: { from: 15, to: 15 }, radius: { to: 1200 }, start: 0, end: 300, ease: "sine.inOut" })
.rackFocus({ fromDistance: 2000, toDistance: 1200, fromFStop: 1.8, toFStop: 4, start: 20, end: 60 }),
),
);

CameraAnimation.camera() moves: orbit, dolly, truck, pedestal, pan, tilt, roll, rackFocus, handheld({ translationAmplitude, rotationAmplitude }). Camera mode is "lookAt" (default), "free" or "orbit".

import { Layer, Light } from "framefields";
comp.add([
Layer.environment("studio", { // presets: studio | soft | sunset | night | neutral
exposure: 0.3,
toneMapping: "neutral", // default; "agx" filmic, "aces" punchy, "none"
rotation: 30,
fog: { color: "#0b0b0c", start: 2000, end: 5000 },
bloom: true, // or { intensity, threshold, radius }
}),
Light.directional({ x: 400, y: -1200, z: -600, targetX: 960, targetY: 540, castShadow: true }),
Light.ambient("#ffffff", 0.3),
]);

Light.ambient, Light.directional, Light.point, Light.spot (also Layer.ambientLight, Layer.directionalLight, Layer.pointLight, Layer.spotLight).

Rule Why
Add Layer.environment(...) for roughness / metallic to mean anything Without it the scene uses classic Blinn-Phong (lint: pbr_without_environment)
One castShadow light, directional or spot Only the first casts (multiple_shadow_lights); point/ambient can’t (shadow_unsupported_light)
Tone mapping "neutral" keeps brand colors as authored "agx" rolls highlights off filmically
Bloom only takes light well past white Use emissiveIntensity ≳ 3 to make something glow
Set fog.color to the background Surfaces fade into it seamlessly

From framefields 3.0.1, pathTrace on the environment traces the scene’s 3D layers instead of rasterizing them. Shadows, reflections (of things off screen too), refraction through glass, occlusion and light bouncing between surfaces are computed, not approximated, and glowing meshes light what is around them. Everything else stays as it was: the same lights, environment, floor, exposure, tone mapping, fog, bloom and motion blur.

comp.add([
Layer.environment("night", {
floor: { y: 420, color: "#22252c", reflectivity: 0.35, roughness: 0.25 },
pathTrace: true, // or { quality: "draft" } while you iterate
}),
Light.directional({ x: 0, y: -800, z: -400, targetX: 480, targetY: 300, castShadow: true }),
Layer3D.torus({ x: 760, y: 260, z: 120, radius: 90, tubeRadius: 10, color: "#111", emissive: "#3fb6ff", emissiveIntensity: 4 }),
]);

examples/43_path_tracer, at the default preset.

Preset Samples per pixel / bounces Use
"draft" 8 / 3, denoised iterating; checking frames and grids
"standard" 32 / 5, denoised quick finals of simple scenes
"high" (default) 128 / 8, denoised finals: glass, interiors, product shots
"reference" 1024 / 16, no denoiser the unbiased answer, to compare against

Override any part with samples, bounces, transmissionBounces, denoise, clamp (brightest bounced light per sample) and filterGlossy. At 1080p on an Apple M1 Pro, a frame with a character, a ball, a glowing ring and a floor takes about 12 s at "high"; desktop GPUs are several times faster.

Rule Why
A render takes exactly samples per pixel on any GPU Frames are deterministic, so a split cloud render joins without seams
The preview fits each frame to previewBudgetMs (33) of GPU time Slower GPUs see fewer samples or a lower resolution while you scrub; the export doesn’t
Sparkles on matte surfaces next to shiny ones: raise filterGlossy Light bounced off a glossy floor or a chrome ball arrives through rare paths; filterGlossy (draft 0.7, standard 0.6, high 0.45) turns it into a soft glow
Thick glass has its own bounce budget, transmissionBounces Crossing a vase or a lamp globe takes four or more passes; draft allows 8, standard 12, high 16. Raise it if stacked glass turns dark
Glass from a model keeps its roughness Frosted where the model says so; material: "glass" on a primitive is clear unless you set roughness
Glowing meshes emit from their front faces As the raster draws them; set twoSided for both sides. material: "unlit" layers show their picture and light nothing
Not with ssr, gi, outlines, volumetricFog or a cube camera The tracer does reflections and bounce light itself; the others aren’t traced yet (framefields check flags each)

Not traced yet, and named in an error if a traced scene uses them: text drawn on a 3D plane (use Layer3D.extrudedText), toon, mattes, reliefs, triplanar textures, wireframes, instanced scatter, swarms and crowds, wind, and audio deformation. subsurface shades as plain diffuse. Point and directional lights cast hard shadows; rect lights cast soft ones.

Every Layer3D procedural mesh is centered on x/y/z (y is down, so the top face is at -y). Equal shapes share GPU buffers automatically.

// Solids & motion-design primitives
Layer3D.roundedBox({ x: 960, y: 540, z: 0, width: 300, height: 80, depth: 300, radius: 18, taper: 0.9, color: "#ff5a1f", roughness: 0.45 });
Layer3D.sphere({ x: 700, y: 540, z: 0, radius: 90, color: "#e8e8e8", metallic: 1, roughness: 0.15 });
Layer3D.cylinder({ x: 1200, y: 540, z: 0, radius: 12, height: 400, color: "#111", emissive: "#4da3ff", emissiveIntensity: 3 });
Layer3D.capsule({ x: 960, y: 240, z: 0, radius: 40, height: 80, color: "#22c55e" });
Layer3D.torus({ x: 300, y: 240, z: 0, radius: 68, tubeRadius: 24, arc: 360, color: "#ff5a1f" }); // partial arcs (e.g. arc: 250) are capped
Layer3D.ring({ x: 1290, y: 240, z: 0, innerRadius: 36, outerRadius: 80, color: "#eab308", metallic: 0.6 });
// Solid capped polygonal prisms & pyramids (flat-shaded by default)
Layer3D.prism({ x: 1620, y: 240, z: 0, sides: 6, radius: 66, height: 110, color: "#3b82f6" });
Layer3D.pyramid({ x: 300, y: 540, z: 0, sides: 4, radius: 76, height: 125, color: "#a855f7" });
// Polyhedra & geodesic icospheres
Layer3D.polyhedron({ shape: "dodecahedron", radius: 74, color: "#c084fc" }); // "tetrahedron" | "octahedron" | "dodecahedron" | "icosahedron"
Layer3D.icosahedron({ radius: 74, color: "#fbbf24" });
Layer3D.icosphere({ radius: 74, detail: 2, flatShaded: true, color: "#4ade80" }); // detail: 0..5, smooth or flat
// 2D shape extrusion & lathe / revolve geometry
Layer3D.extrude({
x: 630, y: 540, z: 0,
d: "M -60 -60 L 60 -60 L 60 60 L -60 60 Z M 20 0 A 20 20 0 1 0 -20 0 A 20 20 0 1 0 20 0 Z", // SVG path with holes or contour array
depth: 32,
bevelThickness: 6,
bevelSize: 4,
bevelSegments: 3,
color: "#f43f5e",
bevelColor: "#fecdd3", // optional separate side-wall color
});
Layer3D.lathe({
x: 960, y: 540, z: 0,
points: [[0, -75], [52, -70], [58, -35], [20, 5], [15, 48], [48, 70], [0, 75]], // [r, y][] profile revolved around Y
segments: 48,
capped: true,
color: "#06b6d4",
});
// 3D curves, thick-walled hollow tubes, lines, and diagram points
Layer3D.tube({
path: Path3D.catmullRom([[-70, 50, -15], [-25, -50, 25], [25, 50, -25], [70, -50, 15]]),
radius: 24,
innerRadius: 14, // hollow thick-walled pipe with annular end caps
color: "#10b981",
});
Layer3D.line({
points: [[0, 0, 0], [100, -50, 30], [200, 20, -10]],
dashSize: 10,
gapSize: 5,
color: "#93c5fd",
});
Layer3D.points({
points: [[0, 0, 0], [100, -50, 30], [200, 20, -10]],
pointSize: 12, // perspective-scaled 3D sphere dots (or 0 for GPU pixel point-list)
colors: ["#fde047", "#f472b6", "#60a5fa"],
});
Builder Description & Key Options
Layer3D.roundedBox width, height, depth, radius, taper, segments
Layer3D.sphere radius, widthSegments, heightSegments
Layer3D.cylinder radius or radiusTop/radiusBottom, height, radialSegments, openEnded, flatShaded
Layer3D.capsule radius, height (shaft) or totalHeight, capSegments, radialSegments
Layer3D.torus radius, tubeRadius, arc (degrees; capped when < 360), radialSegments, tubularSegments
Layer3D.ring innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength
Layer3D.prism solid capped flat-shaded N-gon prism (sides, radius, radiusTop, radiusBottom, height, openEnded, flatShaded) or multi-panel container via sideConfigs
Layer3D.pyramid solid capped flat-shaded pyramid (sides, radius, radiusTop, height, openEnded, flatShaded)
Layer3D.polyhedron Platonic solids (shape: "tetrahedron" | "octahedron" | "dodecahedron" | "icosahedron" | "icosphere", radius, detail, flatShaded)
Layer3D.icosahedron 20-sided regular polyhedron (radius, detail, flatShaded)
Layer3D.icosphere geodesic sphere with subdivision detail (radius, detail, flatShaded)
Layer3D.shard procedural flat-faceted crystal clipped against Fibonacci lattice normals (radius, cuts, irregularity, seed)
Layer3D.extrude extrudes an SVG path d (with curves and subpaths/holes) or 2D contour/holes (depth, bevelThickness, bevelSize, bevelSegments, bevelColor, center)
Layer3D.lathe revolves a 2D profile points [r, y][] around the Y axis (segments, phiStart, phiLength, capped, flatShaded) with crease-aware normal splitting
Layer3D.tube sweeps a solid or thick-walled pipe (innerRadius, radiusTaper, closed, capped) along a Path3D or 3D points using Rotation-Minimizing Frames
Layer3D.line 3D polyline/segment geometry (line-list topology) along 3D points or Path3D, with dashSize/gapSize dashing and vertex colors
Layer3D.points 3D point cloud (pointSize: 0 for GPU point-list pixels, or pointSize > 0 for perspective-scaled 3D sphere dots) with per-point colors
Layer3D.cube({ size, faces }) a cube whose faces are 2D layers
Layer3D.carousel({ radius, items }) 2D items on a ring
Layer3D.plane, Layer3D.grid flat cards, ground grids
Layer3D.text / Layer3D.extrudedText extruded, bevelled vector type from registered fonts

Meshes take a material: "pbr" (default), "unlit", "glass", "acrylic" or "frosted".

glass, acrylic and frosted materials physically refract what is behind them on screen — with chromatic dispersion, slab thickness, tint, and studio reflections — instead of rendering as simple translucent plastic:

Layer3D.roundedBox({
x: 960, y: 540, z: 0,
width: 320, height: 200, depth: 36, radius: 18,
material: "glass",
color: "#eef5ff",
roughness: 0.03, // smooth clear glass; higher roughness gives frosted glass
});

From 3.0.1, openPBR takes OpenPBR Surface parameters with the spec’s own names and linear colors, as Blender, Houdini, Maya or Substance show them, and returns surface props to spread into any mesh or model. standardSurface does the same for Autodesk Standard Surface.

import { openPBR, parseMtlx } from "framefields";
Layer3D.sphere({ radius: 90, ...openPBR({ base_color: [0.6, 0.02, 0.02], coat_weight: 1, specular_roughness: 0.4 }) }); // lacquered red
Layer3D.sphere({ radius: 90, ...openPBR({ base_color: [0.95, 0.64, 0.54], base_metalness: 1, specular_roughness_anisotropy: 0.8 }) }); // brushed copper
const materials = parseMtlx(await fs.readFile("assets/table.mtlx", "utf8"), { baseDir: "assets" });
Layer.glb("assets/table.glb", { ...materials.M_table.props });

Transmission above 0.5 becomes glass (frosted when rough), emission_luminance is read against a 100-nit white (300 nits is emissiveIntensity: 3), and thin-film thickness is in micrometres. parseMtlx reads a MaterialX document’s open_pbr_surface and standard_surface materials by name. A base color wired to an image node becomes the mesh’s texture. Other connected maps and parameters framefields has no lobe for are listed in each material’s unsupported, so nothing is dropped silently.

Surface props on meshes: color, tint (animates as color), roughness, metallic, emissive, emissiveIntensity, castShadow. Flat layers cast shadows only with castShadow: true; meshes cast by default.

From 3.1, Layer3D.clay is a sculpture written as a list of moves (ops) that run in order. It is drawn per pixel from those moves, so it stays sharp at any size and has no polygon count to choose. Local space is in px with up as -y, like the other primitives.

Layer3D.clay({
x: 960, y: 420, symmetry: "x", color: "#cdbba6", roughness: 0.6,
ops: [
{ type: "stroke", path: [[-105, 88, 18], [0, 70, 6], [105, 88, 18]], radius: 48 }, // shoulders
{ type: "sphere", center: [0, -70, 0], radius: 72, smoothness: 22 }, // head
{ type: "sphere", center: [30, -74, -66], radius: 15, mode: "carve" }, // eye socket
{ type: "grab", center: [0, -14, -104], radius: 26, delta: [0, 16, -6] }, // pull the chin
{ type: "detail", amplitude: 2.2, scale: 22, ridged: true, seed: 7 }, // stone
],
});
Move What it does
sphere box cylinder capsule torus Solids: mode: "add" (default), "carve" or "intersect", smoothness (blend radius, px), center, rotation, color
stroke A brush stroke: a ball swept along a smooth curve through path ([x, y, z] or [x, y, z, radius]), radius, progress 0..1, plus the solids’ mode, smoothness and color
grab twist bulge Elastic brushes that move what is already sculpted: center, radius, and delta, axis + angle, or amount
inflate Swells (or with a negative amount, shrinks) a round region by amount px
detail Relief texture: amplitude, scale, octaves, ridged, seed, optionally limited to center + radius. It fades where it would be smaller than a pixel, so put it last

symmetry: "x" mirrors what you sculpt at positive x. Moves are fixed for a layer: animate the node, or show several layers in turn, as examples/45_sculpture does to film a sculpture being made. Path tracing, glass, blended and textured draws, physics and scatter use a mesh of the sculpture, built at resolution (16–1024, default 64). Raise it for a finer traced or exported mesh. draw: "mesh" draws that mesh for ordinary draws too.

comp.add(Layer.glb("assets/models/character.glb", { x: 960, y: 640, z: 0, scale: 2.5, loop: true }));

Loaders: Layer.glb, gltf, obj, fbx, stl, ply, vox, threeDS, off (also on Layer3D). glTF brings base color, normal, metallic-roughness, occlusion and emissive maps, and skeletal animation (up to 128 bones). Animate playback with animationProgress, animationTime or animationSpeed.

The other way round, comp.exportModel({ frame }) writes a frame’s 3D scene as a .glb for Blender, Unreal, Unity or the web: see 3D models (glTF).

Animate primitives and models with deterministic 3D physics (Rapier) using Physics.world3d: collision responses, joints, and forces. See the Physics & particles guide.

z, rotateX/Y/Z, scaleX/Y/Z, roughness, metallic, emissive, emissiveIntensity, exposure, intensity, plus camera props (cameraX/Y/Z, targetX/Y/Z, cameraFov, focusDistance, fStop, orbitRadius, orbitAzimuth, orbitElevation).