Skip to content

3D engine that AI agents drive

Rank the parts a pose samples against the floor so a blast's dust and rubble do not z-fight (#2054)

Nguyen Xuan Anffb83afa6ff5
diff --git a/changes/2054.md b/changes/2054.md
new file mode 100644
index 00000000..b727c991
--- /dev/null
+++ b/changes/2054.md
@@ -0,0 +1 @@
+- A pose that samples particles, cloth or an ocean ranks its new parts against the others, so a blast's dust and rubble on a floor draw without z-fighting or coplanar-overlap warnings.
diff --git a/src/agent-scene.js b/src/agent-scene.js
index 70258db9..038fb925 100644
--- a/src/agent-scene.js
+++ b/src/agent-scene.js
@@ -1461,9 +1461,9 @@ function publishPose(stagedState, pose) {
stagedState.renderCamera = pose.camera;
stagedState.movedLook = pose.movedLook;
stagedState.motionTime = pose.time;
- const nextParts = partsWithCloth(stagedState.restParts, pose.clothGeometries, stagedState.parts);
- const partsChanged = nextParts !== stagedState.parts;
- stagedState.parts = nextParts;
+ const sampledParts = partsWithCloth(stagedState.restParts, pose.clothGeometries, stagedState.parts);
+ const partsChanged = sampledParts !== stagedState.parts;
+ stagedState.parts = partsChanged && stagedState.rankFlushParts ? stagedState.rankFlushParts(sampledParts) : sampledParts;
return partsChanged;
}
@@ -1798,6 +1798,8 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {
// Part identity decides what the next stage reuses, so it compares the parts as built, before any bake.
sourceRestParts,
parts: restParts, restParts,
+ // Parts a pose replaces (cloth, particles, ocean) are new objects with no flush rank, so the pose ranks them again.
+ rankFlushParts: parts => stageCoplanarOffsets(recipe, parts),
bakeSkipped: skippedBake,
bakeReport: lightBakeResult ? agentSceneModule('bake').withLocalVolumeReport({ ...lightBakeResult.report, reused: lightBakeResult.reused }, recipe.environment.localVolumes) : null,
reflectionReport: reflected ? reflected.report : null,
diff --git a/tests/agent-explosion.test.js b/tests/agent-explosion.test.js
index c3371a66..152fb30e 100644
--- a/tests/agent-explosion.test.js
+++ b/tests/agent-explosion.test.js
@@ -8,6 +8,7 @@ import { EXPLOSION_EMPTY_GRID, EXPLOSION_EMPTY_VELOCITY_GRID, explosionGridBytes
import { decodeVolumeGrid, hasGridVelocity } from '../src/volume-grid.js';
import { readVolumeGridFiles } from '../src/mcp-volume-grids.js';
import { agentSceneModulesNeeded, needsPhysics } from '../src/agent-scene-modules.js';
+import { findCoplanarOverlaps } from '../src/coplanar-overlap.js';
await loadPhysicsEngine();
@@ -296,3 +297,15 @@ test('bad sparks and motionBlur values name the field and a valid value', () =>
];
for (const [operation, pattern] of cases) assert.throws(() => applyBlast(operation), pattern, JSON.stringify(operation));
});
+
+test('the blast dust and rubble sampled at a later time are ranked against a box floor, so no coplanar pair is left (#2054)', () => {
+ const recipe = setRecipe();
+ delete recipe.physics;
+ recipe.nodes = [{ id: 'floor', geometry: 'slab', material: 'stone', translation: [0, -0.05, 0], scale: [6, 0.1, 6] }];
+ const { scene } = applyBlast(blast({ start: 0.5, seed: 7, fuel: 'oily', shake: 0.4 }), recipe);
+ scene.sampleMotion(1.2);
+ const blastParts = scene.parts.filter(part => part.name.startsWith('blast-'));
+ assert.ok(blastParts.some(part => part.name === 'blast-dust'), 'the sampled dust part exists');
+ const pairs = findCoplanarOverlaps(scene.parts).overlaps.map(overlap => [overlap.first?.name ?? overlap.larger?.name, overlap.second?.name ?? overlap.smaller?.name]);
+ assert.deepEqual(pairs, []);
+});