3D engine that AI agents drive
Say why a native job was flattened when the flattened scene is over the triangle bound (#1041)
Nguyen Xuan An3edd0afd481d
diff --git a/scripts/native-bake-page.js b/scripts/native-bake-page.jsindex 396ebce4..476ff861 100644--- a/scripts/native-bake-page.js+++ b/scripts/native-bake-page.js@@ -70,7 +70,7 @@ export function exportNativeSceneTables({ parts, environment, camera, options, k} catch (error) {if (!(error instanceof RangeError)) throw error;flattenedBecause = error.message;- traceScene = buildTraceScene(parts, environment, triangleLimit);+ traceScene = flattenRefusedScene(buildTraceScene, parts, environment, triangleLimit, flattenedBecause);}}const instancingNote = flattenedBecause === undefined ? {} : { instancing: 'flattened', instancingReason: flattenedBecause };@@ -89,6 +89,17 @@ export function exportNativeSceneTables({ parts, environment, camera, options, k...(materialsReason === undefined ? {} : { materialsReason }), ...instancingNote };}+// The flattened scene of parts the packer refused as instances. Every copy counts against the bound once flattened, so a scene+// that fitted as instances can be over it; the error then names the packer's refusal, since the geometry was already shared.+function flattenRefusedScene(buildTraceScene, parts, environment, triangleLimit, refusal) {+ try {+ return buildTraceScene(parts, environment, triangleLimit);+ } catch (error) {+ if (!(error instanceof RangeError)) throw error;+ throw new RangeError(`The scene could not stay instanced (${refusal}) and is too large once every copy is flattened: ${error.message}`);+ }+}+function floatsFromBase64(data) {const bytes = bytesFromBase64(data);return new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / Float32Array.BYTES_PER_ELEMENT);diff --git a/tests/path-tracer-native-triangle-limit.test.js b/tests/path-tracer-native-triangle-limit.test.jsindex b17105d6..ddc00927 100644--- a/tests/path-tracer-native-triangle-limit.test.js+++ b/tests/path-tracer-native-triangle-limit.test.js@@ -103,6 +103,18 @@ test('a native render job with the cycles kernel exports an instanced scene abovassert.equal(exported.triangleCount, MAX_TRACE_TRIANGLES + 1);});+test('a refused instanced job that is over the bound once flattened says why it was flattened', () => {+ const parts = copiesOf(triangleStack(8), 2);+ const smallBound = (sceneParts, environment, options) => buildTraceScene(sceneParts, environment, { ...options, maximumTriangles: 10 });+ const refuseInstances = () => {+ throw new RangeError('copies of this mesh emit different triangles');+ };+ assert.throws(+ () => exportNativeSceneTables({ parts, environment: ENVIRONMENT, camera, options: packOptions, kernel: 'cycles', instancing: true,+ modules: { ...modules, buildTraceScene: smallBound, buildJobNativeInput: refuseInstances } }),+ { name: 'RangeError', message: /could not stay instanced \(copies of this mesh emit different triangles\).*at most 10 triangles/ });+});+test('a native render job with the legacy kernel keeps the 400,000 bound', () => {const parts = copiesOf(triangleStack(MAX_TRACE_TRIANGLES + 1), 1);assert.throws(() => exportNativeSceneTables({ parts, environment: ENVIRONMENT, camera, options: packOptions, kernel: 'legacy', instancing: false, modules }),