3D engine that AI agents drive
JavaScript 3d3d-engineagentic-aiai-agentsblenderclaude-codegame-enginegaussian-splattinggltfjavascriptmcpmcp-servermodel-context-protocolpath-tracerpath-tracingpbrrenderingthreejs-alternativewebgl2webgpu
Turn denseLods on by default for scene files (#1163)
Nguyen Xuan Anfa1855d47127
diff --git a/changes/1163-dense-lods-default.md b/changes/1163-dense-lods-default.mdnew file mode 100644index 00000000..ebdf86f3--- /dev/null+++ b/changes/1163-dense-lods-default.md@@ -0,0 +1 @@+- A scene file now gives a dense scan levels of detail by default (`renderer.denseLods`, about 2.7x faster GPU frames on the Monster scan, a slight change in far detail); set `"denseLods": false` to keep every triangle (#1163).diff --git a/docs/culling-lod.md b/docs/culling-lod.mdindex 80ba9d1a..825c810e 100644--- a/docs/culling-lod.md+++ b/docs/culling-lod.md@@ -60,4 +60,4 @@ A scan with about one triangle per pixel or more is shaded once per sample at ne`addLodsToDenseParts(parts, { pixels })` from `src/dense-lods.js` gives levels to the parts of a scene that has more than one triangle per pixel (`pixels` is the canvas width times its height times the pixel ratio squared). A part gets levels when it has at least `minimumTriangles` (default 20000) triangles and can take them; parts with the same geometry share one set. It returns `parts` itself for a scene under the density. It is not applied by itself, and it takes seconds on a million triangles, so call it once while loading. On the Monster scene (1.6 million triangles, 1280 by 720, 4 samples) called with the canvas size, the frame went from 5.8 to 1.9 ms, and Lone Monk (5.6 million) from 15.4 to 9.5 ms (measured before the error metric was changed to a distance); the picture changes slightly (root mean square 2.0 of 255), because far parts draw from coarser levels (#1163).-A scene file (`scene.json`, rendered by `scripts/render-media.mjs --scene file`) asks for the same levels with `"renderer": { "denseLods": true }`. The option is off by default, so a scene file without it draws exactly as before; with it, `partsForRendererOptions` in `src/dense-lods.js` calls `addLodsToDenseParts` at the canvas size and pixel ratio before the renderer is built (#1163).+A scene file (`scene.json`, rendered by `scripts/render-media.mjs --scene file`) gets the same levels by default; `"renderer": { "denseLods": false }` keeps every triangle of a dense scan. With the option on, `partsForRendererOptions` in `src/dense-lods.js` calls `addLodsToDenseParts` at the canvas size and pixel ratio before the renderer is built (#1163).diff --git a/src/dense-lods.js b/src/dense-lods.jsindex 94ca938c..992d18ea 100644--- a/src/dense-lods.js+++ b/src/dense-lods.js@@ -36,12 +36,12 @@ export function addLodsToDenseParts(parts, { pixels, minimumTrianglesPerPixel =}/**- * The parts a scene file's renderer options ask for: `denseLods: true` runs addLodsToDenseParts at the canvas's size and- * pixel ratio (the default ratio of CrucibleRenderer is 1.5); absent or `false` returns `parts` itself, so a scene file- * without the option draws exactly as before.+ * The parts a scene file's renderer options ask for: `denseLods` (on by default) runs addLodsToDenseParts at the canvas's+ * size and pixel ratio (the default ratio of CrucibleRenderer is 1.5); `false` returns `parts` itself, so a scene file+ * can keep every triangle of a dense scan.*/export function partsForRendererOptions(parts, canvas, rendererOptions = {}) {- const { denseLods = false, pixelRatio = 1.5 } = rendererOptions;+ const { denseLods = true, pixelRatio = 1.5 } = rendererOptions;if (typeof denseLods !== 'boolean') throw new TypeError('renderer.denseLods must be true or false.');if (!denseLods) return parts;const pixels = Math.max(1, canvas.clientWidth) * Math.max(1, canvas.clientHeight) * pixelRatio * pixelRatio;diff --git a/tests/dense-lods-option.test.js b/tests/dense-lods-option.test.jsindex 1d7e840c..aea1fa69 100644--- a/tests/dense-lods-option.test.js+++ b/tests/dense-lods-option.test.js@@ -1,4 +1,4 @@-// A scene file's renderer option `denseLods` gives a dense scan levels of detail (#1163); without it the parts are untouched.+// A scene file's renderer option `denseLods` gives a dense scan levels of detail, on by default (#1163); `false` leaves the parts untouched.import test from 'node:test';import assert from 'node:assert/strict';import { sphere } from '../src/geometry.js';@@ -18,11 +18,18 @@ test('denseLods true gives levels to a scan that has more than one triangle perassert.ok(result[0].lods.length > 1, 'the part carries levels');});-test('without denseLods, or with it false, the same parts come back', () => {+test('denseLods is on by default: a dense scan gets levels without the option', () => {+ for (const options of [{ pixelRatio: 1 }, {}, undefined]) {+ const parts = [scanPart()];+ const result = partsForRendererOptions(parts, SMALL_CANVAS, options);+ assert.notEqual(result, parts);+ assert.ok(result[0].lods.length > 1, 'the part carries levels');+ }+});++test('denseLods false returns the same parts', () => {const parts = [scanPart()];- assert.equal(partsForRendererOptions(parts, SMALL_CANVAS, {}), parts);assert.equal(partsForRendererOptions(parts, SMALL_CANVAS, { denseLods: false }), parts);- assert.equal(partsForRendererOptions(parts, SMALL_CANVAS), parts);});test('the pixel ratio counts: the same scan is sparse on a big canvas', () => {