File size: 917 Bytes
3aea7c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import type { RobotState } from "$lib/types/robot";
import type { RobotUrdfConfig } from "$lib/types/urdf";
import { UrdfParser } from "./utils/UrdfParser";

export async function createRobot(urdfConfig: RobotUrdfConfig): Promise<RobotState> {
    const customParser = new UrdfParser(urdfConfig.urdfUrl, "/robots/so-100/");
    const urdfData = await customParser.load();
    const robot = customParser.fromString(urdfData);

    // Make the robot data reactive so mutations to joint.rotation trigger reactivity
    const reactiveRobot = $state(robot);
    
    // Make the selection state reactive as well
    const reactiveSelection = $state({
        isSelected: false,
        selectedLink: undefined,
        selectedJoint: undefined
    });

    const robotState: RobotState = {
        robot: reactiveRobot,
        urdfConfig: urdfConfig,
        selection: reactiveSelection
    };

    return robotState;
}