This project demonstrates an Embodied Reasoning loop where a Google Gemini Vision model analyzes a 3D robotic scene to guide a Franka Emika Panda robot in picking up objects. The application combines React for the UI, Three.js for rendering, and MuJoCo (via WASM) for physics simulation.
- Frontend (React): Handles the user interface, captures simulation state (images), communicates with the Gemini API, and visualizes logs.
- Visualization (Three.js): Renders the robot, objects, and environment. It synchronizes with the physics engine frame-by-frame.
- Physics (MuJoCo WASM): Runs the robotic simulation, collision detection, and inverse kinematics (IK) target tracking.
- AI (Gemini API): Receives a 2D snapshot of the scene and a text prompt, returning 2D bounding boxes or keypoints which are projected back into 3D space for the robot.
index.tsx: Application entry point. Mounts the React root.App.tsx: The main controller component.- Initializes the
MujocoSim. - Manages application state (loading, dark mode, logs).
- Handles the "Sense-Plan-Act" loop:
- Captures canvas snapshot.
- Sends request to Gemini (
handleErSend). - Parses JSON response.
- Projects 2D detections to 3D coordinates.
- Commands the robot to pickup (
handlePickup).
- Initializes the
types.ts: Shared TypeScript definitions (e.g.,LogEntry,DetectType).
MujocoSim.ts: The central orchestrator.- Loads the robot model XML (
init). - Runs the main simulation loop (
startLoop). - Syncs physics state (
mjData) to graphics (RenderSystem). - Manages the sequence of actions for picking up items (
pickupItems).
- Loads the robot model XML (
RenderSystem.ts: Manages the Three.js scene graph.- Creates meshes from MuJoCo geoms (
GeomBuilder). - Handles lighting, shadows, and camera controls.
- Provides
project2DTo3Dto convert AI vision results into world coordinates.
- Creates meshes from MuJoCo geoms (
RobotLoader.ts: Fetches MJCF (XML) files and assets from remote repositories (DeepMind Menagerie) and writes them to the in-memory WASM filesystem.
IkSystem.ts: Manages Inverse Kinematics targets.- Uses
FrankaAnalyticalIKto solve joint angles for a desired end-effector pose. - Handles redundancy resolution for the 7-DOF arm.
- Uses
FrankaAnalyticalIK.ts: An analytical geometry-based IK solver specifically for the Franka Emika Panda.SequenceAnimator.ts: A state machine that drives the robot through pick-and-place phases (Hover -> Open -> Lower -> Grasp -> Lift -> Move -> Drop).- Interpolates joint angles for smooth motion.
DragStateManager.ts: Handles mouse interaction raycasting (configured here for read-only cursor tracking as manipulation is disabled).SelectionManager.ts: Handles double-click object highlighting.utils/StringUtils.ts: Decodes C++ null-terminated strings from MuJoCo's WASM memory.rendering/GeomBuilder.ts: Factory that converts MuJoCo collision shapes (Box, Sphere, Mesh, etc.) into Three.js Geometry.Reflector.ts: A custom Three.js mesh for the reflective floor plane.CapsuleGeometry.ts: Custom geometry for MuJoCo's capsule primitives.MatMath.ts: Lightweight linear algebra helpers.
components/UnifiedSidebar.tsx: The main control panel. Contains the Prompt input, Detection Type selector, and Interaction History list.components/Toolbar.tsx: Bottom-left floating controls for Play/Pause, Reset, Dark Mode, and Sidebar toggle.components/RobotSelector.tsx: Top-left overlay displaying robot status and coordinates.
- User Prompt: User types "red cubes" and selects "Segmentation masks" in the Sidebar.
- Capture:
App.tsxcallssim.renderSys.getCanvasSnapshot()to get a base64 JPEG of the current 3D view. - Inference: A request is sent to
gemini-robotics-er-1.6-previewwith the image and prompt. - Response: Gemini returns a JSON list of detected objects with 2D bounding boxes/masks.
- Projection:
- The app calculates the center
(x, y)of the box in the 2D image. RenderSystem.tscasts a ray from the camera through that pixel into the 3D scene (project2DTo3D).- The intersection point on the table/object becomes the 3D target.
- The app calculates the center
- Action:
App.tsxpasses these 3D points toMujocoSim.MujocoSiminitiatesSequenceAnimator.SequenceAnimatorcalculates the path and drives the robot joints usingIkSystemto pick up the object and place it in the tray.