Files
vibemake/scripts/prepare-current-robot-preview.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

23 lines
1.9 KiB
JavaScript

import fs from 'node:fs/promises';
import path from 'node:path';
const root = new URL('../deliverables/current-robots/',import.meta.url).pathname;
const uploads='/Users/jerry/Downloads/三个机器人-后台上传-20261030';
const names={microduck:'01-小鸭子-Microduck',microban:'02-人形机器人-Microban',rp1:'03-双足机器人-RP1'};
const projects={};
async function list(dir,base=dir){let rows=[];for(const e of await fs.readdir(dir,{withFileTypes:true})){
const file=path.join(dir,e.name);if(e.isDirectory())rows.push(...await list(file,base));else {const stat=await fs.stat(file);rows.push({relativePath:path.relative(base,file),url:'http://localhost:8090'+file.slice(root.indexOf('/deliverables'))+'?v='+stat.size+'-'+Math.floor(stat.mtimeMs),sizeBytes:stat.size});}}return rows;}
for(const [id,folder]of Object.entries(names)){
const target=path.join(root,id);await fs.mkdir(target,{recursive:true});
const whole=path.join(uploads,folder,'01-整机模型',(await fs.readdir(path.join(uploads,folder,'01-整机模型')))[0]);
try{await fs.symlink(whole,path.join(target,'whole.glb'));}catch(e){if(e.code!=='EEXIST')throw e;}
const wholeStat=await fs.stat(whole);
const p={name:id,modelGlbUrl:`/deliverables/current-robots/${id}/whole.glb?v=${wholeStat.size}-${Math.floor(wholeStat.mtimeMs)}`,walkingResourcesBaseUrl:`/deliverables/current-robots/${id}/motion/`,walkingResourcesFiles:await list(path.join(target,'motion'))};
if(id==='microduck'){
await fs.copyFile(path.join(uploads,folder,'03-拼装步骤/小鸭子-239步装配.json'),path.join(target,'assembly.json'));
p.assemblyJsonUrl=`/deliverables/current-robots/${id}/assembly.json`;
p.modelPartsFiles=await list(path.join(root,'duck-parts'));
}
projects[id]=p;
}
await fs.writeFile(path.join(root,'preview.json'),JSON.stringify(projects,null,2));console.log(Object.fromEntries(Object.entries(projects).map(([id,p])=>[id,p.walkingResourcesFiles.length])));