1c837766cd
Add backend-driven assembly and simulation experiences, MAKE branding, mobile rendering budgets and desktop-only CAD/PCB routes. Improve logo loading progress, document image recovery and URDF request handling; include dev packaging and regression coverage.
60 lines
4.6 KiB
JavaScript
60 lines
4.6 KiB
JavaScript
// Add declarative tightening instructions to the existing, aligned duck package.
|
|
// This one-off asset preparation knows the supplied fastener names; the player does not.
|
|
import { readFileSync, writeFileSync, mkdirSync, copyFileSync, constants } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { createHash } from 'node:crypto';
|
|
import assert from 'node:assert/strict';
|
|
import { validatePackage, validateEmbeddedGlb } from '../js/experience-packages.js';
|
|
|
|
const root = new URL('..', import.meta.url).pathname;
|
|
const source = join(root, 'deliverables/experience-packages/microduck-parts-assembly');
|
|
const out = join(root, 'deliverables/experience-packages/microduck-screw-assembly');
|
|
const upload = '/Users/jerry/Downloads/小鸭子-扳手装配';
|
|
const toolSource = '/Users/jerry/Downloads/内六角扳手.glb';
|
|
const toolName = '内六角扳手.glb';
|
|
const hash = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
const original = JSON.parse(readFileSync(join(source, 'manifest.json'), 'utf8'));
|
|
const manifest = structuredClone(original);
|
|
const toolBytes = readFileSync(toolSource);
|
|
validateEmbeddedGlb(toolBytes.buffer.slice(toolBytes.byteOffset, toolBytes.byteOffset + toolBytes.length));
|
|
manifest.title = 'Microduck · 内六角扳手装配';
|
|
manifest.files.push({ path: toolName, bytes: toolBytes.length, sha256: hash(toolBytes) });
|
|
manifest.tools = [{ id: 'hex-key-1-5', file: toolName,
|
|
// Measured long-end cap center including the GLB node translation (meters).
|
|
tipPosition: [0.005250010406598449, -0.000000003587008764, 0.03276707977056503] }];
|
|
let screwCount = 0;
|
|
for (const part of manifest.parts) {
|
|
if (!/^标准杯头内六角螺钉_M2x(?:4|5|6|8)(?:\.\d+)?\.glb$/.test(part.file)) continue;
|
|
part.installation = {
|
|
type: 'screw', toolId: 'hex-key-1-5',
|
|
axis: [0, 0, -1], socketPosition: [0, 0, -0.0009],
|
|
// Hex key flats rotated 30° to match this screw's six-sided socket.
|
|
toolQuaternion: [0, 0, Math.sin(Math.PI / 12), Math.cos(Math.PI / 12)],
|
|
direction: 'clockwise', turns: 3, travel: 0.0012,
|
|
approachDuration: 0.45, engageDuration: 0.3, tightenDuration: 2.4,
|
|
retractDuration: 0.35, toolClearance: 0.012,
|
|
};
|
|
screwCount++;
|
|
}
|
|
assert.equal(screwCount, 144);
|
|
assert.deepEqual(manifest.parts.map(({ installation, ...part }) => part), original.parts);
|
|
assert.deepEqual(manifest.steps, original.steps);
|
|
validatePackage(manifest, 'assembly', 'http://localhost:8090/manifest.json');
|
|
for (const dir of [out, join(upload, '零件模型')]) mkdirSync(dir, { recursive: true });
|
|
for (const file of manifest.files) {
|
|
const sourceFile = file.path === toolName ? toolSource : join(source, file.path);
|
|
assert.equal(hash(readFileSync(sourceFile)), file.sha256, `原文件校验失败:${file.path}`);
|
|
for (const dir of [out, join(upload, '零件模型')]) {
|
|
const destination = join(dir, file.path);
|
|
copyFileSync(sourceFile, destination, constants.COPYFILE_FICLONE);
|
|
assert.equal(hash(readFileSync(destination)), file.sha256, `复制校验失败:${file.path}`);
|
|
}
|
|
}
|
|
const json = JSON.stringify(manifest, null, 2) + '\n';
|
|
writeFileSync(join(out, 'manifest.json'), json);
|
|
writeFileSync(join(upload, '鸭子-拼装步骤-带扳手.json'), json);
|
|
copyFileSync(join(root, 'docs/assembly-screw-animation.md'), join(upload, '螺丝动画配置说明.md'));
|
|
writeFileSync(join(upload, '上传说明.txt'), `小鸭子 · 内六角扳手装配\n\n1. 后台“零件模型”选择本文件夹下的“零件模型”整个目录(293 个 GLB)。\n 包含原来的 292 个零件和 1 个扳手。不要只传扳手覆盖整批绑定。\n2. “拼装步骤”上传“鸭子-拼装步骤-带扳手.json”。\n3. 社区使用本次更新后的前端,点击 AI 装配 → 逐步装配 → 播放装配。\n 扳手只在螺丝安装时出现;查看整体不显示工具。\n\n所有 GLB 均原样复制,材质、颜色、几何体没有重写。\n原 292 个零件的最终位置、方向以及 91 个步骤不变。\n144 颗标准杯头内六角螺钉按 JSON 逐颗拧紧,其余零件保持平移安装。\n每颗默认顺时针 3 圈、拧入 1.2 mm、旋转 2.4 秒,可在 JSON 的 installation 中修改。\n顺时针指从工具一侧看向螺丝孔。模型局部 -Z 是这批螺丝的插入方向。\n这是装配展示动画,未做工具碰撞、实际紧固工艺或扭矩验证。\n\n详细配置:项目 docs/assembly-screw-animation.md\n本地效果:http://localhost:8090/examples/screw-assembly.html\n`);
|
|
console.log(JSON.stringify({ out, upload, screws: screwCount, parts: manifest.parts.length,
|
|
files: manifest.files.length, steps: manifest.steps.length, toolBytes: toolBytes.length }, null, 2));
|