3D engine that AI agents drive
Skip repeated material checks in renderer.updateParts (part of #299)
Nguyen Xuan Ana6287c5af757
diff --git a/changes/299.md b/changes/299.mdnew file mode 100644index 00000000..7a5ab42d--- /dev/null+++ b/changes/299.md@@ -0,0 +1 @@+- Speed up `renderer.updateParts` for matrix and colour updates (closes #299). A part whose material still holds the values that passed the checks skips them, and the morph pass runs only when a morph or skin is in the update. 25,000 matrix-only parts take about 5 to 8 ms of JavaScript, from 33 to 55 ms (`npm run benchmark:update-parts`).diff --git a/package.json b/package.jsonindex 0d63acfd..342bbed1 100644--- a/package.json+++ b/package.json@@ -133,6 +133,7 @@"smoke:modeling": "node scripts/smoke-modeling.mjs","smoke:material-maps": "node scripts/smoke-material-maps.mjs","benchmark:mesh-query": "node scripts/benchmark-mesh-query.mjs",+ "benchmark:update-parts": "node scripts/benchmark-update-parts.mjs","smoke:imported-topology": "node scripts/smoke-imported-topology.mjs","smoke:agent-character": "node scripts/smoke-agent-character.mjs","smoke:agent-review": "node scripts/smoke-agent-review.mjs",diff --git a/scripts/benchmark-update-parts.mjs b/scripts/benchmark-update-parts.mjsnew file mode 100644index 00000000..dcb3c8ee--- /dev/null+++ b/scripts/benchmark-update-parts.mjs@@ -0,0 +1,60 @@+// Times renderer.updateParts for matrix-only and colour-only updates: node scripts/benchmark-update-parts.mjs [partCount] [rounds]+// The renderer is built without a GL context and the buffer upload is a no-op, so the number is JavaScript time only.+import { constants, setPriority } from 'node:os';+import { mat3, mat4 } from 'gl-matrix';+import { box } from '../src/geometry.js';+import { Renderer67, groupParts } from '../src/renderer.js';+import { materialLayerState } from '../src/material-layers.js';++setPriority(0, constants.priority.PRIORITY_BELOW_NORMAL);+const partCount = Number(process.argv[2] ?? 25000);+const rounds = Number(process.argv[3] ?? 30);+const INSTANCE_STRIDE = 41;++function createParts(count) {+ const geometry = box();+ return Array.from({ length: count }, (_, index) => ({+ name: `part-${index}`,+ geometry,+ matrix: mat4.fromTranslation(mat4.create(), [index % 100, 0, Math.floor(index / 100)]),+ material: { color: [0.4, 0.5, 0.6], metallic: 0, roughness: 0.7, emission: 0 },+ }));+}++function createRenderer(parts) {+ const renderer = Object.create(Renderer67.prototype);+ renderer.context = { ARRAY_BUFFER: 34962, bindBuffer() {}, bufferSubData() {} };+ renderer.updateSkins = new Set();+ renderer.updateBatches = new Set();+ renderer.partLocations = new Map();+ renderer.batches = groupParts(parts).map(group => {+ const first = group[0];+ const batch = {+ instanceBuffer: {}, instanceData: new Float32Array(group.length * INSTANCE_STRIDE), castShadow: true,+ alphaMode: 'opaque', alphaCutoff: 0, opacity: 1, doubleSided: false,+ };+ group.forEach((part, index) => renderer.partLocations.set(part, {+ batch, index, geometry: first.geometry, skin: null, map: null, layerState: materialLayerState({}),+ mapState: [null, null, null, null, null, 1, 1, 1, 0, 0.05, 0.085, 0.02], normalMatrix: mat3.create(),+ }));+ return batch;+ });+ return renderer;+}++function measure(label, parts, renderer, change) {+ const samples = [];+ for (let round = 0; round < rounds + 5; round++) {+ change(round);+ const started = performance.now();+ renderer.updateParts(parts, { shadows: false });+ samples.push(performance.now() - started);+ }+ const kept = samples.slice(5).sort((a, b) => a - b);+ console.log(`${label}: ${partCount} parts, min ${kept[0].toFixed(2)} ms, median ${kept[kept.length >> 1].toFixed(2)} ms, max ${kept.at(-1).toFixed(2)} ms (${(kept[kept.length >> 1] * 1000 / partCount).toFixed(2)} us per part)`);+}++const parts = createParts(partCount);+const renderer = createRenderer(parts);+measure('matrix only', parts, renderer, round => parts.forEach(part => { part.matrix[12] += 0.01 * (round + 1); }));+measure('matrix and colour', parts, renderer, round => parts.forEach(part => { part.matrix[12] += 0.01; part.material.color[0] = (round % 10) / 10; }));diff --git a/src/material-snapshot.js b/src/material-snapshot.jsnew file mode 100644index 00000000..3740d70a--- /dev/null+++ b/src/material-snapshot.js@@ -0,0 +1,92 @@+// Lets renderer.updateParts skip the material checks for a part whose material still holds the values that passed them.+// The fields are written out one by one: a loop over field names reads each one through a megamorphic keyed load, which costs+// more than the checks it saves. tests/material-snapshot.test.js keeps the lists in step with the renderer's material fields.++/** Material fields that the renderer compares with the batch a part was committed to. */+export const SNAPSHOT_VALUE_FIELDS = Object.freeze(['map', 'normalMap', 'metallicRoughnessMap', 'occlusionMap', 'emissiveMap', 'tag', 'alphaMode', 'alphaCutoff', 'opacity', 'doubleSided', 'occlusionStrength', 'moss', 'boxMapScale', 'boxMapAxis', 'lightMapScale', 'layerMaps', 'lightMask', 'clearcoat', 'clearcoatRoughness', 'transmission', 'thickness', 'ior', 'sheenRoughness', 'specular', 'anisotropy', 'anisotropyRotation', 'iridescence', 'iridescenceIor', 'iridescenceThickness', 'attenuationDistance']);++/** Fields holding an array or descriptor, which can change in place. A material that sets one is never snapshotted. */+export const SNAPSHOT_REFERENCE_FIELDS = Object.freeze(['normalScale', 'mossColor', 'lightMap', 'attenuationColor', 'sheenColor', 'specularColor']);++function hasNoReferenceFields(material) {+ return material.normalScale === undefined &&+ material.mossColor === undefined &&+ material.lightMap === undefined &&+ material.attenuationColor === undefined &&+ material.sheenColor === undefined &&+ material.specularColor === undefined;+}++export class MaterialSnapshot {+ /** Null when the material sets an array-valued field. */+ static of(material) {+ return hasNoReferenceFields(material) ? new MaterialSnapshot(material) : null;+ }++ constructor(material) {+ this.map = material.map;+ this.normalMap = material.normalMap;+ this.metallicRoughnessMap = material.metallicRoughnessMap;+ this.occlusionMap = material.occlusionMap;+ this.emissiveMap = material.emissiveMap;+ this.tag = material.tag;+ this.alphaMode = material.alphaMode;+ this.alphaCutoff = material.alphaCutoff;+ this.opacity = material.opacity;+ this.doubleSided = material.doubleSided;+ this.occlusionStrength = material.occlusionStrength;+ this.moss = material.moss;+ this.boxMapScale = material.boxMapScale;+ this.boxMapAxis = material.boxMapAxis;+ this.lightMapScale = material.lightMapScale;+ this.layerMaps = material.layerMaps;+ this.lightMask = material.lightMask;+ this.clearcoat = material.clearcoat;+ this.clearcoatRoughness = material.clearcoatRoughness;+ this.transmission = material.transmission;+ this.thickness = material.thickness;+ this.ior = material.ior;+ this.sheenRoughness = material.sheenRoughness;+ this.specular = material.specular;+ this.anisotropy = material.anisotropy;+ this.anisotropyRotation = material.anisotropyRotation;+ this.iridescence = material.iridescence;+ this.iridescenceIor = material.iridescenceIor;+ this.iridescenceThickness = material.iridescenceThickness;+ this.attenuationDistance = material.attenuationDistance;+ }++ matches(material) {+ return hasNoReferenceFields(material) &&+ this.map === material.map &&+ this.normalMap === material.normalMap &&+ this.metallicRoughnessMap === material.metallicRoughnessMap &&+ this.occlusionMap === material.occlusionMap &&+ this.emissiveMap === material.emissiveMap &&+ this.tag === material.tag &&+ this.alphaMode === material.alphaMode &&+ this.alphaCutoff === material.alphaCutoff &&+ this.opacity === material.opacity &&+ this.doubleSided === material.doubleSided &&+ this.occlusionStrength === material.occlusionStrength &&+ this.moss === material.moss &&+ this.boxMapScale === material.boxMapScale &&+ this.boxMapAxis === material.boxMapAxis &&+ this.lightMapScale === material.lightMapScale &&+ this.layerMaps === material.layerMaps &&+ this.lightMask === material.lightMask &&+ this.clearcoat === material.clearcoat &&+ this.clearcoatRoughness === material.clearcoatRoughness &&+ this.transmission === material.transmission &&+ this.thickness === material.thickness &&+ this.ior === material.ior &&+ this.sheenRoughness === material.sheenRoughness &&+ this.specular === material.specular &&+ this.anisotropy === material.anisotropy &&+ this.anisotropyRotation === material.anisotropyRotation &&+ this.iridescence === material.iridescence &&+ this.iridescenceIor === material.iridescenceIor &&+ this.iridescenceThickness === material.iridescenceThickness &&+ this.attenuationDistance === material.attenuationDistance;+ }+}diff --git a/src/renderer.js b/src/renderer.jsindex dfc432ce..8ec77ca2 100644--- a/src/renderer.js+++ b/src/renderer.js@@ -14,6 +14,7 @@ import { assertEnvironmentMap, createEnvironmentResources, environmentBackgroundimport { validateSkinGeometry, validateSkinPose, skinTextureLayout, packSkinInfluences } from './skinning.js';import { validateSplatMaterial, splatBatchState, splatTextureBytes, resolveSplatSize, packSplatParameters, buildSplatPixels } from './splat.js';import { materialLayerState, materialLayerValue } from './material-layers.js';+import { MaterialSnapshot } from './material-snapshot.js';import { fittedFogDensity } from './fog-fit.js';import { InstanceSelection, extractFrustumPlanes, geometryBoundingSphere, selectInstances } from './render-culling.js';import { resolveShadowLight, shadowBiasPerSlope } from './shadow-light.js';@@ -212,12 +213,21 @@ function hasMaterialMap(material) {return MATERIAL_MAPS.some(field => material[field]);}+// Math.fround turns a double of 2^128 - 2^103 or more into Infinity, so that is the first value that is not a finite float.+const FLOAT_OVERFLOW = 2 ** 128 - 2 ** 103;+function finiteFloat(value) {- return Number.isFinite(value) && Number.isFinite(Math.fround(value));+ return typeof value === 'number' && value > -FLOAT_OVERFLOW && value < FLOAT_OVERFLOW;}function finiteVector(value, size) {if (value?.length !== size) return false;+ if (value instanceof Float32Array) {+ // Every float is already in range, so it is finite exactly when 0 * value is 0 and not NaN. This runs without a branch per element.+ let zeroSum = 0;+ for (let index = 0; index < size; index++) zeroSum += value[index] * 0;+ return zeroSum === 0;+ }for (let index = 0; index < size; index++) if (!finiteFloat(value[index])) return false;return true;}@@ -225,26 +235,37 @@ function finiteVector(value, size) {function validateTransform(part, normalMatrix = mat3.create()) {if (!finiteVector(part.matrix, 16)) throw new Error(`Invalid transform: ${part.name}`);if (!mat3.normalFromMat4(normalMatrix, part.matrix) || !finiteVector(normalMatrix, 9)) throw new Error(`Singular transform: ${part.name}`);- if (!finiteVector(part.material.color, 3) || !finiteVector(part.material.emissiveColor ?? part.material.color, 3) ||- !finiteVector(part.assembly?.offset ?? ZERO_VECTOR, 3) || !finiteVector(part.assembly?.detailOffset ?? ZERO_VECTOR, 3)) {+ // An absent emissive colour or assembly offset packs as the base colour or zero, which need no second check.+ const material = part.material;+ const assembly = part.assembly;+ if (!finiteVector(material.color, 3) || (material.emissiveColor !== undefined && !finiteVector(material.emissiveColor, 3)) ||+ (assembly && (!finiteVector(assembly.offset ?? ZERO_VECTOR, 3) || !finiteVector(assembly.detailOffset ?? ZERO_VECTOR, 3)))) {throw new Error(`Invalid instance vector: ${part.name}`);}if (!finiteFloat(part.material.metallic) || !finiteFloat(part.material.roughness) || !finiteFloat(part.material.emission ?? 0)) throw new Error(`Invalid material: ${part.name}`);return normalMatrix;}+// TypedArray.set costs more per call than three stores, and a loop shared by every vector length reads its source through a slow polymorphic path.+function copyVector3(target, offset, source) {+ target[offset] = source[0];+ target[offset + 1] = source[1];+ target[offset + 2] = source[2];+}+function packInstance(data, index, part, normalMatrix) {const offset = index * INSTANCE_STRIDE;+ const material = part.material;data.set(part.matrix, offset);data.set(normalMatrix, offset + 16);- data.set(part.material.color, offset + 25);- data[offset + 28] = part.material.metallic;- data[offset + 29] = part.material.roughness;- data[offset + 30] = part.material.emission ?? 0;- data[offset + 31] = MATERIAL_TAGS[part.material.tag] ?? 0;- data.set(part.assembly?.offset ?? ZERO_VECTOR, offset + 32);- data.set(part.assembly?.detailOffset ?? ZERO_VECTOR, offset + 35);- data.set(part.material.emissiveColor ?? part.material.color, offset + 38);+ copyVector3(data, offset + 25, material.color);+ data[offset + 28] = material.metallic;+ data[offset + 29] = material.roughness;+ data[offset + 30] = material.emission ?? 0;+ data[offset + 31] = MATERIAL_TAGS[material.tag] ?? 0;+ copyVector3(data, offset + 32, part.assembly?.offset ?? ZERO_VECTOR);+ copyVector3(data, offset + 35, part.assembly?.detailOffset ?? ZERO_VECTOR);+ copyVector3(data, offset + 38, material.emissiveColor ?? material.color);}// The objectId mode of RENDER_PASS_MODES in render-passes.js.@@ -1171,18 +1192,26 @@ export class Renderer67 {this.updateMorphs ??= new Set();this.updateMorphs.clear();this.updateBatches.clear();+ const locations = this.updateLocations ??= [];+ locations.length = parts.length;// Preflight every part before touching packed data or submitting GPU writes.- for (const part of parts) {- this.updatePartIdentities.add(part);+ for (let partIndex = 0; partIndex < parts.length; partIndex++) {+ const part = parts[partIndex];const location = this.partLocations.get(part);if (!location) throw new Error(`Unknown part identity: ${part.name}`);+ locations[partIndex] = location;+ if (part.skin || part.morph) this.updatePartIdentities.add(part);if (part.castShadow !== undefined && typeof part.castShadow !== 'boolean') throw new TypeError('castShadow must be a boolean');if (castsShadow(part) !== location.batch.castShadow) throw new Error(`Shadow casting changes require a new renderer: ${part.name}`);- const alphaState = materialAlphaState(part.material);- const batchAlphaState = [location.batch.alphaMode, location.batch.alphaCutoff, location.batch.opacity, location.batch.doubleSided];- if (alphaState.some((value, index) => value !== batchAlphaState[index])) throw new Error(`Alpha mode, cutoff, opacity and double-sided changes require a new renderer: ${part.name}`);+ // A material whose fields still equal the ones that passed the full checks below needs none of them again.+ const materialUnchanged = location.materialSnapshot?.matches(part.material) === true;+ if (!materialUnchanged) {+ const alphaState = materialAlphaState(part.material);+ const batchAlphaState = [location.batch.alphaMode, location.batch.alphaCutoff, location.batch.opacity, location.batch.doubleSided];+ if (alphaState.some((value, index) => value !== batchAlphaState[index])) throw new Error(`Alpha mode, cutoff, opacity and double-sided changes require a new renderer: ${part.name}`);+ }if (part.geometry !== location.geometry) throw new Error(`Geometry changes require a new renderer: ${part.name}`);- if (renderPass(part.material) !== batchPass(location.batch)) throw new Error(`Moving a part into or out of the liquid or foam pass requires replaceParts: ${part.name}`);+ if (!materialUnchanged && renderPass(part.material) !== batchPass(location.batch)) throw new Error(`Moving a part into or out of the liquid or foam pass requires replaceParts: ${part.name}`);if ((part.skin ?? null) !== location.skin || part.skin?.jointMatrices !== location.jointMatrices || part.geometry.skinIndices !== location.skinIndices || part.geometry.skinWeights !== location.skinWeights) throw new Error(`Skin identity changes require a new renderer: ${part.name}`);if (part.skin) {if (PROCEDURAL_MATERIAL_TAGS.has(part.material.tag)) throw new Error('Skinned parts require a standard material tag.');@@ -1195,6 +1224,10 @@ export class Renderer67 {validateMorphTransform(part.morph, location.batch.morphTexture.info, part.matrix, part.skin);this.updateMorphs.add(part.morph);}+ if (materialUnchanged) {+ validateTransform(part, location.normalMatrix);+ continue;+ }if ((part.material.map ?? null) !== location.map) throw new Error(`Texture map changes require a new renderer: ${part.name}`);validateMaterialMaps(part.material);const normalScale = part.material.normalScale ?? DEFAULT_NORMAL_SCALE;@@ -1206,6 +1239,7 @@ export class Renderer67 {if (lightMapDescriptor !== (mapState[14] ?? null) || lightMapScale !== (mapState[15] ?? 0) || (part.material.layerMaps ?? null) !== (mapState[18] ?? null)) throw new Error(`Light map and layer texture changes require a new renderer: ${part.name}`);if (normalScale[0] !== mapState[5] || normalScale[1] !== mapState[6] || (part.material.occlusionStrength ?? 1) !== mapState[7] || mossState(part.material).some((value, index) => value !== mapState[8 + index]) || materialLayerState(part.material).some((value, index) => value !== location.layerState[index])) throw new Error(`Material map or scale changes require a new renderer: ${part.name}`);validateTransform(part, location.normalMatrix);+ location.materialSnapshot = MaterialSnapshot.of(part.material);}// A palette upload also changes consumers absent from the submitted part list.if (this.updateSkins.size) {@@ -1216,15 +1250,19 @@ export class Renderer67 {}}// Shared weights also affect batches absent from the submitted part list.- for (const [part, location] of this.partLocations) {- if (!location.morph || this.updatePartIdentities.has(part)) continue;- if (!this.updateMorphs.has(location.morph) && !this.updateSkins.has(location.batch.skinTexture)) continue;- const committedMatrix = location.committedMatrix ?? location.batch.instanceData.subarray(location.index * INSTANCE_STRIDE, location.index * INSTANCE_STRIDE + 16);- validateMorphTransform(location.morph, location.batch.morphTexture.info, committedMatrix, location.skin);+ // Nothing is shared when the update carries no morph and no skin.+ if (this.updateMorphs.size || this.updateSkins.size) {+ for (const [part, location] of this.partLocations) {+ if (!location.morph || this.updatePartIdentities.has(part)) continue;+ if (!this.updateMorphs.has(location.morph) && !this.updateSkins.has(location.batch.skinTexture)) continue;+ const committedMatrix = location.committedMatrix ?? location.batch.instanceData.subarray(location.index * INSTANCE_STRIDE, location.index * INSTANCE_STRIDE + 16);+ validateMorphTransform(location.morph, location.batch.morphTexture.info, committedMatrix, location.skin);+ }}this.updateBatches.clear();- for (const part of parts) {- const location = this.partLocations.get(part);+ for (let partIndex = 0; partIndex < parts.length; partIndex++) {+ const part = parts[partIndex];+ const location = locations[partIndex];// A tag can change between frames without a new batch, so its shader code may not be compiled yet.if (TAG_SHADER_FEATURES.has(part.material.tag) && !this.shaderFeatures?.has(part.material.tag)) this.requireShaderFeatures([part]);packInstance(location.batch.instanceData, location.index, part, location.normalMatrix);diff --git a/tests/update-parts-fast-path.test.js b/tests/update-parts-fast-path.test.jsnew file mode 100644index 00000000..af7e25e7--- /dev/null+++ b/tests/update-parts-fast-path.test.js@@ -0,0 +1,107 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import { mat3, mat4 } from 'gl-matrix';+import { Renderer67 } from '../src/renderer.js';+import { MATERIAL_LAYER_FIELDS, materialLayerState } from '../src/material-layers.js';+import { SNAPSHOT_REFERENCE_FIELDS, SNAPSHOT_VALUE_FIELDS, MaterialSnapshot } from '../src/material-snapshot.js';++const GEOMETRY = {};++function createPart(name, material = {}) {+ return { name, geometry: GEOMETRY, matrix: mat4.create(), material: { color: [0.1, 0.2, 0.3], metallic: 0.5, roughness: 0.3, emission: 0, ...material } };+}++function createRenderer(parts) {+ const renderer = Object.create(Renderer67.prototype);+ const batch = { instanceBuffer: {}, instanceData: new Float32Array(parts.length * 41), castShadow: true, alphaMode: 'opaque', alphaCutoff: 0, opacity: 1, doubleSided: false, pass: 'opaque' };+ renderer.context = { ARRAY_BUFFER: 34962, bindBuffer() {}, bufferSubData() {} };+ renderer.partLocations = new Map(parts.map((part, index) => [part, {+ batch, index, geometry: GEOMETRY, map: null, normalMatrix: mat3.create(), layerState: materialLayerState({}), skin: null,+ mapState: [null, null, null, null, null, 1, 1, 1, 0, 0.05, 0.085, 0.02],+ }]));+ renderer.updateBatches = new Set();+ renderer.updateSkins = new Set();+ renderer.shadowsDirty = false;+ return { renderer, batch };+}++test('the snapshot lists cover every material map and layer field the batch compares', () => {+ const covered = new Set([...SNAPSHOT_VALUE_FIELDS, ...SNAPSHOT_REFERENCE_FIELDS]);+ for (const field of ['map', 'normalMap', 'metallicRoughnessMap', 'occlusionMap', 'emissiveMap', 'alphaMode', 'alphaCutoff', 'opacity', 'doubleSided', 'tag', 'lightMask', ...MATERIAL_LAYER_FIELDS]) {+ assert.ok(covered.has(field), `${field} is missing from the material snapshot`);+ }+});++test('a snapshot matches only a material whose compared fields are unchanged', () => {+ const material = { color: [1, 1, 1], metallic: 0, roughness: 1 };+ const snapshot = MaterialSnapshot.of(material);+ material.color = [0, 0, 0];+ material.roughness = 0.2;+ assert.equal(snapshot.matches(material), true);+ for (const field of SNAPSHOT_VALUE_FIELDS) {+ const changed = { ...material, [field]: {} };+ assert.equal(snapshot.matches(changed), false, `${field} change went unnoticed`);+ }+ for (const field of SNAPSHOT_REFERENCE_FIELDS) {+ assert.equal(MaterialSnapshot.of({ ...material, [field]: [1, 1] }), null, `${field} must not be snapshotted`);+ }+});++test('matrix, colour, emission and roughness changes update through the fast path', () => {+ const parts = [createPart('first'), createPart('second')];+ const { renderer, batch } = createRenderer(parts);+ assert.equal(renderer.updateParts(parts), 2);+ parts[1].matrix[12] = 5;+ parts[1].material.color = [0.9, 0.8, 0.7];+ parts[1].material.roughness = 0.6;+ parts[1].material.emission = 2;+ assert.equal(renderer.updateParts(parts), 2);+ assert.equal(batch.instanceData[41 + 12], 5);+ assert.deepEqual(Array.from(batch.instanceData.subarray(41 + 25, 41 + 28)).map(value => Math.round(value * 10)), [9, 8, 7]);+ assert.equal(Math.round(batch.instanceData[41 + 29] * 10), 6);+ assert.equal(batch.instanceData[41 + 30], 2);+});++test('rejections still throw after the fast path has been taken', () => {+ const rejected = [+ [material => { material.alphaMode = 'blend'; }, /Shadow casting|Alpha mode/],+ [material => { material.alphaMode = 'mask'; }, /Alpha mode/],+ [material => { material.doubleSided = true; }, /double-sided/],+ [material => { material.map = { name: 'other' }; }, /Texture map/],+ [material => { material.normalMap = {}; }, /new renderer|standard PBR/],+ [material => { material.transmission = 0.5; }, /liquid or foam pass/],+ [material => { material.tag = 'liquid'; }, /liquid or foam pass/],+ [material => { material.clearcoat = 0.5; }, /Material map or scale/],+ [material => { material.moss = 0.5; }, /Material map or scale/],+ [material => { material.normalScale = [2, 2]; }, /Material map or scale/],+ [material => { material.lightMask = 1; }, /Material map or scale/],+ ];+ for (const [change, expected] of rejected) {+ const parts = [createPart('mover')];+ const { renderer } = createRenderer(parts);+ renderer.updateParts(parts);+ renderer.updateParts(parts);+ change(parts[0].material);+ assert.throws(() => renderer.updateParts(parts), expected);+ }+});++test('geometry changes and bad numbers still throw after the fast path has been taken', () => {+ const parts = [createPart('mover')];+ const { renderer } = createRenderer(parts);+ renderer.updateParts(parts);+ parts[0].geometry = {};+ assert.throws(() => renderer.updateParts(parts), /Geometry changes/);+ parts[0].geometry = GEOMETRY;+ parts[0].matrix[0] = NaN;+ assert.throws(() => renderer.updateParts(parts), /Invalid transform/);+ parts[0].matrix[0] = 1;+ parts[0].material.color = [0, NaN, 0];+ assert.throws(() => renderer.updateParts(parts), /Invalid instance vector/);+ parts[0].material.color = [0, 0, 0];+ parts[0].material.emissiveColor = [0, Infinity, 0];+ assert.throws(() => renderer.updateParts(parts), /Invalid instance vector/);+ delete parts[0].material.emissiveColor;+ parts[0].material.roughness = 1e39;+ assert.throws(() => renderer.updateParts(parts), /Invalid material/);+});