Spaces:
Running
Running
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; | |
} | |