Files
vibemake/scripts/export-duck-current-upload.mjs
T
Jerry 1c837766cd feat: integrate robot assembly and simulation with resilient loading
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.
2026-10-30 18:38:39 +08:00

49 lines
5.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// User preference: retain yesterday's confirmed leg directions, without replanning.
import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import {Vector3,Quaternion} from 'three';
import {validatePackage} from '../js/experience-packages.js';
const root=new URL('../deliverables/experience-packages/microduck-current/',import.meta.url).pathname;
const old=JSON.parse(fs.readFileSync('/Users/jerry/Downloads/小鸭子-双腿及躯干-当前上传/小鸭子-双腿及躯干-149步装配.json'));
const out=JSON.parse(fs.readFileSync(path.join(root,'manifest.json')));
const oldParts=new Map(old.parts.map(p=>[p.id,p])),parts=new Map(out.parts.map(p=>[p.id,p]));
const steps=new Map(out.steps.map(s=>[s.id,s])),q=new Quaternion(...old.displayQuaternion),retained=[];
for(const s of old.steps){
const code=s.id.split('-').slice(-2).join('-');
// Previous body directions are also retained wherever the same numbered step exists.
const target=steps.get(`step-${code}`);if(!target)continue;
const original=oldParts.get(s.parts[0]),offset=new Vector3(...original.installOffset).applyQuaternion(q);
for(const id of target.parts){const p=parts.get(id);
if(/螺钉/.test(p.file)){
// Same axial-entry rule; new exported screw geometry can have baked local rotations.
const direction=new Vector3(...p.installOffset).normalize();p.installOffset=direction.multiplyScalar(offset.length()).toArray();
}else p.installOffset=offset.toArray().map(n=>Math.abs(n)<1e-11?0:n);
}
retained.push(code);
}
assert.equal(retained.filter(c=>/^[12]-/.test(c)).length,104);
out.title='小鸭子 · 完整编号装配(239步,沿用双腿规则)';
validatePackage(out,'assembly','http://localhost:8090/manifest.json');
fs.writeFileSync(path.join(root,'manifest.json'),JSON.stringify(out,null,2)+'\n');
const notes=JSON.parse(fs.readFileSync(path.join(root,'manifest.notes.json')));
out.steps.forEach((s,i)=>{if(retained.includes(s.id.replace('step-','')))notes.steps[i].reason='沿用已确认的编号装配规则;位置来自本次整机,螺丝沿自身轴线进入。';});
fs.writeFileSync(path.join(root,'manifest.notes.json'),JSON.stringify(notes,null,2)+'\n');
const review=JSON.parse(fs.readFileSync(path.join(root,'axis-review.json')));
for(const r of review.records)if(retained.includes(r.code)){
r.experimentalCandidate=r.selected;r.experimentalCheck=r.check;
r.finalDirectionSource='user-requested-previous-numbered-rules';r.check={status:'retained-previous-rule'};
r.offsets=steps.get(`step-${r.code}`).parts.map(id=>parts.get(id).installOffset);
r.selected={name:'沿用昨日规则',vector:new Vector3(...r.offsets[0]).normalize().toArray(),travel:Math.hypot(...r.offsets[0])};
}
fs.writeFileSync(path.join(root,'axis-review.json'),JSON.stringify(review,null,2)+'\n');
const destination='/Users/jerry/Downloads/小鸭子-最新完整装配-20261030';
fs.mkdirSync(path.join(destination,'零件模型'),{recursive:true});
for(const f of out.files)fs.copyFileSync(path.join(root,f.path),path.join(destination,'零件模型',f.path));
fs.copyFileSync(path.join(root,'manifest.json'),path.join(destination,'小鸭子-完整装配步骤.json'));
const mapping=JSON.parse(fs.readFileSync(path.join(root,'mapping.json')));
const text=`小鸭子最新完整装配 · 239 步\n\n上传方式\n1. 后台“零件模型”:选择本目录中的“零件模型”文件夹(242 个整机零件 + 1 个扳手)。\n2. 后台“拼装步骤”:上传“小鸭子-完整装配步骤.json”。\n3. 使用当前本地前端打开 AI 装配。新的 GLB 使用 Draco 压缩,旧版前端需更新装配播放器后再部署。\n\n这次整机的零件划分、文件名与旧包不同,请把配套零件一起上传,不要混用旧文件夹。\n\n顺序与方向\n左腿 52 步 → 右腿 52 步 → 躯干 47 步 → 颈部 24 步 → 头部 64 步。\n两条腿沿用之前确认的安装方向规则;已有躯干步骤也保留旧规则。\n螺丝沿本次实际几何体的轴线进入,保留扳手拧入动画。\n新 GLB 为 Y 向上,installOffset 表示“起点相对最终位置的偏移”,不是运动速度方向。\n所有最终位置来自本次整机;压缩几何、材质参数、贴图字节保持原样。\n这是一份可上传的装配展示 JSON,不代表机械工艺或全程无碰撞认证。保留顺序和原始终点时,部分源模型配合面接触不能仅靠改变轴向消除。\n\n与编号清单的差异(保留新整机实际模型,没有改螺丝)\n${mapping.mismatches.map(x=>`${x.code}:清单 ${x.label};整机 ${x.name}`).join('\n')}\n\n整机附带但顺序未单列的对象\n${mapping.extras.map(x=>`${x.code}:${x.reason}`).join('\n')}\n原先跳过的 3-36、3-37 在新整机找到对应 M2x4.070、M2x4.071,本次已加入。\n`;
fs.writeFileSync(path.join(destination,'上传说明.txt'),text);
fs.writeFileSync(path.join(root,'retained-rules.json'),JSON.stringify({source:'previous 149-step package',retained,legSteps:104},null,2)+'\n');
console.log(JSON.stringify({destination,steps:out.steps.length,parts:out.parts.length,files:out.files.length,retained:retained.length},null,2));