"use client"; import { useId, type CSSProperties, type ReactNode } from "react"; import "./robot-loader.css"; import { G1_LINKS, OPENARM_LINKS, SO101_LINKS, type LoaderLink, } from "@/components/robot-loader-shapes"; export type LoaderRobot = "so101" | "openarm" | "g1"; interface Motion { from: string; to: string; duration: number; delay: number; } const LINKS: Record = { so101: SO101_LINKS, openarm: OPENARM_LINKS, g1: G1_LINKS, }; /// The joints that turn (or slide) within the drawing's plane, so they can move about their pivots. const MOTIONS: Record> = { so101: { upper_arm_link: { from: "rotate(-4deg)", to: "rotate(10deg)", duration: 3.6, delay: 0, }, lower_arm_link: { from: "rotate(6deg)", to: "rotate(-14deg)", duration: 3.6, delay: -1.2, }, wrist_link: { from: "rotate(-10deg)", to: "rotate(18deg)", duration: 2.8, delay: -0.6, }, moving_jaw_so101_v1_link: { from: "rotate(0deg)", to: "rotate(-22deg)", duration: 1.6, delay: 0, }, }, openarm: { openarm_left_link2: { from: "rotate(0deg)", to: "rotate(14deg)", duration: 3.4, delay: 0, }, openarm_right_link2: { from: "rotate(0deg)", to: "rotate(-14deg)", duration: 3.4, delay: -1.7, }, openarm_left_link6: { from: "rotate(-8deg)", to: "rotate(8deg)", duration: 2.6, delay: -0.4, }, openarm_right_link6: { from: "rotate(8deg)", to: "rotate(-8deg)", duration: 2.6, delay: -1.6, }, openarm_left_right_finger: { from: "translateX(0px)", to: "translateX(-1.6px)", duration: 1.4, delay: 0, }, openarm_left_left_finger: { from: "translateX(0px)", to: "translateX(1.6px)", duration: 1.4, delay: 0, }, openarm_right_right_finger: { from: "translateX(0px)", to: "translateX(-1.6px)", duration: 1.4, delay: -0.7, }, openarm_right_left_finger: { from: "translateX(0px)", to: "translateX(1.6px)", duration: 1.4, delay: -0.7, }, }, g1: { waist_roll_link: { from: "rotate(-4deg)", to: "rotate(4deg)", duration: 3.2, delay: 0, }, left_shoulder_roll_link: { from: "rotate(-4deg)", to: "rotate(-40deg)", duration: 3.2, delay: 0, }, right_shoulder_roll_link: { from: "rotate(40deg)", to: "rotate(4deg)", duration: 3.2, delay: 0, }, left_hip_roll_link: { from: "rotate(0deg)", to: "rotate(-5deg)", duration: 3.2, delay: 0, }, right_hip_roll_link: { from: "rotate(5deg)", to: "rotate(0deg)", duration: 3.2, delay: 0, }, left_ankle_roll_link: { from: "rotate(0deg)", to: "rotate(5deg)", duration: 3.2, delay: 0, }, right_ankle_roll_link: { from: "rotate(-5deg)", to: "rotate(0deg)", duration: 3.2, delay: 0, }, }, }; /** A wireframe illustration of the robot, drawing itself in and moving its joints, while its 3D model loads. */ export default function RobotLoader({ robot, caption, }: { robot: LoaderRobot; /** Shown above the loading text, like the dataset's robot type. */ caption?: string; }) { /// SVG ids are document-wide; useId's own characters aren't valid in url(#…). const uid = `rl${useId().replace(/[^a-zA-Z0-9]/g, "")}`; const links = LINKS[robot]; const motions = MOTIONS[robot]; const names = new Set(links.map((l) => l.name)); const childrenOf = new Map(); for (const link of links) { const parent = link.parent && names.has(link.parent) ? link.parent : null; childrenOf.set(parent, [...(childrenOf.get(parent) ?? []), link]); } let drawn = 0; const renderLink = (link: LoaderLink): ReactNode => { const motion = motions[link.name]; const style = motion && link.pivot ? ({ transformOrigin: `${link.pivot[0]}px ${link.pivot[1]}px`, "--rl-from": motion.from, "--rl-to": motion.to, "--rl-duration": `${motion.duration}s`, "--rl-delay": `${motion.delay}s`, } as CSSProperties) : undefined; return ( {link.paths.map((d, i) => ( ))} {style && motion.from.startsWith("rotate") && link.pivot && ( <> )} {(childrenOf.get(link.name) ?? []).map(renderLink)} ); }; return (
{caption && (
{caption}
)}
Loading 3D model
); }