Files
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

43 lines
1.2 KiB
JavaScript
Raw Permalink 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.
// 机器人数据来源。现在读本地 robots/robots.json;
// 接入后端时把 ROBOTS_ENDPOINT 换成接口地址,只要返回同样结构的数组即可。
export const ROBOTS_ENDPOINT = 'robots/robots.json';
export const DEFAULTS = {
maker: 'make',
description: '',
tags: [],
archetype: 'generic',
upAxis: 'z',
jointMap: {},
jointSign: {},
stance: {},
gait: {},
view: {},
stats: {},
hardware: null,
thumbnail: null,
};
export async function fetchRobots(endpoint = ROBOTS_ENDPOINT) {
const res = await fetch(endpoint, { cache: 'no-cache' });
if (!res.ok) throw new Error(`读取机器人列表失败:${res.status}`);
const data = await res.json();
const list = Array.isArray(data) ? data : data.robots || [];
return list.filter((r) => r && r.id && r.urdf && !r.hidden).map(normalizeRobot);
}
export const normalizeRobot = (r) => ({ ...DEFAULTS, ...r });
export const ARCHETYPE_LABEL = {
quadruped: '四足',
hexapod: '六足',
biped: '双足',
arm: '机械臂',
wheeled: '轮式',
generic: '通用',
};
export function archetypeLabel(config) {
return [].concat(config.archetype).map((a) => ARCHETYPE_LABEL[a] || a).join(' + ');
}