a8be5e0134
Unify lighting and line-colour controls across robots, replace the football with a shared layout of draggable physical props, and import the supplied RP1 GLBs without changing trained physics or policies. Include reproducible visual import/provenance, regression coverage and verification records. Verified 66 unit tests, 55 browser tests and production-build checks.
109 lines
4.0 KiB
JavaScript
109 lines
4.0 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs/promises";
|
|
import { createHash } from "node:crypto";
|
|
import { validateBodyGlb } from "../src/platform/render/BodyVisuals.js";
|
|
import { validatePackage } from "../src/platform/loader/SchemaValidator.js";
|
|
|
|
const root = new URL("../public/robots/rp1/", import.meta.url);
|
|
const config = JSON.parse(await fs.readFile(new URL("robot.json", root)));
|
|
const manifest = JSON.parse(
|
|
await fs.readFile(new URL("visual-source-manifest.json", root)),
|
|
);
|
|
const load = async (path) => {
|
|
const b = await fs.readFile(new URL(path, root));
|
|
return validateBodyGlb(
|
|
b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength),
|
|
);
|
|
};
|
|
|
|
test("RP1 maps all 63 supplied parts exactly once onto 25 visual-only body attachments", async () => {
|
|
validatePackage(config);
|
|
assert.equal(config.render.body_visuals.length, 25);
|
|
assert.equal(manifest.input_files.length, 63);
|
|
const parts = Object.values(manifest.body_mapping).flatMap((m) => m.parts);
|
|
assert.equal(parts.length, 63);
|
|
assert.equal(new Set(parts).size, 63);
|
|
let normals = 0,
|
|
colourTextures = 0,
|
|
emissive = 0;
|
|
for (const spec of config.render.body_visuals) {
|
|
assert.ok(!config.assets.some((a) => a.path === spec.path));
|
|
assert.deepEqual(spec.quaternion, [Math.SQRT1_2, 0, 0, Math.SQRT1_2]);
|
|
const doc = await load(spec.path);
|
|
for (const mat of doc.materials) {
|
|
if (mat.normalTexture) {
|
|
normals++;
|
|
assert.ok(doc.textures[mat.normalTexture.index]);
|
|
}
|
|
if (mat.pbrMetallicRoughness?.baseColorTexture) colourTextures++;
|
|
if (mat.extensions?.KHR_materials_emissive_strength?.emissiveStrength > 1)
|
|
emissive++;
|
|
}
|
|
for (const texture of doc.textures) assert.ok(doc.images[texture.source]);
|
|
if (spec.body.endsWith("_wrist_link")) {
|
|
const wrappers = doc.nodes.filter((n) => n.extras?.sourcePart);
|
|
assert.equal(wrappers.length, 20);
|
|
assert.equal(new Set(wrappers.map((n) => n.extras.sourcePart)).size, 20);
|
|
assert.deepEqual(
|
|
wrappers.map((n) => n.extras.sourcePart).sort(),
|
|
[...manifest.body_mapping[spec.body].parts].sort(),
|
|
);
|
|
}
|
|
}
|
|
assert.ok(normals >= 63);
|
|
assert.ok(colourTextures >= 1, "face screen texture retained");
|
|
assert.ok(emissive >= 1, "torso logo emissive strength retained");
|
|
});
|
|
|
|
test("23 unchanged body shapes align exactly with original STL bounds after Y-up conversion", async () => {
|
|
for (const { body, path } of config.render.body_visuals.filter(
|
|
(s) => !s.body.endsWith("_wrist_link"),
|
|
)) {
|
|
const doc = await load(path),
|
|
lo = [Infinity, Infinity, Infinity],
|
|
hi = [-Infinity, -Infinity, -Infinity];
|
|
for (const mesh of doc.meshes)
|
|
for (const p of mesh.primitives) {
|
|
const a = doc.accessors[p.attributes.POSITION];
|
|
for (let i = 0; i < 3; i++) {
|
|
lo[i] = Math.min(lo[i], a.min[i]);
|
|
hi[i] = Math.max(hi[i], a.max[i]);
|
|
}
|
|
}
|
|
const transformed = [lo[0], -hi[2], lo[1], hi[0], -lo[2], hi[1]];
|
|
const stl = await fs.readFile(new URL(`meshes/${body}.STL`, root));
|
|
const expected = [
|
|
Infinity,
|
|
Infinity,
|
|
Infinity,
|
|
-Infinity,
|
|
-Infinity,
|
|
-Infinity,
|
|
];
|
|
for (let t = 0; t < stl.readUInt32LE(80); t++)
|
|
for (let v = 0; v < 3; v++)
|
|
for (let axis = 0; axis < 3; axis++) {
|
|
const x = stl.readFloatLE(84 + t * 50 + 12 + v * 12 + axis * 4);
|
|
expected[axis] = Math.min(expected[axis], x);
|
|
expected[axis + 3] = Math.max(expected[axis + 3], x);
|
|
}
|
|
assert.deepEqual(transformed, expected, body);
|
|
}
|
|
});
|
|
|
|
test("original model, physics meshes, policies/motions and imported visual provenance retain reviewed hashes", async () => {
|
|
const physical = JSON.parse(
|
|
await fs.readFile(new URL("source-manifest.json", root)),
|
|
);
|
|
for (const file of [...physical.files, ...manifest.files]) {
|
|
assert.equal(
|
|
createHash("sha256")
|
|
.update(await fs.readFile(new URL(file.file, root)))
|
|
.digest("hex"),
|
|
file.sha256,
|
|
file.file,
|
|
);
|
|
}
|
|
});
|