Skip to content

3D engine that AI agents drive

Follow an oceanTime sea with spray emitters and make the docs spray example valid (#2152)

Nguyen Xuan An88e7ae72e5ff
diff --git a/changes/2152.md b/changes/2152.md
new file mode 100644
index 00000000..0d4f8e9f
--- /dev/null
+++ b/changes/2152.md
@@ -0,0 +1 @@
+- A particle emitter on a sea animated by an `oceanTime` track now takes its droplets from the crests of each particle's birth time, and the "Spray from the sea" example in `docs/physics.md` is a whole recipe that `scene_create` accepts (#2152)
diff --git a/changes/2152.size.md b/changes/2152.size.md
new file mode 100644
index 00000000..812b48c1
--- /dev/null
+++ b/changes/2152.size.md
@@ -0,0 +1,3 @@
+- scene:agent-scene: about 190 bytes gzip so an emitter on a sea with an oceanTime track samples the animated crests; before it, such a sea could not spray at all (#2152).
+- scene:agent-scene+lazy: the same code, counted again in the lazy bundle.
+- goal:agent-scene: the same 190 bytes, for the agent-facing capability above; nothing else in the scene grew.
diff --git a/docs/physics.md b/docs/physics.md
index edc1368e..52d296e7 100644
--- a/docs/physics.md
+++ b/docs/physics.md
@@ -437,14 +437,19 @@ The boat code is part of the buoyancy chunk, so a scene without floating bodies
An `ocean` edit with `spray: true` writes the vertex group `spray` and the vector `spray` (the velocity of the surface, m/s). A particle system takes its droplets from the crests that are rising and sends them off with that velocity:
-```jsonc
-{ "geometries": [{ "id": "sea", "type": "mesh", "base": { "type": "box", "bevel": 0 },
- "edits": [{ "op": "subdivide", "levels": 5 }, { "op": "ocean", "windSpeed": 12, "choppiness": 2, "spray": true }] }],
- "particles": { "systems": [{ "node": "droplet", "count": 400, "speed": [0, 1], "lifetime": [0.6, 1.4],
- "emitter": { "shape": "mesh", "mesh": "surface", "from": "vertices", "group": "spray", "groupThreshold": 0.3, "scale": "shrink", "velocityFrom": "spray", "velocityScale": 2 } }] } }
+```json
+{ "format": "crucible.scene", "schemaVersion": 1,
+ "geometries": [
+ { "id": "sea", "type": "mesh", "base": { "type": "box", "bevel": 0 },
+ "edits": [{ "op": "subdivide", "levels": 4 }, { "op": "ocean", "windSpeed": 12, "choppiness": 2, "resolution": 16, "time": 3, "spray": true }] },
+ { "id": "drop", "type": "icoSphere", "subdivisions": 1 }],
+ "materials": [{ "id": "water", "color": [0.02, 0.14, 0.24] }, { "id": "foam", "color": [0.95, 0.97, 1] }],
+ "nodes": [{ "id": "surface", "geometry": "sea", "material": "water" }, { "id": "droplet", "geometry": "drop", "material": "foam" }],
+ "particles": { "systems": [{ "node": "droplet", "count": 400, "speed": [0, 1], "lifetime": [0.6, 1.4], "size": [0.01, 0.05], "scale": "shrink",
+ "emitter": { "shape": "mesh", "mesh": "surface", "from": "vertices", "group": "spray", "groupThreshold": 0.3, "velocityFrom": "spray", "velocityScale": 2 } }] } }
```
-`velocityFrom` (the name of a vector on the emitter mesh; `from` "surface" or "vertices") adds that velocity, times `velocityScale` (1, -1000 to 1000) and in world space, to every particle. A name the mesh lacks is an error that lists the vectors it has. `groupThreshold` (0 to 1, default 0, needs `group`) keeps the emitter off weakly painted water: only points where the group weighs at least that much emit, so spray comes from the crests and not from the whole foamy triangle around them. The foam must fold for there to be spray, so a sea with `choppiness` 0 sprays nowhere. The emitter reads the sea at the edit's `time`: droplets do not follow an `oceanTime` track, and there is no bow-spray emitter on a `boat` yet. The same seed gives the same droplets.
+`velocityFrom` (the name of a vector on the emitter mesh; `from` "surface" or "vertices") adds that velocity, times `velocityScale` (1, -1000 to 1000) and in world space, to every particle. A name the mesh lacks is an error that lists the vectors it has. `groupThreshold` (0 to 1, default 0, needs `group`) keeps the emitter off weakly painted water: only points where the group weighs at least that much emit, so spray comes from the crests and not from the whole foamy triangle around them. The foam must fold for there to be spray, so a sea with `choppiness` 0 sprays nowhere. Which points spray depends on the edit's `time`, `size`, `resolution`, `windSpeed` and `choppiness`: a sea can have no spray at one `time` and plenty at another, and then the scene is refused with "no weight in vertex group spray" on the emitter mesh. Raise `windSpeed` or `choppiness`, lower `groupThreshold`, or change `time` (the example uses `resolution` 16 and `time` 3). A sea animated by a `motion` track `{ "kind": "geometry", "id": "sea", "property": "oceanTime" }` is followed: each droplet leaves the crests of the sea at the ocean time of its birth (sampled every 1/24 s of ocean time), and a birth at a moment with no spray takes the nearest moment that has some; only when the sea has none anywhere near is the scene refused, with an error that names `ocean.time` and the track. There is no bow-spray emitter on a `boat` yet. The same seed gives the same droplets.
## Fracture and breakable glue
diff --git a/src/agent-particles.js b/src/agent-particles.js
index 94f50abc..d0e78072 100644
--- a/src/agent-particles.js
+++ b/src/agent-particles.js
@@ -493,25 +493,63 @@ function velocityVectorOf(emitter, geometry, matrix, emitterPath) {
return world;
}
-function meshSourceOf(system, nodes, geometries, systemIndex) {
- const emitterPath = `particles.systems[${systemIndex}].emitter`;
- const emitter = system.emitter;
- if (emitter.shape !== 'mesh') return emitter;
- const sourceNode = nodes.get(emitter.mesh);
- const geometry = geometries.get(sourceNode.geometry);
+// A sea whose oceanTime a motion track drives is sampled at the ocean time of each particle's birth, rounded to this step (seconds of ocean time).
+const OCEAN_TIME_STEP = 1 / 24;
+// How many steps either side of a birth to look when the sea has no spray at that moment.
+const OCEAN_TIME_SEARCH_STEPS = 96;
+
+function meshSourceFrom(emitter, geometry, sourceNode, emitterPath) {
const world = surfaceInWorld(geometry, nodeMatrix(sourceNode));
const weights = emitter.group ? vertexGroupOf(emitter, geometry, emitterPath) : null;
const sharpAngle = emitter.sharpAngle ?? null;
- const sourceMatrix = nodeMatrix(sourceNode);
- const vectors = emitter.velocityFrom ? velocityVectorOf(emitter, geometry, sourceMatrix, emitterPath) : null;
+ const vectors = emitter.velocityFrom ? velocityVectorOf(emitter, geometry, nodeMatrix(sourceNode), emitterPath) : null;
const source = createMeshSource(world.positions, world.normals, geometry.indices, emitter.from, weights, sharpAngle, vectors, emitter.groupThreshold ?? 0);
- if (!source) {
- const groupNote = emitter.group ? ` and some weight in vertex group "${emitter.group}"` : '';
- throw invalidField(`${emitterPath}.mesh`, emitter.mesh, `a node whose mesh has triangles with some area${groupNote}, because emitter.from is "${emitter.from}"`);
- }
- if (source.triangleCount > PARTICLE_LIMITS.maxEmitterTriangles) {
+ if (source && source.triangleCount > PARTICLE_LIMITS.maxEmitterTriangles) {
throw invalidField(`${emitterPath}.mesh`, `${source.triangleCount} triangles on node ${emitter.mesh}`, `a mesh with at most ${PARTICLE_LIMITS.maxEmitterTriangles} triangles, such as a simpler proxy mesh`);
}
+ return source;
+}
+
+function emptySourceError(emitter, emitterPath, detail) {
+ const groupNote = emitter.group ? ` and some weight in vertex group "${emitter.group}"` : '';
+ return invalidField(`${emitterPath}.mesh`, emitter.mesh, `a node whose mesh has triangles with some area${groupNote}, because emitter.from is "${emitter.from}"${detail}`);
+}
+
+// The source of a sea that an oceanTime track moves: each particle takes its point from the sea as it is when the particle is born.
+function followingSeaSource(emitter, sourceNode, sea, emitterPath) {
+ const frames = new Map();
+ const sourceAt = step => {
+ if (!frames.has(step)) {
+ const geometry = sea.geometryAt(sourceNode.geometry, step * OCEAN_TIME_STEP);
+ frames.set(step, meshSourceFrom(emitter, geometry, sourceNode, emitterPath));
+ }
+ return frames.get(step);
+ };
+ const nearestSource = step => {
+ for (let distance = 0; distance <= OCEAN_TIME_SEARCH_STEPS; distance++) {
+ const source = sourceAt(step + distance) ?? sourceAt(step - distance);
+ if (source) return source;
+ }
+ throw emptySourceError(emitter, emitterPath, `; the sea of node ${emitter.mesh} has no weight in that group at any ocean time its oceanTime track gives near the births; raise the ocean windSpeed or choppiness, lower groupThreshold, or change ocean.time and the oceanTime track`);
+ };
+ return Object.freeze({
+ mode: emitter.from,
+ triangleCount: 0,
+ sample: (random, birth) => nearestSource(Math.round(sea.oceanTimeAt(sourceNode.geometry, birth) / OCEAN_TIME_STEP)).sample(random),
+ });
+}
+
+function meshSourceOf(system, nodes, geometries, systemIndex, sea) {
+ const emitterPath = `particles.systems[${systemIndex}].emitter`;
+ const emitter = system.emitter;
+ if (emitter.shape !== 'mesh') return emitter;
+ const sourceNode = nodes.get(emitter.mesh);
+ const followsSea = sea?.oceanTimeAt(sourceNode.geometry, 0) != null;
+ if (followsSea) return { ...emitter, source: followingSeaSource(emitter, sourceNode, sea, emitterPath) };
+ const source = meshSourceFrom(emitter, geometries.get(sourceNode.geometry), sourceNode, emitterPath);
+ if (!source) {
+ throw emptySourceError(emitter, emitterPath, emitter.group ? '; an ocean edit with spray: true has spray only on crests that rise, and that depends on its time, size, resolution and windSpeed: change them, lower groupThreshold, or animate the sea with an oceanTime track' : '');
+ }
return { ...emitter, source };
}
@@ -598,7 +636,8 @@ function nodeTransformProblems(particles, recipe) {
return problems;
}
-export function bakeAgentParticles(particles, recipe, geometries) {
+/** `sea` is `{ oceanTimeAt(geometryId, time), geometryAt(geometryId, oceanTime) }`: an emitter on a geometry that an oceanTime track drives follows that sea. */
+export function bakeAgentParticles(particles, recipe, geometries, sea) {
const nodes = new Map(recipe.nodes.map(node => [node.id, node]));
const forces = { gravity: particles.gravity ?? DEFAULT_GRAVITY, wind: particles.wind ?? [0, 0, 0], fields: particles.fields ?? [] };
let totalVertices = 0;
@@ -611,9 +650,9 @@ export function bakeAgentParticles(particles, recipe, geometries) {
const surfaceNode = nodes.get(system.surface);
return prepareHair(system, node, surfaceNode, geometries.get(surfaceNode.geometry), forces);
}
- if (system.type === 'sparks') return prepareSparks(system, node, forces, meshSourceOf(system, nodes, geometries, systemIndex));
+ if (system.type === 'sparks') return prepareSparks(system, node, forces, meshSourceOf(system, nodes, geometries, systemIndex, sea));
const templates = templateNodeIds(system).map(nodeId => geometries.get(nodes.get(nodeId).geometry));
- return prepareEmitter(system, node, templates, forces, collisionSurfaceOf(system, nodes, geometries), meshSourceOf(system, nodes, geometries, systemIndex));
+ return prepareEmitter(system, node, templates, forces, collisionSurfaceOf(system, nodes, geometries), meshSourceOf(system, nodes, geometries, systemIndex, sea));
});
return Object.freeze({
/** Warnings for a recipe that loads but does not do what its author likely meant. */
diff --git a/src/agent-scene-capabilities.js b/src/agent-scene-capabilities.js
index 4c9e755d..02bdef50 100644
--- a/src/agent-scene-capabilities.js
+++ b/src/agent-scene-capabilities.js
@@ -198,7 +198,7 @@ export const MESH_MODIFIER_NOTES = Object.freeze({
bounding_box: 'becomes its axis-aligned box.',
convex_hull: 'becomes its convex hull, up to 8192 vertices.',
build: 'shows faces one by one as frame runs from start 0 over length 60 frames (frame 0; give the current frame, e.g. from your film clock): order index (default), random (seed 0) or axis (axis y, lowest centroid first); reverse true unbuilds. Unused vertices drop; while none shows, one zero-area triangle stays.',
- ocean: 'seeded sea: lifts axis (y) by waves of windSpeed 10 m/s (0-60) toward direction 0 deg, size 100 m (repeats), seed 0, time 0 s, resolution 8 (1-16); choppiness 1 (0-4) pulls points to crests. Writes group foam; spray true also writes group spray (foam where the surface rises) and the vector spray (surface velocity m/s) for particles emitter group spray + velocityFrom spray. wake {points up to 64 [x, z, strength, width], height 0.06} adds white foam and a small choppy displacement along a boat trail (physics float.boat.wake fills it).',
+ ocean: 'seeded sea: lifts axis (y) by waves of windSpeed 10 m/s (0-60) toward direction 0 deg, size 100 m (repeats), seed 0, time 0 s, resolution 8 (1-16); choppiness 1 (0-4) pulls points to crests. Writes group foam; spray true also writes group spray (foam where the surface rises) and the vector spray (surface velocity m/s) for particles emitter group spray + velocityFrom spray. Spray depends on time, size, resolution, windSpeed and choppiness: a sea with no spray at its time makes the emitter refuse ("no weight in vertex group spray"); a sea with an oceanTime geometry track is followed (droplets leave the crests of their birth time). wake {points up to 64 [x, z, strength, width], height 0.06} adds white foam and a small choppy displacement along a boat trail (physics float.boat.wake fills it).',
});
// Vertex colors and groups. Details stay here so the tool schemas stay small.
diff --git a/src/agent-scene.js b/src/agent-scene.js
index 628c864a..b05040a8 100644
--- a/src/agent-scene.js
+++ b/src/agent-scene.js
@@ -1326,6 +1326,13 @@ function stagePose(stagedState, time) {
return { graph, materialUpdates, camera, time, clothGeometries, assetClips, hiddenNodes, movedLook, morphs: sampled?.morphs ?? null };
}
+/** A mesh stack built with every ocean node's `time` set to `oceanTime`: the sea the renderer draws at that moment of an oceanTime track. */
+function oceanTimeGeometry(recipe, maxGeometryVertices, geometryId, oceanTime, wakeField) {
+ const definition = recipe.geometries.find(candidate => candidate.id === geometryId);
+ const stack = definition.stack.map(node => (node.op === 'ocean' ? { ...node, ...wakeField, time: oceanTime } : node));
+ return Object.freeze(generateGeometry({ ...definition, stack }, maxGeometryVertices, cutterScopeOf(recipe.geometries)));
+}
+
/**
* Geometries of mesh stacks whose ocean time a geometry track drives, keyed by node ID. Each one is built from the cached edits with
* every ocean node's `time` set to the sampled value, so it equals the still of a recipe that writes that time into the node. The last
@@ -1343,10 +1350,7 @@ function oceanTimeGeometries(stagedState, sampled, time) {
const wakeField = stagedState.physicsSampler?.wakeField?.(geometryId, time);
const key = wakeField ? `${patch.oceanTime}|${time}` : patch.oceanTime;
if (frame?.key !== key) {
- const definition = stagedState.recipe.geometries.find(candidate => candidate.id === geometryId);
- const stack = definition.stack.map(node => (node.op === 'ocean' ? { ...node, ...wakeField, time: patch.oceanTime } : node));
- const scope = cutterScopeOf(stagedState.recipe.geometries);
- frame = { key, geometry: Object.freeze(generateGeometry({ ...definition, stack }, stagedState.maxGeometryVertices, scope)) };
+ frame = { key, geometry: oceanTimeGeometry(stagedState.recipe, stagedState.maxGeometryVertices, geometryId, patch.oceanTime, wakeField) };
frames.set(geometryId, frame);
}
for (const node of stagedState.recipe.nodes) {
@@ -1816,7 +1820,7 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {
stagedState.motionSampler = recipe.motion ? agentSceneModule('motion').compileAgentMotion(recipe.motion, recipe) : null;
stagedState.physicsSampler = stagePhysics(recipe, geometryRecords);
stagedState.clothSampler = stageCloth(recipe, geometryRecords, stagedState.motionSampler);
- stagedState.particleSampler = stageParticles(recipe, geometryRecords);
+ stagedState.particleSampler = stageParticles(recipe, geometryRecords, stagedState);
const animated = Boolean(stagedState.motionSampler || stagedState.physicsSampler || stagedState.clothSampler || stagedState.particleSampler || assetRuntime.animators.length);
stagedState.poseGraph = animated ? compile(recipe, geometries, localBounds, limits) : null;
stagedState.initialPose = stagePose(stagedState, animated ? 0 : null);
@@ -1998,15 +2002,22 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {
}
// Particle launches are cheap to recompute, but an unchanged section on unchanged nodes still reuses them.
- function stageParticles(recipe, geometryRecords) {
+ function stageParticles(recipe, geometryRecords, stagedState) {
if (!recipe.particles) {
return null;
}
- const involvedNodes = recipe.nodes.filter(node => recipe.particles.systems.some(system => system.node === node.id));
- const key = JSON.stringify([recipe.particles, involvedNodes, involvedNodes.map(node => geometryRecords.get(node.geometry).signature)]);
+ const emitterMeshes = new Set(recipe.particles.systems.map(system => system.emitter?.mesh));
+ const involvedNodes = recipe.nodes.filter(node => emitterMeshes.has(node.id) || recipe.particles.systems.some(system => system.node === node.id));
+ const oceanTracks = (recipe.motion?.tracks ?? []).filter(track => track.kind === 'geometry' && track.property === 'oceanTime');
+ const key = JSON.stringify([recipe.particles, involvedNodes, involvedNodes.map(node => geometryRecords.get(node.geometry).signature), oceanTracks]);
if (particleBake?.key !== key) {
const geometries = new Map([...geometryRecords].map(([id, record]) => [id, record.geometry]));
- particleBake = { key, sampler: agentSceneModule('particles').bakeAgentParticles(recipe.particles, recipe, geometries) };
+ // An emitter on a sea with an oceanTime track samples the sea at the ocean time of each particle's birth (#2152).
+ const sea = {
+ oceanTimeAt: (geometryId, time) => stagedState.motionSampler?.sample(time)?.geometries?.get(geometryId)?.oceanTime ?? null,
+ geometryAt: (geometryId, oceanTime) => oceanTimeGeometry(recipe, stagedState.maxGeometryVertices, geometryId, oceanTime),
+ };
+ particleBake = { key, sampler: agentSceneModule('particles').bakeAgentParticles(recipe.particles, recipe, geometries, sea) };
}
return particleBake.sampler;
}
diff --git a/src/particles.js b/src/particles.js
index a62cba9c..6d9ea725 100644
--- a/src/particles.js
+++ b/src/particles.js
@@ -128,7 +128,9 @@ export function createParticleLaunches(settings) {
for (let index = 0; index < count; index++) {
const random = createGenerator(seed, index);
random();
- const emission = emitter.shape === 'mesh' ? emitter.source.sample(random) : { point: pointInEmitter(emitter, [random(), random(), random()]), normal: null };
+ const birthTime = (settings.delay ?? 0) + (rate ? index / rate : 0);
+ // A source that follows a moving sea reads the time the particle is born at; a fixed mesh ignores it.
+ const emission = emitter.shape === 'mesh' ? emitter.source.sample(random, birthTime) : { point: pointInEmitter(emitter, [random(), random(), random()]), normal: null };
const launch = directionInCone(axis, spreadRadians, random(), random());
const launchSpeed = between(speed, random());
for (let component = 0; component < 3; component++) {
@@ -137,7 +139,7 @@ export function createParticleLaunches(settings) {
}
life[index] = between(lifetime, random());
particleSize[index] = between(size, random());
- birth[index] = (settings.delay ?? 0) + (rate ? index / rate : 0);
+ birth[index] = birthTime;
// Drawn last, so adding spin never changes the launch of a particle that existed before.
const spinDirection = directionInCone([0, 1, 0], Math.PI, random(), random());
spinAxis.set(spinDirection, index * 3);
diff --git a/tests/docs-recipe-examples.test.js b/tests/docs-recipe-examples.test.js
index 6d8e5292..365ba8a3 100644
--- a/tests/docs-recipe-examples.test.js
+++ b/tests/docs-recipe-examples.test.js
@@ -68,6 +68,8 @@ const EXAMPLES = {
block => create(baseRecipe({ geometries: [sea], nodes: [seaNode, boxNode('crate', { translation: [0, 1, 0] }), boxNode('boat', { translation: [4, 1, 0] })], ...block })),
block => create(baseRecipe({ geometries: [sea], nodes: [seaNode, boxNode('hull', { translation: [0, 1, 0] })],
physics: { duration: 4, ocean: { geometry: 'sea' }, bodies: [block] } })),
+ // The whole recipe of Spray from the sea (#2152).
+ block => create(block),
block => apply(baseRecipe({ nodes: [floor, boxNode('ball', { translation: [0, 1, 4] }), boxNode('wall', { translation: [0, 1, 0], scale: [3, 2, 0.3] })] }), block),
block => create(ragdollRecipe(block.physics)),
block => create(mergedRecipe(block)),
diff --git a/tests/ocean-spray-example.test.js b/tests/ocean-spray-example.test.js
new file mode 100644
index 00000000..dd2e632d
--- /dev/null
+++ b/tests/ocean-spray-example.test.js
@@ -0,0 +1,67 @@
+import './support/load-agent-scene-modules.mjs';
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { readFile } from 'node:fs/promises';
+import { createAgentScene } from '../src/agent-scene.js';
+
+// The "Spray from the sea" example of docs/physics.md is a whole recipe that sends as written and sprays (#2152), and an emitter on a sea
+// that an oceanTime track animates takes its droplets from the crests of the moment they are born, not from the sea frozen at its authored time.
+
+const DROPLET_VERTICES = 42;
+
+async function docsSprayExample() {
+ const text = (await readFile(new URL('../docs/physics.md', import.meta.url), 'utf8')).replaceAll('\r\n', '\n');
+ const section = text.slice(text.indexOf('### Spray from the sea'));
+ return JSON.parse(/```json\n([\s\S]*?)```/.exec(section)[1]);
+}
+
+function dropletCentres(scene, time) {
+ scene.sampleMotion(time);
+ const positions = scene.parts.find(part => part.name === 'droplet').geometry.positions;
+ const centres = [];
+ for (let first = 0; first < positions.length / 3; first += DROPLET_VERTICES) {
+ const centre = [0, 0, 0];
+ for (let vertex = first; vertex < first + DROPLET_VERTICES; vertex++) {
+ for (let axis = 0; axis < 3; axis++) centre[axis] += positions[vertex * 3 + axis] / DROPLET_VERTICES;
+ }
+ centres.push(centre);
+ }
+ return centres;
+}
+
+function seaRecipe({ windSpeed = 14, choppiness = 2, time = 0, track = true } = {}) {
+ const recipe = {
+ format: 'crucible.scene', schemaVersion: 1,
+ geometries: [
+ { id: 'sea', type: 'mesh', base: { type: 'box', bevel: 0 }, edits: [{ op: 'subdivide', levels: 4 }], stack: [{ op: 'ocean', windSpeed, choppiness, size: 30, seed: 5, resolution: 5, time, spray: true }] },
+ { id: 'drop', type: 'icoSphere', subdivisions: 1 },
+ ],
+ materials: [{ id: 'water' }],
+ nodes: [{ id: 'surface', geometry: 'sea', material: 'water' }, { id: 'droplet', geometry: 'drop', material: 'water' }],
+ particles: { systems: [{ node: 'droplet', count: 100, rate: 50, speed: [0, 1], lifetime: [0.6, 1.4], size: 0.02,
+ emitter: { shape: 'mesh', mesh: 'surface', from: 'surface', group: 'spray', groupThreshold: 0.3, velocityFrom: 'spray' } }] },
+ };
+ if (track) {
+ recipe.motion = { duration: 3, tracks: [{ kind: 'geometry', id: 'sea', property: 'oceanTime', keyframes: [{ time: 0, value: 0 }, { time: 3, value: 3 }] }] };
+ }
+ return recipe;
+}
+
+test('the docs spray example builds as written and its droplets leave the water', async () => {
+ const scene = createAgentScene(await docsSprayExample());
+ const centres = dropletCentres(scene, 0.5);
+ assert.equal(centres.length, 400);
+ assert.ok(centres.filter(([, height]) => Math.abs(height) > 1e-3).length > 100, 'droplets are born and move off the origin');
+});
+
+test('the same sea with the authored time alone has no spray, and the oceanTime track gives it some', () => {
+ assert.throws(() => createAgentScene(seaRecipe({ track: false })), /emitter\.mesh[\s\S]*vertex group "spray"/);
+ const scene = createAgentScene(seaRecipe());
+ const centres = dropletCentres(scene, 2.9);
+ const born = centres.filter(centre => centre.some(component => Math.abs(component) > 1e-3));
+ assert.ok(born.length >= 100, `${born.length} of 100 droplets have a place after the sea has risen`);
+});
+
+test('a sea that never sprays says which ocean setting and track to change', () => {
+ assert.throws(() => createAgentScene(seaRecipe({ windSpeed: 0.5, choppiness: 0 })), /ocean\.time[\s\S]*oceanTime track/);
+});