Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(engine-qa): grade a GLB for real-time-engine fitness (draw calls, texel density, LOD budget, collider)

nirholas891c0801e47c
diff --git a/api/_lib/engine-qa.js b/api/_lib/engine-qa.js
new file mode 100644
index 000000000..ef9990d1a
--- /dev/null
+++ b/api/_lib/engine-qa.js
@@ -0,0 +1,325 @@
+// Engine QA grading for a generated GLB: the questions a game engine or a
+// real-time renderer asks that neither glb-inspect.js ("is this valid glTF")
+// nor sim-readiness.js ("can a physics solver integrate this") answers:
+// "will this run, and can it collide?"
+//
+// draw calls one estimate per (node, primitive) pair actually in the
+// default scene graph: the real GPU cost, not just the
+// primitive count a mesh happens to own (a mesh referenced
+// by two nodes draws twice).
+// material count distinct materials, the other half of the draw-call
+// story (same primitive, more materials, more batches a
+// renderer can't merge).
+// texel density texels per meter: sqrt(UV-triangle-area-in-texels /
+// world-triangle-area-in-m²), summed across every
+// textured triangle after applying the node's world
+// transform. `null` with a reason when nothing is UV
+// mapped to a texture, never a fabricated number.
+// triangle budget each LOD level's triangle count against a configured
+// per-level ceiling, plus the monotonic-decrease check
+// every LOD chain must satisfy (highest to lowest detail).
+// collider reuses the print pipeline's manifold/watertight check
+// (api/_lib/print/{mesh-io,analyze}.js): a closed,
+// budget-sized mesh is a cheap physics collider; anything
+// else needs a convex-hull or primitive proxy instead.
+//
+// Every check is `pass` | `warn` | `fail`, or `skip` when the asset carries
+// nothing the check can measure (no textures, no LOD chain supplied). The
+// overall verdict is the worst non-skip verdict.
+
+import { NodeIO } from '@gltf-transform/core';
+import { ALL_EXTENSIONS } from '@gltf-transform/extensions';
+import { loadMesh } from './print/mesh-io.js';
+import { analyzeMesh } from './print/analyze.js';
+
+const MODE_TRIANGLES = 4;
+
+export const ENGINE_QA_VERSION = 'threews.engine.qa.v1';
+
+// Pass/fail thresholds in one place, per the work order: every number a
+// report cites traces back to this object, never a literal buried in a check.
+export const ENGINE_QA_THRESHOLDS = Object.freeze({
+ // One real-time frame budget on mid-tier mobile hardware. Above `warn`,
+ // batching/atlasing stops being optional.
+ drawCalls: Object.freeze({ good: 20, warn: 60 }),
+ // Distinct materials: each one is a potential draw-call split and a texture
+ // set a mobile GPU has to keep resident.
+ materialCount: Object.freeze({ good: 8, warn: 20 }),
+ // Triangle ceiling per LOD level. A level whose own `name` isn't one of
+ // these keys falls back to LOD0's ceiling (the most permissive) rather
+ // than failing on an unrecognized label.
+ triangleBudget: Object.freeze({ LOD0: 100_000, LOD1: 40_000, LOD2: 12_000 }),
+ // Game-ready texel density window (texels per meter of surface). Below the
+ // floor, textures visibly smear up close; above the ceiling, the asset is
+ // paying for resolution the eye can't resolve at normal viewing distance.
+ texelDensity: Object.freeze({ minPxPerMeter: 128, maxPxPerMeter: 2048 }),
+ // A mesh collider heavier than this belongs on a convex-hull or primitive
+ // proxy instead: not because physics engines refuse it, but because the
+ // broad-phase cost stops being worth the precision.
+ colliderTriangleBudget: 5_000,
+});
+
+let ioPromise = null;
+
+// Mirrors sim-readiness.js's getIO(): Draco/meshopt registration is
+// best-effort so an asset that doesn't use either compression is never
+// penalized for the dependency being unavailable.
+async function getIO() {
+ if (!ioPromise) {
+ ioPromise = (async () => {
+ const io = new NodeIO().registerExtensions(ALL_EXTENSIONS);
+ const dependencies = {};
+ try {
+ const draco = await import('draco3dgltf');
+ const create = draco.default ?? draco;
+ dependencies['draco3d.decoder'] = await create.createDecoderModule();
+ } catch {
+ /* asset is only ungradeable if it actually uses Draco */
+ }
+ try {
+ const { MeshoptDecoder } = await import('meshoptimizer');
+ await MeshoptDecoder.ready;
+ dependencies['meshopt.decoder'] = MeshoptDecoder;
+ } catch {
+ /* same: absence only matters for meshopt-compressed input */
+ }
+ if (Object.keys(dependencies).length) io.registerDependencies(dependencies);
+ return io;
+ })();
+ }
+ return ioPromise;
+}
+
+// gltf-transform world matrices are column-major, glTF's own convention.
+function transformPoint(m, x, y, z) {
+ const w = m[3] * x + m[7] * y + m[11] * z + m[15] || 1;
+ return [
+ (m[0] * x + m[4] * y + m[8] * z + m[12]) / w,
+ (m[1] * x + m[5] * y + m[9] * z + m[13]) / w,
+ (m[2] * x + m[6] * y + m[10] * z + m[14]) / w,
+ ];
+}
+
+function triangleArea(a, b, c) {
+ const abx = b[0] - a[0], aby = b[1] - a[1], abz = b[2] - a[2];
+ const acx = c[0] - a[0], acy = c[1] - a[1], acz = c[2] - a[2];
+ const cx = aby * acz - abz * acy;
+ const cy = abz * acx - abx * acz;
+ const cz = abx * acy - aby * acx;
+ return 0.5 * Math.sqrt(cx * cx + cy * cy + cz * cz);
+}
+
+function triangleAreaUv(a, b, c) {
+ // 2D cross product / 2, absolute value (winding doesn't matter for area).
+ return Math.abs((b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1])) / 2;
+}
+
+/**
+ * Walk the default scene once, counting real draw calls (one per node +
+ * triangle-primitive pair actually reachable from the scene root, so an
+ * instanced mesh counts once per instance) and accumulating textured-triangle
+ * world/UV area for the texel-density estimate.
+ */
+function collectSceneStats(doc) {
+ let drawCalls = 0;
+ let totalWorldAreaM2 = 0;
+ let totalUvAreaTexels = 0;
+
+ const root = doc.getRoot();
+ const scene = root.getDefaultScene() ?? root.listScenes()[0] ?? null;
+ const roots = scene ? scene.listChildren() : root.listNodes();
+ const seen = new Set();
+
+ const visit = (node) => {
+ if (seen.has(node)) return;
+ seen.add(node);
+ const mesh = node.getMesh();
+ if (mesh) {
+ const matrix = node.getWorldMatrix();
+ for (const prim of mesh.listPrimitives()) {
+ if (prim.getMode() !== MODE_TRIANGLES) continue;
+ drawCalls += 1;
+
+ const position = prim.getAttribute('POSITION');
+ const uv = prim.getAttribute('TEXCOORD_0');
+ const material = prim.getMaterial();
+ const texture = material?.getBaseColorTexture() ?? firstTexture(material);
+ if (!position || !uv || !texture) continue;
+ const size = texture.getSize();
+ if (!size) continue;
+ const [texWidth, texHeight] = size;
+
+ const index = prim.getIndices();
+ const count = index ? index.getCount() : position.getCount();
+ const p = [0, 0, 0];
+ const uvA = [0, 0], uvB = [0, 0], uvC = [0, 0];
+ for (let i = 0; i + 2 < count; i += 3) {
+ const ia = index ? index.getScalar(i) : i;
+ const ib = index ? index.getScalar(i + 1) : i + 1;
+ const ic = index ? index.getScalar(i + 2) : i + 2;
+
+ position.getElement(ia, p);
+ const a = transformPoint(matrix, p[0], p[1], p[2]);
+ position.getElement(ib, p);
+ const b = transformPoint(matrix, p[0], p[1], p[2]);
+ position.getElement(ic, p);
+ const c = transformPoint(matrix, p[0], p[1], p[2]);
+ totalWorldAreaM2 += triangleArea(a, b, c);
+
+ uv.getElement(ia, uvA);
+ uv.getElement(ib, uvB);
+ uv.getElement(ic, uvC);
+ totalUvAreaTexels += triangleAreaUv(uvA, uvB, uvC) * texWidth * texHeight;
+ }
+ }
+ }
+ for (const child of node.listChildren()) visit(child);
+ };
+ for (const node of roots) visit(node);
+
+ return { drawCalls, totalWorldAreaM2, totalUvAreaTexels };
+}
+
+function firstTexture(material) {
+ if (!material) return null;
+ return (
+ material.getNormalTexture() ??
+ material.getMetallicRoughnessTexture() ??
+ material.getEmissiveTexture() ??
+ material.getOcclusionTexture() ??
+ null
+ );
+}
+
+function worstVerdict(verdicts) {
+ const real = verdicts.filter((v) => v !== 'skip');
+ if (real.includes('fail')) return 'fail';
+ if (real.includes('warn')) return 'warn';
+ if (real.length === 0) return 'skip';
+ return 'pass';
+}
+
+function verdictFromBand(value, { good, warn }) {
+ if (value <= good) return 'pass';
+ if (value <= warn) return 'warn';
+ return 'fail';
+}
+
+/**
+ * Grade each LOD level's triangle count against ENGINE_QA_THRESHOLDS.triangleBudget
+ * and confirm the chain is monotonically decreasing (highest to lowest detail).
+ *
+ * @param {Array<{ name: string, triangleCount: number }>|null} lods
+ */
+function gradeTriangleBudget(lods) {
+ if (!Array.isArray(lods) || lods.length === 0) {
+ return { value: null, verdict: 'skip', reason: 'no LOD chain supplied' };
+ }
+
+ const perLevel = lods.map((level) => {
+ const budget = ENGINE_QA_THRESHOLDS.triangleBudget[level.name] ?? ENGINE_QA_THRESHOLDS.triangleBudget.LOD0;
+ return {
+ name: level.name,
+ triangleCount: level.triangleCount,
+ budget,
+ verdict: level.triangleCount <= budget ? 'pass' : 'fail',
+ };
+ });
+
+ let monotonicDecrease = true;
+ for (let i = 1; i < lods.length; i++) {
+ if (lods[i].triangleCount > lods[i - 1].triangleCount) monotonicDecrease = false;
+ }
+
+ return {
+ value: perLevel,
+ monotonicDecrease,
+ verdict: worstVerdict([...perLevel.map((l) => l.verdict), monotonicDecrease ? 'pass' : 'fail']),
+ };
+}
+
+/**
+ * Reuse the print pipeline's manifold/watertight check: a closed mesh under
+ * the collider triangle budget is cheap to collide against as-is; anything
+ * else needs a convex-hull or primitive proxy instead of its render mesh.
+ */
+async function gradeColliderSuitability(bytes) {
+ try {
+ const mesh = await loadMesh(bytes, { color: false });
+ const analysis = await analyzeMesh(mesh);
+ const budget = ENGINE_QA_THRESHOLDS.colliderTriangleBudget;
+ const overBudget = analysis.triangles > budget;
+ let verdict = 'pass';
+ if (!analysis.watertight) verdict = 'fail';
+ else if (overBudget) verdict = 'warn';
+ return {
+ value: {
+ watertight: analysis.watertight,
+ manifold: analysis.manifold,
+ shells: analysis.shells,
+ openEdges: analysis.open_edges,
+ triangleCount: analysis.triangles,
+ budget,
+ },
+ verdict,
+ reason: !analysis.watertight
+ ? 'mesh is not watertight; repair it or use a convex-hull/primitive collider'
+ : overBudget
+ ? 'watertight but too heavy for a mesh collider; use a convex-hull or primitive proxy'
+ : null,
+ };
+ } catch (err) {
+ return { value: null, verdict: 'skip', reason: err?.message || 'collider analysis failed' };
+ }
+}
+
+/**
+ * Grade a GLB for real-time-engine fitness.
+ *
+ * @param {Uint8Array|ArrayBuffer} glb
+ * @param {{ lods?: Array<{ name: string, triangleCount: number }> }} [options]
+ */
+export async function gradeEngineQa(glb, options = {}) {
+ const input = glb instanceof Uint8Array ? glb : new Uint8Array(glb);
+ const io = await getIO();
+ const doc = await io.readBinary(input);
+ const root = doc.getRoot();
+
+ const materialCount = root.listMaterials().length;
+ const textureCount = root.listTextures().length;
+ const { drawCalls, totalWorldAreaM2, totalUvAreaTexels } = collectSceneStats(doc);
+
+ const drawCallsCheck = { value: drawCalls, verdict: verdictFromBand(drawCalls, ENGINE_QA_THRESHOLDS.drawCalls), thresholds: ENGINE_QA_THRESHOLDS.drawCalls };
+ const materialCountCheck = { value: materialCount, verdict: verdictFromBand(materialCount, ENGINE_QA_THRESHOLDS.materialCount), thresholds: ENGINE_QA_THRESHOLDS.materialCount };
+
+ let texelDensityCheck;
+ if (totalWorldAreaM2 > 0 && totalUvAreaTexels > 0) {
+ const texelsPerM2 = totalUvAreaTexels / totalWorldAreaM2;
+ const pxPerMeter = Math.round(Math.sqrt(texelsPerM2));
+ const { minPxPerMeter, maxPxPerMeter } = ENGINE_QA_THRESHOLDS.texelDensity;
+ const verdict = pxPerMeter < minPxPerMeter ? 'fail' : pxPerMeter > maxPxPerMeter ? 'warn' : 'pass';
+ texelDensityCheck = { value: pxPerMeter, verdict, thresholds: ENGINE_QA_THRESHOLDS.texelDensity };
+ } else {
+ texelDensityCheck = { value: null, verdict: 'skip', reason: 'no UV-mapped texture found to measure' };
+ }
+
+ const triangleBudgetCheck = gradeTriangleBudget(options.lods ?? null);
+ const colliderCheck = await gradeColliderSuitability(input);
+
+ const checks = {
+ drawCalls: drawCallsCheck,
+ materialCount: materialCountCheck,
+ texelDensity: texelDensityCheck,
+ triangleBudget: triangleBudgetCheck,
+ collider: colliderCheck,
+ };
+
+ return {
+ version: ENGINE_QA_VERSION,
+ overall: worstVerdict(Object.values(checks).map((c) => c.verdict)),
+ materialCount,
+ textureCount,
+ drawCalls,
+ checks,
+ };
+}
diff --git a/tests/engine-qa.test.js b/tests/engine-qa.test.js
new file mode 100644
index 000000000..547276cd4
--- /dev/null
+++ b/tests/engine-qa.test.js
@@ -0,0 +1,256 @@
+import { describe, it, expect, beforeAll } from 'vitest';
+import { Document, NodeIO } from '@gltf-transform/core';
+import { gradeEngineQa, ENGINE_QA_VERSION, ENGINE_QA_THRESHOLDS } from '../api/_lib/engine-qa.js';
+
+// A single flat, closed solid with analytically known dimensions, authored
+// in-process so expectations derive from the shape's geometry rather than a
+// previous run of this same code - same philosophy as sim-readiness.test.js.
+function cubeMesh(size, { open = false } = {}) {
+ const h = size / 2;
+ const positions = [
+ -h, -h, -h, h, -h, -h, h, h, -h, -h, h, -h,
+ -h, -h, h, h, -h, h, h, h, h, -h, h, h,
+ ];
+ const faces = [
+ [0, 2, 1], [0, 3, 2],
+ [4, 5, 6], [4, 6, 7],
+ [0, 1, 5], [0, 5, 4],
+ [3, 7, 6], [3, 6, 2],
+ [0, 4, 7], [0, 7, 3],
+ [1, 2, 6], [1, 6, 5],
+ ];
+ if (open) faces.splice(0, 2);
+ return { positions, indices: faces.flat() };
+}
+
+// A UV sphere: manifold and watertight like the cube above, but with enough
+// triangles to clear the collider budget, which a hand-authored solid can't
+// reach without being unreadable. Degenerate triangles collapse to zero area
+// at the poles; analyzeMesh's own dropDegenerate step removes them exactly as
+// it would for any real asset, so the count below is deliberately well clear
+// of the budget rather than tuned to land exactly on it.
+function uvSphereMesh(radius, segments, rings) {
+ const positions = [];
+ for (let r = 0; r <= rings; r++) {
+ const theta = (r * Math.PI) / rings;
+ const y = radius * Math.cos(theta);
+ const ringRadius = radius * Math.sin(theta);
+ for (let s = 0; s <= segments; s++) {
+ const phi = (s * 2 * Math.PI) / segments;
+ positions.push(ringRadius * Math.cos(phi), y, ringRadius * Math.sin(phi));
+ }
+ }
+ const indices = [];
+ for (let r = 0; r < rings; r++) {
+ for (let s = 0; s < segments; s++) {
+ const a = r * (segments + 1) + s;
+ const b = a + segments + 1;
+ indices.push(a, b, a + 1, a + 1, b, b + 1);
+ }
+ }
+ return { positions, indices };
+}
+
+// A single rectangular quad in the XZ plane, UV-mapped edge to edge, so texel
+// density has a closed form: sqrt(texWidth*texHeight / (width*depth)).
+function planeMesh(width, depth) {
+ const hw = width / 2, hd = depth / 2;
+ return {
+ positions: [-hw, 0, -hd, hw, 0, -hd, hw, 0, hd, -hw, 0, hd],
+ indices: [0, 2, 1, 0, 3, 2],
+ uv: [0, 0, 1, 0, 1, 1, 0, 1],
+ };
+}
+
+let pngCache = new Map();
+async function pngBuffer(width, height) {
+ const key = `${width}x${height}`;
+ if (!pngCache.has(key)) {
+ const sharp = (await import('sharp')).default;
+ pngCache.set(key, sharp({ create: { width, height, channels: 4, background: { r: 128, g: 128, b: 128, alpha: 1 } } }).png().toBuffer());
+ }
+ return pngCache.get(key);
+}
+
+/**
+ * @param {Array<{ positions: number[], indices: number[], uv?: number[], textureSize?: [number, number], materialKey?: string }>} parts
+ * one node + one primitive per part, so part count == expected draw calls.
+ */
+async function buildGlb(parts) {
+ const doc = new Document();
+ const buffer = doc.createBuffer();
+ const scene = doc.createScene('scene');
+ const materials = new Map();
+ const textures = new Map();
+
+ for (const [i, part] of parts.entries()) {
+ const position = doc.createAccessor().setType('VEC3').setArray(new Float32Array(part.positions)).setBuffer(buffer);
+ const index = doc.createAccessor().setType('SCALAR').setArray(new Uint32Array(part.indices)).setBuffer(buffer);
+ const prim = doc.createPrimitive().setAttribute('POSITION', position).setIndices(index);
+
+ if (part.uv) {
+ const uv = doc.createAccessor().setType('VEC2').setArray(new Float32Array(part.uv)).setBuffer(buffer);
+ prim.setAttribute('TEXCOORD_0', uv);
+ }
+
+ const materialKey = part.materialKey ?? `material-${i}`;
+ if (!materials.has(materialKey)) {
+ const material = doc.createMaterial(materialKey);
+ if (part.textureSize) {
+ const textureKey = `${materialKey}:${part.textureSize.join('x')}`;
+ if (!textures.has(textureKey)) {
+ const [w, h] = part.textureSize;
+ const image = await pngBuffer(w, h);
+ textures.set(textureKey, doc.createTexture(textureKey).setMimeType('image/png').setImage(new Uint8Array(image)));
+ }
+ material.setBaseColorTexture(textures.get(textureKey));
+ }
+ materials.set(materialKey, material);
+ }
+ prim.setMaterial(materials.get(materialKey));
+
+ const mesh = doc.createMesh(`mesh-${i}`).addPrimitive(prim);
+ const node = doc.createNode(`node-${i}`).setMesh(mesh);
+ scene.addChild(node);
+ }
+
+ return Buffer.from(await new NodeIO().writeBinary(doc));
+}
+
+describe('gradeEngineQa', () => {
+ it('grades a simple textured, closed cube as engine-ready', async () => {
+ const glb = await buildGlb([{ ...cubeMesh(0.4) }]);
+ const report = await gradeEngineQa(glb);
+
+ expect(report.version).toBe(ENGINE_QA_VERSION);
+ expect(report.drawCalls).toBe(1);
+ expect(report.materialCount).toBe(1);
+ expect(report.checks.drawCalls.verdict).toBe('pass');
+ expect(report.checks.materialCount.verdict).toBe('pass');
+ expect(report.checks.collider.verdict).toBe('pass');
+ expect(report.checks.collider.value.watertight).toBe(true);
+ expect(report.overall).toBe('pass');
+ });
+
+ it('counts one draw call per node+primitive and reports a worse verdict past the warn band', async () => {
+ const parts = Array.from({ length: 25 }, () => ({ ...cubeMesh(0.1) }));
+ const glb = await buildGlb(parts);
+ const report = await gradeEngineQa(glb);
+
+ expect(report.drawCalls).toBe(25);
+ expect(report.checks.drawCalls.verdict).toBe('warn');
+ });
+
+ it('counts distinct materials, not primitives, for materialCount', async () => {
+ const shared = [
+ { ...cubeMesh(0.1), materialKey: 'shared' },
+ { ...cubeMesh(0.1), materialKey: 'shared' },
+ ];
+ const glb = await buildGlb(shared);
+ const report = await gradeEngineQa(glb);
+
+ expect(report.drawCalls).toBe(2);
+ expect(report.materialCount).toBe(1);
+ expect(report.checks.materialCount.verdict).toBe('pass');
+ });
+
+ it('flags a non-manifold-material count past the fail band', async () => {
+ const parts = Array.from({ length: 25 }, (_, i) => ({ ...cubeMesh(0.1), materialKey: `m${i}` }));
+ const glb = await buildGlb(parts);
+ const report = await gradeEngineQa(glb);
+
+ expect(report.materialCount).toBe(25);
+ expect(report.checks.materialCount.verdict).toBe('fail');
+ expect(report.overall).toBe('fail');
+ });
+
+ it('skips texel density when nothing is UV-mapped to a texture', async () => {
+ const glb = await buildGlb([{ ...cubeMesh(0.4) }]);
+ const report = await gradeEngineQa(glb);
+
+ expect(report.checks.texelDensity.verdict).toBe('skip');
+ expect(report.checks.texelDensity.value).toBeNull();
+ });
+
+ it('measures texel density from real UV + texture-pixel data, matching the closed form', async () => {
+ const glb = await buildGlb([{ ...planeMesh(1, 1), textureSize: [512, 512] }]);
+ const report = await gradeEngineQa(glb);
+
+ // sqrt(512*512 / (1*1)) = 512
+ expect(report.checks.texelDensity.value).toBeCloseTo(512, 0);
+ expect(report.checks.texelDensity.verdict).toBe('pass');
+ });
+
+ it('fails texel density below the floor (stretched texture) and warns above the ceiling (oversampled)', async () => {
+ const stretched = await buildGlb([{ ...planeMesh(10, 10), textureSize: [32, 32] }]);
+ const stretchedReport = await gradeEngineQa(stretched);
+ expect(stretchedReport.checks.texelDensity.value).toBe(3); // round(sqrt(1024/100))
+ expect(stretchedReport.checks.texelDensity.verdict).toBe('fail');
+
+ const oversampled = await buildGlb([{ ...planeMesh(0.01, 0.01), textureSize: [512, 512] }]);
+ const oversampledReport = await gradeEngineQa(oversampled);
+ expect(oversampledReport.checks.texelDensity.value).toBeCloseTo(51200, -2);
+ expect(oversampledReport.checks.texelDensity.verdict).toBe('warn');
+ });
+
+ it('skips the triangle budget check when no LOD chain is supplied', async () => {
+ const glb = await buildGlb([{ ...cubeMesh(0.4) }]);
+ const report = await gradeEngineQa(glb);
+
+ expect(report.checks.triangleBudget.verdict).toBe('skip');
+ });
+
+ it('passes a LOD chain within budget and flags one that exceeds it', async () => {
+ const glb = await buildGlb([{ ...cubeMesh(0.4) }]);
+ const withinBudget = await gradeEngineQa(glb, {
+ lods: [
+ { name: 'LOD0', triangleCount: 50_000 },
+ { name: 'LOD1', triangleCount: 20_000 },
+ { name: 'LOD2', triangleCount: 5_000 },
+ ],
+ });
+ expect(withinBudget.checks.triangleBudget.verdict).toBe('pass');
+ expect(withinBudget.checks.triangleBudget.monotonicDecrease).toBe(true);
+
+ const overBudget = await gradeEngineQa(glb, {
+ lods: [
+ { name: 'LOD0', triangleCount: 50_000 },
+ { name: 'LOD1', triangleCount: 45_000 }, // over the LOD1 ceiling of 40,000
+ ],
+ });
+ expect(overBudget.checks.triangleBudget.verdict).toBe('fail');
+ expect(overBudget.checks.triangleBudget.value[1].verdict).toBe('fail');
+ });
+
+ it('flags a LOD chain that is not monotonically decreasing', async () => {
+ const glb = await buildGlb([{ ...cubeMesh(0.4) }]);
+ const report = await gradeEngineQa(glb, {
+ lods: [
+ { name: 'LOD0', triangleCount: 1000 },
+ { name: 'LOD1', triangleCount: 2000 },
+ ],
+ });
+
+ expect(report.checks.triangleBudget.monotonicDecrease).toBe(false);
+ expect(report.checks.triangleBudget.verdict).toBe('fail');
+ });
+
+ it('reports a non-watertight mesh as collider-unsuitable with an actionable reason', async () => {
+ const glb = await buildGlb([{ ...cubeMesh(0.4, { open: true }) }]);
+ const report = await gradeEngineQa(glb);
+
+ expect(report.checks.collider.verdict).toBe('fail');
+ expect(report.checks.collider.value.watertight).toBe(false);
+ expect(report.checks.collider.reason).toMatch(/not watertight/);
+ });
+
+ it('warns on a watertight mesh that is too heavy for a cheap mesh collider', async () => {
+ const glb = await buildGlb([{ ...uvSphereMesh(0.5, 90, 70) }]);
+ const report = await gradeEngineQa(glb);
+
+ expect(report.checks.collider.value.watertight).toBe(true);
+ expect(report.checks.collider.value.triangleCount).toBeGreaterThan(ENGINE_QA_THRESHOLDS.colliderTriangleBudget);
+ expect(report.checks.collider.verdict).toBe('warn');
+ expect(report.checks.collider.reason).toMatch(/convex-hull|primitive proxy/);
+ });
+});