3D engine that AI agents drive
Keep exact-flush layering when reversedDepth is false (issue #593)
Nguyen Xuan Anb83e873ca82d
diff --git a/changes/593-false-pairs.size.md b/changes/593-false-pairs.size.mdnew file mode 100644index 00000000..e80bd0bf--- /dev/null+++ b/changes/593-false-pairs.size.md@@ -0,0 +1,3 @@+- goal:lit-box: 10 bytes for passing the exact-flush gap to resolveCoplanar so reversedDepth false keeps layering exact-flush pairs (#593)+- goal:gltf-box: 16 bytes, same renderer line (#593)+- goal:agent-scene: 13 bytes, same renderer line (#593)diff --git a/src/coplanar-overlap.js b/src/coplanar-overlap.jsindex 68388a21..c2b79fde 100644--- a/src/coplanar-overlap.js+++ b/src/coplanar-overlap.js@@ -502,9 +502,12 @@ export function installCoplanarDiagnostics(renderer, onOverlaps = null) {/*** Puts the smaller part of each coplanar pair on the next depth layer (a polygon offset at draw time, geometry never moves),* for the parts of one scene. The renderer calls it once when it is built; a part that sets `decal` or `depthLayer` keeps its own.+ * Pairs on one plane to within `minimumGap` (default EXACT_FLUSH_DISTANCE) are left to the depth buffer; the renderer passes+ * `{ minimumGap: 0 }` when `reversedDepth` is false. With 'auto', a scene whose far / near ratio stays low never switches+ * reversed depth on, and there exact-flush pairs rely on the plain depth buffer.*/-export function resolveFlushParts(parts) {- const layers = coplanarLayers(findCoplanarOverlaps(parts).overlaps, { minimumGap: EXACT_FLUSH_DISTANCE });+export function resolveFlushParts(parts, { minimumGap = EXACT_FLUSH_DISTANCE } = {}) {+ const layers = coplanarLayers(findCoplanarOverlaps(parts).overlaps, { minimumGap });setFlushDepthLayers(layers);return layers.size;}diff --git a/src/renderer.js b/src/renderer.jsindex 4ecbed73..9ce1514a 100644--- a/src/renderer.js+++ b/src/renderer.js@@ -599,7 +599,8 @@ export class Renderer67 {this.assemblyAmount = 0;// `resolveCoplanar` is resolveFlushParts from the coplanar-overlap addon, passed in so the search stays out of the core bundle.if (resolveCoplanar && typeof resolveCoplanar !== 'function') throw new TypeError('resolveCoplanar is resolveFlushParts from 67js/addons/coplanar-overlap.');- if (resolveCoplanar && !benchmark) resolveCoplanar(parts);+ // Exact-flush pairs are left to a float depth buffer, so they are layered only when reversed depth is switched off.+ if (resolveCoplanar && !benchmark) resolveCoplanar(parts, reversedDepth === false && { minimumGap: 0 });const groups = groupParts(this.groundPart ? [...parts, this.groundPart] : parts, batching);const textureLimit = this.context.getParameter(this.context.MAX_TEXTURE_SIZE);this.hasSkins = groups.some(group => group[0].skin || group[0].crowd);diff --git a/tests/coplanar-overlap.test.js b/tests/coplanar-overlap.test.jsindex 48d8b2c7..10b83209 100644--- a/tests/coplanar-overlap.test.js+++ b/tests/coplanar-overlap.test.js@@ -215,6 +215,8 @@ test('resolveFlushParts leaves exactly flush pairs to the depth buffer; coplanarconst marking = gridPart('markingExact', 2, 2, 0);assert.equal(resolveFlushParts([road, marking]), 0);assert.equal(coplanarLayers(findCoplanarOverlaps([road, marking]).overlaps).get(marking), 1);+ assert.equal(resolveFlushParts([road, marking], { minimumGap: 0 }), 1, 'the renderer passes a gap of 0 when reversedDepth is false');+ assert.equal(depthLayerOf(marking), 1);});test('layers settle in chains and never pile up on the top layer', () => {