From 13dfcfba13bdd87ce7820417df9708d34e77d966 Mon Sep 17 00:00:00 2001 From: cen617-code <1057290604@qq.com> Date: Tue, 27 Oct 2026 16:54:17 +0800 Subject: [PATCH] chore(app): refresh npm lockfile metadata --- .gitattributes | 40 + .gitignore | 1 + Dockerfile | 15 + LICENSE | 202 ++ README.md | 152 ++ app/.gitignore | 2 + app/index.html | 29 + app/package-lock.json | 2226 ++++++++++++++++ app/package.json | 29 + app/public/assets/duck-head-mark-open.webp | 3 + app/public/assets/duck-head-mark.webp | 3 + app/public/assets/microduck-wordmark.svg | 1 + app/public/assets/props/arcade.glb | 3 + app/public/assets/props/boombox.glb | 3 + app/public/assets/props/crt-tv.glb | 3 + app/public/assets/props/dartboard.glb | 3 + app/public/assets/props/lavalamp.glb | 3 + app/public/assets/props/segaconsole.glb | 3 + app/public/assets/props/skateboard.glb | 3 + app/public/assets/props/sneakers.glb | 3 + app/public/assets/props/walkman.glb | 3 + app/public/assets/sfx/click_a.wav | 3 + app/public/assets/sfx/click_b.wav | 3 + app/public/assets/sfx/step_a.wav | 3 + app/public/assets/sfx/step_b.wav | 3 + app/public/assets/sfx/step_c.wav | 3 + app/public/assets/sfx/step_d.wav | 3 + app/public/assets/sfx/step_e.wav | 3 + app/public/assets/sfx/thump_a.wav | 3 + app/public/assets/sfx/thump_b.wav | 3 + app/public/assets/sfx/thump_c.wav | 3 + app/public/assets/stickers/bang-red.webp | 3 + app/public/assets/stickers/boom.webp | 3 + app/public/assets/stickers/burst-yellow.webp | 3 + app/public/assets/stickers/quack-quack.webp | 3 + app/public/assets/stickers/quack.webp | 3 + app/public/assets/stickers/shooting-star.webp | 3 + app/public/assets/stickers/star-yellow.webp | 3 + app/public/assets/stickers/wave.webp | 3 + app/public/assets/stickers/ziouuu.webp | 3 + app/public/assets/voices/duck1/chirp_a.wav | 3 + app/public/assets/voices/duck1/chirp_b.wav | 3 + app/public/assets/voices/duck1/chirp_c.wav | 3 + app/public/assets/voices/duck1/chirp_d.wav | 3 + app/public/assets/voices/duck1/chirp_e.wav | 3 + app/public/assets/voices/duck1/chirp_f.wav | 3 + app/public/assets/voices/duck1/chirp_g.wav | 3 + app/public/assets/voices/duck1/chirp_h.wav | 3 + app/public/assets/voices/duck1/chirp_i.wav | 3 + app/public/assets/voices/duck1/chirp_j.wav | 3 + app/public/assets/voices/duck1/chirp_k.wav | 3 + app/public/assets/voices/duck1/chirp_l.wav | 3 + .../assets/voices/duck1/wheee_end_a.wav | 3 + .../assets/voices/duck1/wheee_end_b.wav | 3 + .../assets/voices/duck1/wheee_loop_a.wav | 3 + .../assets/voices/duck1/wheee_loop_b.wav | 3 + .../assets/voices/duck1/wheee_start_a.wav | 3 + .../assets/voices/duck1/wheee_start_b.wav | 3 + app/public/assets/voices/duck2/chirp_a.wav | 3 + app/public/assets/voices/duck2/chirp_b.wav | 3 + app/public/assets/voices/duck2/chirp_c.wav | 3 + app/public/assets/voices/duck2/chirp_d.wav | 3 + app/public/assets/voices/duck2/chirp_e.wav | 3 + app/public/assets/voices/duck2/chirp_f.wav | 3 + app/public/assets/voices/duck2/chirp_g.wav | 3 + app/public/assets/voices/duck2/chirp_h.wav | 3 + app/public/assets/voices/duck2/chirp_i.wav | 3 + app/public/assets/voices/duck2/chirp_j.wav | 3 + app/public/assets/voices/duck2/chirp_k.wav | 3 + app/public/assets/voices/duck2/chirp_l.wav | 3 + .../assets/voices/duck2/wheee_end_a.wav | 3 + .../assets/voices/duck2/wheee_end_b.wav | 3 + .../assets/voices/duck2/wheee_loop_a.wav | 3 + .../assets/voices/duck2/wheee_loop_b.wav | 3 + .../assets/voices/duck2/wheee_start_a.wav | 3 + .../assets/voices/duck2/wheee_start_b.wav | 3 + app/public/assets/voices/duck3/chirp_a.wav | 3 + app/public/assets/voices/duck3/chirp_b.wav | 3 + app/public/assets/voices/duck3/chirp_c.wav | 3 + app/public/assets/voices/duck3/chirp_d.wav | 3 + app/public/assets/voices/duck3/chirp_e.wav | 3 + app/public/assets/voices/duck3/chirp_f.wav | 3 + app/public/assets/voices/duck3/chirp_g.wav | 3 + app/public/assets/voices/duck3/chirp_h.wav | 3 + app/public/assets/voices/duck3/chirp_i.wav | 3 + app/public/assets/voices/duck3/chirp_j.wav | 3 + app/public/assets/voices/duck3/chirp_k.wav | 3 + app/public/assets/voices/duck3/chirp_l.wav | 3 + .../assets/voices/duck3/wheee_end_a.wav | 3 + .../assets/voices/duck3/wheee_end_b.wav | 3 + .../assets/voices/duck3/wheee_loop_a.wav | 3 + .../assets/voices/duck3/wheee_loop_b.wav | 3 + .../assets/voices/duck3/wheee_start_a.wav | 3 + .../assets/voices/duck3/wheee_start_b.wav | 3 + app/public/assets/voices/duck4/chirp_a.wav | 3 + app/public/assets/voices/duck4/chirp_b.wav | 3 + app/public/assets/voices/duck4/chirp_c.wav | 3 + app/public/assets/voices/duck4/chirp_d.wav | 3 + app/public/assets/voices/duck4/chirp_e.wav | 3 + app/public/assets/voices/duck4/chirp_f.wav | 3 + app/public/assets/voices/duck4/chirp_g.wav | 3 + app/public/assets/voices/duck4/chirp_h.wav | 3 + app/public/assets/voices/duck4/chirp_i.wav | 3 + app/public/assets/voices/duck4/chirp_j.wav | 3 + app/public/assets/voices/duck4/chirp_k.wav | 3 + app/public/assets/voices/duck4/chirp_l.wav | 3 + .../assets/voices/duck4/wheee_end_a.wav | 3 + .../assets/voices/duck4/wheee_end_b.wav | 3 + .../assets/voices/duck4/wheee_loop_a.wav | 3 + .../assets/voices/duck4/wheee_loop_b.wav | 3 + .../assets/voices/duck4/wheee_start_a.wav | 3 + .../assets/voices/duck4/wheee_start_b.wav | 3 + app/public/policies/BEST_alpha_sitstand.onnx | 3 + app/public/policies/BEST_alpha_stand.onnx | 3 + app/public/policies/BEST_alpha_walking.onnx | 3 + app/public/policies/BEST_roller.onnx | 3 + app/public/policies/BEST_roller_crouch.onnx | 3 + app/public/policies/alpha_ground_pick.onnx | 3 + app/public/policies/ball_kick_left.onnx | 3 + app/public/policies/ball_kick_right.onnx | 3 + app/public/policies/roulade.onnx | 3 + app/public/robot/mjlab/kinematics.json | 2013 ++++++++++++++ .../robot/mjlab/kinematics_rollers.json | 2267 ++++++++++++++++ app/public/robot/mjlab/meshes/ankle_l_v1.stl | 3 + app/public/robot/mjlab/meshes/ankle_left.stl | 3 + app/public/robot/mjlab/meshes/ankle_r_v1.stl | 3 + app/public/robot/mjlab/meshes/ankle_right.stl | 3 + .../robot/mjlab/meshes/banana_pcb_locker.stl | 3 + .../robot/mjlab/meshes/bearing_roll.stl | 3 + .../robot/mjlab/meshes/bottom_head_shell.stl | 3 + .../mjlab/meshes/elec_rpi_robot_hat_pcb.stl | 3 + app/public/robot/mjlab/meshes/face_part.stl | 3 + app/public/robot/mjlab/meshes/foot_left.stl | 3 + app/public/robot/mjlab/meshes/foot_right.stl | 3 + app/public/robot/mjlab/meshes/hip_l.stl | 3 + app/public/robot/mjlab/meshes/jaw.stl | 3 + app/public/robot/mjlab/meshes/jaw_soft.stl | 3 + app/public/robot/mjlab/meshes/left_shell.stl | 3 + app/public/robot/mjlab/meshes/leg.stl | 3 + app/public/robot/mjlab/meshes/lens.stl | 3 + .../robot/mjlab/meshes/m12_lens_holder.stl | 3 + .../robot/mjlab/meshes/motor_support.stl | 3 + app/public/robot/mjlab/meshes/neck.stl | 3 + app/public/robot/mjlab/meshes/neck_pitch.stl | 3 + app/public/robot/mjlab/meshes/noenoeil.stl | 3 + app/public/robot/mjlab/meshes/np_f970.stl | 3 + .../meshes/pcb__raspberry_pi_zero_2_w.stl | 3 + .../robot/mjlab/meshes/power_support.stl | 3 + app/public/robot/mjlab/meshes/right_shell.stl | 3 + app/public/robot/mjlab/meshes/rim.stl | 3 + .../robot/mjlab/meshes/roller_blade.stl | 3 + .../seeed_bearing__configuration__22x16x4.stl | 3 + .../seeed_bearing__configuration_default.stl | 3 + .../robot/mjlab/meshes/soft_mouth_top.stl | 3 + app/public/robot/mjlab/meshes/sole_left.stl | 3 + app/public/robot/mjlab/meshes/sole_right.stl | 3 + app/public/robot/mjlab/meshes/speaker.stl | 3 + app/public/robot/mjlab/meshes/tire.stl | 3 + .../robot/mjlab/meshes/top_head_shell.stl | 3 + app/public/robot/mjlab/meshes/trunk_base.stl | 3 + .../robot/mjlab/meshes/upper_leg_left.stl | 3 + .../robot/mjlab/meshes/upper_leg_right.stl | 3 + .../mjlab/meshes/upper_leg_rigidity_plate.stl | 3 + app/public/robot/mjlab/meshes/xl330.stl | 3 + app/public/robot/mjlab/meshes/yaw2roll.stl | 3 + .../robot/mjlab/meshes/yaw_roll_motion.stl | 3 + app/public/robot/mjlab/microduck.glb | 3 + .../robot/mjlab/robot_allcollisions.xml | 434 ++++ .../mjlab/robot_allcollisions_rollers.xml | 470 ++++ app/src/App.jsx | 89 + app/src/game/arena.js | 301 +++ app/src/game/audio.js | 581 +++++ app/src/game/ball-actor.js | 102 + app/src/game/ball-visual.js | 149 ++ app/src/game/ceremony.js | 267 ++ app/src/game/constants.js | 117 + app/src/game/controls/controller.js | 194 ++ app/src/game/controls/gamepad.js | 250 ++ app/src/game/controls/keyboard.js | 118 + app/src/game/controls/touch.js | 180 ++ app/src/game/controls/waypoint.js | 153 ++ app/src/game/custom-policy.js | 365 +++ app/src/game/duck.js | 415 +++ app/src/game/fx/demo-glitch.html | 140 + app/src/game/fx/demo-wireframe.html | 113 + app/src/game/fx/fx-glitch.js | 311 +++ app/src/game/fx/fx-wireframe.js | 339 +++ app/src/game/fx/waypoint-marker.js | 181 ++ app/src/game/game.js | 2311 +++++++++++++++++ app/src/game/ghosts.js | 601 +++++ app/src/game/haptics.js | 139 + app/src/game/props.js | 338 +++ app/src/game/signed.js | 13 + app/src/game/stickers.js | 222 ++ app/src/game/variants.js | 358 +++ app/src/game/vendor/zzfx.js | 60 + app/src/main.jsx | 27 + app/src/scene/CrtDistortion.jsx | 154 ++ app/src/scene/GameCanvas.jsx | 61 + app/src/store.js | 87 + app/src/theme.js | 25 + app/src/ui/BiosOverlay.jsx | 195 ++ app/src/ui/Hud.jsx | 635 +++++ app/src/ui/MenuDuck.jsx | 350 +++ app/src/ui/Overlays.jsx | 111 + app/src/ui/Soundboard.jsx | 368 +++ app/src/ui/TitleMenu.jsx | 751 ++++++ app/src/ui/TouchOverlay.jsx | 128 + app/src/ui/comic.jsx | 277 ++ app/src/ui/keyboard-layout.js | 44 + app/test/keyboard-layout.test.js | 81 + app/vite.config.js | 24 + 212 files changed, 20071 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 app/.gitignore create mode 100644 app/index.html create mode 100644 app/package-lock.json create mode 100644 app/package.json create mode 100644 app/public/assets/duck-head-mark-open.webp create mode 100644 app/public/assets/duck-head-mark.webp create mode 100644 app/public/assets/microduck-wordmark.svg create mode 100644 app/public/assets/props/arcade.glb create mode 100644 app/public/assets/props/boombox.glb create mode 100644 app/public/assets/props/crt-tv.glb create mode 100644 app/public/assets/props/dartboard.glb create mode 100644 app/public/assets/props/lavalamp.glb create mode 100644 app/public/assets/props/segaconsole.glb create mode 100644 app/public/assets/props/skateboard.glb create mode 100644 app/public/assets/props/sneakers.glb create mode 100644 app/public/assets/props/walkman.glb create mode 100644 app/public/assets/sfx/click_a.wav create mode 100644 app/public/assets/sfx/click_b.wav create mode 100644 app/public/assets/sfx/step_a.wav create mode 100644 app/public/assets/sfx/step_b.wav create mode 100644 app/public/assets/sfx/step_c.wav create mode 100644 app/public/assets/sfx/step_d.wav create mode 100644 app/public/assets/sfx/step_e.wav create mode 100644 app/public/assets/sfx/thump_a.wav create mode 100644 app/public/assets/sfx/thump_b.wav create mode 100644 app/public/assets/sfx/thump_c.wav create mode 100644 app/public/assets/stickers/bang-red.webp create mode 100644 app/public/assets/stickers/boom.webp create mode 100644 app/public/assets/stickers/burst-yellow.webp create mode 100644 app/public/assets/stickers/quack-quack.webp create mode 100644 app/public/assets/stickers/quack.webp create mode 100644 app/public/assets/stickers/shooting-star.webp create mode 100644 app/public/assets/stickers/star-yellow.webp create mode 100644 app/public/assets/stickers/wave.webp create mode 100644 app/public/assets/stickers/ziouuu.webp create mode 100644 app/public/assets/voices/duck1/chirp_a.wav create mode 100644 app/public/assets/voices/duck1/chirp_b.wav create mode 100644 app/public/assets/voices/duck1/chirp_c.wav create mode 100644 app/public/assets/voices/duck1/chirp_d.wav create mode 100644 app/public/assets/voices/duck1/chirp_e.wav create mode 100644 app/public/assets/voices/duck1/chirp_f.wav create mode 100644 app/public/assets/voices/duck1/chirp_g.wav create mode 100644 app/public/assets/voices/duck1/chirp_h.wav create mode 100644 app/public/assets/voices/duck1/chirp_i.wav create mode 100644 app/public/assets/voices/duck1/chirp_j.wav create mode 100644 app/public/assets/voices/duck1/chirp_k.wav create mode 100644 app/public/assets/voices/duck1/chirp_l.wav create mode 100644 app/public/assets/voices/duck1/wheee_end_a.wav create mode 100644 app/public/assets/voices/duck1/wheee_end_b.wav create mode 100644 app/public/assets/voices/duck1/wheee_loop_a.wav create mode 100644 app/public/assets/voices/duck1/wheee_loop_b.wav create mode 100644 app/public/assets/voices/duck1/wheee_start_a.wav create mode 100644 app/public/assets/voices/duck1/wheee_start_b.wav create mode 100644 app/public/assets/voices/duck2/chirp_a.wav create mode 100644 app/public/assets/voices/duck2/chirp_b.wav create mode 100644 app/public/assets/voices/duck2/chirp_c.wav create mode 100644 app/public/assets/voices/duck2/chirp_d.wav create mode 100644 app/public/assets/voices/duck2/chirp_e.wav create mode 100644 app/public/assets/voices/duck2/chirp_f.wav create mode 100644 app/public/assets/voices/duck2/chirp_g.wav create mode 100644 app/public/assets/voices/duck2/chirp_h.wav create mode 100644 app/public/assets/voices/duck2/chirp_i.wav create mode 100644 app/public/assets/voices/duck2/chirp_j.wav create mode 100644 app/public/assets/voices/duck2/chirp_k.wav create mode 100644 app/public/assets/voices/duck2/chirp_l.wav create mode 100644 app/public/assets/voices/duck2/wheee_end_a.wav create mode 100644 app/public/assets/voices/duck2/wheee_end_b.wav create mode 100644 app/public/assets/voices/duck2/wheee_loop_a.wav create mode 100644 app/public/assets/voices/duck2/wheee_loop_b.wav create mode 100644 app/public/assets/voices/duck2/wheee_start_a.wav create mode 100644 app/public/assets/voices/duck2/wheee_start_b.wav create mode 100644 app/public/assets/voices/duck3/chirp_a.wav create mode 100644 app/public/assets/voices/duck3/chirp_b.wav create mode 100644 app/public/assets/voices/duck3/chirp_c.wav create mode 100644 app/public/assets/voices/duck3/chirp_d.wav create mode 100644 app/public/assets/voices/duck3/chirp_e.wav create mode 100644 app/public/assets/voices/duck3/chirp_f.wav create mode 100644 app/public/assets/voices/duck3/chirp_g.wav create mode 100644 app/public/assets/voices/duck3/chirp_h.wav create mode 100644 app/public/assets/voices/duck3/chirp_i.wav create mode 100644 app/public/assets/voices/duck3/chirp_j.wav create mode 100644 app/public/assets/voices/duck3/chirp_k.wav create mode 100644 app/public/assets/voices/duck3/chirp_l.wav create mode 100644 app/public/assets/voices/duck3/wheee_end_a.wav create mode 100644 app/public/assets/voices/duck3/wheee_end_b.wav create mode 100644 app/public/assets/voices/duck3/wheee_loop_a.wav create mode 100644 app/public/assets/voices/duck3/wheee_loop_b.wav create mode 100644 app/public/assets/voices/duck3/wheee_start_a.wav create mode 100644 app/public/assets/voices/duck3/wheee_start_b.wav create mode 100644 app/public/assets/voices/duck4/chirp_a.wav create mode 100644 app/public/assets/voices/duck4/chirp_b.wav create mode 100644 app/public/assets/voices/duck4/chirp_c.wav create mode 100644 app/public/assets/voices/duck4/chirp_d.wav create mode 100644 app/public/assets/voices/duck4/chirp_e.wav create mode 100644 app/public/assets/voices/duck4/chirp_f.wav create mode 100644 app/public/assets/voices/duck4/chirp_g.wav create mode 100644 app/public/assets/voices/duck4/chirp_h.wav create mode 100644 app/public/assets/voices/duck4/chirp_i.wav create mode 100644 app/public/assets/voices/duck4/chirp_j.wav create mode 100644 app/public/assets/voices/duck4/chirp_k.wav create mode 100644 app/public/assets/voices/duck4/chirp_l.wav create mode 100644 app/public/assets/voices/duck4/wheee_end_a.wav create mode 100644 app/public/assets/voices/duck4/wheee_end_b.wav create mode 100644 app/public/assets/voices/duck4/wheee_loop_a.wav create mode 100644 app/public/assets/voices/duck4/wheee_loop_b.wav create mode 100644 app/public/assets/voices/duck4/wheee_start_a.wav create mode 100644 app/public/assets/voices/duck4/wheee_start_b.wav create mode 100644 app/public/policies/BEST_alpha_sitstand.onnx create mode 100644 app/public/policies/BEST_alpha_stand.onnx create mode 100644 app/public/policies/BEST_alpha_walking.onnx create mode 100644 app/public/policies/BEST_roller.onnx create mode 100644 app/public/policies/BEST_roller_crouch.onnx create mode 100644 app/public/policies/alpha_ground_pick.onnx create mode 100644 app/public/policies/ball_kick_left.onnx create mode 100644 app/public/policies/ball_kick_right.onnx create mode 100644 app/public/policies/roulade.onnx create mode 100644 app/public/robot/mjlab/kinematics.json create mode 100644 app/public/robot/mjlab/kinematics_rollers.json create mode 100644 app/public/robot/mjlab/meshes/ankle_l_v1.stl create mode 100644 app/public/robot/mjlab/meshes/ankle_left.stl create mode 100644 app/public/robot/mjlab/meshes/ankle_r_v1.stl create mode 100644 app/public/robot/mjlab/meshes/ankle_right.stl create mode 100644 app/public/robot/mjlab/meshes/banana_pcb_locker.stl create mode 100644 app/public/robot/mjlab/meshes/bearing_roll.stl create mode 100644 app/public/robot/mjlab/meshes/bottom_head_shell.stl create mode 100644 app/public/robot/mjlab/meshes/elec_rpi_robot_hat_pcb.stl create mode 100644 app/public/robot/mjlab/meshes/face_part.stl create mode 100644 app/public/robot/mjlab/meshes/foot_left.stl create mode 100644 app/public/robot/mjlab/meshes/foot_right.stl create mode 100644 app/public/robot/mjlab/meshes/hip_l.stl create mode 100644 app/public/robot/mjlab/meshes/jaw.stl create mode 100644 app/public/robot/mjlab/meshes/jaw_soft.stl create mode 100644 app/public/robot/mjlab/meshes/left_shell.stl create mode 100644 app/public/robot/mjlab/meshes/leg.stl create mode 100644 app/public/robot/mjlab/meshes/lens.stl create mode 100644 app/public/robot/mjlab/meshes/m12_lens_holder.stl create mode 100644 app/public/robot/mjlab/meshes/motor_support.stl create mode 100644 app/public/robot/mjlab/meshes/neck.stl create mode 100644 app/public/robot/mjlab/meshes/neck_pitch.stl create mode 100644 app/public/robot/mjlab/meshes/noenoeil.stl create mode 100644 app/public/robot/mjlab/meshes/np_f970.stl create mode 100644 app/public/robot/mjlab/meshes/pcb__raspberry_pi_zero_2_w.stl create mode 100644 app/public/robot/mjlab/meshes/power_support.stl create mode 100644 app/public/robot/mjlab/meshes/right_shell.stl create mode 100644 app/public/robot/mjlab/meshes/rim.stl create mode 100644 app/public/robot/mjlab/meshes/roller_blade.stl create mode 100644 app/public/robot/mjlab/meshes/seeed_bearing__configuration__22x16x4.stl create mode 100644 app/public/robot/mjlab/meshes/seeed_bearing__configuration_default.stl create mode 100644 app/public/robot/mjlab/meshes/soft_mouth_top.stl create mode 100644 app/public/robot/mjlab/meshes/sole_left.stl create mode 100644 app/public/robot/mjlab/meshes/sole_right.stl create mode 100644 app/public/robot/mjlab/meshes/speaker.stl create mode 100644 app/public/robot/mjlab/meshes/tire.stl create mode 100644 app/public/robot/mjlab/meshes/top_head_shell.stl create mode 100644 app/public/robot/mjlab/meshes/trunk_base.stl create mode 100644 app/public/robot/mjlab/meshes/upper_leg_left.stl create mode 100644 app/public/robot/mjlab/meshes/upper_leg_right.stl create mode 100644 app/public/robot/mjlab/meshes/upper_leg_rigidity_plate.stl create mode 100644 app/public/robot/mjlab/meshes/xl330.stl create mode 100644 app/public/robot/mjlab/meshes/yaw2roll.stl create mode 100644 app/public/robot/mjlab/meshes/yaw_roll_motion.stl create mode 100644 app/public/robot/mjlab/microduck.glb create mode 100644 app/public/robot/mjlab/robot_allcollisions.xml create mode 100644 app/public/robot/mjlab/robot_allcollisions_rollers.xml create mode 100644 app/src/App.jsx create mode 100644 app/src/game/arena.js create mode 100644 app/src/game/audio.js create mode 100644 app/src/game/ball-actor.js create mode 100644 app/src/game/ball-visual.js create mode 100644 app/src/game/ceremony.js create mode 100644 app/src/game/constants.js create mode 100644 app/src/game/controls/controller.js create mode 100644 app/src/game/controls/gamepad.js create mode 100644 app/src/game/controls/keyboard.js create mode 100644 app/src/game/controls/touch.js create mode 100644 app/src/game/controls/waypoint.js create mode 100644 app/src/game/custom-policy.js create mode 100644 app/src/game/duck.js create mode 100644 app/src/game/fx/demo-glitch.html create mode 100644 app/src/game/fx/demo-wireframe.html create mode 100644 app/src/game/fx/fx-glitch.js create mode 100644 app/src/game/fx/fx-wireframe.js create mode 100644 app/src/game/fx/waypoint-marker.js create mode 100644 app/src/game/game.js create mode 100644 app/src/game/ghosts.js create mode 100644 app/src/game/haptics.js create mode 100644 app/src/game/props.js create mode 100644 app/src/game/signed.js create mode 100644 app/src/game/stickers.js create mode 100644 app/src/game/variants.js create mode 100644 app/src/game/vendor/zzfx.js create mode 100644 app/src/main.jsx create mode 100644 app/src/scene/CrtDistortion.jsx create mode 100644 app/src/scene/GameCanvas.jsx create mode 100644 app/src/store.js create mode 100644 app/src/theme.js create mode 100644 app/src/ui/BiosOverlay.jsx create mode 100644 app/src/ui/Hud.jsx create mode 100644 app/src/ui/MenuDuck.jsx create mode 100644 app/src/ui/Overlays.jsx create mode 100644 app/src/ui/Soundboard.jsx create mode 100644 app/src/ui/TitleMenu.jsx create mode 100644 app/src/ui/TouchOverlay.jsx create mode 100644 app/src/ui/comic.jsx create mode 100644 app/src/ui/keyboard-layout.js create mode 100644 app/test/keyboard-layout.test.js create mode 100644 app/vite.config.js diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..68528d4 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,40 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.ckpt filter=lfs diff=lfs merge=lfs -text +*.ftz filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.joblib filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text +*.mlmodel filter=lfs diff=lfs merge=lfs -text +*.model filter=lfs diff=lfs merge=lfs -text +*.msgpack filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.npz filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.parquet filter=lfs diff=lfs merge=lfs -text +*.pb filter=lfs diff=lfs merge=lfs -text +*.pickle filter=lfs diff=lfs merge=lfs -text +*.pkl filter=lfs diff=lfs merge=lfs -text +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +*.safetensors filter=lfs diff=lfs merge=lfs -text +saved_model/**/* filter=lfs diff=lfs merge=lfs -text +*.tar.* filter=lfs diff=lfs merge=lfs -text +*.tar filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.wasm filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text +*tfevents* filter=lfs diff=lfs merge=lfs -text +*.stl filter=lfs diff=lfs merge=lfs -text +*.wav filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.webp filter=lfs diff=lfs merge=lfs -text +*.glb filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..00689f0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +# Build the Vite app, then serve the static bundle with nginx. +# HF Spaces docker SDK: the container must listen on app_port (8080); +# nginx-unprivileged listens on 8080 by default and runs as non-root, +# which is exactly what Spaces expects. + +FROM node:22-alpine AS build +WORKDIR /build +COPY app/package.json app/package-lock.json ./ +RUN npm ci +COPY app/ ./ +RUN npm run build + +FROM nginxinc/nginx-unprivileged:alpine +COPY --from=build /build/dist /usr/share/nginx/html +EXPOSE 8080 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..eb10d32 --- /dev/null +++ b/README.md @@ -0,0 +1,152 @@ +--- +title: Microduck Sandbox +emoji: 🐤 +colorFrom: yellow +colorTo: gray +sdk: docker +app_port: 8080 +pinned: false +license: apache-2.0 +--- + +# Microduck RL playground + +Real trained RL policies for the Microduck robot, running fully in the +browser: MuJoCo compiled to WebAssembly steps the physics, onnxruntime-web +runs the policy network at 50 Hz. No server, no backend. + +Two locomotion variants of the same robot are included: **legs** (walking, +the default) and **rollers** (the wheeled skating variant). Press `M` (or +hold D-pad up ~1 s on a gamepad) to switch; the roller model, meshes and +policies are lazy-loaded on the first switch. + +## Policies + +| Mode | Checkpoint | What it does | +|--------|-----------|--------------| +| Run (legs) | `BEST_alpha_walking.onnx` | Velocity-tracking locomotion (arrows / WASD to steer) | +| Sit | `BEST_alpha_sitstand.onnx` | Sits down on its hull, stands back up | +| Roll | `roulade.onnx` | Rolls over and recovers | +| Kick | `ball_kick_left.onnx` / `ball_kick_right.onnx` | Blind one-shot kick (0.5 s window, zeroed commands), left or right leg | +| Drive (rollers) | `BEST_roller.onnx` | Velocity-tracking skating on 4 passive wheels (higher top speed: 0.6 m/s) | +| Crouch (rollers) | `BEST_roller_crouch.onnx` | One-shot crouch-glide: sinks low over ~3.5 s and stands back up (phase-encoded command) | + +Policies and MJCF model from +[pollen-robotics/microduck](https://github.com/pollen-robotics/microduck) +and [pollen-robotics/microduck_rl](https://github.com/pollen-robotics/microduck_rl). + +## Controls + +- Arrows or WASD / ZQSD: forward / back + turn +- M: switch legs <-> rollers +- Q / E (A / E on AZERTY): kick left / right (legs only) +- F: alternate left / right kicks (legs only) +- R: sit / stand (legs) / crouch-glide (rollers) +- G: ground pick (legs only) +- C: toggle the chase camera (on by default; dragging detaches it) +- Space: reset +- Drag to orbit, scroll to zoom +- Colour dots: repaint the duck (it quacks) + +In roller mode the legs-only actions (kicks, sit) are disabled and their +hints fade out; play the ball by driving into it. + +### URL parameters + +- `?boot=1`: skip the welcome modal and land straight on the BIOS console, + which then shows the real loading progress live (honest loader) before + the normal entrance plays. Boot failures (missing asset, policy fetch + error...) freeze the console on a `SYSTEM HALTED` screen with the error + detail - handy for debugging. + +The ball's physics are local to your tab, but its pose is broadcast with +your duck's, so other visitors see a translucent copy of your ball next +to your ghost (and you see theirs). A square arena (3 x 3 m) fences the +play area so neither the ball nor the duck can wander off. + +### Gamepad + +Plug in a controller and the same mapping as the real robot runtime applies: + +- Left stick: forward / back + turn +- Right stick: orbit the camera (detaches the chase cam) +- R3 (right stick click): toggle the chase cam back on +- X or D-pad down: sit / stand (legs) / crouch-glide (rollers) +- A: ground pick (legs only) +- Y: toggle head control +- RB / LB: right / left kick (legs only) +- D-pad up: hold ~1 s to switch legs <-> rollers (the real robot uses a 3 s hold) +- Right trigger: mouth (analog) + quack +- Left trigger: hold for wheee +- A: enter / resume the game while the title or pause overlay is up +- Menu/Start (or Select): exit back to the title overlay while in-game + +## Multiplayer ghosts + +Other people visiting the Space at the same time show up as translucent +ducks, live. Peer-to-peer WebRTC via [Trystero](https://github.com/dmotz/trystero) +(serverless signaling over public Nostr relays), so it works from a static +Space with no backend. Each tab broadcasts its duck's pose (trunk + 14 +joints + jaw + colour + locomotion variant) at 10 Hz; up to 3 ghosts are +rendered, extra peers stay connected but invisible. The camcorder-style OSD +in the top-right corner shows "N ONLINE" when peers are around. + +Ghost limitations in v1: a peer in roller mode renders with the roller rig +only if your tab has already loaded it (otherwise it falls back to the leg +rig), and ghost wheels don't spin (passive wheel joints aren't broadcast). +Old clients simply ignore the new variant flag. + +## How it works + +The app is a Vite + React + MUI shell around an imperative game core: +React/MUI renders the UI chrome (title menu, BIOS console, HUD, touch +overlay), react-three-fiber owns the canvas/lights/environment, and the +physics/policy/rig loop lives in framework-agnostic modules under +`app/src/game/`. A zustand store bridges the two (game state out, +UI intents in). + +- `app/src/game/game.js` fetches the MJCF (`robot_allcollisions.xml`, or + `robot_allcollisions_rollers.xml` for the roller variant), strips the + visual geoms, injects a floor, arena walls, a ball, a collision box for + the arcade cabinet row and a STAND keyframe, and compiles it with the + official `@mujoco/mujoco` WASM bindings. +- Both variants share the exact same policy interface: 61D observation + (gyro, projected gravity, 14 joint pos/vel, last action, 13D command) + and 14 position-targets, matching [`microduck_rl/scripts/infer_policy.py`](https://github.com/pollen-robotics/microduck_rl/blob/main/scripts/infer_policy.py). + The roller variant adds 4 passive wheel hinges that appear in `qpos` + (zeroed in the keyframe) but not in the observation. +- Rendering is a three.js rig built from `kinematics.json` / + `kinematics_rollers.json` + decimated STL meshes, driven directly from + MuJoCo `qpos` (including the passive wheel spin). +- Switching variants swaps the compiled model + data + rig + ONNX sessions + wholesale; both stay resident after the first load so toggling back and + forth is instant. + +## Development + +Large binary assets (robot meshes, GLB models, ONNX policies) are stored +with [Git LFS](https://git-lfs.com/). Clone with LFS installed, or pull +the real files after a plain clone - otherwise the app boots against +text pointer files and fails with errors like +`SyntaxError: Unexpected token 'v', "version ht"... is not valid JSON` +(that string is the start of an LFS pointer, not your model): + +```bash +git lfs install # once per machine +git lfs pull # fetch the actual binaries in an existing clone +``` + +```bash +cd app +npm install +npm run dev # dev server on http://localhost:5173 +npm run build # production bundle in app/dist/ +``` + +The Space builds with the included `Dockerfile` (Vite build, served by +nginx-unprivileged on port 8080). Static assets (meshes, policies, audio, +images) live in `app/public/` and keep their historical URLs. + +## License + +The app code is released under the [Apache License 2.0](LICENSE). diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..b947077 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +dist/ diff --git a/app/index.html b/app/index.html new file mode 100644 index 0000000..6c88f95 --- /dev/null +++ b/app/index.html @@ -0,0 +1,29 @@ + + + + + + Microduck + + + + + + + +
+ + + diff --git a/app/package-lock.json b/app/package-lock.json new file mode 100644 index 0000000..c34ed60 --- /dev/null +++ b/app/package-lock.json @@ -0,0 +1,2226 @@ +{ + "name": "microduck-sandbox", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "microduck-sandbox", + "version": "1.0.0", + "dependencies": { + "@emotion/react": "^11.14.0", + "@emotion/styled": "^11.14.1", + "@mui/material": "^9.3.1", + "@mujoco/mujoco": "^3.11.0", + "@react-three/fiber": "^9.7.0", + "onnxruntime-web": "^1.27.0", + "react": "^19.2.8", + "react-dom": "^19.2.8", + "three": "^0.164.1", + "trystero": "^0.25.3", + "zustand": "^5.0.15" + }, + "devDependencies": { + "@vitejs/plugin-react": "^6.1.0", + "vite": "^8.2.2" + } + }, + "node_modules/@babel/code-frame": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz", + "integrity": "sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==", + "license": "MIT", + "dependencies": { + "@babel/helper-validator-identifier": "^7.29.7", + "js-tokens": "^4.0.0", + "picocolors": "^1.1.1" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/generator": { + "version": "7.29.8", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.29.8.tgz", + "integrity": "sha512-gZbepsdh3WDtgZKWL+vTPh71LSBrm/Y4/QDZBVCcYfmeTEEuoOYwlSy+G1StfJg+/Zy550u/3TATbm7qDbbMtg==", + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.29.8", + "@babel/types": "^7.29.8", + "@jridgewell/gen-mapping": "^0.3.12", + "@jridgewell/trace-mapping": "^0.3.28", + "jsesc": "^3.0.2" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-globals": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-globals/-/helper-globals-7.29.7.tgz", + "integrity": "sha512-3nQVUAtvkKH9zahfWgw96Jc/uFOmjACE1kQz82E2lqWmHBgjzbNlsC22nuQTfahmWeQtTq5nQ/4Nnd2A1wj4zA==", + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-module-imports": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.29.7.tgz", + "integrity": "sha512-ejHwrQQYcm9xnTivShn2IDOlIzInN34AXskvq9QicvCtEzq1Vzclu/tKF8Jq1Cg8JG2GL6/EmjgsCT7lXepE3g==", + "license": "MIT", + "dependencies": { + "@babel/traverse": "^7.29.7", + "@babel/types": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-string-parser": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.7.tgz", + "integrity": "sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw==", + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-validator-identifier": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz", + "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==", + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/parser": { + "version": "7.29.8", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.8.tgz", + "integrity": "sha512-E8lTAYNB1KW+FH+VGJuZM1ioAx2E6oVlvQFRrf5P8ZZmsiJXYAD9vTFV7yyEURNzgh1dFqMZuO6tUwcARbqFCA==", + "license": "MIT", + "dependencies": { + "@babel/types": "^7.29.8" + }, + "bin": { + "parser": "bin/babel-parser.js" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@babel/runtime": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.29.7.tgz", + "integrity": "sha512-Nq8OhGWiZIZGV6hLHoyAKLLcJihP/xFeBMGJoUrxTX2psI8dCifzLhZISFb+VWS3wFMRDmCGw5R+dOySCqPLhw==", + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/template": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.29.7.tgz", + "integrity": "sha512-puq+Gf35oI24FeN11LkoUQFqv9uwNeWpxXZi/Ji3rRIoKAzKnxRaZ+Gkj0vKS9ZCiTESfng1N9LyOyXvo+m+Gg==", + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^7.29.7", + "@babel/parser": "^7.29.7", + "@babel/types": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/traverse": { + "version": "7.29.8", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.29.8.tgz", + "integrity": "sha512-I5z7H3bf/41ktsNVLtpN0wAa336HkqIHQ5BuPLEhTkt1jVSyZpeNKIzTgEWmlxjdg81R0IgUCcaE+Ok3NvrfZg==", + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^7.29.7", + "@babel/generator": "^7.29.8", + "@babel/helper-globals": "^7.29.7", + "@babel/parser": "^7.29.8", + "@babel/template": "^7.29.7", + "@babel/types": "^7.29.8", + "debug": "^4.3.1" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/types": { + "version": "7.29.8", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.8.tgz", + "integrity": "sha512-Vj1jF3cPfxg7OAfoI7QnVKLoILlm2JF9pnVHrX8qx7AHMiYWT+NDAA7jChlNgRS4WTLc/fD1lXLmPixluj+3Gg==", + "license": "MIT", + "dependencies": { + "@babel/helper-string-parser": "^7.29.7", + "@babel/helper-validator-identifier": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@emotion/babel-plugin": { + "version": "11.13.5", + "resolved": "https://registry.npmjs.org/@emotion/babel-plugin/-/babel-plugin-11.13.5.tgz", + "integrity": "sha512-pxHCpT2ex+0q+HH91/zsdHkw/lXd468DIN2zvfvLtPKLLMo6gQj7oLObq8PhkrxOZb/gGCq03S3Z7PDhS8pduQ==", + "license": "MIT", + "dependencies": { + "@babel/helper-module-imports": "^7.16.7", + "@babel/runtime": "^7.18.3", + "@emotion/hash": "^0.9.2", + "@emotion/memoize": "^0.9.0", + "@emotion/serialize": "^1.3.3", + "babel-plugin-macros": "^3.1.0", + "convert-source-map": "^1.5.0", + "escape-string-regexp": "^4.0.0", + "find-root": "^1.1.0", + "source-map": "^0.5.7", + "stylis": "4.2.0" + } + }, + "node_modules/@emotion/cache": { + "version": "11.14.0", + "resolved": "https://registry.npmjs.org/@emotion/cache/-/cache-11.14.0.tgz", + "integrity": "sha512-L/B1lc/TViYk4DcpGxtAVbx0ZyiKM5ktoIyafGkH6zg/tj+mA+NE//aPYKG0k8kCHSHVJrpLpcAlOBEXQ3SavA==", + "license": "MIT", + "dependencies": { + "@emotion/memoize": "^0.9.0", + "@emotion/sheet": "^1.4.0", + "@emotion/utils": "^1.4.2", + "@emotion/weak-memoize": "^0.4.0", + "stylis": "4.2.0" + } + }, + "node_modules/@emotion/hash": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/@emotion/hash/-/hash-0.9.2.tgz", + "integrity": "sha512-MyqliTZGuOm3+5ZRSaaBGP3USLw6+EGykkwZns2EPC5g8jJ4z9OrdZY9apkl3+UP9+sdz76YYkwCKP5gh8iY3g==", + "license": "MIT" + }, + "node_modules/@emotion/is-prop-valid": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-1.4.0.tgz", + "integrity": "sha512-QgD4fyscGcbbKwJmqNvUMSE02OsHUa+lAWKdEUIJKgqe5IwRSKd7+KhibEWdaKwgjLj0DRSHA9biAIqGBk05lw==", + "license": "MIT", + "dependencies": { + "@emotion/memoize": "^0.9.0" + } + }, + "node_modules/@emotion/memoize": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.9.0.tgz", + "integrity": "sha512-30FAj7/EoJ5mwVPOWhAyCX+FPfMDrVecJAM+Iw9NRoSl4BBAQeqj4cApHHUXOVvIPgLVDsCFoz/hGD+5QQD1GQ==", + "license": "MIT" + }, + "node_modules/@emotion/react": { + "version": "11.14.0", + "resolved": "https://registry.npmjs.org/@emotion/react/-/react-11.14.0.tgz", + "integrity": "sha512-O000MLDBDdk/EohJPFUqvnp4qnHeYkVP5B0xEG0D/L7cOKP9kefu2DXn8dj74cQfsEzUqh+sr1RzFqiL1o+PpA==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.18.3", + "@emotion/babel-plugin": "^11.13.5", + "@emotion/cache": "^11.14.0", + "@emotion/serialize": "^1.3.3", + "@emotion/use-insertion-effect-with-fallbacks": "^1.2.0", + "@emotion/utils": "^1.4.2", + "@emotion/weak-memoize": "^0.4.0", + "hoist-non-react-statics": "^3.3.1" + }, + "peerDependencies": { + "react": ">=16.8.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@emotion/serialize": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@emotion/serialize/-/serialize-1.3.3.tgz", + "integrity": "sha512-EISGqt7sSNWHGI76hC7x1CksiXPahbxEOrC5RjmFRJTqLyEK9/9hZvBbiYn70dw4wuwMKiEMCUlR6ZXTSWQqxA==", + "license": "MIT", + "dependencies": { + "@emotion/hash": "^0.9.2", + "@emotion/memoize": "^0.9.0", + "@emotion/unitless": "^0.10.0", + "@emotion/utils": "^1.4.2", + "csstype": "^3.0.2" + } + }, + "node_modules/@emotion/sheet": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@emotion/sheet/-/sheet-1.4.0.tgz", + "integrity": "sha512-fTBW9/8r2w3dXWYM4HCB1Rdp8NLibOw2+XELH5m5+AkWiL/KqYX6dc0kKYlaYyKjrQ6ds33MCdMPEwgs2z1rqg==", + "license": "MIT" + }, + "node_modules/@emotion/styled": { + "version": "11.14.1", + "resolved": "https://registry.npmjs.org/@emotion/styled/-/styled-11.14.1.tgz", + "integrity": "sha512-qEEJt42DuToa3gurlH4Qqc1kVpNq8wO8cJtDzU46TjlzWjDlsVyevtYCRijVq3SrHsROS+gVQ8Fnea108GnKzw==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.18.3", + "@emotion/babel-plugin": "^11.13.5", + "@emotion/is-prop-valid": "^1.3.0", + "@emotion/serialize": "^1.3.3", + "@emotion/use-insertion-effect-with-fallbacks": "^1.2.0", + "@emotion/utils": "^1.4.2" + }, + "peerDependencies": { + "@emotion/react": "^11.0.0-rc.0", + "react": ">=16.8.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@emotion/unitless": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.10.0.tgz", + "integrity": "sha512-dFoMUuQA20zvtVTuxZww6OHoJYgrzfKM1t52mVySDJnMSEa08ruEvdYQbhvyu6soU+NeLVd3yKfTfT0NeV6qGg==", + "license": "MIT" + }, + "node_modules/@emotion/use-insertion-effect-with-fallbacks": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@emotion/use-insertion-effect-with-fallbacks/-/use-insertion-effect-with-fallbacks-1.2.0.tgz", + "integrity": "sha512-yJMtVdH59sxi/aVJBpk9FQq+OR8ll5GT8oWd57UpeaKEVGab41JWaCFA7FRLoMLloOZF/c/wsPoe+bfGmRKgDg==", + "license": "MIT", + "peerDependencies": { + "react": ">=16.8.0" + } + }, + "node_modules/@emotion/utils": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@emotion/utils/-/utils-1.4.2.tgz", + "integrity": "sha512-3vLclRofFziIa3J2wDh9jjbkUz9qk5Vi3IZ/FSTKViB0k+ef0fPV7dYrUIugbgupYDx7v9ud/SjrtEP8Y4xLoA==", + "license": "MIT" + }, + "node_modules/@emotion/weak-memoize": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@emotion/weak-memoize/-/weak-memoize-0.4.0.tgz", + "integrity": "sha512-snKqtPW01tN0ui7yu9rGv69aJXr/a/Ywvl11sUjNtEcRc+ng/mQriFL0wLXMef74iHa/EkftbDzU9F8iFbH+zg==", + "license": "MIT" + }, + "node_modules/@jridgewell/gen-mapping": { + "version": "0.3.13", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", + "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==", + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.0", + "@jridgewell/trace-mapping": "^0.3.24" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", + "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.31", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", + "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "node_modules/@mui/core-downloads-tracker": { + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/@mui/core-downloads-tracker/-/core-downloads-tracker-9.3.1.tgz", + "integrity": "sha512-IAyAFNQbT7hysJ9HXphiOmWJF7G1OglzHanqCgvQgH9LA2ydxtmaTBDbcBqw6euZesyShiwvpvbnYO1GY1AyXQ==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mui-org" + } + }, + "node_modules/@mui/material": { + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/@mui/material/-/material-9.3.1.tgz", + "integrity": "sha512-NahAEGIXqS1K0bA4th1jeFxBguS59NOcLbMA0vU+fSaPWKjtwGBGGHeTwlc9PSmzMjOZKceeFWESB8fVHr31hA==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.29.7", + "@mui/core-downloads-tracker": "^9.3.1", + "@mui/system": "^9.3.0", + "@mui/types": "^9.3.0", + "@mui/utils": "^9.3.0", + "@popperjs/core": "^2.11.8", + "@types/react-transition-group": "^4.4.12", + "clsx": "^2.1.1", + "csstype": "^3.2.3", + "prop-types": "^15.8.1", + "react-is": "^19.2.8", + "react-transition-group": "^4.4.5" + }, + "engines": { + "node": ">=14.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mui-org" + }, + "peerDependencies": { + "@emotion/react": "^11.5.0", + "@emotion/styled": "^11.3.0", + "@mui/material-pigment-css": "^9.3.0", + "@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0", + "react": "^17.0.0 || ^18.0.0 || ^19.0.0", + "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "@emotion/react": { + "optional": true + }, + "@emotion/styled": { + "optional": true + }, + "@mui/material-pigment-css": { + "optional": true + }, + "@types/react": { + "optional": true + } + } + }, + "node_modules/@mui/private-theming": { + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/@mui/private-theming/-/private-theming-9.3.0.tgz", + "integrity": "sha512-ERvqk5pejf9aRnQcDILSWGtFmsEMiVxlQ4+xsVCjsEvmK0fV9BiVP/cQwAF5dwyDFbve4lTrlcgeFEecVzTNiA==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.29.7", + "@mui/utils": "^9.3.0", + "prop-types": "^15.8.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mui-org" + }, + "peerDependencies": { + "@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0", + "react": "^17.0.0 || ^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@mui/styled-engine": { + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/@mui/styled-engine/-/styled-engine-9.3.0.tgz", + "integrity": "sha512-x9+KYxhjoHYZ4nioxdKnvQWdw0RScbhoZfQ4tv3Db742683U3wlYSp6zV6Us78dMFnKnyTrPTkQKyutp14gnKA==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.29.7", + "@emotion/cache": "^11.14.0", + "@emotion/serialize": "^1.3.3", + "@emotion/sheet": "^1.4.0", + "csstype": "^3.2.3", + "prop-types": "^15.8.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mui-org" + }, + "peerDependencies": { + "@emotion/react": "^11.4.1", + "@emotion/styled": "^11.3.0", + "react": "^17.0.0 || ^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "@emotion/react": { + "optional": true + }, + "@emotion/styled": { + "optional": true + } + } + }, + "node_modules/@mui/system": { + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/@mui/system/-/system-9.3.0.tgz", + "integrity": "sha512-0l4LqHJxZj65xSrioniGsxm7VNoGXonPo203oZjhBUvIDPeBqRTb7Mqc45Qxs6sO6WGR7WE/9cJ6lb4lkvHkjg==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.29.7", + "@mui/private-theming": "^9.3.0", + "@mui/styled-engine": "^9.3.0", + "@mui/types": "^9.3.0", + "@mui/utils": "^9.3.0", + "clsx": "^2.1.1", + "csstype": "^3.2.3", + "prop-types": "^15.8.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mui-org" + }, + "peerDependencies": { + "@emotion/react": "^11.5.0", + "@emotion/styled": "^11.3.0", + "@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0", + "react": "^17.0.0 || ^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "@emotion/react": { + "optional": true + }, + "@emotion/styled": { + "optional": true + }, + "@types/react": { + "optional": true + } + } + }, + "node_modules/@mui/types": { + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/@mui/types/-/types-9.3.0.tgz", + "integrity": "sha512-2JSxyfpEFWNUB2vKs/T1BvkfyNisMHWph8bLMj8T0uHwmLl/0qfAwQkfwMT6kxLXN9uIum9AEbECXU8er3amIg==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.29.7" + }, + "peerDependencies": { + "@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@mui/utils": { + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/@mui/utils/-/utils-9.3.0.tgz", + "integrity": "sha512-2HZdHwWJ6eB+7lVGSOHsByGw8jeRulT4g0NZ608Wb8Q57DE2jbNqrWPFuJsvkQQiBiTmlpvQL3i+/62zsiPrkw==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.29.7", + "@mui/types": "^9.3.0", + "@types/prop-types": "^15.7.15", + "clsx": "^2.1.1", + "prop-types": "^15.8.1", + "react-is": "^19.2.8" + }, + "engines": { + "node": ">=14.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mui-org" + }, + "peerDependencies": { + "@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0", + "react": "^17.0.0 || ^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@mujoco/mujoco": { + "version": "3.11.0", + "resolved": "https://registry.npmjs.org/@mujoco/mujoco/-/mujoco-3.11.0.tgz", + "integrity": "sha512-ZtBhIX8It5EZUcRfxalYTilSG52JYoItEOBYOXdkviwZWaZ8XBuuSuNBwnXqhV1VkXpWbpPc27vGdQsTiSVX3Q==", + "license": "Apache-2.0" + }, + "node_modules/@noble/secp256k1": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@noble/secp256k1/-/secp256k1-3.2.0.tgz", + "integrity": "sha512-Z3ZAWOTxJ0EuTuZTi7Y69iK7GgrLHh8sgm45lVDhg/b3Nk1TpAiKhick2KkZisHuupeepSkyIydN/J459SdX1w==", + "license": "MIT", + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@oxc-project/types": { + "version": "0.146.0", + "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.146.0.tgz", + "integrity": "sha512-XC0QsnnhVe7sLIWmYmdPw7x5P0h4W8vUU3Nv1ySgWXtvCz8NizoAEpGXA0sOYoJQV2Rl13LgURAHQ5cI5ILCSA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/Boshen" + } + }, + "node_modules/@popperjs/core": { + "version": "2.11.8", + "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz", + "integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/popperjs" + } + }, + "node_modules/@protobufjs/aspromise": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", + "integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/base64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", + "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/codegen": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.5.tgz", + "integrity": "sha512-zgXFLzW3Ap33e6d0Wlj4MGIm6Ce8O89n/apUaGNB/jx+hw+ruWEp7EwGUshdLKVRCxZW12fp9r40E1mQrf/34g==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/eventemitter": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.1.tgz", + "integrity": "sha512-vW1GmwMZNnL+gMRaovlh9yZX74kc+TTU3FObkkurpMaRtBfLP3ldjS9KQWlwZgraRE0+dheEEoAxdzcJQ8eXZg==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/fetch": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.1.tgz", + "integrity": "sha512-GpptLrs57adMSuHi3VNj0mAF8dwh36LMaYF6XyJ6JMWlVsc+t42tm1HSEDmOs3A8fC9yyeisgLhsTVQokOZ0zw==", + "license": "BSD-3-Clause", + "dependencies": { + "@protobufjs/aspromise": "^1.1.1" + } + }, + "node_modules/@protobufjs/float": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", + "integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/path": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", + "integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/pool": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", + "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/utf8": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.2.tgz", + "integrity": "sha512-b1UQwcEZ4yCnMCD8DAL1VlbvBJE9/IX4FTIp7BG1xYpf29SLazLSrqUkj4w7Y5y7cCVP6E5tcqqcI0xemPkHug==", + "license": "BSD-3-Clause" + }, + "node_modules/@react-three/fiber": { + "version": "9.7.0", + "resolved": "https://registry.npmjs.org/@react-three/fiber/-/fiber-9.7.0.tgz", + "integrity": "sha512-EWm9FwcaOZQu/ExFW5rggoCMM1NJet5YbxVxKaOE+KSncrjU0Wx7017qSyGFvupviK89nMYGCWU3BIK4dI1clw==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.17.8", + "@types/webxr": "*", + "base64-js": "^1.5.1", + "buffer": "^6.0.3", + "its-fine": "^2.0.0", + "react-use-measure": "^2.1.7", + "scheduler": "^0.27.0", + "suspend-react": "^0.1.3", + "use-sync-external-store": "^1.4.0", + "zustand": "^5.0.3" + }, + "peerDependencies": { + "expo": ">=43.0", + "expo-asset": ">=8.4", + "expo-file-system": ">=11.0", + "expo-gl": ">=11.0", + "react": ">=19 <19.3", + "react-dom": ">=19 <19.3", + "react-native": ">=0.78", + "three": ">=0.156" + }, + "peerDependenciesMeta": { + "expo": { + "optional": true + }, + "expo-asset": { + "optional": true + }, + "expo-file-system": { + "optional": true + }, + "expo-gl": { + "optional": true + }, + "react-dom": { + "optional": true + }, + "react-native": { + "optional": true + } + } + }, + "node_modules/@rolldown/binding-android-arm-eabi": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.5.tgz", + "integrity": "sha512-DLe/i+l8ynIBY7XEQ191TeZvCoowIGa18R+dIV30GW7DiOtp74i/xX8hs8GUjW5ARV7VZuie3d6AumSmCwbeRA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-android-arm64": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.2.5.tgz", + "integrity": "sha512-zXcwKlQApYAOELHd8PwKDFkagYF9Wy4e0RJ+0qnzl9Pjnpj75TEG8ufv40p2J7kCEfwZAsNiuzRIyNNMWT38ig==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-arm64": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.2.5.tgz", + "integrity": "sha512-dK4QakI42nzWgJT5sm4y4y/O//D4OxM75/cH28RLV+nzIN9AY+YsbuUVrUTjlLjXR6vpyxFbSsbmNuJ6BP9sww==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-x64": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.2.5.tgz", + "integrity": "sha512-fqSALaUu1Wjd1nK2uW2kJDWdLCc8lx1IcY+MTY26Aurfdx19anlzhqXOgCFbBFQnlFDTn4TC1/7Nz4Bl2mLP3A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-freebsd-x64": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.2.5.tgz", + "integrity": "sha512-/vCnNxlkxs9tKxNDcyWUePpJ/PgTzxIaVhoM5SmG8UV+GR/IcPam4VYxi7GIMo7PSDuNqlJqvprqii9NqqVCMw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm-gnueabihf": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.2.5.tgz", + "integrity": "sha512-abk0NLA519LxRCszmbE0jYKuQ9YPocOXTiOXOo6Yr+YAT95VH+PtqYAjOJvGKt3viEd/x4qzabAlwd5bHOOARg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-gnu": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.2.5.tgz", + "integrity": "sha512-Y7eALiJ8lr0M2HH103Js+g7V34wf6snlpZLAsHI90uLhr3PVlNsbFVAXJC9d/V6BnPyKtpSwI+NcB/RLxsQxuA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-musl": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.2.5.tgz", + "integrity": "sha512-xMvZgnbZg4YVnR/AX2b3oOPDTFYJvUVaJg5FedA/LuvexAtXibZQej4cnTkw3rjsJ/ggUROB64TdtETiim+FYA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-ppc64-gnu": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.2.5.tgz", + "integrity": "sha512-GRjeqTUDHTo5GwntsLaAMcBahG3nlpjftXWZLN73HiYQlhwEowvarFgQnRnQZtIp4keXX7quXFbG38uPZBa2EA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-s390x-gnu": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.2.5.tgz", + "integrity": "sha512-vLNTR45F2Uwc8AufkNXPmB4VliaXs+FvcheEogIzOXzO4l+LzieXF5A/TWxLy5HtqpsRCHUfd0lPVrrdgXdLHQ==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-gnu": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.2.5.tgz", + "integrity": "sha512-Mgj59/HTuYeK9Gz2MA+mBWKnHsAgkBSec15ZMb1st3oIfFbX7gCjOae7GydHhzcyQi9Z/7M1QuN9bR3oFqF0jQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-musl": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.2.5.tgz", + "integrity": "sha512-mY8AP0/ichsbhAxGnLa3d3+MwV0EfgrPND2bplI3Ym8T6R2pJ0N87bvrKVwNXmdy3jnr6eQBecdqx/HMknBmpA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-openharmony-arm64": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.2.5.tgz", + "integrity": "sha512-8SLssA2oweAxyRgDp789ACfRb/3P+zNRJpzZxSizxF9m8NUDQ4+3xjo8ttjhVGGw6Qxb70oZiEtIjaKikCO7Yw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-arm64-msvc": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.5.tgz", + "integrity": "sha512-vGbruD5zquhoc8D9SViXgN2FBJtNdTyQ4DtG+SWiEGlJiAzoKcZ2xp+xuXCffhubVdt0NJlTZqkeRuERy7g8Cw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-x64-msvc": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.2.5.tgz", + "integrity": "sha512-e/SXpgISz+IoqVcSSI0rx/d/he8zqLex+/rCWpnHpmVfmPIUjag9H6P7zotf0gJHwPUhQxZ/mF8tr6acebT9yw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/pluginutils": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz", + "integrity": "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@trystero-p2p/core": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@trystero-p2p/core/-/core-0.25.3.tgz", + "integrity": "sha512-lQKNq/ha+vF6kQZrpaXJGzlzxLF/Fhizoy5dwJUYQlkqRrbPup/Jov2EpPX/CPr2X+f79HxVzonkeni3MxmCuQ==", + "license": "MIT" + }, + "node_modules/@trystero-p2p/nostr": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@trystero-p2p/nostr/-/nostr-0.25.3.tgz", + "integrity": "sha512-nZV9Fl/GXuhIkJSQ+wIkdMoRLO1oSTUL/+vZorukaojeAdOpT/61e8b9Vzbt8L1ktMTaGPEJHw2BG/B5BCwBuw==", + "license": "MIT", + "dependencies": { + "@noble/secp256k1": "^3.1.0", + "@trystero-p2p/core": "0.25.3" + } + }, + "node_modules/@types/node": { + "version": "26.4.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-26.4.1.tgz", + "integrity": "sha512-k97ENvZWtvA6yqz5/FS6a7duDgOPEeOQOc2iKS/nY6mX6qJUKtLnWzQS+Xj6tXweyj6ZcTAK2Qecetnvi9nCLA==", + "license": "MIT", + "dependencies": { + "undici-types": "~8.3.0" + } + }, + "node_modules/@types/parse-json": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.2.tgz", + "integrity": "sha512-dISoDXWWQwUquiKsyZ4Ng+HX2KsPL7LyHKHQwgGFEA3IaKac4Obd+h2a/a6waisAoepJlBcx9paWqjA8/HVjCw==", + "license": "MIT" + }, + "node_modules/@types/prop-types": { + "version": "15.7.15", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.15.tgz", + "integrity": "sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw==", + "license": "MIT" + }, + "node_modules/@types/react": { + "version": "19.2.18", + "resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.18.tgz", + "integrity": "sha512-AnzbBERsrLKtk2XSfTbYRLjQPdy116Sty4q+T+Bp3IC4l6jNBvreVPAHmpq9qhXQM7CXZPjLVmGMw9sy+hxQ3w==", + "license": "MIT", + "peer": true, + "dependencies": { + "csstype": "^3.2.2" + } + }, + "node_modules/@types/react-reconciler": { + "version": "0.28.9", + "resolved": "https://registry.npmjs.org/@types/react-reconciler/-/react-reconciler-0.28.9.tgz", + "integrity": "sha512-HHM3nxyUZ3zAylX8ZEyrDNd2XZOnQ0D5XfunJF5FLQnZbHHYq4UWvW1QfelQNXv1ICNkwYhfxjwfnqivYB6bFg==", + "license": "MIT", + "peerDependencies": { + "@types/react": "*" + } + }, + "node_modules/@types/react-transition-group": { + "version": "4.4.12", + "resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.12.tgz", + "integrity": "sha512-8TV6R3h2j7a91c+1DXdJi3Syo69zzIZbz7Lg5tORM5LEJG7X/E6a1V3drRyBRZq7/utz7A+c4OgYLiLcYGHG6w==", + "license": "MIT", + "peerDependencies": { + "@types/react": "*" + } + }, + "node_modules/@types/webxr": { + "version": "0.5.24", + "resolved": "https://registry.npmjs.org/@types/webxr/-/webxr-0.5.24.tgz", + "integrity": "sha512-h8fgEd/DpoS9CBrjEQXR+dIDraopAEfu4wYVNY2tEPwk60stPWhvZMf4Foo5FakuQ7HFZoa8WceaWFervK2Ovg==", + "license": "MIT" + }, + "node_modules/@vitejs/plugin-react": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-6.1.0.tgz", + "integrity": "sha512-qd2BzUBehkov86WFhg0JkEFEYyCLG9uPCe6qWTY/kRlss9OvJrOF2UbIWT7p+8IzZHkEu0DNGHc4HSv+JdDLsw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@rolldown/pluginutils": "^1.0.1" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "peerDependencies": { + "@rolldown/plugin-babel": "^0.1.7 || ^0.2.0", + "babel-plugin-react-compiler": "^1.0.0", + "oxc-transform-react": "^0.145.0", + "vite": "^8.0.0" + }, + "peerDependenciesMeta": { + "@rolldown/plugin-babel": { + "optional": true + }, + "babel-plugin-react-compiler": { + "optional": true + }, + "oxc-transform-react": { + "optional": true + } + } + }, + "node_modules/babel-plugin-macros": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/babel-plugin-macros/-/babel-plugin-macros-3.1.0.tgz", + "integrity": "sha512-Cg7TFGpIr01vOQNODXOOaGz2NpCU5gl8x1qJFbb6hbZxR7XrcE2vtbAsTAbJ7/xwJtUuJEw8K8Zr/AE0LHlesg==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.12.5", + "cosmiconfig": "^7.0.0", + "resolve": "^1.19.0" + }, + "engines": { + "node": ">=10", + "npm": ">=6" + } + }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/clsx": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz", + "integrity": "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/convert-source-map": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", + "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==", + "license": "MIT" + }, + "node_modules/cosmiconfig": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.1.0.tgz", + "integrity": "sha512-AdmX6xUzdNASswsFtmwSt7Vj8po9IuqXm0UXz7QKPuEUmPB4XyjGfaAr2PSuELMwkRMVH1EpIkX5bTZGRB3eCA==", + "license": "MIT", + "dependencies": { + "@types/parse-json": "^4.0.0", + "import-fresh": "^3.2.1", + "parse-json": "^5.0.0", + "path-type": "^4.0.0", + "yaml": "^1.10.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/cosmiconfig/node_modules/yaml": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.3.tgz", + "integrity": "sha512-vIYeF1u3CjlhAFekPPAk2h/Kv4T3mAkMox5OymRiJQB0spDP10LHvt+K7G9Ny6NuuMAb25/6n1qyUjAcGNf/AA==", + "license": "ISC", + "engines": { + "node": ">= 6" + } + }, + "node_modules/csstype": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz", + "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", + "license": "MIT" + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/detect-libc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=8" + } + }, + "node_modules/dom-helpers": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-5.2.1.tgz", + "integrity": "sha512-nRCa7CK3VTrM2NmGkIy4cbK7IZlgBE/PYMn55rrXefr5xXDP0LdtfPnblFDoVdcAfslJ7or6iqAUnx0CCGIWQA==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.8.7", + "csstype": "^3.0.2" + } + }, + "node_modules/error-ex": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.4.tgz", + "integrity": "sha512-sqQamAnR14VgCr1A618A3sGrygcpK+HEbenA/HiEAkkUwcZIIB/tgWqHFxWgOyDh4nB4JCRimh79dR5Ywc9MDQ==", + "license": "MIT", + "dependencies": { + "is-arrayish": "^0.2.1" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/find-root": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/find-root/-/find-root-1.1.0.tgz", + "integrity": "sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng==", + "license": "MIT" + }, + "node_modules/flatbuffers": { + "version": "25.9.23", + "resolved": "https://registry.npmjs.org/flatbuffers/-/flatbuffers-25.9.23.tgz", + "integrity": "sha512-MI1qs7Lo4Syw0EOzUl0xjs2lsoeqFku44KpngfIduHBYvzm8h2+7K8YMQh1JtVVVrUvhLpNwqVi4DERegUJhPQ==", + "license": "Apache-2.0" + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/guid-typescript": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/guid-typescript/-/guid-typescript-1.0.9.tgz", + "integrity": "sha512-Y8T4vYhEfwJOTbouREvG+3XDsjr8E3kIr7uf+JZ0BYloFsttiHU0WfvANVsR7TxNUJa/WpCnw/Ino/p+DeBhBQ==", + "license": "ISC" + }, + "node_modules/hasown": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", + "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/hoist-non-react-statics": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", + "integrity": "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==", + "license": "BSD-3-Clause", + "dependencies": { + "react-is": "^16.7.0" + } + }, + "node_modules/hoist-non-react-statics/node_modules/react-is": { + "version": "16.13.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", + "license": "MIT" + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/import-fresh": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.1.tgz", + "integrity": "sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ==", + "license": "MIT", + "dependencies": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-arrayish": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==", + "license": "MIT" + }, + "node_modules/is-core-module": { + "version": "2.16.2", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.2.tgz", + "integrity": "sha512-evOr8xfXKxE6qSR0hSXL2r3sd7ALj8+7jQEUvPYcm5sgZFdJ+AYzT6yNmJenvIYQBgIGwfwz08sL8zoL7yq2BA==", + "license": "MIT", + "dependencies": { + "hasown": "^2.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/its-fine": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/its-fine/-/its-fine-2.0.0.tgz", + "integrity": "sha512-KLViCmWx94zOvpLwSlsx6yOCeMhZYaxrJV87Po5k/FoZzcPSahvK5qJ7fYhS61sZi5ikmh2S3Hz55A2l3U69ng==", + "license": "MIT", + "dependencies": { + "@types/react-reconciler": "^0.28.9" + }, + "peerDependencies": { + "react": "^19.0.0" + } + }, + "node_modules/js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "license": "MIT" + }, + "node_modules/jsesc": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", + "integrity": "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==", + "license": "MIT", + "bin": { + "jsesc": "bin/jsesc" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/json-parse-even-better-errors": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", + "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", + "license": "MIT" + }, + "node_modules/lightningcss": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", + "integrity": "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==", + "dev": true, + "license": "MPL-2.0", + "dependencies": { + "detect-libc": "^2.0.3" + }, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "lightningcss-android-arm64": "1.33.0", + "lightningcss-darwin-arm64": "1.33.0", + "lightningcss-darwin-x64": "1.33.0", + "lightningcss-freebsd-x64": "1.33.0", + "lightningcss-linux-arm-gnueabihf": "1.33.0", + "lightningcss-linux-arm64-gnu": "1.33.0", + "lightningcss-linux-arm64-musl": "1.33.0", + "lightningcss-linux-x64-gnu": "1.33.0", + "lightningcss-linux-x64-musl": "1.33.0", + "lightningcss-win32-arm64-msvc": "1.33.0", + "lightningcss-win32-x64-msvc": "1.33.0" + } + }, + "node_modules/lightningcss-android-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.33.0.tgz", + "integrity": "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.33.0.tgz", + "integrity": "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.33.0.tgz", + "integrity": "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-freebsd-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.33.0.tgz", + "integrity": "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm-gnueabihf": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.33.0.tgz", + "integrity": "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.33.0.tgz", + "integrity": "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.33.0.tgz", + "integrity": "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.33.0.tgz", + "integrity": "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.33.0.tgz", + "integrity": "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-arm64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.33.0.tgz", + "integrity": "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-x64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.33.0.tgz", + "integrity": "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lines-and-columns": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", + "integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==", + "license": "MIT" + }, + "node_modules/long": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", + "integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==", + "license": "Apache-2.0" + }, + "node_modules/loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "license": "MIT", + "dependencies": { + "js-tokens": "^3.0.0 || ^4.0.0" + }, + "bin": { + "loose-envify": "cli.js" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/nanoid": { + "version": "3.3.18", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.18.tgz", + "integrity": "sha512-DTg4MJbGMWkfi6VZFdNt2/caMbQy4Ou+Op/hJQvGEWcnVfoA1QA+xzRKAzw9jD6+GVOOeYr/mIcuDSdug6F6+w==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/onnxruntime-common": { + "version": "1.27.0", + "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.27.0.tgz", + "integrity": "sha512-3KxL5wIVqa8Ex08jxSzncm9CMgw8CjOFyOQ7SxvG9o0cVLlhTNKXyIQuTbtX4tGPJEf73OER2xrjt4HJSBL4ow==", + "license": "MIT" + }, + "node_modules/onnxruntime-web": { + "version": "1.27.0", + "resolved": "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.27.0.tgz", + "integrity": "sha512-ogDLsqIozHZwifPuN37OproAo0byX6t43/bP8GzeZWBWD6MOGExswFAx3up4NS/vvWBOg2u2PXomDt3rMmdQSg==", + "license": "MIT", + "dependencies": { + "flatbuffers": "^25.1.24", + "guid-typescript": "^1.0.9", + "long": "^5.2.3", + "onnxruntime-common": "1.27.0", + "platform": "^1.3.6", + "protobufjs": "^7.2.4" + } + }, + "node_modules/parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "license": "MIT", + "dependencies": { + "callsites": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/parse-json": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz", + "integrity": "sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==", + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^7.0.0", + "error-ex": "^1.3.1", + "json-parse-even-better-errors": "^2.3.0", + "lines-and-columns": "^1.1.6" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "license": "MIT" + }, + "node_modules/path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.5.tgz", + "integrity": "sha512-RvwwcruNjI1ncT5xRakeyS9Lf8lcItv34KD+aif+VH9kduAyfYBipGh12274xtenIPZ119/R9BdTBa8gAwSh0A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/platform": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz", + "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==", + "license": "MIT" + }, + "node_modules/postcss": { + "version": "8.5.26", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.26.tgz", + "integrity": "sha512-u82N74LFzG8ca+dD8puPnplTXoGH4fTPpVGuIbt36G3qvNlkvfD0lEAZSxaly3KX8TS/L1A1gsCEmvKmBcVbkQ==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.17", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.1" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/prop-types": { + "version": "15.8.1", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", + "integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==", + "license": "MIT", + "dependencies": { + "loose-envify": "^1.4.0", + "object-assign": "^4.1.1", + "react-is": "^16.13.1" + } + }, + "node_modules/prop-types/node_modules/react-is": { + "version": "16.13.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", + "license": "MIT" + }, + "node_modules/protobufjs": { + "version": "7.6.6", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.6.6.tgz", + "integrity": "sha512-dYDWdjSl5RNb7SgPxGQcRU+GtvP7s2fpkrY0r432PcOIaZ0/rBcxEZnQN67iJhFuQiVw754JDoPruPCNdGsbjg==", + "hasInstallScript": true, + "license": "BSD-3-Clause", + "dependencies": { + "@protobufjs/aspromise": "^1.1.2", + "@protobufjs/base64": "^1.1.2", + "@protobufjs/codegen": "^2.0.5", + "@protobufjs/eventemitter": "^1.1.1", + "@protobufjs/fetch": "^1.1.1", + "@protobufjs/float": "^1.0.2", + "@protobufjs/path": "^1.1.2", + "@protobufjs/pool": "^1.1.0", + "@protobufjs/utf8": "^1.1.1", + "@types/node": ">=13.7.0", + "long": "^5.3.2" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/react": { + "version": "19.2.8", + "resolved": "https://registry.npmjs.org/react/-/react-19.2.8.tgz", + "integrity": "sha512-PWaYA1L/q9u2u7xYQi+Y3L3Yfnie7XyLeaJICV1MGD6LprsBxcAqGjYyr0eY3p+QdsA+x/Irkt4Qif8D63+Sbw==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/react-dom": { + "version": "19.2.8", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.8.tgz", + "integrity": "sha512-rVprimfGBG3DR+Tq0IQG2DT5PxKth1WIGDmj5yPmlzr4YBe7uyE+Du4oVqTDXZSHGGGXRtTJEGSSePyQCMBglQ==", + "license": "MIT", + "dependencies": { + "scheduler": "^0.27.0" + }, + "peerDependencies": { + "react": "^19.2.8" + } + }, + "node_modules/react-is": { + "version": "19.2.8", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-19.2.8.tgz", + "integrity": "sha512-s5un28nYxKJw5gvUHyW5PCC28CvBqLu9r3cWgzHT4Vo/5fqqkFcdRYsGcKf50WMPpjjFZS5d76fn3YCo2njKwQ==", + "license": "MIT" + }, + "node_modules/react-transition-group": { + "version": "4.4.5", + "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.5.tgz", + "integrity": "sha512-pZcd1MCJoiKiBR2NRxeCRg13uCXbydPnmB4EOeRrY7480qNWO8IIgQG6zlDkm6uRMsURXPuKq0GWtiM59a5Q6g==", + "license": "BSD-3-Clause", + "dependencies": { + "@babel/runtime": "^7.5.5", + "dom-helpers": "^5.0.1", + "loose-envify": "^1.4.0", + "prop-types": "^15.6.2" + }, + "peerDependencies": { + "react": ">=16.6.0", + "react-dom": ">=16.6.0" + } + }, + "node_modules/react-use-measure": { + "version": "2.1.7", + "resolved": "https://registry.npmjs.org/react-use-measure/-/react-use-measure-2.1.7.tgz", + "integrity": "sha512-KrvcAo13I/60HpwGO5jpW7E9DfusKyLPLvuHlUyP5zqnmAPhNc6qTRjUQrdTADl0lpPpDVU2/Gg51UlOGHXbdg==", + "license": "MIT", + "peerDependencies": { + "react": ">=16.13", + "react-dom": ">=16.13" + }, + "peerDependenciesMeta": { + "react-dom": { + "optional": true + } + } + }, + "node_modules/resolve": { + "version": "1.22.12", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.12.tgz", + "integrity": "sha512-TyeJ1zif53BPfHootBGwPRYT1RUt6oGWsaQr8UyZW/eAm9bKoijtvruSDEmZHm92CwS9nj7/fWttqPCgzep8CA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "is-core-module": "^2.16.1", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/rolldown": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.5.tgz", + "integrity": "sha512-VD2IE5PUG4Oj8zz2VGykiYd5wbnjdIiSsNQb8Qu5B+noEp+A78mu2iVvpp27g8es14Tk9rofNs5Tku9iQCS4fA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@oxc-project/types": "=0.146.0", + "@rolldown/pluginutils": "^1.0.0" + }, + "bin": { + "rolldown": "bin/cli.mjs" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "optionalDependencies": { + "@rolldown/binding-android-arm-eabi": "1.2.5", + "@rolldown/binding-android-arm64": "1.2.5", + "@rolldown/binding-darwin-arm64": "1.2.5", + "@rolldown/binding-darwin-x64": "1.2.5", + "@rolldown/binding-freebsd-x64": "1.2.5", + "@rolldown/binding-linux-arm-gnueabihf": "1.2.5", + "@rolldown/binding-linux-arm64-gnu": "1.2.5", + "@rolldown/binding-linux-arm64-musl": "1.2.5", + "@rolldown/binding-linux-ppc64-gnu": "1.2.5", + "@rolldown/binding-linux-s390x-gnu": "1.2.5", + "@rolldown/binding-linux-x64-gnu": "1.2.5", + "@rolldown/binding-linux-x64-musl": "1.2.5", + "@rolldown/binding-openharmony-arm64": "1.2.5", + "@rolldown/binding-win32-arm64-msvc": "1.2.5", + "@rolldown/binding-win32-x64-msvc": "1.2.5" + } + }, + "node_modules/scheduler": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz", + "integrity": "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q==", + "license": "MIT" + }, + "node_modules/source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/source-map-js": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", + "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/stylis": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/stylis/-/stylis-4.2.0.tgz", + "integrity": "sha512-Orov6g6BB1sDfYgzWfTHDOxamtX1bE/zo104Dh9e6fqJ3PooipYyfJ0pUmrZO2wAvO8YbEyeFrkV91XTsGMSrw==", + "license": "MIT" + }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/suspend-react": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/suspend-react/-/suspend-react-0.1.3.tgz", + "integrity": "sha512-aqldKgX9aZqpoDp3e8/BZ8Dm7x1pJl+qI3ZKxDN0i/IQTWUwBx/ManmlVJ3wowqbno6c2bmiIfs+Um6LbsjJyQ==", + "license": "MIT", + "peerDependencies": { + "react": ">=17.0" + } + }, + "node_modules/three": { + "version": "0.164.1", + "resolved": "https://registry.npmjs.org/three/-/three-0.164.1.tgz", + "integrity": "sha512-iC/hUBbl1vzFny7f5GtqzVXYjMJKaTPxiCxXfrvVdBi1Sf+jhd1CAkitiFwC7mIBFCo3MrDLJG97yisoaWig0w==", + "license": "MIT" + }, + "node_modules/tinyglobby": { + "version": "0.2.17", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", + "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/trystero": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/trystero/-/trystero-0.25.3.tgz", + "integrity": "sha512-mm6Mzmm10OXKfvOA0tUG6XXqlQDIPdHg0//mEqA4ayrtdqiie4ZQpSluEp6074L+dCtotCfCn/B/CWLWavZK6Q==", + "license": "MIT", + "dependencies": { + "@trystero-p2p/nostr": "0.25.3" + } + }, + "node_modules/undici-types": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.3.0.tgz", + "integrity": "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==", + "license": "MIT" + }, + "node_modules/use-sync-external-store": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz", + "integrity": "sha512-Pp6GSwGP/NrPIrxVFAIkOQeyw8lFenOHijQWkUTrDvrF4ALqylP2C/KCkeS9dpUM3KvYRQhna5vt7IL95+ZQ9w==", + "license": "MIT", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, + "node_modules/vite": { + "version": "8.2.2", + "resolved": "https://registry.npmjs.org/vite/-/vite-8.2.2.tgz", + "integrity": "sha512-cFKLV/PRgAUlIRm5WjMjJ86jrftzpqcgH+Us+DS8mI3CDNiH30Whrz8uHL3+MOLPAgqbMBAqWdAHAphOAM+z/Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "lightningcss": "^1.33.0", + "picomatch": "^4.0.5", + "postcss": "^8.5.26", + "rolldown": "~1.2.4", + "tinyglobby": "^0.2.17" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "@vitejs/devtools": "^0.4.0 || ^0.5.0", + "esbuild": "^0.27.0 || ^0.28.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "@vitejs/devtools": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/zustand": { + "version": "5.0.15", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-5.0.15.tgz", + "integrity": "sha512-MpSEjRiBkA9crSYeOUH32rJC7SVqAbm0Fqcqge/bUi2PPoLcBWKOsG+C8mevmpr8TwXHBVkChbbJiyvkE+i/3A==", + "license": "MIT", + "engines": { + "node": ">=12.20.0" + }, + "peerDependencies": { + "@types/react": ">=18.0.0", + "immer": ">=9.0.6", + "react": ">=18.0.0", + "use-sync-external-store": ">=1.2.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "immer": { + "optional": true + }, + "react": { + "optional": true + }, + "use-sync-external-store": { + "optional": true + } + } + } + } +} diff --git a/app/package.json b/app/package.json new file mode 100644 index 0000000..2302af7 --- /dev/null +++ b/app/package.json @@ -0,0 +1,29 @@ +{ + "name": "microduck-sandbox", + "private": true, + "version": "1.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "test": "node --test \"test/**/*.test.js\"", + "build": "vite build", + "preview": "vite preview" + }, + "dependencies": { + "@emotion/react": "^11.14.0", + "@emotion/styled": "^11.14.1", + "@mui/material": "^9.3.1", + "@mujoco/mujoco": "^3.11.0", + "@react-three/fiber": "^9.7.0", + "onnxruntime-web": "^1.27.0", + "react": "^19.2.8", + "react-dom": "^19.2.8", + "three": "^0.164.1", + "trystero": "^0.25.3", + "zustand": "^5.0.15" + }, + "devDependencies": { + "@vitejs/plugin-react": "^6.1.0", + "vite": "^8.2.2" + } +} diff --git a/app/public/assets/duck-head-mark-open.webp b/app/public/assets/duck-head-mark-open.webp new file mode 100644 index 0000000..a00b7cc --- /dev/null +++ b/app/public/assets/duck-head-mark-open.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e4c51525c4c79a82c9c7a32be1632e7488ed8d6119068375095ba6f8e8d06c94 +size 40026 diff --git a/app/public/assets/duck-head-mark.webp b/app/public/assets/duck-head-mark.webp new file mode 100644 index 0000000..720f57a --- /dev/null +++ b/app/public/assets/duck-head-mark.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ad08b60991fa0568409a68001d53868341d55179c757007831ad8000cc1f96bd +size 32622 diff --git a/app/public/assets/microduck-wordmark.svg b/app/public/assets/microduck-wordmark.svg new file mode 100644 index 0000000..213ee79 --- /dev/null +++ b/app/public/assets/microduck-wordmark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/public/assets/props/arcade.glb b/app/public/assets/props/arcade.glb new file mode 100644 index 0000000..18bf379 --- /dev/null +++ b/app/public/assets/props/arcade.glb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1343e6a6851f8f09f91d746c2e0ff030fbf2abeacc3d06b41906fe3200a7704e +size 498180 diff --git a/app/public/assets/props/boombox.glb b/app/public/assets/props/boombox.glb new file mode 100644 index 0000000..210bb15 --- /dev/null +++ b/app/public/assets/props/boombox.glb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7089c3838d8e257b206c0fbc890ae434ca1796686fba3d46a3819c6496295177 +size 258308 diff --git a/app/public/assets/props/crt-tv.glb b/app/public/assets/props/crt-tv.glb new file mode 100644 index 0000000..a64d5fa --- /dev/null +++ b/app/public/assets/props/crt-tv.glb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:92f024ca18c6d52052136ac22a516fb50adc8a4621b6dd833810afca23518a78 +size 170156 diff --git a/app/public/assets/props/dartboard.glb b/app/public/assets/props/dartboard.glb new file mode 100644 index 0000000..869d18b --- /dev/null +++ b/app/public/assets/props/dartboard.glb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:191cacd006611b00e82fae8ed20f6fd6c6c004c2b36d217951ad277207f2aeeb +size 241448 diff --git a/app/public/assets/props/lavalamp.glb b/app/public/assets/props/lavalamp.glb new file mode 100644 index 0000000..7ef957f --- /dev/null +++ b/app/public/assets/props/lavalamp.glb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:edd9d7f31ec2128d84c8c34d42ed9e3149c1a43d5af9d8b9eb0aadfb56f53459 +size 93984 diff --git a/app/public/assets/props/segaconsole.glb b/app/public/assets/props/segaconsole.glb new file mode 100644 index 0000000..341f4ec --- /dev/null +++ b/app/public/assets/props/segaconsole.glb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a9856ef7b628b2b20347fbfb87c8ccba3188a0f83c43945e45edd049bcff6fe3 +size 213776 diff --git a/app/public/assets/props/skateboard.glb b/app/public/assets/props/skateboard.glb new file mode 100644 index 0000000..9c07003 --- /dev/null +++ b/app/public/assets/props/skateboard.glb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:23f4e8164a243ff6ce33022ad8109d129b3cb7d703afab51d05e2ff0a560e760 +size 256724 diff --git a/app/public/assets/props/sneakers.glb b/app/public/assets/props/sneakers.glb new file mode 100644 index 0000000..0098746 --- /dev/null +++ b/app/public/assets/props/sneakers.glb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1dd5160f94716bcbc8c0c35eefd80aa3395f10ae2f8abb22fdb1938e60377786 +size 259280 diff --git a/app/public/assets/props/walkman.glb b/app/public/assets/props/walkman.glb new file mode 100644 index 0000000..ee67755 --- /dev/null +++ b/app/public/assets/props/walkman.glb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9c1a34e840d8722ba6e39beaff4614e1e463fda4eb55e918779f4dc69987f54 +size 152704 diff --git a/app/public/assets/sfx/click_a.wav b/app/public/assets/sfx/click_a.wav new file mode 100644 index 0000000..22a64b8 --- /dev/null +++ b/app/public/assets/sfx/click_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f32c69bad5518fc3c04fac976b3d50579acfe0699512c8ceee91140338add875 +size 590 diff --git a/app/public/assets/sfx/click_b.wav b/app/public/assets/sfx/click_b.wav new file mode 100644 index 0000000..9c5818b --- /dev/null +++ b/app/public/assets/sfx/click_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4edce0301e1be6d384a20384d6059fa589af454cd1f31b94bef0c2bf7c349bef +size 1038 diff --git a/app/public/assets/sfx/step_a.wav b/app/public/assets/sfx/step_a.wav new file mode 100644 index 0000000..1f6d0d5 --- /dev/null +++ b/app/public/assets/sfx/step_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a6afd9783e72a73276e975d5baba29845835fa326002c31546651f0f6dfb6ebd +size 4622 diff --git a/app/public/assets/sfx/step_b.wav b/app/public/assets/sfx/step_b.wav new file mode 100644 index 0000000..0b7df78 --- /dev/null +++ b/app/public/assets/sfx/step_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2ea5271e219a8c2bc91ec9e253b71714b22e44a7f3e3fd1f5c33cea3435118a7 +size 4698 diff --git a/app/public/assets/sfx/step_c.wav b/app/public/assets/sfx/step_c.wav new file mode 100644 index 0000000..47c6cf2 --- /dev/null +++ b/app/public/assets/sfx/step_c.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a3bdc8a240a9d20b1215e7d24787e0c478373fcf02c4971c919151dbb7113ef4 +size 4924 diff --git a/app/public/assets/sfx/step_d.wav b/app/public/assets/sfx/step_d.wav new file mode 100644 index 0000000..1659948 --- /dev/null +++ b/app/public/assets/sfx/step_d.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bad640d37d62a21589aa363dcfc763546bd548da260ec371841dcfb2f47ee2a5 +size 4824 diff --git a/app/public/assets/sfx/step_e.wav b/app/public/assets/sfx/step_e.wav new file mode 100644 index 0000000..5deef4d --- /dev/null +++ b/app/public/assets/sfx/step_e.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2b06c21370d2ffffad065cb0b1a6c54343ec130b9073d291769d24f6ca60e3bb +size 4994 diff --git a/app/public/assets/sfx/thump_a.wav b/app/public/assets/sfx/thump_a.wav new file mode 100644 index 0000000..49b87bd --- /dev/null +++ b/app/public/assets/sfx/thump_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8fc501c13cb17d31b5db880c12326848a09afbdf194b771afbdcefd922a5607f +size 19066 diff --git a/app/public/assets/sfx/thump_b.wav b/app/public/assets/sfx/thump_b.wav new file mode 100644 index 0000000..fbb852d --- /dev/null +++ b/app/public/assets/sfx/thump_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27597d19b0ffc351f0a56b83c8ea7a76aae3c97e6aeb4a9fdb57ebe0400cfe81 +size 17794 diff --git a/app/public/assets/sfx/thump_c.wav b/app/public/assets/sfx/thump_c.wav new file mode 100644 index 0000000..51d8329 --- /dev/null +++ b/app/public/assets/sfx/thump_c.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:46205843156b8d4923ed392f213ccc2a326b67881b3f67dc4c082958a52fdf4f +size 23954 diff --git a/app/public/assets/stickers/bang-red.webp b/app/public/assets/stickers/bang-red.webp new file mode 100644 index 0000000..3c08e7f --- /dev/null +++ b/app/public/assets/stickers/bang-red.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9ad4baa5430230a2d5e982c54dac279a86f479ffca3763932b943075a3d9a122 +size 44386 diff --git a/app/public/assets/stickers/boom.webp b/app/public/assets/stickers/boom.webp new file mode 100644 index 0000000..4571822 --- /dev/null +++ b/app/public/assets/stickers/boom.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81083452beb521d1e304540534d20525c19f46102c4ef63e951f685cab61bfcc +size 44314 diff --git a/app/public/assets/stickers/burst-yellow.webp b/app/public/assets/stickers/burst-yellow.webp new file mode 100644 index 0000000..66096aa --- /dev/null +++ b/app/public/assets/stickers/burst-yellow.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b08865ed6ad01b10d54e0fb7ef0783c9d709fbe532cf99621ce789f12d213bfd +size 20162 diff --git a/app/public/assets/stickers/quack-quack.webp b/app/public/assets/stickers/quack-quack.webp new file mode 100644 index 0000000..a4e23bf --- /dev/null +++ b/app/public/assets/stickers/quack-quack.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3608b49bda042808ca69c75bddfed14226867bab741f18b186059ecd3e5e0b08 +size 32972 diff --git a/app/public/assets/stickers/quack.webp b/app/public/assets/stickers/quack.webp new file mode 100644 index 0000000..64c0b62 --- /dev/null +++ b/app/public/assets/stickers/quack.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:289e830372b197078e2d3f9e0ab1d8ae7d941895e73e1037d6b5e7871f1fe64f +size 39484 diff --git a/app/public/assets/stickers/shooting-star.webp b/app/public/assets/stickers/shooting-star.webp new file mode 100644 index 0000000..f9d2856 --- /dev/null +++ b/app/public/assets/stickers/shooting-star.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f31230606d12fc64af7c4d6a39efb339e36ae81eb79caa297ec4e0ebc7c073c5 +size 26220 diff --git a/app/public/assets/stickers/star-yellow.webp b/app/public/assets/stickers/star-yellow.webp new file mode 100644 index 0000000..99f9840 --- /dev/null +++ b/app/public/assets/stickers/star-yellow.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:93ee62a3e5e697c4dc7af15a00a24919c81c940f56c53cc730caf9eae110cf77 +size 10466 diff --git a/app/public/assets/stickers/wave.webp b/app/public/assets/stickers/wave.webp new file mode 100644 index 0000000..31c61a5 --- /dev/null +++ b/app/public/assets/stickers/wave.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eb115e0f06dcc7d6e86b63052bb52e5d2568186138cff09d801106cc5ab6d607 +size 41602 diff --git a/app/public/assets/stickers/ziouuu.webp b/app/public/assets/stickers/ziouuu.webp new file mode 100644 index 0000000..e22f029 --- /dev/null +++ b/app/public/assets/stickers/ziouuu.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:737f020f74e1cbe3b0b0d9e58de38cf5c5ea0be8b5ee872313aad7cb0673b441 +size 35972 diff --git a/app/public/assets/voices/duck1/chirp_a.wav b/app/public/assets/voices/duck1/chirp_a.wav new file mode 100644 index 0000000..2c3a5e1 --- /dev/null +++ b/app/public/assets/voices/duck1/chirp_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:450d807c1e6f535f30a1e50491df9b57567b8b8be357148de731de8b7582c8c2 +size 5336 diff --git a/app/public/assets/voices/duck1/chirp_b.wav b/app/public/assets/voices/duck1/chirp_b.wav new file mode 100644 index 0000000..9d27b4c --- /dev/null +++ b/app/public/assets/voices/duck1/chirp_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:660fa601e43eb7f05e67903446ccb11b9205bec31fdf4695a824c885e1da621e +size 5510 diff --git a/app/public/assets/voices/duck1/chirp_c.wav b/app/public/assets/voices/duck1/chirp_c.wav new file mode 100644 index 0000000..fca146b --- /dev/null +++ b/app/public/assets/voices/duck1/chirp_c.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2451a1286f28eaa5f54875c54486e03dd234c425c70c62ecc35c37f1bc745fc8 +size 8658 diff --git a/app/public/assets/voices/duck1/chirp_d.wav b/app/public/assets/voices/duck1/chirp_d.wav new file mode 100644 index 0000000..823c3c6 --- /dev/null +++ b/app/public/assets/voices/duck1/chirp_d.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:070253cd8fd2323226677935a6a7f6bb664e556a2292493e9269c8bc50cda188 +size 11002 diff --git a/app/public/assets/voices/duck1/chirp_e.wav b/app/public/assets/voices/duck1/chirp_e.wav new file mode 100644 index 0000000..de5e7af --- /dev/null +++ b/app/public/assets/voices/duck1/chirp_e.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9f0225bf39edae00420250f26610b923ca369eacaae97d775ca6e0d68d0789f2 +size 7214 diff --git a/app/public/assets/voices/duck1/chirp_f.wav b/app/public/assets/voices/duck1/chirp_f.wav new file mode 100644 index 0000000..1da4fa3 --- /dev/null +++ b/app/public/assets/voices/duck1/chirp_f.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:41bb6b9105669e0d297ab4e396491ff4798d0092c9f67911858cc970bb6e2fee +size 6460 diff --git a/app/public/assets/voices/duck1/chirp_g.wav b/app/public/assets/voices/duck1/chirp_g.wav new file mode 100644 index 0000000..b65ff9f --- /dev/null +++ b/app/public/assets/voices/duck1/chirp_g.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c33fe26fc9491564c12a2ab4d49da7d5502d02e097067e1ca7b5e48078a5f2c8 +size 11068 diff --git a/app/public/assets/voices/duck1/chirp_h.wav b/app/public/assets/voices/duck1/chirp_h.wav new file mode 100644 index 0000000..9da2253 --- /dev/null +++ b/app/public/assets/voices/duck1/chirp_h.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47a7a3b9d6e06b601daaa47c3426c5dab963c9a05bd9878ca39155fbe7a55f8b +size 10512 diff --git a/app/public/assets/voices/duck1/chirp_i.wav b/app/public/assets/voices/duck1/chirp_i.wav new file mode 100644 index 0000000..2ea673a --- /dev/null +++ b/app/public/assets/voices/duck1/chirp_i.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0114c825dec129ae02fbd2aacf0595497d919108865e25e57b6610dd2f41e270 +size 6578 diff --git a/app/public/assets/voices/duck1/chirp_j.wav b/app/public/assets/voices/duck1/chirp_j.wav new file mode 100644 index 0000000..56fc59e --- /dev/null +++ b/app/public/assets/voices/duck1/chirp_j.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a7a18a47c5a18d9fd21a78ea25dcb657feb7460680171357c5f123fc05ec454 +size 7278 diff --git a/app/public/assets/voices/duck1/chirp_k.wav b/app/public/assets/voices/duck1/chirp_k.wav new file mode 100644 index 0000000..9b2c87f --- /dev/null +++ b/app/public/assets/voices/duck1/chirp_k.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bd64c51c26fe8f311e41ef9e949ca5a47718b529ce973d32d9490b2a350c89db +size 9542 diff --git a/app/public/assets/voices/duck1/chirp_l.wav b/app/public/assets/voices/duck1/chirp_l.wav new file mode 100644 index 0000000..2a56104 --- /dev/null +++ b/app/public/assets/voices/duck1/chirp_l.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cecbff6accd2f0d525d302db9c6582d695e31e907bcee14bb82ede4db1d204e0 +size 8632 diff --git a/app/public/assets/voices/duck1/wheee_end_a.wav b/app/public/assets/voices/duck1/wheee_end_a.wav new file mode 100644 index 0000000..36005cd --- /dev/null +++ b/app/public/assets/voices/duck1/wheee_end_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0617f06a8eddd65d7ce2a21c93e5487b812be4e2f6defd0c37fd9724523efd76 +size 23916 diff --git a/app/public/assets/voices/duck1/wheee_end_b.wav b/app/public/assets/voices/duck1/wheee_end_b.wav new file mode 100644 index 0000000..0fa67ac --- /dev/null +++ b/app/public/assets/voices/duck1/wheee_end_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:654cde4a30bb25f4dd80f357edb3fdc067c632f0aa4b779e6689e88a78c216d0 +size 21502 diff --git a/app/public/assets/voices/duck1/wheee_loop_a.wav b/app/public/assets/voices/duck1/wheee_loop_a.wav new file mode 100644 index 0000000..08c4eac --- /dev/null +++ b/app/public/assets/voices/duck1/wheee_loop_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca5316b7ca36637bb7d855798f98afbd4c74ec59d82ac1997a5d630bd617b54c +size 69248 diff --git a/app/public/assets/voices/duck1/wheee_loop_b.wav b/app/public/assets/voices/duck1/wheee_loop_b.wav new file mode 100644 index 0000000..b93d335 --- /dev/null +++ b/app/public/assets/voices/duck1/wheee_loop_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c242e7730b4d8ee14b76435ae4c3df97e765dce932b6b8c5efb8ab6ae129943e +size 79170 diff --git a/app/public/assets/voices/duck1/wheee_start_a.wav b/app/public/assets/voices/duck1/wheee_start_a.wav new file mode 100644 index 0000000..f43d3f1 --- /dev/null +++ b/app/public/assets/voices/duck1/wheee_start_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0d1d30e7966083df05e63478bed2e2edb5a399ac15ce255d5071c297fcddf412 +size 39870 diff --git a/app/public/assets/voices/duck1/wheee_start_b.wav b/app/public/assets/voices/duck1/wheee_start_b.wav new file mode 100644 index 0000000..fcacbe7 --- /dev/null +++ b/app/public/assets/voices/duck1/wheee_start_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:875dbd94dc37da1bbfecd112805b636167e6919d96ebb1df3e6cbe514c637e39 +size 34966 diff --git a/app/public/assets/voices/duck2/chirp_a.wav b/app/public/assets/voices/duck2/chirp_a.wav new file mode 100644 index 0000000..049e0d1 --- /dev/null +++ b/app/public/assets/voices/duck2/chirp_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9f7aa1decf578eab8c05b1fc2ed5205439d19541bf270d26762440d0a8ca0aa9 +size 8702 diff --git a/app/public/assets/voices/duck2/chirp_b.wav b/app/public/assets/voices/duck2/chirp_b.wav new file mode 100644 index 0000000..ef1b33a --- /dev/null +++ b/app/public/assets/voices/duck2/chirp_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2fa61541951c240fa9e94cfb3582bf61f6a57254b1233e6c7342b852474bd33e +size 7032 diff --git a/app/public/assets/voices/duck2/chirp_c.wav b/app/public/assets/voices/duck2/chirp_c.wav new file mode 100644 index 0000000..b14ee9b --- /dev/null +++ b/app/public/assets/voices/duck2/chirp_c.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ae92893fe916f96629c26ded93e71855fd0cee490c1690027ce0a19b3a29284 +size 16544 diff --git a/app/public/assets/voices/duck2/chirp_d.wav b/app/public/assets/voices/duck2/chirp_d.wav new file mode 100644 index 0000000..a8f7bdc --- /dev/null +++ b/app/public/assets/voices/duck2/chirp_d.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:971282d4fa0ab372713bc42bc510d03d6f033e8760e7592658cfec8c4ceace71 +size 10252 diff --git a/app/public/assets/voices/duck2/chirp_e.wav b/app/public/assets/voices/duck2/chirp_e.wav new file mode 100644 index 0000000..f2d8eb6 --- /dev/null +++ b/app/public/assets/voices/duck2/chirp_e.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1d662e8b23203d5622984e698e9ed67a749133416fee6ddc59a3552675259b9 +size 8972 diff --git a/app/public/assets/voices/duck2/chirp_f.wav b/app/public/assets/voices/duck2/chirp_f.wav new file mode 100644 index 0000000..5a33875 --- /dev/null +++ b/app/public/assets/voices/duck2/chirp_f.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d340696b480ae7cc2cc5b85de00741e86bd29ce766ad8eaa5f305726a079ae35 +size 8576 diff --git a/app/public/assets/voices/duck2/chirp_g.wav b/app/public/assets/voices/duck2/chirp_g.wav new file mode 100644 index 0000000..44f7482 --- /dev/null +++ b/app/public/assets/voices/duck2/chirp_g.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d79c3369e113a4323ec8afe3a4ca22b7a47e3867266af233974ff423d8fc134a +size 13824 diff --git a/app/public/assets/voices/duck2/chirp_h.wav b/app/public/assets/voices/duck2/chirp_h.wav new file mode 100644 index 0000000..ef76a67 --- /dev/null +++ b/app/public/assets/voices/duck2/chirp_h.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b04e48823c5b41f61c60633644bb3ffbf20611de9dcdc9bcdaff3c02ed5b2b5b +size 13046 diff --git a/app/public/assets/voices/duck2/chirp_i.wav b/app/public/assets/voices/duck2/chirp_i.wav new file mode 100644 index 0000000..11975e4 --- /dev/null +++ b/app/public/assets/voices/duck2/chirp_i.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d34507b77bbab2a1ca9a467c19089e4605c6836194bc4a56b2dbd1890ad0f487 +size 5716 diff --git a/app/public/assets/voices/duck2/chirp_j.wav b/app/public/assets/voices/duck2/chirp_j.wav new file mode 100644 index 0000000..12ca7d4 --- /dev/null +++ b/app/public/assets/voices/duck2/chirp_j.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e7c217684a7fb0f27acb3a06052c784f3a66f775122bb368c2be4c27a50ac3f2 +size 9098 diff --git a/app/public/assets/voices/duck2/chirp_k.wav b/app/public/assets/voices/duck2/chirp_k.wav new file mode 100644 index 0000000..f58f0fd --- /dev/null +++ b/app/public/assets/voices/duck2/chirp_k.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:00d2a8938313ea05addc67743d36dd21ba466601817c7ad891bd0ea15dfc1ec2 +size 11676 diff --git a/app/public/assets/voices/duck2/chirp_l.wav b/app/public/assets/voices/duck2/chirp_l.wav new file mode 100644 index 0000000..2f1a858 --- /dev/null +++ b/app/public/assets/voices/duck2/chirp_l.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1fc77cdb7c00e5ed7ebe618452c11c517b7f3f647dfaa70566896ec2bfae084 +size 13124 diff --git a/app/public/assets/voices/duck2/wheee_end_a.wav b/app/public/assets/voices/duck2/wheee_end_a.wav new file mode 100644 index 0000000..b371c64 --- /dev/null +++ b/app/public/assets/voices/duck2/wheee_end_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f8cde236043a3a0656aa6d6db61d2ff0dc6f653a04429aa298d2c8829513d427 +size 33064 diff --git a/app/public/assets/voices/duck2/wheee_end_b.wav b/app/public/assets/voices/duck2/wheee_end_b.wav new file mode 100644 index 0000000..6a07c37 --- /dev/null +++ b/app/public/assets/voices/duck2/wheee_end_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e9e767d1133bc6070ca8a212c633c19cee258e65df056c85b77f162308a1baf +size 39824 diff --git a/app/public/assets/voices/duck2/wheee_loop_a.wav b/app/public/assets/voices/duck2/wheee_loop_a.wav new file mode 100644 index 0000000..72206a7 --- /dev/null +++ b/app/public/assets/voices/duck2/wheee_loop_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6905ceca635fa23d164af335d09ef35043c5c50c3202e1737ea730a7289be118 +size 101852 diff --git a/app/public/assets/voices/duck2/wheee_loop_b.wav b/app/public/assets/voices/duck2/wheee_loop_b.wav new file mode 100644 index 0000000..ab4c1fe --- /dev/null +++ b/app/public/assets/voices/duck2/wheee_loop_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:90e92a91316b91a3b76e59647bc657fa5a40c3c92e9ab533388ddd2ad9455c1d +size 85670 diff --git a/app/public/assets/voices/duck2/wheee_start_a.wav b/app/public/assets/voices/duck2/wheee_start_a.wav new file mode 100644 index 0000000..310c2cc --- /dev/null +++ b/app/public/assets/voices/duck2/wheee_start_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c223b4be6572a0aeb5a5c27309bb91b0dc5d9fd238eeafde40526cf19bce4326 +size 48186 diff --git a/app/public/assets/voices/duck2/wheee_start_b.wav b/app/public/assets/voices/duck2/wheee_start_b.wav new file mode 100644 index 0000000..9f86a76 --- /dev/null +++ b/app/public/assets/voices/duck2/wheee_start_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b90a40207ee49e4bfbac25e72b6fb49b83acc01a9bcbbb6289a98e1f3e8c8b85 +size 50640 diff --git a/app/public/assets/voices/duck3/chirp_a.wav b/app/public/assets/voices/duck3/chirp_a.wav new file mode 100644 index 0000000..9dbe38d --- /dev/null +++ b/app/public/assets/voices/duck3/chirp_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ed6496a3208db4057f1547e2cc5c18a078d4200abdd1b564d7a502640448854 +size 5896 diff --git a/app/public/assets/voices/duck3/chirp_b.wav b/app/public/assets/voices/duck3/chirp_b.wav new file mode 100644 index 0000000..21f9229 --- /dev/null +++ b/app/public/assets/voices/duck3/chirp_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b701381ae6aaa98a46114ad96847fcd4b087a4b3f1f02b5f1f2bbda7219dd183 +size 8448 diff --git a/app/public/assets/voices/duck3/chirp_c.wav b/app/public/assets/voices/duck3/chirp_c.wav new file mode 100644 index 0000000..64d1233 --- /dev/null +++ b/app/public/assets/voices/duck3/chirp_c.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f4e678fe44d371931ce323495a2e9bf9957fda5a382526acc58c1a82cc3e9eef +size 13430 diff --git a/app/public/assets/voices/duck3/chirp_d.wav b/app/public/assets/voices/duck3/chirp_d.wav new file mode 100644 index 0000000..66dbc7a --- /dev/null +++ b/app/public/assets/voices/duck3/chirp_d.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6f52cab48cb6eb9566e40da17023d8365064848746be2b444786431e8d8bd092 +size 12864 diff --git a/app/public/assets/voices/duck3/chirp_e.wav b/app/public/assets/voices/duck3/chirp_e.wav new file mode 100644 index 0000000..a29647c --- /dev/null +++ b/app/public/assets/voices/duck3/chirp_e.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95f839d2c444acfa5bf823d9b8c65e84774f82650f4d8e3b5c7aa80cd4f242a0 +size 5496 diff --git a/app/public/assets/voices/duck3/chirp_f.wav b/app/public/assets/voices/duck3/chirp_f.wav new file mode 100644 index 0000000..03f4971 --- /dev/null +++ b/app/public/assets/voices/duck3/chirp_f.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f6e581b10f2b4e81f13ffa186f9761285e581dda161614008a922ed59f46079a +size 6528 diff --git a/app/public/assets/voices/duck3/chirp_g.wav b/app/public/assets/voices/duck3/chirp_g.wav new file mode 100644 index 0000000..647bf49 --- /dev/null +++ b/app/public/assets/voices/duck3/chirp_g.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f78916cbdc2065d914f20c509ef0157500d14d386c1d8e2be00c018a99a8e942 +size 17304 diff --git a/app/public/assets/voices/duck3/chirp_h.wav b/app/public/assets/voices/duck3/chirp_h.wav new file mode 100644 index 0000000..728fa87 --- /dev/null +++ b/app/public/assets/voices/duck3/chirp_h.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c9a4c5a0b36cc2e684b7e00e95f9e6ec02f6dc2799337a2cddb1e791f84278e2 +size 12524 diff --git a/app/public/assets/voices/duck3/chirp_i.wav b/app/public/assets/voices/duck3/chirp_i.wav new file mode 100644 index 0000000..7a46846 --- /dev/null +++ b/app/public/assets/voices/duck3/chirp_i.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4dc2ef2ce703297da12fbe5f9722236df4a5faa907142cfc00e56970c75bc445 +size 8418 diff --git a/app/public/assets/voices/duck3/chirp_j.wav b/app/public/assets/voices/duck3/chirp_j.wav new file mode 100644 index 0000000..392760b --- /dev/null +++ b/app/public/assets/voices/duck3/chirp_j.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:97931d92be70e1448d6bed56515b8ffb1a439a6e44ae6c35b8c5e3ae7b400c00 +size 5182 diff --git a/app/public/assets/voices/duck3/chirp_k.wav b/app/public/assets/voices/duck3/chirp_k.wav new file mode 100644 index 0000000..b5b6338 --- /dev/null +++ b/app/public/assets/voices/duck3/chirp_k.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d68b91b7b6ae44a24b693183587dd27f1c8d8e9c6fd94e0f5c7c0931d9f98f0 +size 17800 diff --git a/app/public/assets/voices/duck3/chirp_l.wav b/app/public/assets/voices/duck3/chirp_l.wav new file mode 100644 index 0000000..4e60860 --- /dev/null +++ b/app/public/assets/voices/duck3/chirp_l.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0f874aacabad93a0f706695874260dc421b3624e716ba4bfbc3e83e5ba840af6 +size 13884 diff --git a/app/public/assets/voices/duck3/wheee_end_a.wav b/app/public/assets/voices/duck3/wheee_end_a.wav new file mode 100644 index 0000000..293287d --- /dev/null +++ b/app/public/assets/voices/duck3/wheee_end_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b11c497576b4cc4e7e2e4988ba77b243e7370e4a59a201de88fee5010f3ff30 +size 35260 diff --git a/app/public/assets/voices/duck3/wheee_end_b.wav b/app/public/assets/voices/duck3/wheee_end_b.wav new file mode 100644 index 0000000..8ee9107 --- /dev/null +++ b/app/public/assets/voices/duck3/wheee_end_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:642f786a9c0f982190de8d9fa375c4bb02525cd637436249ea53fbff6f169bc1 +size 29742 diff --git a/app/public/assets/voices/duck3/wheee_loop_a.wav b/app/public/assets/voices/duck3/wheee_loop_a.wav new file mode 100644 index 0000000..d5136f3 --- /dev/null +++ b/app/public/assets/voices/duck3/wheee_loop_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aeb0c5f9410b4886dc6310cb3de55fac783fce382b5a52556a9ecfff1fdcd4e8 +size 98112 diff --git a/app/public/assets/voices/duck3/wheee_loop_b.wav b/app/public/assets/voices/duck3/wheee_loop_b.wav new file mode 100644 index 0000000..da64d6b --- /dev/null +++ b/app/public/assets/voices/duck3/wheee_loop_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:44436e417339efb1e99296e95ea40df24c15867fd1f6f75c94b40a018cafcc95 +size 80292 diff --git a/app/public/assets/voices/duck3/wheee_start_a.wav b/app/public/assets/voices/duck3/wheee_start_a.wav new file mode 100644 index 0000000..6efe424 --- /dev/null +++ b/app/public/assets/voices/duck3/wheee_start_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:499945accdcdc1ba5a2a307093026029f361b94dfbb5fa43a33d2da09dfa1d14 +size 45614 diff --git a/app/public/assets/voices/duck3/wheee_start_b.wav b/app/public/assets/voices/duck3/wheee_start_b.wav new file mode 100644 index 0000000..d733b8e --- /dev/null +++ b/app/public/assets/voices/duck3/wheee_start_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fe757d0491a06242c148cb518658700ff27a93868bf31c93b6a96a6240e3da7e +size 41362 diff --git a/app/public/assets/voices/duck4/chirp_a.wav b/app/public/assets/voices/duck4/chirp_a.wav new file mode 100644 index 0000000..b80fe56 --- /dev/null +++ b/app/public/assets/voices/duck4/chirp_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:356abe1da47758ab6df17954975123c53be79a9bcc919b5adf06d7ac8a602fb2 +size 7350 diff --git a/app/public/assets/voices/duck4/chirp_b.wav b/app/public/assets/voices/duck4/chirp_b.wav new file mode 100644 index 0000000..2d5a41c --- /dev/null +++ b/app/public/assets/voices/duck4/chirp_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:63c6dba54db0a001e7ed9376cdccb9bd47a9e255fa7fd909e2505dc9fd332193 +size 9116 diff --git a/app/public/assets/voices/duck4/chirp_c.wav b/app/public/assets/voices/duck4/chirp_c.wav new file mode 100644 index 0000000..eb8ea47 --- /dev/null +++ b/app/public/assets/voices/duck4/chirp_c.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:22804c3f59ff7eccef58aacbfd855fe9808f35cbe21ff4cd72264c2e30fd156a +size 13554 diff --git a/app/public/assets/voices/duck4/chirp_d.wav b/app/public/assets/voices/duck4/chirp_d.wav new file mode 100644 index 0000000..7424646 --- /dev/null +++ b/app/public/assets/voices/duck4/chirp_d.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8158e8e9d118037bd03bed4d564dd9e70b07ade5acf8cb56b7d52cbe77dc53cd +size 11580 diff --git a/app/public/assets/voices/duck4/chirp_e.wav b/app/public/assets/voices/duck4/chirp_e.wav new file mode 100644 index 0000000..6085461 --- /dev/null +++ b/app/public/assets/voices/duck4/chirp_e.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:836664d06509dbe43daddef6bd3415372774158145d950139b0e30f4057be41a +size 8552 diff --git a/app/public/assets/voices/duck4/chirp_f.wav b/app/public/assets/voices/duck4/chirp_f.wav new file mode 100644 index 0000000..10cd210 --- /dev/null +++ b/app/public/assets/voices/duck4/chirp_f.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2839e0865a5e42aff830b2d1ccf113fba60c28e403c42886ba1b1e5bd470ce52 +size 7752 diff --git a/app/public/assets/voices/duck4/chirp_g.wav b/app/public/assets/voices/duck4/chirp_g.wav new file mode 100644 index 0000000..2da6b26 --- /dev/null +++ b/app/public/assets/voices/duck4/chirp_g.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3ba26ccde31aafa4d43df34058da9a7b53aacdeaa847b2a9f12660b31a022a1e +size 12176 diff --git a/app/public/assets/voices/duck4/chirp_h.wav b/app/public/assets/voices/duck4/chirp_h.wav new file mode 100644 index 0000000..886e97b --- /dev/null +++ b/app/public/assets/voices/duck4/chirp_h.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:28231a6ec54e9fabf53c6add53987b8b946ded9b384e7d0af5a9bca5fe0c0f57 +size 13742 diff --git a/app/public/assets/voices/duck4/chirp_i.wav b/app/public/assets/voices/duck4/chirp_i.wav new file mode 100644 index 0000000..504174b --- /dev/null +++ b/app/public/assets/voices/duck4/chirp_i.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d028418fb90dcf2b91efb8bc034ac6a934a302e50243271cc9cd272f956d3810 +size 6604 diff --git a/app/public/assets/voices/duck4/chirp_j.wav b/app/public/assets/voices/duck4/chirp_j.wav new file mode 100644 index 0000000..80e85aa --- /dev/null +++ b/app/public/assets/voices/duck4/chirp_j.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e768b952f37f22c2852e06ae1c88ef84d662721b7b518204b79292fbd794b543 +size 6472 diff --git a/app/public/assets/voices/duck4/chirp_k.wav b/app/public/assets/voices/duck4/chirp_k.wav new file mode 100644 index 0000000..2c6386e --- /dev/null +++ b/app/public/assets/voices/duck4/chirp_k.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:80ccda91a3632145bfa6a750f8f1230ab59e94e541b82fb81c74810a56802c24 +size 17340 diff --git a/app/public/assets/voices/duck4/chirp_l.wav b/app/public/assets/voices/duck4/chirp_l.wav new file mode 100644 index 0000000..cef0720 --- /dev/null +++ b/app/public/assets/voices/duck4/chirp_l.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5a683cdb89ec94c655e900275a5afbd0a618e7523888d6bc681de4bbffe30f3d +size 11280 diff --git a/app/public/assets/voices/duck4/wheee_end_a.wav b/app/public/assets/voices/duck4/wheee_end_a.wav new file mode 100644 index 0000000..1eb0795 --- /dev/null +++ b/app/public/assets/voices/duck4/wheee_end_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:430f8b816b3ee0136f16b8089db353ad680b3856e9fc50ca043d32f13e6135fd +size 30588 diff --git a/app/public/assets/voices/duck4/wheee_end_b.wav b/app/public/assets/voices/duck4/wheee_end_b.wav new file mode 100644 index 0000000..9055c11 --- /dev/null +++ b/app/public/assets/voices/duck4/wheee_end_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50a75726a70c66f9b162452f600e29bd329e74952345e9d388dcac5114ebeb9c +size 41004 diff --git a/app/public/assets/voices/duck4/wheee_loop_a.wav b/app/public/assets/voices/duck4/wheee_loop_a.wav new file mode 100644 index 0000000..ffad47a --- /dev/null +++ b/app/public/assets/voices/duck4/wheee_loop_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d311e25fd5d5edbd5bb511b78afba9568f1d6d25e5e6bf4db4551c7163d82d60 +size 104542 diff --git a/app/public/assets/voices/duck4/wheee_loop_b.wav b/app/public/assets/voices/duck4/wheee_loop_b.wav new file mode 100644 index 0000000..77ba1c7 --- /dev/null +++ b/app/public/assets/voices/duck4/wheee_loop_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7bf9e869f057f1458a9c54adf9f7ed2cc0e736860687ae3fb3b60a998de3d0d1 +size 111594 diff --git a/app/public/assets/voices/duck4/wheee_start_a.wav b/app/public/assets/voices/duck4/wheee_start_a.wav new file mode 100644 index 0000000..a7622fa --- /dev/null +++ b/app/public/assets/voices/duck4/wheee_start_a.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:968670339047d1787dc5b1e1feb2050d60dfc076d9df10bf3b0c979f866dbe2f +size 58604 diff --git a/app/public/assets/voices/duck4/wheee_start_b.wav b/app/public/assets/voices/duck4/wheee_start_b.wav new file mode 100644 index 0000000..c31ec73 --- /dev/null +++ b/app/public/assets/voices/duck4/wheee_start_b.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9240c331d936d247d132a9a334145551dde01cd34d37aed67ba7ab7e94bd2aa5 +size 46872 diff --git a/app/public/policies/BEST_alpha_sitstand.onnx b/app/public/policies/BEST_alpha_sitstand.onnx new file mode 100644 index 0000000..6b26011 --- /dev/null +++ b/app/public/policies/BEST_alpha_sitstand.onnx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c6c40e35e726eabd803d633e090d112994f469921152448367953fbaf9799bc8 +size 793695 diff --git a/app/public/policies/BEST_alpha_stand.onnx b/app/public/policies/BEST_alpha_stand.onnx new file mode 100644 index 0000000..c5e77ae --- /dev/null +++ b/app/public/policies/BEST_alpha_stand.onnx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1569268713e40deea795dd2922dba50d3621e15a872855408b6b1b125b1c094b +size 793705 diff --git a/app/public/policies/BEST_alpha_walking.onnx b/app/public/policies/BEST_alpha_walking.onnx new file mode 100644 index 0000000..a43a72e --- /dev/null +++ b/app/public/policies/BEST_alpha_walking.onnx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e36332d383997d51401897734cd3e79cf5038406feddb18b4d57ecfb141daa6c +size 793705 diff --git a/app/public/policies/BEST_roller.onnx b/app/public/policies/BEST_roller.onnx new file mode 100644 index 0000000..89cbd63 --- /dev/null +++ b/app/public/policies/BEST_roller.onnx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cf05651d2708a2f9364212e86b866c97a70ace8131c492500105e8f28bf99afd +size 793685 diff --git a/app/public/policies/BEST_roller_crouch.onnx b/app/public/policies/BEST_roller_crouch.onnx new file mode 100644 index 0000000..e8406b9 --- /dev/null +++ b/app/public/policies/BEST_roller_crouch.onnx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1a084be240469c76ac9d3fa44d4792f16d4b1da60398b3ecd3cfc5e2244d990 +size 793685 diff --git a/app/public/policies/alpha_ground_pick.onnx b/app/public/policies/alpha_ground_pick.onnx new file mode 100644 index 0000000..3bc3882 --- /dev/null +++ b/app/public/policies/alpha_ground_pick.onnx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ffbf5109982ff999b0ba53afe86b9ae731bbec679d67fb7f8ab4c52152c88872 +size 793685 diff --git a/app/public/policies/ball_kick_left.onnx b/app/public/policies/ball_kick_left.onnx new file mode 100644 index 0000000..52d5b3e --- /dev/null +++ b/app/public/policies/ball_kick_left.onnx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d6928284dccd3dd61e08bf2f760effa74309fbefd97b2b31afb2a60f526d196a +size 793685 diff --git a/app/public/policies/ball_kick_right.onnx b/app/public/policies/ball_kick_right.onnx new file mode 100644 index 0000000..cecab18 --- /dev/null +++ b/app/public/policies/ball_kick_right.onnx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:147a32c388c6b19111b3ac3b550a9a6dc8b8bf267118af4d8c3712522eedb5af +size 793685 diff --git a/app/public/policies/roulade.onnx b/app/public/policies/roulade.onnx new file mode 100644 index 0000000..060c707 --- /dev/null +++ b/app/public/policies/roulade.onnx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d60da08fc13f29c1b57f41977aa898132c0d60042100149d8e775affcbca32b +size 793685 diff --git a/app/public/robot/mjlab/kinematics.json b/app/public/robot/mjlab/kinematics.json new file mode 100644 index 0000000..9090b3b --- /dev/null +++ b/app/public/robot/mjlab/kinematics.json @@ -0,0 +1,2013 @@ +{ + "bodies": [ + { + "name": "trunk_base", + "parent": null, + "pos": [ + 0.0, + 0.0, + 0.12 + ], + "quat": [ + 1.0, + 0.0, + 0.0, + 0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + 0.006, + 0.0175, + -0.005 + ], + "quat": [ + 1.0, + -0.0, + -0.0, + 0.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "right_shell.stl", + "pos": [ + 0.004, + -0.0005, + -0.0175 + ], + "quat": [ + 0.707107, + -0.0, + -0.0, + 0.707107 + ], + "color": [ + 0.8, + 0.8, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "banana_pcb_locker.stl", + "pos": [ + 0.0042, + -0.0, + -0.0175215 + ], + "quat": [ + 0.707107, + -0.0, + 0.0, + 0.707107 + ], + "color": [ + 0.647059, + 0.647059, + 0.647059, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "trunk_base.stl", + "pos": [ + 0.004, + -0.0, + -0.0175 + ], + "quat": [ + 0.707107, + -0.0, + -0.0, + 0.707107 + ], + "color": [ + 0.34902, + 0.376471, + 0.4, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.006, + 0.0175, + 0.0115 + ], + "quat": [ + 0.0, + 0.707107, + -0.0, + 0.707107 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "power_support.stl", + "pos": [ + 0.004, + -0.0, + -0.0175215 + ], + "quat": [ + 0.707107, + -0.0, + 0.0, + 0.707107 + ], + "color": [ + 0.901961, + 0.901961, + 0.901961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "np_f970.stl", + "pos": [ + -0.0359693, + 0.0, + -0.00385049 + ], + "quat": [ + 0.00617059, + 0.70708, + -0.70708, + -0.00617059 + ], + "color": [ + 0.901961, + 0.901961, + 0.901961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.006, + -0.0175, + 0.0115 + ], + "quat": [ + 0.0, + 0.707107, + -0.0, + 0.707107 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "left_shell.stl", + "pos": [ + 0.004, + -0.0, + -0.0175785 + ], + "quat": [ + 0.707107, + 0.0, + -0.0, + 0.707107 + ], + "color": [ + 0.8, + 0.8, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + 0.006, + -0.0175, + -0.005 + ], + "quat": [ + 1.0, + -0.0, + -0.0, + 0.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + } + ], + "joint": null + }, + { + "name": "yaw2roll", + "parent": "trunk_base", + "pos": [ + 0.006, + 0.0175, + -0.005 + ], + "quat": [ + 0.0, + -0.707107, + -0.707107, + -0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "yaw2roll.stl", + "pos": [ + -0.0175, + -0.002, + 0.0125 + ], + "quat": [ + 0.0, + 1.0, + 0.0, + 0.0 + ], + "color": [ + 0.647059, + 0.647059, + 0.647059, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + -0.0, + 0.0, + 0.0125 + ], + "quat": [ + 0.0, + -0.707107, + 0.707107, + -0.0 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + -0.0, + 0.0165, + 0.0125 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + -0.5 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "bearing_roll.stl", + "pos": [ + -0.0175, + -0.002, + 0.0125 + ], + "quat": [ + 0.0, + -1.0, + -0.0, + -0.0 + ], + "color": [ + 0.262745, + 0.282353, + 0.301961, + 1.0 + ] + } + ], + "joint": { + "name": "left_hip_yaw", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0.0, + 0.0, + 0.0 + ], + "range": [ + -0.4363323129985824, + 0.5235987755982988 + ], + "actuator_index": 0 + } + }, + { + "name": "hip_l", + "parent": "yaw2roll", + "pos": [ + 0.0, + 0.0165, + 0.0125 + ], + "quat": [ + 0.707107, + -0.707107, + -0.0, + -0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + 0.021, + 0.0, + -0.0185 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "hip_l.stl", + "pos": [ + -0.0175, + 0.0, + -0.0185 + ], + "quat": [ + 0.707107, + -0.707107, + 0.0, + -0.0 + ], + "color": [ + 0.901961, + 0.901961, + 0.901961, + 1.0 + ] + } + ], + "joint": { + "name": "left_hip_roll", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0.0, + 0.0, + 0.0 + ], + "range": [ + -0.3839724354387525, + 0.3839724354387525 + ], + "actuator_index": 1 + } + }, + { + "name": "upper_leg_left", + "parent": "hip_l", + "pos": [ + 0.025, + 0.0, + -0.0185 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + -0.5 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "upper_leg_left.stl", + "pos": [ + -0.0, + -0.0, + -0.0425 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.866667, + 0.866667, + 0.866667, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.022, + 0.0357771, + 0.0125 + ], + "quat": [ + 0.0, + -0.707107, + -0.0, + -0.707107 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "upper_leg_rigidity_plate.stl", + "pos": [ + 0.0, + -0.0, + -0.0425 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.537255, + 0.854902, + 0.827451, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + 0.022, + 0.0357771, + -0.004 + ], + "quat": [ + 0.0, + 0.0, + 0.0, + 1.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + -0.0, + -0.0, + 0.0125 + ], + "quat": [ + 0.5, + 0.5, + -0.5, + 0.5 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + } + ], + "joint": { + "name": "left_hip_pitch", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0.0, + 0.0, + 0.0 + ], + "range": [ + -1.570796326795005, + 1.5707963267947882 + ], + "actuator_index": 2 + } + }, + { + "name": "leg", + "parent": "upper_leg_left", + "pos": [ + 0.022, + 0.0357771, + -0.004 + ], + "quat": [ + 0.0, + 0.707107, + 0.707107, + 0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "leg.stl", + "pos": [ + -0.022, + 0.0357771, + 0.0385 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + -0.5 + ], + "color": [ + 0.811765, + 0.858824, + 0.898039, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.0, + 0.042, + -0.0115 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + } + ], + "joint": { + "name": "left_knee", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0.0, + 0.0, + 0.0 + ], + "range": [ + -1.570796326795012, + 1.570796326794781 + ], + "actuator_index": 3 + } + }, + { + "name": "ankle_left", + "parent": "leg", + "pos": [ + 0.0, + 0.042, + -0.026 + ], + "quat": [ + 0.0, + 1.0, + -0.0, + 0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "sole_left.stl", + "pos": [ + -0.022, + 0.00622291, + -0.0647 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.537255, + 0.854902, + 0.827451, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "foot_left.stl", + "pos": [ + -0.022, + 0.00622291, + -0.0647 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.980392, + 0.713725, + 0.00392157, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration_default.stl", + "pos": [ + 0.0, + 0.0, + -0.0322 + ], + "quat": [ + 0.0, + 0.0, + -0.0, + 1.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "ankle_left.stl", + "pos": [ + -0.022, + 0.00622291, + -0.0647 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.980392, + 0.713725, + 0.00392157, + 1.0 + ] + } + ], + "joint": { + "name": "left_ankle", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0.0, + 0.0, + 0.0 + ], + "range": [ + -1.5707963267949019, + 1.5707963267948912 + ], + "actuator_index": 4 + } + }, + { + "name": "neck", + "parent": "trunk_base", + "pos": [ + 0.026, + 0.0145, + 0.0324215 + ], + "quat": [ + 0.0, + 0.0, + 0.707107, + -0.707107 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "neck.stl", + "pos": [ + 0.022, + 0.05, + 0.028 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + -0.5 + ], + "color": [ + 0.8, + 0.8, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.0, + 0.0, + 0.0145 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.0, + -0.05, + 0.0145 + ], + "quat": [ + 0.5, + 0.5, + -0.5, + 0.5 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "neck.stl", + "pos": [ + 0.022, + 0.05, + 0.003 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + -0.5 + ], + "color": [ + 0.8, + 0.8, + 0.8, + 1.0 + ] + } + ], + "joint": { + "name": "neck_pitch", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0.0, + 0.0, + 0.0 + ], + "range": [ + -1.5707963267948966, + 1.0471975511965976 + ], + "actuator_index": 5 + } + }, + { + "name": "neck_pitch", + "parent": "neck", + "pos": [ + 0.0, + -0.05, + -0.0 + ], + "quat": [ + 0.0, + 1.0, + 0.0, + 0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "neck_pitch.stl", + "pos": [ + -0.0, + 0.0287931, + -0.0145 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.34902, + 0.376471, + 0.4, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + -0.0, + 0.0207931, + -0.0145 + ], + "quat": [ + 0.707107, + 0.707107, + 0.0, + 0.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + } + ], + "joint": { + "name": "head_pitch", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0.0, + 0.0, + 0.0 + ], + "range": [ + -1.5707963267948974, + 1.5707963267948957 + ], + "actuator_index": 6 + } + }, + { + "name": "yaw_roll_motion", + "parent": "neck_pitch", + "pos": [ + -0.0, + 0.0186931, + -0.0145 + ], + "quat": [ + 0.0, + 0.0, + -0.707107, + -0.707107 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "yaw_roll_motion.stl", + "pos": [ + 0.0, + 0.0, + 0.01 + ], + "quat": [ + 0.707107, + 0.0, + -0.0, + 0.707107 + ], + "color": [ + 0.768627, + 0.886275, + 0.952941, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.0, + 0.0, + 0.0145 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + -0.016, + 0.0, + 0.0145 + ], + "quat": [ + 0.707107, + -0.0, + -0.707107, + -0.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + 0.018, + 0.0, + 0.0145 + ], + "quat": [ + 0.707107, + -0.0, + -0.707107, + -0.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + } + ], + "joint": { + "name": "head_yaw", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0.0, + 0.0, + 0.0 + ], + "range": [ + -2.967059728390373, + 2.967059728390348 + ], + "actuator_index": 7 + } + }, + { + "name": "jaw_soft", + "parent": "yaw_roll_motion", + "pos": [ + -0.0179, + 0.0, + 0.0145 + ], + "quat": [ + 0.707107, + -0.0, + -0.707107, + -0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "lens.stl", + "pos": [ + 0.0155, + -9.13778e-05, + -0.05548 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + -0.5 + ], + "color": [ + 0.262745, + 0.282353, + 0.301961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "face_part.stl", + "pos": [ + -0.0045, + -9.13778e-05, + -0.0178 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.34902, + 0.376471, + 0.4, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.003, + 0.0255, + -0.018 + ], + "quat": [ + 0.707107, + 0.0, + -0.0, + -0.707107 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "jaw_soft.stl", + "pos": [ + -0.0046, + 0.0, + -0.0179996 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.85098, + 0.756863, + 0.866667, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "motor_support.stl", + "pos": [ + -0.0045, + 0.0, + -0.018 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.262745, + 0.282353, + 0.301961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "top_head_shell.stl", + "pos": [ + -0.0045, + -0.0, + -0.018 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.901961, + 0.901961, + 0.901961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.0, + 0.0, + 0.0145 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration_default.stl", + "pos": [ + 0.0032, + -0.04, + -0.018 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + 0.5 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "elec_rpi_robot_hat_pcb.stl", + "pos": [ + 0.02694, + 0.0289936, + -0.0519 + ], + "quat": [ + 0.707107, + 0.0, + 0.0, + -0.707107 + ], + "color": [ + 0.313725, + 0.486275, + 0.411765, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "soft_mouth_top.stl", + "pos": [ + -0.00420071, + 1.7776e-08, + -0.0180814 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.85098, + 0.756863, + 0.866667, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "noenoeil.stl", + "pos": [ + -0.0045, + -9.13778e-05, + -0.0178 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.262745, + 0.282353, + 0.301961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "jaw.stl", + "pos": [ + -0.0045, + 0.0, + -0.018 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.980392, + 0.713725, + 0.00392157, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "bottom_head_shell.stl", + "pos": [ + -0.0043, + -0.0, + -0.018 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.980392, + 0.713725, + 0.00392157, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "m12_lens_holder.stl", + "pos": [ + 0.0155, + -9.13778e-05, + -0.05558 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + -0.5 + ], + "color": [ + 0.262745, + 0.282353, + 0.301961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "pcb__raspberry_pi_zero_2_w.stl", + "pos": [ + 0.015435, + -1.13778e-05, + -0.06001 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + 0.5 + ], + "color": [ + 0.498039, + 0.498039, + 0.498039, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "speaker.stl", + "pos": [ + 0.01, + -0.016786, + 0.0260226 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.294118, + 0.290196, + 0.290196, + 1.0 + ] + } + ], + "joint": { + "name": "head_roll", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0.0, + 0.0, + 0.0 + ], + "range": [ + -0.43633231299859127, + 0.4363323129985735 + ], + "actuator_index": 8 + } + }, + { + "name": "bearing_roll", + "parent": "trunk_base", + "pos": [ + 0.006, + -0.0175, + -0.005 + ], + "quat": [ + 0.0, + 0.707107, + 0.707107, + 0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "yaw2roll.stl", + "pos": [ + -0.0175, + -0.002, + 0.0125 + ], + "quat": [ + 0.0, + 1.0, + 0.0, + 0.0 + ], + "color": [ + 0.647059, + 0.647059, + 0.647059, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + -0.0, + 0.0, + 0.0125 + ], + "quat": [ + 0.0, + -0.707107, + 0.707107, + -0.0 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "bearing_roll.stl", + "pos": [ + -0.0175, + -0.002, + 0.0125 + ], + "quat": [ + 0.0, + -1.0, + -0.0, + -0.0 + ], + "color": [ + 0.262745, + 0.282353, + 0.301961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + -0.0, + 0.0165, + 0.0125 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + -0.5 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + } + ], + "joint": { + "name": "right_hip_yaw", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0.0, + 0.0, + 0.0 + ], + "range": [ + -0.5235987755982988, + 0.4363323129985824 + ], + "actuator_index": 9 + } + }, + { + "name": "hip_l_2", + "parent": "bearing_roll", + "pos": [ + -0.0, + 0.0165, + 0.0125 + ], + "quat": [ + 0.0, + -0.0, + 0.707107, + 0.707107 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "hip_l.stl", + "pos": [ + -0.0175, + 0.0, + -0.0185 + ], + "quat": [ + 0.707107, + -0.707107, + -0.0, + -0.0 + ], + "color": [ + 0.901961, + 0.901961, + 0.901961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + 0.025, + 0.0, + -0.0185 + ], + "quat": [ + 0.5, + 0.5, + -0.5, + -0.5 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + } + ], + "joint": { + "name": "right_hip_roll", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0.0, + 0.0, + 0.0 + ], + "range": [ + -0.3839724354387525, + 0.3839724354387525 + ], + "actuator_index": 10 + } + }, + { + "name": "upper_leg_right", + "parent": "hip_l_2", + "pos": [ + 0.025, + 0.0, + -0.0185 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + -0.5 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + -0.022, + 0.0357771, + 0.0125 + ], + "quat": [ + 0.707107, + -0.0, + -0.707107, + -0.0 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + -0.022, + 0.0357771, + 0.0 + ], + "quat": [ + 0.0, + 1.0, + -0.0, + -0.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "upper_leg_rigidity_plate.stl", + "pos": [ + 0.0, + 0.0, + 0.0435 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + 0.5 + ], + "color": [ + 0.537255, + 0.854902, + 0.827451, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "upper_leg_right.stl", + "pos": [ + -0.0, + 0.0, + -0.0425 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + 0.5 + ], + "color": [ + 0.866667, + 0.866667, + 0.866667, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.0, + 0.0, + 0.0125 + ], + "quat": [ + 0.5, + 0.5, + -0.5, + 0.5 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + } + ], + "joint": { + "name": "right_hip_pitch", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0.0, + 0.0, + 0.0 + ], + "range": [ + -1.5707963267949268, + 1.5707963267948664 + ], + "actuator_index": 11 + } + }, + { + "name": "leg_2", + "parent": "upper_leg_right", + "pos": [ + -0.022, + 0.0357771, + -0.004 + ], + "quat": [ + 0.0, + 1.0, + -0.0, + -0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + -0.042, + 0.0, + -0.0115 + ], + "quat": [ + 0.707107, + -0.0, + -0.707107, + -0.0 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "leg.stl", + "pos": [ + -0.0357771, + -0.022, + 0.0385 + ], + "quat": [ + 0.707107, + 0.0, + 0.707107, + -0.0 + ], + "color": [ + 0.811765, + 0.858824, + 0.898039, + 1.0 + ] + } + ], + "joint": { + "name": "right_knee", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0.0, + 0.0, + 0.0 + ], + "range": [ + -1.570796326794932, + 1.570796326794861 + ], + "actuator_index": 12 + } + }, + { + "name": "ankle_right", + "parent": "leg_2", + "pos": [ + -0.042, + 0.0, + -0.026 + ], + "quat": [ + 0.0, + -0.707107, + -0.707107, + 0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "ankle_right.stl", + "pos": [ + 0.022, + 0.00622291, + -0.0647 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + 0.5 + ], + "color": [ + 0.980392, + 0.713725, + 0.00392157, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "sole_right.stl", + "pos": [ + 0.022, + 0.00622291, + -0.0647 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + 0.5 + ], + "color": [ + 0.537255, + 0.854902, + 0.827451, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration_default.stl", + "pos": [ + -0.0, + 0.0, + -0.0292 + ], + "quat": [ + 0.0, + 1.0, + -0.0, + -0.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "foot_right.stl", + "pos": [ + 0.022, + 0.00622291, + -0.0647 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + 0.5 + ], + "color": [ + 0.980392, + 0.713725, + 0.00392157, + 1.0 + ] + } + ], + "joint": { + "name": "right_ankle", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0.0, + 0.0, + 0.0 + ], + "range": [ + -1.5707963267949054, + 1.5707963267948877 + ], + "actuator_index": 13 + } + } + ], + "actuated_joints": [ + "left_hip_yaw", + "left_hip_roll", + "left_hip_pitch", + "left_knee", + "left_ankle", + "neck_pitch", + "head_pitch", + "head_yaw", + "head_roll", + "right_hip_yaw", + "right_hip_roll", + "right_hip_pitch", + "right_knee", + "right_ankle" + ], + "mesh_dir": "/robot/mjlab/meshes" +} \ No newline at end of file diff --git a/app/public/robot/mjlab/kinematics_rollers.json b/app/public/robot/mjlab/kinematics_rollers.json new file mode 100644 index 0000000..c7bc95d --- /dev/null +++ b/app/public/robot/mjlab/kinematics_rollers.json @@ -0,0 +1,2267 @@ +{ + "bodies": [ + { + "name": "trunk_base", + "parent": null, + "pos": [ + 0.0, + 0.0, + 0.12 + ], + "quat": [ + 1.0, + 0.0, + 0.0, + 0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + 0.006, + 0.0175, + -0.005 + ], + "quat": [ + 1.0, + -0.0, + -0.0, + 0.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "right_shell.stl", + "pos": [ + 0.004, + -0.0005, + -0.0175 + ], + "quat": [ + 0.707107, + -0.0, + -0.0, + 0.707107 + ], + "color": [ + 0.8, + 0.8, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "banana_pcb_locker.stl", + "pos": [ + 0.0042, + -0.0, + -0.0175215 + ], + "quat": [ + 0.707107, + -0.0, + 0.0, + 0.707107 + ], + "color": [ + 0.647059, + 0.647059, + 0.647059, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "trunk_base.stl", + "pos": [ + 0.004, + -0.0, + -0.0175 + ], + "quat": [ + 0.707107, + -0.0, + -0.0, + 0.707107 + ], + "color": [ + 0.34902, + 0.376471, + 0.4, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.006, + 0.0175, + 0.0115 + ], + "quat": [ + 0.0, + 0.707107, + -0.0, + 0.707107 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "power_support.stl", + "pos": [ + 0.004, + -0.0, + -0.0175215 + ], + "quat": [ + 0.707107, + -0.0, + 0.0, + 0.707107 + ], + "color": [ + 0.901961, + 0.901961, + 0.901961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "np_f970.stl", + "pos": [ + -0.0359693, + 0.0, + -0.00385049 + ], + "quat": [ + 0.00617059, + 0.70708, + -0.70708, + -0.00617059 + ], + "color": [ + 0.901961, + 0.901961, + 0.901961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.006, + -0.0175, + 0.0115 + ], + "quat": [ + 0.0, + 0.707107, + -0.0, + 0.707107 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "left_shell.stl", + "pos": [ + 0.004, + -0.0, + -0.0175785 + ], + "quat": [ + 0.707107, + 0.0, + -0.0, + 0.707107 + ], + "color": [ + 0.8, + 0.8, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + 0.006, + -0.0175, + -0.005 + ], + "quat": [ + 1.0, + -0.0, + -0.0, + 0.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + } + ], + "joint": null + }, + { + "name": "yaw2roll", + "parent": "trunk_base", + "pos": [ + 0.006, + 0.0175, + -0.005 + ], + "quat": [ + 0.0, + -0.707107, + -0.707107, + -0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "yaw2roll.stl", + "pos": [ + -0.0175, + -0.002, + 0.0125 + ], + "quat": [ + 0.0, + 1.0, + 0.0, + 0.0 + ], + "color": [ + 0.647059, + 0.647059, + 0.647059, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + -0.0, + 0.0, + 0.0125 + ], + "quat": [ + 0.0, + -0.707107, + 0.707107, + -0.0 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + -0.0, + 0.0165, + 0.0125 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + -0.5 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "bearing_roll.stl", + "pos": [ + -0.0175, + -0.002, + 0.0125 + ], + "quat": [ + 0.0, + -1.0, + -0.0, + -0.0 + ], + "color": [ + 0.262745, + 0.282353, + 0.301961, + 1.0 + ] + } + ], + "joint": { + "name": "left_hip_yaw", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": [ + -0.4363323129985824, + 0.5235987755982988 + ], + "actuator_index": 0 + } + }, + { + "name": "hip_l", + "parent": "yaw2roll", + "pos": [ + 0.0, + 0.0165, + 0.0125 + ], + "quat": [ + 0.707107, + -0.707107, + -0.0, + -0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + 0.021, + 0.0, + -0.0185 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "hip_l.stl", + "pos": [ + -0.0175, + 0.0, + -0.0185 + ], + "quat": [ + 0.707107, + -0.707107, + 0.0, + -0.0 + ], + "color": [ + 0.901961, + 0.901961, + 0.901961, + 1.0 + ] + } + ], + "joint": { + "name": "left_hip_roll", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": [ + -0.3839724354387525, + 0.3839724354387525 + ], + "actuator_index": 1 + } + }, + { + "name": "upper_leg_left", + "parent": "hip_l", + "pos": [ + 0.025, + 0.0, + -0.0185 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + -0.5 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "upper_leg_left.stl", + "pos": [ + -0.0, + -0.0, + -0.0425 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.866667, + 0.866667, + 0.866667, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.022, + 0.0357771, + 0.0125 + ], + "quat": [ + 0.0, + -0.707107, + -0.0, + -0.707107 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "upper_leg_rigidity_plate.stl", + "pos": [ + 0.0, + -0.0, + -0.0425 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.537255, + 0.854902, + 0.827451, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + 0.022, + 0.0357771, + -0.004 + ], + "quat": [ + 0.0, + 0.0, + 0.0, + 1.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + -0.0, + -0.0, + 0.0125 + ], + "quat": [ + 0.5, + 0.5, + -0.5, + 0.5 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + } + ], + "joint": { + "name": "left_hip_pitch", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": [ + -1.570796326795005, + 1.5707963267947882 + ], + "actuator_index": 2 + } + }, + { + "name": "leg", + "parent": "upper_leg_left", + "pos": [ + 0.022, + 0.0357771, + -0.004 + ], + "quat": [ + 0.0, + 0.707107, + 0.707107, + 0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "leg.stl", + "pos": [ + -0.022, + 0.0357771, + 0.0385 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + -0.5 + ], + "color": [ + 0.811765, + 0.858824, + 0.898039, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.0, + 0.042, + -0.0115 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + } + ], + "joint": { + "name": "left_knee", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": [ + -1.570796326795012, + 1.570796326794781 + ], + "actuator_index": 3 + } + }, + { + "name": "ankle_l_v1", + "parent": "leg", + "pos": [ + 0.0, + 0.042, + -0.026 + ], + "quat": [ + 0.0, + 1.0, + -0.0, + 0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "roller_blade.stl", + "pos": [ + -0.022, + 0.00622291, + -0.0647 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.901961, + 0.901961, + 0.901961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration_default.stl", + "pos": [ + 0.0, + 0.0, + -0.0314 + ], + "quat": [ + 0.0, + -0.0, + 0.0, + -1.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "ankle_l_v1.stl", + "pos": [ + -0.022, + 0.00622291, + -0.0647 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.980392, + 0.713725, + 0.00392157, + 1.0 + ] + } + ], + "joint": { + "name": "left_ankle", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": [ + -1.5707963267949054, + 1.5707963267948877 + ], + "actuator_index": 4 + } + }, + { + "name": "tire", + "parent": "ankle_l_v1", + "pos": [ + -0.0395, + -0.0325, + -0.0147 + ], + "quat": [ + 1.0, + -0.0, + 0.0, + -0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "tire.stl", + "pos": [ + 0.0175, + 0.0387229, + -0.05 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.34902, + 0.376471, + 0.4, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "rim.stl", + "pos": [ + 0.0175, + 0.0387229, + -0.05 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.729412, + 0.25098, + 0.105882, + 1.0 + ] + } + ], + "joint": { + "name": "passive_LF_wheel", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": null + } + }, + { + "name": "tire_2", + "parent": "ankle_l_v1", + "pos": [ + 0.0255, + -0.0325, + -0.0147 + ], + "quat": [ + 1.0, + -0.0, + 0.0, + -0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "rim.stl", + "pos": [ + 0.0175, + 0.0387229, + -0.05 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.729412, + 0.25098, + 0.105882, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "tire.stl", + "pos": [ + 0.0175, + 0.0387229, + -0.05 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.34902, + 0.376471, + 0.4, + 1.0 + ] + } + ], + "joint": { + "name": "passive_LR_wheel", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": null + } + }, + { + "name": "neck", + "parent": "trunk_base", + "pos": [ + 0.026, + 0.0145, + 0.0324215 + ], + "quat": [ + 0.0, + 0.0, + 0.707107, + -0.707107 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "neck.stl", + "pos": [ + 0.022, + 0.05, + 0.028 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + -0.5 + ], + "color": [ + 0.8, + 0.8, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.0, + 0.0, + 0.0145 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.0, + -0.05, + 0.0145 + ], + "quat": [ + 0.5, + 0.5, + -0.5, + 0.5 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "neck.stl", + "pos": [ + 0.022, + 0.05, + 0.003 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + -0.5 + ], + "color": [ + 0.8, + 0.8, + 0.8, + 1.0 + ] + } + ], + "joint": { + "name": "neck_pitch", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": [ + -1.5707963267948966, + 1.0471975511965976 + ], + "actuator_index": 5 + } + }, + { + "name": "neck_pitch", + "parent": "neck", + "pos": [ + 0.0, + -0.05, + -0.0 + ], + "quat": [ + 0.0, + 1.0, + 0.0, + 0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "neck_pitch.stl", + "pos": [ + -0.0, + 0.0287931, + -0.0145 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.34902, + 0.376471, + 0.4, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + -0.0, + 0.0207931, + -0.0145 + ], + "quat": [ + 0.707107, + 0.707107, + 0.0, + 0.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + } + ], + "joint": { + "name": "head_pitch", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": [ + -1.5707963267948974, + 1.5707963267948957 + ], + "actuator_index": 6 + } + }, + { + "name": "yaw_roll_motion", + "parent": "neck_pitch", + "pos": [ + -0.0, + 0.0186931, + -0.0145 + ], + "quat": [ + 0.0, + 0.0, + -0.707107, + -0.707107 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "yaw_roll_motion.stl", + "pos": [ + 0.0, + 0.0, + 0.01 + ], + "quat": [ + 0.707107, + 0.0, + -0.0, + 0.707107 + ], + "color": [ + 0.768627, + 0.886275, + 0.952941, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.0, + 0.0, + 0.0145 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + -0.016, + 0.0, + 0.0145 + ], + "quat": [ + 0.707107, + -0.0, + -0.707107, + -0.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + 0.018, + 0.0, + 0.0145 + ], + "quat": [ + 0.707107, + -0.0, + -0.707107, + -0.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + } + ], + "joint": { + "name": "head_yaw", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": [ + -2.967059728390373, + 2.967059728390348 + ], + "actuator_index": 7 + } + }, + { + "name": "jaw_soft", + "parent": "yaw_roll_motion", + "pos": [ + -0.0179, + 0.0, + 0.0145 + ], + "quat": [ + 0.707107, + -0.0, + -0.707107, + -0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "lens.stl", + "pos": [ + 0.0155, + -9.13778e-05, + -0.05548 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + -0.5 + ], + "color": [ + 0.262745, + 0.282353, + 0.301961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "face_part.stl", + "pos": [ + -0.0045, + -9.13778e-05, + -0.0178 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.34902, + 0.376471, + 0.4, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.003, + 0.0255, + -0.018 + ], + "quat": [ + 0.707107, + 0.0, + -0.0, + -0.707107 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "jaw_soft.stl", + "pos": [ + -0.0046, + 0.0, + -0.0179996 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.85098, + 0.756863, + 0.866667, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "motor_support.stl", + "pos": [ + -0.0045, + 0.0, + -0.018 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.262745, + 0.282353, + 0.301961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "top_head_shell.stl", + "pos": [ + -0.0045, + -0.0, + -0.018 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.901961, + 0.901961, + 0.901961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.0, + 0.0, + 0.0145 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration_default.stl", + "pos": [ + 0.0032, + -0.04, + -0.018 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + 0.5 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "elec_rpi_robot_hat_pcb.stl", + "pos": [ + 0.02694, + 0.0289936, + -0.0519 + ], + "quat": [ + 0.707107, + 0.0, + 0.0, + -0.707107 + ], + "color": [ + 0.313725, + 0.486275, + 0.411765, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "soft_mouth_top.stl", + "pos": [ + -0.00420071, + 1.7776e-08, + -0.0180814 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.85098, + 0.756863, + 0.866667, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "noenoeil.stl", + "pos": [ + -0.0045, + -9.13778e-05, + -0.0178 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.262745, + 0.282353, + 0.301961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "jaw.stl", + "pos": [ + -0.0045, + 0.0, + -0.018 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.980392, + 0.713725, + 0.00392157, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "bottom_head_shell.stl", + "pos": [ + -0.0043, + -0.0, + -0.018 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.980392, + 0.713725, + 0.00392157, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "m12_lens_holder.stl", + "pos": [ + 0.0155, + -9.13778e-05, + -0.05558 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + -0.5 + ], + "color": [ + 0.262745, + 0.282353, + 0.301961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "pcb__raspberry_pi_zero_2_w.stl", + "pos": [ + 0.015435, + -1.13778e-05, + -0.06001 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + 0.5 + ], + "color": [ + 0.498039, + 0.498039, + 0.498039, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "speaker.stl", + "pos": [ + 0.01, + -0.016786, + 0.0260226 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + 0.5 + ], + "color": [ + 0.294118, + 0.290196, + 0.290196, + 1.0 + ] + } + ], + "joint": { + "name": "head_roll", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": [ + -0.43633231299859127, + 0.4363323129985735 + ], + "actuator_index": 8 + } + }, + { + "name": "bearing_roll", + "parent": "trunk_base", + "pos": [ + 0.006, + -0.0175, + -0.005 + ], + "quat": [ + 0.0, + 0.707107, + 0.707107, + 0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "yaw2roll.stl", + "pos": [ + -0.0175, + -0.002, + 0.0125 + ], + "quat": [ + 0.0, + 1.0, + 0.0, + 0.0 + ], + "color": [ + 0.647059, + 0.647059, + 0.647059, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + -0.0, + 0.0, + 0.0125 + ], + "quat": [ + 0.0, + -0.707107, + 0.707107, + -0.0 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "bearing_roll.stl", + "pos": [ + -0.0175, + -0.002, + 0.0125 + ], + "quat": [ + 0.0, + -1.0, + -0.0, + -0.0 + ], + "color": [ + 0.262745, + 0.282353, + 0.301961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + -0.0, + 0.0165, + 0.0125 + ], + "quat": [ + 0.5, + 0.5, + 0.5, + -0.5 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + } + ], + "joint": { + "name": "right_hip_yaw", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": [ + -0.5235987755982988, + 0.4363323129985824 + ], + "actuator_index": 9 + } + }, + { + "name": "hip_l_2", + "parent": "bearing_roll", + "pos": [ + -0.0, + 0.0165, + 0.0125 + ], + "quat": [ + 0.0, + -0.0, + 0.707107, + 0.707107 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "hip_l.stl", + "pos": [ + -0.0175, + 0.0, + -0.0185 + ], + "quat": [ + 0.707107, + -0.707107, + -0.0, + -0.0 + ], + "color": [ + 0.901961, + 0.901961, + 0.901961, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + 0.025, + 0.0, + -0.0185 + ], + "quat": [ + 0.5, + 0.5, + -0.5, + -0.5 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + } + ], + "joint": { + "name": "right_hip_roll", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": [ + -0.3839724354387525, + 0.3839724354387525 + ], + "actuator_index": 10 + } + }, + { + "name": "upper_leg_right", + "parent": "hip_l_2", + "pos": [ + 0.025, + 0.0, + -0.0185 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + -0.5 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + -0.022, + 0.0357771, + 0.0125 + ], + "quat": [ + 0.707107, + -0.0, + -0.707107, + -0.0 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration__22x16x4.stl", + "pos": [ + -0.022, + 0.0357771, + 0.0 + ], + "quat": [ + 0.0, + 1.0, + -0.0, + -0.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "upper_leg_rigidity_plate.stl", + "pos": [ + 0.0, + 0.0, + 0.0435 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + 0.5 + ], + "color": [ + 0.537255, + 0.854902, + 0.827451, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "upper_leg_right.stl", + "pos": [ + -0.0, + 0.0, + -0.0425 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + 0.5 + ], + "color": [ + 0.866667, + 0.866667, + 0.866667, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + 0.0, + 0.0, + 0.0125 + ], + "quat": [ + 0.5, + 0.5, + -0.5, + 0.5 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + } + ], + "joint": { + "name": "right_hip_pitch", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": [ + -1.5707963267949268, + 1.5707963267948664 + ], + "actuator_index": 11 + } + }, + { + "name": "leg_2", + "parent": "upper_leg_right", + "pos": [ + -0.022, + 0.0357771, + -0.004 + ], + "quat": [ + 0.0, + 1.0, + -0.0, + -0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "xl330.stl", + "pos": [ + -0.042, + 0.0, + -0.0115 + ], + "quat": [ + 0.707107, + -0.0, + -0.707107, + -0.0 + ], + "color": [ + 0.286275, + 0.286275, + 0.286275, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "leg.stl", + "pos": [ + -0.0357771, + -0.022, + 0.0385 + ], + "quat": [ + 0.707107, + 0.0, + 0.707107, + -0.0 + ], + "color": [ + 0.811765, + 0.858824, + 0.898039, + 1.0 + ] + } + ], + "joint": { + "name": "right_knee", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": [ + -1.570796326794932, + 1.570796326794861 + ], + "actuator_index": 12 + } + }, + { + "name": "ankle_r_v1", + "parent": "leg_2", + "pos": [ + -0.042, + 0.0, + -0.026 + ], + "quat": [ + 0.0, + -0.707107, + -0.707107, + 0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "ankle_r_v1.stl", + "pos": [ + 0.022, + 0.00622291, + -0.0647 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + 0.5 + ], + "color": [ + 0.980392, + 0.713725, + 0.00392157, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "seeed_bearing__configuration_default.stl", + "pos": [ + 0.0, + 0.0, + -0.0284 + ], + "quat": [ + 0.0, + 1.0, + 0.0, + -0.0 + ], + "color": [ + 0.713725, + 0.760784, + 0.8, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "roller_blade.stl", + "pos": [ + 0.022, + 0.00622291, + 0.0355181 + ], + "quat": [ + 0.5, + -0.5, + 0.5, + 0.5 + ], + "color": [ + 0.901961, + 0.901961, + 0.901961, + 1.0 + ] + } + ], + "joint": { + "name": "right_ankle", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": [ + -1.5707963267949063, + 1.5707963267948868 + ], + "actuator_index": 13 + } + }, + { + "name": "tire_3", + "parent": "ankle_r_v1", + "pos": [ + 0.0395, + -0.0325, + -0.0144819 + ], + "quat": [ + 0.0, + -0.0, + 1.0, + -0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "tire.stl", + "pos": [ + 0.0175, + 0.0387229, + -0.05 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.34902, + 0.376471, + 0.4, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "rim.stl", + "pos": [ + 0.0175, + 0.0387229, + -0.05 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.729412, + 0.25098, + 0.105882, + 1.0 + ] + } + ], + "joint": { + "name": "passive_RF_wheel", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": null + } + }, + { + "name": "tire_4", + "parent": "ankle_r_v1", + "pos": [ + -0.0255, + -0.0325, + -0.0144819 + ], + "quat": [ + 0.0, + -0.0, + 1.0, + -0.0 + ], + "geoms": [ + { + "type": "mesh", + "mesh": "rim.stl", + "pos": [ + 0.0175, + 0.0387229, + -0.05 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.729412, + 0.25098, + 0.105882, + 1.0 + ] + }, + { + "type": "mesh", + "mesh": "tire.stl", + "pos": [ + 0.0175, + 0.0387229, + -0.05 + ], + "quat": [ + 0.5, + -0.5, + -0.5, + -0.5 + ], + "color": [ + 0.34902, + 0.376471, + 0.4, + 1.0 + ] + } + ], + "joint": { + "name": "passive_RR_wheel", + "axis": [ + 0.0, + 0.0, + 1.0 + ], + "type": "hinge", + "pos": [ + 0, + 0, + 0 + ], + "range": null + } + } + ], + "actuated_joints": [ + "left_hip_yaw", + "left_hip_roll", + "left_hip_pitch", + "left_knee", + "left_ankle", + "neck_pitch", + "head_pitch", + "head_yaw", + "head_roll", + "right_hip_yaw", + "right_hip_roll", + "right_hip_pitch", + "right_knee", + "right_ankle" + ], + "mesh_dir": "/robot/mjlab/meshes" +} \ No newline at end of file diff --git a/app/public/robot/mjlab/meshes/ankle_l_v1.stl b/app/public/robot/mjlab/meshes/ankle_l_v1.stl new file mode 100644 index 0000000..ded9820 --- /dev/null +++ b/app/public/robot/mjlab/meshes/ankle_l_v1.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:74f9a51e15ac8fef93fc2efa35b61dc53cf832d798f75c3229700bd9b3aed4c4 +size 79484 diff --git a/app/public/robot/mjlab/meshes/ankle_left.stl b/app/public/robot/mjlab/meshes/ankle_left.stl new file mode 100644 index 0000000..de8d978 --- /dev/null +++ b/app/public/robot/mjlab/meshes/ankle_left.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:df5d7f04d63390a1e263e0138ee94e1aec2ff2b55cf63729f4ec461b25c1c1f0 +size 58284 diff --git a/app/public/robot/mjlab/meshes/ankle_r_v1.stl b/app/public/robot/mjlab/meshes/ankle_r_v1.stl new file mode 100644 index 0000000..7699482 --- /dev/null +++ b/app/public/robot/mjlab/meshes/ankle_r_v1.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c200102fb6f067cbec73f048fe2020b127e61d47fcffd7dbd84c90439767fd3f +size 69484 diff --git a/app/public/robot/mjlab/meshes/ankle_right.stl b/app/public/robot/mjlab/meshes/ankle_right.stl new file mode 100644 index 0000000..7188517 --- /dev/null +++ b/app/public/robot/mjlab/meshes/ankle_right.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:48b8551a13d22cc8752ddf3148796b357a6cbd6e2ecbd93c3ecdfbf55e533e72 +size 51584 diff --git a/app/public/robot/mjlab/meshes/banana_pcb_locker.stl b/app/public/robot/mjlab/meshes/banana_pcb_locker.stl new file mode 100644 index 0000000..d152ec8 --- /dev/null +++ b/app/public/robot/mjlab/meshes/banana_pcb_locker.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e51f6e23e4dbea660a9dbadcd763bbc77d48a7e3e0a58f047eab45554e07b55 +size 11634 diff --git a/app/public/robot/mjlab/meshes/bearing_roll.stl b/app/public/robot/mjlab/meshes/bearing_roll.stl new file mode 100644 index 0000000..86cb4b8 --- /dev/null +++ b/app/public/robot/mjlab/meshes/bearing_roll.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fa0da0a5eef428a41da6e9639f75120781594e600c5db7518621750221669849 +size 30284 diff --git a/app/public/robot/mjlab/meshes/bottom_head_shell.stl b/app/public/robot/mjlab/meshes/bottom_head_shell.stl new file mode 100644 index 0000000..40d503c --- /dev/null +++ b/app/public/robot/mjlab/meshes/bottom_head_shell.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:331a361406e77c05256e5064197f785ac1e9c8f091079a3519c2e33f28ae5ebc +size 231334 diff --git a/app/public/robot/mjlab/meshes/elec_rpi_robot_hat_pcb.stl b/app/public/robot/mjlab/meshes/elec_rpi_robot_hat_pcb.stl new file mode 100644 index 0000000..34a8e6b --- /dev/null +++ b/app/public/robot/mjlab/meshes/elec_rpi_robot_hat_pcb.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:acc66b75f2ff26f42339577c38c6f348ec73c4fbb52912637ba5244eb1a78ebb +size 225434 diff --git a/app/public/robot/mjlab/meshes/face_part.stl b/app/public/robot/mjlab/meshes/face_part.stl new file mode 100644 index 0000000..5c9b4a4 --- /dev/null +++ b/app/public/robot/mjlab/meshes/face_part.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47ad1137a68bf72b2c93f1bf4836f18fb9a8d21a4f8f86fbe761b9871233fcce +size 136784 diff --git a/app/public/robot/mjlab/meshes/foot_left.stl b/app/public/robot/mjlab/meshes/foot_left.stl new file mode 100644 index 0000000..9d013e2 --- /dev/null +++ b/app/public/robot/mjlab/meshes/foot_left.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b7749b1f4fd9e7faf8180772d7ce8254139c60bc43aee463ec76afc86212d59c +size 241934 diff --git a/app/public/robot/mjlab/meshes/foot_right.stl b/app/public/robot/mjlab/meshes/foot_right.stl new file mode 100644 index 0000000..e4dd68c --- /dev/null +++ b/app/public/robot/mjlab/meshes/foot_right.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e2aba02ec1b949bc8a5a77ad3d0af9009dee80c100aa4bbfcf336f1fa5ef206f +size 246084 diff --git a/app/public/robot/mjlab/meshes/hip_l.stl b/app/public/robot/mjlab/meshes/hip_l.stl new file mode 100644 index 0000000..c6a4f1e --- /dev/null +++ b/app/public/robot/mjlab/meshes/hip_l.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dbdf6e7f5587385c0f6a77b407931b30e81c9a212dac7c52b4e0884156049056 +size 229134 diff --git a/app/public/robot/mjlab/meshes/jaw.stl b/app/public/robot/mjlab/meshes/jaw.stl new file mode 100644 index 0000000..08b5662 --- /dev/null +++ b/app/public/robot/mjlab/meshes/jaw.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:90afa64e47ef237f0f58d6f4830dc3cd6215328ed8a639b1e1a9eb2157307f4a +size 120834 diff --git a/app/public/robot/mjlab/meshes/jaw_soft.stl b/app/public/robot/mjlab/meshes/jaw_soft.stl new file mode 100644 index 0000000..675b1ef --- /dev/null +++ b/app/public/robot/mjlab/meshes/jaw_soft.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c3ebb578ea5e6d7b995baca9b42ef7c9f9858b56dedf6f0d949f5e6ea9d3ef2 +size 84084 diff --git a/app/public/robot/mjlab/meshes/left_shell.stl b/app/public/robot/mjlab/meshes/left_shell.stl new file mode 100644 index 0000000..05cef9a --- /dev/null +++ b/app/public/robot/mjlab/meshes/left_shell.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c31e71e2e55c5daccfef738c80053104ba2fb3589a0836ab1b6ebb5c380a05ae +size 256334 diff --git a/app/public/robot/mjlab/meshes/leg.stl b/app/public/robot/mjlab/meshes/leg.stl new file mode 100644 index 0000000..2541848 --- /dev/null +++ b/app/public/robot/mjlab/meshes/leg.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bfbc6ae5faefc56bd65d860cf3410a08e8286717063584f15b56bbd5302b20f8 +size 166434 diff --git a/app/public/robot/mjlab/meshes/lens.stl b/app/public/robot/mjlab/meshes/lens.stl new file mode 100644 index 0000000..2707472 --- /dev/null +++ b/app/public/robot/mjlab/meshes/lens.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9b86fce70198040781a739e2c15d2996b549b25d73b7544005ae08a415b486e +size 23484 diff --git a/app/public/robot/mjlab/meshes/m12_lens_holder.stl b/app/public/robot/mjlab/meshes/m12_lens_holder.stl new file mode 100644 index 0000000..829f342 --- /dev/null +++ b/app/public/robot/mjlab/meshes/m12_lens_holder.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d96825a096d5d3d5d252086cf0cdb3f5bc22d9f0baef0a3f97a85bae1617be99 +size 98334 diff --git a/app/public/robot/mjlab/meshes/motor_support.stl b/app/public/robot/mjlab/meshes/motor_support.stl new file mode 100644 index 0000000..d831cb7 --- /dev/null +++ b/app/public/robot/mjlab/meshes/motor_support.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d6725004f0a85a5cf0161214ea0d39fb6f14ee3563c9a96cd5aad725b5e2a716 +size 45284 diff --git a/app/public/robot/mjlab/meshes/neck.stl b/app/public/robot/mjlab/meshes/neck.stl new file mode 100644 index 0000000..5a9c62a --- /dev/null +++ b/app/public/robot/mjlab/meshes/neck.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3cb654ee9387d55c7d10d40fc84bb7cbf3cedb3243d1da499cf01c54d366079c +size 18384 diff --git a/app/public/robot/mjlab/meshes/neck_pitch.stl b/app/public/robot/mjlab/meshes/neck_pitch.stl new file mode 100644 index 0000000..d6cb0ad --- /dev/null +++ b/app/public/robot/mjlab/meshes/neck_pitch.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dbd6fcbf8b8f27a8364d5bcae2b9a537d7e384325b44a653b360139b6fa1da2f +size 85284 diff --git a/app/public/robot/mjlab/meshes/noenoeil.stl b/app/public/robot/mjlab/meshes/noenoeil.stl new file mode 100644 index 0000000..0e1d294 --- /dev/null +++ b/app/public/robot/mjlab/meshes/noenoeil.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:55f3167627f6fbd1a19966f92396adf2ccd55795b13ded3b9f52705ba8a7ab77 +size 12384 diff --git a/app/public/robot/mjlab/meshes/np_f970.stl b/app/public/robot/mjlab/meshes/np_f970.stl new file mode 100644 index 0000000..4900717 --- /dev/null +++ b/app/public/robot/mjlab/meshes/np_f970.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:01fbacc788b53ebb7648cda07090133b8c696da31d700c560f45189494977871 +size 247734 diff --git a/app/public/robot/mjlab/meshes/pcb__raspberry_pi_zero_2_w.stl b/app/public/robot/mjlab/meshes/pcb__raspberry_pi_zero_2_w.stl new file mode 100644 index 0000000..e0f881e --- /dev/null +++ b/app/public/robot/mjlab/meshes/pcb__raspberry_pi_zero_2_w.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:43d8368ced3d623eaa5ef538e8361f5878b85931b7cd469a4488eee7aa00bd91 +size 262184 diff --git a/app/public/robot/mjlab/meshes/power_support.stl b/app/public/robot/mjlab/meshes/power_support.stl new file mode 100644 index 0000000..e567d3e --- /dev/null +++ b/app/public/robot/mjlab/meshes/power_support.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4aee9ddf8c12478d334f3d8d9e65af712072bef241283a08c895606fc2e3d9e8 +size 128234 diff --git a/app/public/robot/mjlab/meshes/right_shell.stl b/app/public/robot/mjlab/meshes/right_shell.stl new file mode 100644 index 0000000..d401517 --- /dev/null +++ b/app/public/robot/mjlab/meshes/right_shell.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c346581c2e3c2c189ea49372a147dfbc0dca89db4ec02f9f230921e480e762a7 +size 256384 diff --git a/app/public/robot/mjlab/meshes/rim.stl b/app/public/robot/mjlab/meshes/rim.stl new file mode 100644 index 0000000..8d5497f --- /dev/null +++ b/app/public/robot/mjlab/meshes/rim.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a6d58f80ec60041e721cba1de7af5c834700166a5c10e7f68d1a2b79c7b78cb0 +size 28884 diff --git a/app/public/robot/mjlab/meshes/roller_blade.stl b/app/public/robot/mjlab/meshes/roller_blade.stl new file mode 100644 index 0000000..820f5fc --- /dev/null +++ b/app/public/robot/mjlab/meshes/roller_blade.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a8b0e6dbdb593eceaba1a0cc2a70ad8aac56f4c3b22676dbfb97409c1a094615 +size 262184 diff --git a/app/public/robot/mjlab/meshes/seeed_bearing__configuration__22x16x4.stl b/app/public/robot/mjlab/meshes/seeed_bearing__configuration__22x16x4.stl new file mode 100644 index 0000000..e123c75 --- /dev/null +++ b/app/public/robot/mjlab/meshes/seeed_bearing__configuration__22x16x4.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8551dc99cbdc012bd261c2a175f2cc766dd6aed0786781b35f8381cd3aa95b34 +size 260134 diff --git a/app/public/robot/mjlab/meshes/seeed_bearing__configuration_default.stl b/app/public/robot/mjlab/meshes/seeed_bearing__configuration_default.stl new file mode 100644 index 0000000..524b730 --- /dev/null +++ b/app/public/robot/mjlab/meshes/seeed_bearing__configuration_default.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e4338e0e6c7adeb52a35e02d6fa5babe761e8752ffa0fc2e31b0ba672c18630d +size 260084 diff --git a/app/public/robot/mjlab/meshes/soft_mouth_top.stl b/app/public/robot/mjlab/meshes/soft_mouth_top.stl new file mode 100644 index 0000000..a3bd23f --- /dev/null +++ b/app/public/robot/mjlab/meshes/soft_mouth_top.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:451f53d30350552cb6e26f777698272f7c3fa557f389adb24f94c75a201e67cd +size 98384 diff --git a/app/public/robot/mjlab/meshes/sole_left.stl b/app/public/robot/mjlab/meshes/sole_left.stl new file mode 100644 index 0000000..87ece49 --- /dev/null +++ b/app/public/robot/mjlab/meshes/sole_left.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:357f80bb46855e3ce50f817705acd80471dae90b4ee6b4a0a948614a7daeddb1 +size 197384 diff --git a/app/public/robot/mjlab/meshes/sole_right.stl b/app/public/robot/mjlab/meshes/sole_right.stl new file mode 100644 index 0000000..c57db33 --- /dev/null +++ b/app/public/robot/mjlab/meshes/sole_right.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:07801107a36dbc1c2b83b3b64ad98be39ba662a8a7fa0b62a29119b201f41fe6 +size 198684 diff --git a/app/public/robot/mjlab/meshes/speaker.stl b/app/public/robot/mjlab/meshes/speaker.stl new file mode 100644 index 0000000..7baa6fd --- /dev/null +++ b/app/public/robot/mjlab/meshes/speaker.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ef54df86c6093c166d73e33dc0b8364ef5643a7a1b1dacaba577be5a9c06c32 +size 684 diff --git a/app/public/robot/mjlab/meshes/tire.stl b/app/public/robot/mjlab/meshes/tire.stl new file mode 100644 index 0000000..aa69413 --- /dev/null +++ b/app/public/robot/mjlab/meshes/tire.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:14c08d73185a4b521897aca74fb8b2a6d306a20d80e8822aa56cf1b4ace29bec +size 88284 diff --git a/app/public/robot/mjlab/meshes/top_head_shell.stl b/app/public/robot/mjlab/meshes/top_head_shell.stl new file mode 100644 index 0000000..96716ee --- /dev/null +++ b/app/public/robot/mjlab/meshes/top_head_shell.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a59823b8f2ab23d530e6b071559f7fd308851ae035b7cb4d0b7baf7edef4b3e3 +size 194984 diff --git a/app/public/robot/mjlab/meshes/trunk_base.stl b/app/public/robot/mjlab/meshes/trunk_base.stl new file mode 100644 index 0000000..44e0fa9 --- /dev/null +++ b/app/public/robot/mjlab/meshes/trunk_base.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4b84ebe28041e6236ecafd4a26cebe537e21c14423e6acded3d78478c7650ed7 +size 38734 diff --git a/app/public/robot/mjlab/meshes/upper_leg_left.stl b/app/public/robot/mjlab/meshes/upper_leg_left.stl new file mode 100644 index 0000000..4ed608c --- /dev/null +++ b/app/public/robot/mjlab/meshes/upper_leg_left.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a626dafcdd0074fd4e79e604d377495d304d222f1afd27b13487b7248b35a0b8 +size 133134 diff --git a/app/public/robot/mjlab/meshes/upper_leg_right.stl b/app/public/robot/mjlab/meshes/upper_leg_right.stl new file mode 100644 index 0000000..2b6947f --- /dev/null +++ b/app/public/robot/mjlab/meshes/upper_leg_right.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:97fd516a4c0e593fef9e22b1521d60ca86bd91966a4328db0834bac5ba1cabdf +size 124434 diff --git a/app/public/robot/mjlab/meshes/upper_leg_rigidity_plate.stl b/app/public/robot/mjlab/meshes/upper_leg_rigidity_plate.stl new file mode 100644 index 0000000..ddafee7 --- /dev/null +++ b/app/public/robot/mjlab/meshes/upper_leg_rigidity_plate.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:96e50158d44ef97fc46f5d6330b6bb02fb93116790ae892a170fdd052e696aba +size 45084 diff --git a/app/public/robot/mjlab/meshes/xl330.stl b/app/public/robot/mjlab/meshes/xl330.stl new file mode 100644 index 0000000..3038877 --- /dev/null +++ b/app/public/robot/mjlab/meshes/xl330.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d3c7b71750397083d3dfbad395fd8ac794763f43e2ea2b5006da5840c976fc82 +size 45584 diff --git a/app/public/robot/mjlab/meshes/yaw2roll.stl b/app/public/robot/mjlab/meshes/yaw2roll.stl new file mode 100644 index 0000000..c31f526 --- /dev/null +++ b/app/public/robot/mjlab/meshes/yaw2roll.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c20cbdd8a9d52f789ec5a4b0d4a173a225652c6bc4610d555ea309c7a0e0d559 +size 119884 diff --git a/app/public/robot/mjlab/meshes/yaw_roll_motion.stl b/app/public/robot/mjlab/meshes/yaw_roll_motion.stl new file mode 100644 index 0000000..8f3ebfe --- /dev/null +++ b/app/public/robot/mjlab/meshes/yaw_roll_motion.stl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ae3740fde29a261b79650a25825baedd84d538fc67b6b20b79589125e5e05592 +size 62184 diff --git a/app/public/robot/mjlab/microduck.glb b/app/public/robot/mjlab/microduck.glb new file mode 100644 index 0000000..2f79156 --- /dev/null +++ b/app/public/robot/mjlab/microduck.glb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ad0b8d1c886a857fd09d337be11e731f4ac72bf099b0af63081031f97ed6eadb +size 1279444 diff --git a/app/public/robot/mjlab/robot_allcollisions.xml b/app/public/robot/mjlab/robot_allcollisions.xml new file mode 100644 index 0000000..7f296e3 --- /dev/null +++ b/app/public/robot/mjlab/robot_allcollisions.xml @@ -0,0 +1,434 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/public/robot/mjlab/robot_allcollisions_rollers.xml b/app/public/robot/mjlab/robot_allcollisions_rollers.xml new file mode 100644 index 0000000..f0eb02c --- /dev/null +++ b/app/public/robot/mjlab/robot_allcollisions_rollers.xml @@ -0,0 +1,470 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/App.jsx b/app/src/App.jsx new file mode 100644 index 0000000..d75c6f2 --- /dev/null +++ b/app/src/App.jsx @@ -0,0 +1,89 @@ +// App shell: layers in z order - scene canvas (1), halftone (2), CRT (5), +// HUD + touch overlay (9-12), BIOS readout (20), title menu (30). Also owns +// the pre-game device detection (gamepad, touch) and the title -> enter +// flow. The title menu carries its own loading gate (single central +// spinner), so no separate preboot veil. +import { useEffect } from "react"; +import GameCanvas from "./scene/GameCanvas.jsx"; +import { Halftone, CrtOverlay } from "./ui/Overlays.jsx"; +import Hud from "./ui/Hud.jsx"; +import TouchOverlay from "./ui/TouchOverlay.jsx"; +import BiosOverlay from "./ui/BiosOverlay.jsx"; +import TitleMenu from "./ui/TitleMenu.jsx"; +import { useGame } from "./store.js"; + +export default function App() { + useEffect(() => { + const params = new URLSearchParams(location.search); + + // Gamepad presence for the tutorial variant, before the game controller + // takes over polling (the game loop keeps mirroring it afterwards). + const pollPad = () => { + const gp = [...(navigator.getGamepads?.() ?? [])].find((p) => p && p.connected); + useGame.setState({ padConnected: !!gp }); + }; + window.addEventListener("gamepadconnected", pollPad); + window.addEventListener("gamepaddisconnected", pollPad); + pollPad(); + + // Touch detection, latching: (pointer: coarse) OR any real touch proves + // the device (DevTools device modes and hybrid laptops often fail the + // media query). __microduckTouched hands the proof to controls/touch.js + // which boots later. ?touch=1 forces the thumbs on any device. + const coarse = matchMedia("(pointer: coarse)"); + const armTouch = () => { + window.__microduckTouched = true; + useGame.setState({ touchMode: true }); + }; + const onCoarse = () => coarse.matches && armTouch(); + if (coarse.matches) armTouch(); + else coarse.addEventListener("change", onCoarse); + window.addEventListener("touchstart", armTouch, { once: true, passive: true }); + if (params.get("touch") === "1") armTouch(); + + // ?move=: request a community move (Academy D7). ref is an + // "org/repo" Hub move, "session:[:]" (a private Academy run, + // served same-origin) or a direct .onnx URL. ?policy= is the legacy + // alias, and ?session=[&round=] is sugar for move=session::. + // Only the request is recorded here; the game loads it after boot + // (never blocking it) and flips the status to active/error itself. + let moveRef = params.get("move") || params.get("policy"); + if (!moveRef && params.get("session")) { + const round = params.get("round"); + moveRef = `session:${params.get("session")}${round ? `:${round}` : ""}`; + } + if (moveRef) { + useGame.setState({ + customPolicy: { ref: moveRef, name: moveRef, status: "loading" }, + }); + } + + // The title menu opens right away and holds its own loading gate + // (central spinner) until logo, fonts, duck stage and game boot are + // in. ?boot=1 skips the title entirely - testing hook. + if (params.get("boot") === "1") { + useGame.setState({ prebootDone: true, entered: true, menuOpen: false }); + } else { + useGame.setState({ prebootDone: true, menuOpen: true }); + } + + return () => { + window.removeEventListener("gamepadconnected", pollPad); + window.removeEventListener("gamepaddisconnected", pollPad); + coarse.removeEventListener("change", onCoarse); + window.removeEventListener("touchstart", armTouch); + }; + }, []); + + return ( + <> + + + + + + + + + ); +} diff --git a/app/src/game/arena.js b/app/src/game/arena.js new file mode 100644 index 0000000..f4f4a69 --- /dev/null +++ b/app/src/game/arena.js @@ -0,0 +1,301 @@ +// Arena visuals: the infinite Tron grid floor and the four wall grid +// planes, ported verbatim from the pre-React rl.js. Both carry a uReveal +// uniform for the entrance draw-in (driven by ceremony.js). +import * as THREE from "three"; +import { + ARENA_HALF, ARENA_WALL_H, ARENA_WALL_T, GRID_SECTION, RELIEF_BUMPS, +} from "./constants.js"; + +// Infinite shader grid, ported from drei's : anti-aliased world-space +// lines at cell/section frequencies with a radial fade around the duck. +// Lines derive from world coordinates, so re-centering the mesh under the +// camera target every frame makes the grid effectively infinite without any +// visible swimming. +export function makeInfiniteGrid() { + const material = new THREE.ShaderMaterial({ + transparent: true, + depthWrite: false, + uniforms: { + uCell: { value: 0.1 }, + uSection: { value: GRID_SECTION }, + uCellColor: { value: new THREE.Color(0x8e8371) }, + uSectionColor: { value: new THREE.Color(0xffb366) }, + uFadeDist: { value: 3.0 }, + uFocus: { value: new THREE.Vector3() }, + // Entrance draw-in progress; 1 = steady state (branch skipped). + // Starts at 0: the world stays hidden behind the welcome modal and + // the BIOS readout until playBios cues startEntrance. + uReveal: { value: 0.0 }, + // Relief: 0 = flat, 1 = bumps at full height. Driven by the game's + // relief toggle, mirroring the MuJoCo heightfield's z-size so the + // visual surface and the physics surface are the same function. + uTopoScale: { value: 0.0 }, + // (cx, cz, height, radius) per bump, in three.js world coords + // (MJCF y -> -z done here once). + uBumps: { + value: RELIEF_BUMPS.map( + ([cx, cy, h, r]) => new THREE.Vector4(cx, -cy, h, r), + ), + }, + }, + vertexShader: /* glsl */ ` + #define NBUMPS ${RELIEF_BUMPS.length} + varying vec3 vWorld; + uniform float uTopoScale; + uniform vec4 uBumps[NBUMPS]; + // Same analytic relief as the physics heightfield (game.js topoH): + // a sum of cosine bumps, displacing the grid surface itself so the + // floor genuinely deforms - lines flow up the slopes for free since + // the fragment shader draws them from world xz. + float topoH(vec2 p) { + float H = 0.0; + for (int i = 0; i < NBUMPS; i++) { + float u = distance(p, uBumps[i].xy) / uBumps[i].w; + if (u < 1.0) H += uBumps[i].z * (0.5 + 0.5 * cos(3.14159265 * u)); + } + return H; + } + void main() { + vec4 w = modelMatrix * vec4(position, 1.0); + if (uTopoScale > 0.0) w.y += topoH(w.xz) * uTopoScale; + vWorld = w.xyz; + gl_Position = projectionMatrix * viewMatrix * w; + } + `, + fragmentShader: /* glsl */ ` + varying vec3 vWorld; + uniform float uCell, uSection, uFadeDist, uReveal; + uniform vec3 uCellColor, uSectionColor, uFocus; + // Tron-style line: a thicker antialiased core plus a faint, much + // wider halo added on top (squared falloff keeps it a whisper of a + // glow rather than a bloom wash). + float lineProf(float g) { + float core = 1.0 - smoothstep(0.0, 1.8, g); + float halo = 1.0 - smoothstep(0.0, 7.0, g); + return core + halo * halo * 0.22; + } + float gridLine(vec2 p, float size) { + vec2 r = p / size; + vec2 g = abs(fract(r - 0.5) - 0.5) / fwidth(r); + return lineProf(min(g.x, g.y)); + } + // Entrance draw-in: one family of parallel lines, drawn line by line. + // id picks the line, "along" runs down its length. Each line waits + // out its own hashed delay, then extends from the origin outward with + // a hard front. Returns (mask, head): head marks the bright segment + // right behind the draw front while the line is still growing. + vec2 drawLine(float id, float along, float t0, float spread, float dur, float maxLen) { + float jit = fract(sin(id * 127.1) * 43758.5453); + float grow = clamp((uReveal - t0 - jit * spread) / dur, 0.0, 1.0); + float len = grow * maxLen; + float a = abs(along); + float mask = 1.0 - smoothstep(len - 0.05, len, a); + float head = (1.0 - smoothstep(0.0, 0.6, len - a)) * mask + * step(0.001, grow) * (1.0 - step(0.999, grow)); + return vec2(mask, head); + } + void main() { + float cell = gridLine(vWorld.xz, uCell); + // Section lattice shifted half a cell: with 5 sections across the + // 3 m arena (odd count) this centers a CELL on the origin and puts + // section lines exactly on the walls at +-1.5. + vec2 pSec = vWorld.xz + 0.5 * uSection; + float section = gridLine(pSec, uSection); + float d = distance(vWorld.xz, uFocus.xz); + float fade = pow(clamp(1.0 - d / uFadeDist, 0.0, 1.0), 1.6); + vec3 col = mix(uCellColor, uSectionColor, clamp(section, 0.0, 1.0)); + float alpha = min(max(section * 0.6, cell * 0.4) * fade, 1.0); + // Entrance: only the bright section lines get the line-by-line draw + // (staggered, with a hot draw head); the fine cells just fade in + // over the reveal's second half - drawing every small line reads as + // visual noise. lineProf(min(gx, gy)) == max of per-axis profiles + // (profile is monotonic) and the cell fade lands on exactly the + // steady-state cell term, so at uReveal 1 this branch equals the + // formula above exactly (and is skipped). + if (uReveal < 1.0) { + vec2 rs = pSec / uSection; + vec2 gs = abs(fract(rs - 0.5) - 0.5) / fwidth(rs); + // Const-x lines run along z and vice versa; the offset + // decorrelates the two families' hashed delays. + vec2 sx = drawLine(floor(rs.x + 0.5), vWorld.z, 0.00, 0.30, 0.35, 8.0); + vec2 sz = drawLine(floor(rs.y + 0.5) + 57.0, vWorld.x, 0.05, 0.30, 0.35, 8.0); + float secR = max(lineProf(gs.x) * sx.x, lineProf(gs.y) * sz.x); + float cellR = cell * smoothstep(0.5, 1.0, uReveal); + float headGlow = max(lineProf(gs.x) * sx.y, lineProf(gs.y) * sz.y); + col = mix(uCellColor, uSectionColor, clamp(secR, 0.0, 1.0)); + alpha = min(max(secR * 0.6, cellR * 0.4) * fade, 1.0); + // Bright draw head: a short white-hot tip sells the "drawing" read. + headGlow = clamp(headGlow, 0.0, 1.0); + col = mix(col, vec3(1.0, 0.86, 0.55), headGlow * 0.8); + alpha = min(alpha + headGlow * fade * 0.5, 1.0); + } + if (alpha < 0.004) discard; + gl_FragColor = vec4(col, alpha); + } + `, + }); + // Subdivided so the relief displacement has vertices to push: ~12 cm + // steps, plenty for the gentle bump radii (>= 0.5 m). The displacement + // is computed in world space, so the per-frame recentering under the + // camera target doesn't move the bumps. + const mesh = new THREE.Mesh(new THREE.PlaneGeometry(30, 30, 256, 256), material); + mesh.rotation.x = -Math.PI / 2; + return mesh; +} + +// Arena walls, drawn in the same grid language as the floor: identical +// cell/section lines from world coordinates, same radial fade around the +// duck, plus a vertical fade toward the top edge so the walls read as a +// light enclosure instead of solid slabs. +function makeWallGridMaterial(alongX) { + return new THREE.ShaderMaterial({ + transparent: true, + depthWrite: false, + side: THREE.DoubleSide, + uniforms: { + uCell: { value: 0.1 }, + uSection: { value: GRID_SECTION }, + uCellColor: { value: new THREE.Color(0x8e8371) }, + uSectionColor: { value: new THREE.Color(0xffb366) }, + // Gentler radial fade than the floor: the walls sit 1.5+ m from the + // duck by construction and would vanish with the floor's 3 m fade. + uFadeDist: { value: 5.0 }, + uFocus: { value: new THREE.Vector3() }, + uWallH: { value: ARENA_WALL_H }, + uAlongX: { value: alongX ? 1.0 : 0.0 }, + // Entrance draw-in progress; 1 = steady state (branch skipped). + // Starts at 0, same as the floor grid: hidden until startEntrance. + uReveal: { value: 0.0 }, + }, + vertexShader: /* glsl */ ` + varying vec3 vWorld; + void main() { + vec4 w = modelMatrix * vec4(position, 1.0); + vWorld = w.xyz; + gl_Position = projectionMatrix * viewMatrix * w; + } + `, + fragmentShader: /* glsl */ ` + varying vec3 vWorld; + uniform float uCell, uSection, uFadeDist, uWallH, uAlongX, uReveal; + uniform vec3 uCellColor, uSectionColor, uFocus; + // Same Tron-style core + faint halo as the floor grid. + float lineProf(float g) { + float core = 1.0 - smoothstep(0.0, 1.8, g); + float halo = 1.0 - smoothstep(0.0, 7.0, g); + return core + halo * halo * 0.22; + } + float gridLine(vec2 p, float size) { + vec2 r = p / size; + vec2 g = abs(fract(r - 0.5) - 0.5) / fwidth(r); + return lineProf(min(g.x, g.y)); + } + // Same line-by-line draw as the floor grid (see its comments). + vec2 drawLine(float id, float along, float t0, float spread, float dur, float maxLen) { + float jit = fract(sin(id * 127.1) * 43758.5453); + float grow = clamp((uReveal - t0 - jit * spread) / dur, 0.0, 1.0); + float len = grow * maxLen; + float a = abs(along); + float mask = 1.0 - smoothstep(len - 0.05, len, a); + float head = (1.0 - smoothstep(0.0, 0.35, len - a)) * mask + * step(0.001, grow) * (1.0 - step(0.999, grow)); + return vec2(mask, head); + } + void main() { + // Wall surface coords: the in-plane horizontal world axis + height. + float h = mix(vWorld.z, vWorld.x, uAlongX); + vec2 p = vec2(h, vWorld.y); + float cell = gridLine(p, uCell); + // Horizontal axis shifted half a section to match the floor's odd + // lattice (vertical section lines meet the floor's at the base); + // the height axis keeps its base line at y = 0. + vec2 pSec = vec2(p.x + 0.5 * uSection, p.y); + float section = gridLine(pSec, uSection); + float d = distance(vWorld.xz, uFocus.xz); + float fade = pow(clamp(1.0 - d / uFadeDist, 0.0, 1.0), 1.6); + float vert = 1.0 - clamp(vWorld.y / uWallH, 0.0, 1.0); + vec3 col = mix(uCellColor, uSectionColor, clamp(section, 0.0, 1.0)); + float alpha = min(max(section * 0.9, cell * 0.6) * fade * (0.3 + 0.7 * vert), 1.0); + // Entrance: section lines only - horizontals zip out from the + // wall's center, verticals rise from the ground, each with a + // hashed delay; the fine cells fade in over the reveal's second + // half. Same steady-state equivalence argument as the floor grid. + if (uReveal < 1.0) { + vec2 rs = pSec / uSection; + vec2 gs = abs(fract(rs - 0.5) - 0.5) / fwidth(rs); + // Const-height lines run along h (grow from center outward); + // const-h lines run along y (grow up from the ground). + vec2 sh = drawLine(floor(rs.y + 0.5), p.x, 0.00, 0.30, 0.40, 2.0); + vec2 sv = drawLine(floor(rs.x + 0.5) + 31.0, p.y, 0.30, 0.30, 0.30, uWallH); + float secR = max(lineProf(gs.y) * sh.x, lineProf(gs.x) * sv.x); + float cellR = cell * smoothstep(0.5, 1.0, uReveal); + float headGlow = max(lineProf(gs.y) * sh.y, lineProf(gs.x) * sv.y); + col = mix(uCellColor, uSectionColor, clamp(secR, 0.0, 1.0)); + alpha = min(max(secR * 0.9, cellR * 0.6) * fade * (0.3 + 0.7 * vert), 1.0); + headGlow = clamp(headGlow, 0.0, 1.0); + col = mix(col, vec3(1.0, 0.86, 0.55), headGlow * 0.8); + alpha = min(alpha + headGlow * fade * 0.5, 1.0); + } + if (alpha < 0.004) discard; + gl_FragColor = vec4(col, alpha); + } + `, + }); +} + +// Entrance draw-in cue schedule, for the ceremony's per-line audio blips. +// Replicates the shaders' hashed stagger EXACTLY (same hash, same t0 / +// spread constants, same line ids as drawLine's floor(rs + 0.5)), so each +// blip lands the instant its line starts drawing. Times are normalized to +// the respective reveal (0..1); the ceremony maps them to seconds with its +// own grid/wall reveal durations. `u` is the line's jitter, reused by the +// audio side for per-line pitch variation. The four walls share one id +// space, so their lines draw (and blip) in unison - one cue each. +const jitHash = (x) => { + const s = Math.sin(x * 127.1) * 43758.5453; + return s - Math.floor(s); +}; +export function entranceLineCues() { + const grid = []; + const walls = []; + // Floor: 6 section lines per axis (world x in {-1.5..1.5} step 0.6 maps + // to ids -2..3); the z family is offset by 57 in the shader. + for (let i = -2; i <= 3; i++) { + const jx = jitHash(i); + const jz = jitHash(i + 57); + grid.push({ at: 0.00 + jx * 0.30, u: jx }); + grid.push({ at: 0.05 + jz * 0.30, u: jz }); + } + // Walls: one horizontal section line (the y = 0 base, id 0) and 6 + // verticals (ids -2..3 offset by 31), per the 0.25 m wall height. + walls.push({ at: 0.00 + jitHash(0) * 0.30, u: jitHash(0) }); + for (let i = -2; i <= 3; i++) { + const j = jitHash(i + 31); + walls.push({ at: 0.30 + j * 0.30, u: j }); + } + return { grid, walls }; +} + +// The four wall planes at their inner faces (three coords: MJCF x -> x, +// MJCF y -> -z). Returns the meshes plus their materials (the ceremony and +// the per-frame focus update both need the material list). +export function makeArenaWalls() { + const wallMats = []; + const wallMeshes = []; + const wallLen = 2 * (ARENA_HALF + ARENA_WALL_T); + const wallDefs = [ + { x: ARENA_HALF, z: 0, rotY: -Math.PI / 2, alongX: false }, + { x: -ARENA_HALF, z: 0, rotY: Math.PI / 2, alongX: false }, + { x: 0, z: ARENA_HALF, rotY: Math.PI, alongX: true }, + { x: 0, z: -ARENA_HALF, rotY: 0, alongX: true }, + ]; + for (const w of wallDefs) { + const mat = makeWallGridMaterial(w.alongX); + wallMats.push(mat); + const mesh = new THREE.Mesh(new THREE.PlaneGeometry(wallLen, ARENA_WALL_H), mat); + mesh.position.set(w.x, ARENA_WALL_H / 2, w.z); + mesh.rotation.y = w.rotY; + wallMeshes.push(mesh); + } + return { wallMats, wallMeshes }; +} diff --git a/app/src/game/audio.js b/app/src/game/audio.js new file mode 100644 index 0000000..13e95cc --- /dev/null +++ b/app/src/game/audio.js @@ -0,0 +1,581 @@ +// Game audio: one shared AudioContext behind a master gain, three buses +// (ambient / sfx / voice). Plain functions and maps, no classes, matching +// the imperative game core. The voice bus carries the existing quack and +// wheee (the stars of the mix); sfx carries footsteps / ball thumps / UI +// clicks / the entrance sweep; ambient carries the arcade-room hum bed. +// +// Samples (CC0, Kenney.nl): footsteps and ball thumps from "Impact Sounds", +// UI clicks from "Interface Sounds" - trimmed to mono 22.05 kHz wav in +// public/assets/sfx/. The CRT entrance sweep, the ambient hum and the +// roller rumble are synthesized (oscillators + filtered noise): zero +// payload and a better fit for the retro DA. +// +// Spatialization is plain Web Audio: the context listener follows the +// camera every frame and cheap equalpower PannerNodes act as emitters on +// the duck and the ball (footsteps, thumps and the roller rumble pan and +// attenuate with the chase cam). Voice and UI stay non-spatial. +import { signed } from "./signed.js"; + +// ── Master kill switch ──────────────────────────────────────────────── +// Kill switch: flip to true to silence the whole mix (every public entry +// point early-returns, master gain pinned to 0, context never resumed). +// Node-returning helpers (busNode, createEmitter) keep building their +// graph either way so callers stay untouched. +const SOUND_DISABLED = true; + +// ── Context, master, buses ──────────────────────────────────────────── +const MASTER_LEVEL = 0.9; +const BUS_LEVELS = { ambient: 1, sfx: 0.9, voice: 1 }; +const MUTE_KEY = "microduck-muted"; +let ctx = null; +let master = null; +const buses = {}; // name -> GainNode +let muted = false; +try { muted = localStorage.getItem(MUTE_KEY) === "1"; } catch { /* private mode */ } + +function unlockOnce() { + if (ctx?.state === "suspended") ctx.resume().catch(() => {}); +} + +export function audioCtx() { + if (ctx) return ctx; + ctx = new (window.AudioContext ?? window.webkitAudioContext)(); + master = ctx.createGain(); + master.gain.value = SOUND_DISABLED || muted ? 0 : MASTER_LEVEL; + master.connect(ctx.destination); + for (const [name, level] of Object.entries(BUS_LEVELS)) { + const g = ctx.createGain(); + g.gain.value = level; + g.connect(master); + buses[name] = g; + } + // Autoplay policy: resume on the first user gesture (the Waddle-in + // click normally lands here; keyboard covers the ?boot=1 test path). + // While sound is disabled the context is never resumed, so the + // suspended-state guards below keep every one-shot silent too. + if (!SOUND_DISABLED) { + window.addEventListener("pointerdown", unlockOnce, { passive: true }); + window.addEventListener("keydown", unlockOnce); + } + return ctx; +} + +export function busNode(name) { + audioCtx(); + return buses[name]; +} + +// ── Master mute (HUD toggle, persisted) ─────────────────────────────── +// Ramped over ~50 ms instead of a hard cut; the sources keep running so +// unmuting picks the mix back up exactly where it was. +export const isMuted = () => muted; + +export function setMuted(next) { + if (SOUND_DISABLED) return; + muted = !!next; + try { localStorage.setItem(MUTE_KEY, muted ? "1" : "0"); } catch { /* private mode */ } + if (!ctx) return; + master.gain.setTargetAtTime(muted ? 0 : MASTER_LEVEL, ctx.currentTime, 0.017); +} + +// ── Sample bank (decode-once cache, random takes per name) ──────────── +const SFX_TAKES = { step: 5, thump: 3, click: 2 }; +const bufCache = new Map(); // url -> Promise + +function bufferFor(url) { + let p = bufCache.get(url); + if (!p) { + p = fetch(url) + .then((r) => r.arrayBuffer()) + .then((ab) => audioCtx().decodeAudioData(ab)); + bufCache.set(url, p); + } + return p; +} + +const takeUrl = (name, i) => signed(`./assets/sfx/${name}_${"abcde"[i]}.wav`); + +export function preloadSfx() { + if (SOUND_DISABLED) return; + for (const [name, n] of Object.entries(SFX_TAKES)) { + for (let i = 0; i < n; i++) bufferFor(takeUrl(name, i)).catch(() => {}); + } +} + +// Fire-and-forget one-shot. `out` routes to an emitter panner (spatial); +// otherwise the sound lands on the flat sfx bus. +export function playSfx(name, { gain = 1, rate = 1, out = null } = {}) { + if (SOUND_DISABLED) return; + const c = audioCtx(); + if (c.state === "suspended") return; // pre-gesture: stay silent, don't queue + const take = (Math.random() * SFX_TAKES[name]) | 0; + bufferFor(takeUrl(name, take)).then((buf) => { + const src = c.createBufferSource(); + src.buffer = buf; + src.playbackRate.value = rate; + const g = c.createGain(); + g.gain.value = gain; + src.connect(g); + g.connect(out ?? buses.sfx); + src.onended = () => g.disconnect(); + src.start(); + }).catch(() => {}); +} + +// Decoded playback for arbitrary URLs (the colourway voice banks): same +// cache, routed to a bus - replaces the old HTMLAudio chirp path so the +// quack sits behind the master gain like everything else. +export function playUrl(url, { bus = "voice", gain = 1, rate = 1 } = {}) { + if (SOUND_DISABLED) return; + const c = audioCtx(); + if (c.state === "suspended") return; + bufferFor(url).then((buf) => { + const src = c.createBufferSource(); + src.buffer = buf; + src.playbackRate.value = rate; + const g = c.createGain(); + g.gain.value = gain; + src.connect(g); + g.connect(buses[bus]); + src.onended = () => g.disconnect(); + src.start(); + }).catch(() => {}); +} + +export function uiClick() { + playSfx("click", { gain: 0.16, rate: 0.95 + Math.random() * 0.1 }); +} + +// ── Spatial listener + emitters ─────────────────────────────────────── +// Listener follows the three.js camera (three world coords). Emitters are +// equalpower panners: cheap, and plenty for "the duck is over there". +const _fwd = { x: 0, y: 0, z: -1 }; + +export function updateListener(camera) { + if (!ctx || ctx.state === "suspended") return; + const l = ctx.listener; + const e = camera.matrixWorld.elements; + // Camera forward = -Z column of the world matrix, up = +Y column. + _fwd.x = -e[8]; _fwd.y = -e[9]; _fwd.z = -e[10]; + const t = ctx.currentTime; + if (l.positionX) { + l.positionX.setTargetAtTime(e[12], t, 0.02); + l.positionY.setTargetAtTime(e[13], t, 0.02); + l.positionZ.setTargetAtTime(e[14], t, 0.02); + l.forwardX.setTargetAtTime(_fwd.x, t, 0.02); + l.forwardY.setTargetAtTime(_fwd.y, t, 0.02); + l.forwardZ.setTargetAtTime(_fwd.z, t, 0.02); + l.upX.setTargetAtTime(e[4], t, 0.02); + l.upY.setTargetAtTime(e[5], t, 0.02); + l.upZ.setTargetAtTime(e[6], t, 0.02); + } else { + l.setPosition(e[12], e[13], e[14]); + l.setOrientation(_fwd.x, _fwd.y, _fwd.z, e[4], e[5], e[6]); + } +} + +export function createEmitter({ refDistance = 0.6 } = {}) { + const c = audioCtx(); + const panner = c.createPanner(); + panner.panningModel = "equalpower"; + panner.distanceModel = "inverse"; + panner.refDistance = refDistance; + panner.rolloffFactor = 1.1; + panner.connect(buses.sfx); + return { + node: panner, + setPosition(x, y, z) { + if (panner.positionX) { + const t = c.currentTime; + panner.positionX.setTargetAtTime(x, t, 0.03); + panner.positionY.setTargetAtTime(y, t, 0.03); + panner.positionZ.setTargetAtTime(z, t, 0.03); + } else { + panner.setPosition(x, y, z); + } + }, + }; +} + +// ── Ambient bed (synthesized arcade-room hum) ───────────────────────── +// Mains hum (60 Hz + weak 120 Hz octave) plus a slow-breathing bed of +// lowpassed noise. Sits VERY low in the mix. The whole bed runs through a +// duck filter + duck gain automated when the pause/title overlay opens. +const AMBIENT_LEVEL = 0.05; +const AMBIENT_DUCKED = 0.018; +let ambient = null; // { duckGain, duckFilter } + +export function startAmbient() { + if (SOUND_DISABLED || ambient) return; + const c = audioCtx(); + const duckFilter = c.createBiquadFilter(); + duckFilter.type = "lowpass"; + duckFilter.frequency.value = 18000; + const duckGain = c.createGain(); + duckGain.gain.value = 0; // fade in below + duckFilter.connect(duckGain); + duckGain.connect(buses.ambient); + + const hum = c.createOscillator(); + hum.type = "sine"; + hum.frequency.value = 60; + const humG = c.createGain(); + humG.gain.value = 0.5; + hum.connect(humG); + humG.connect(duckFilter); + + const hum2 = c.createOscillator(); + hum2.type = "triangle"; + hum2.frequency.value = 120; + const hum2G = c.createGain(); + hum2G.gain.value = 0.14; + hum2.connect(hum2G); + hum2G.connect(duckFilter); + + const noise = c.createBufferSource(); + noise.buffer = noiseBuffer(c, 2.0); + noise.loop = true; + const noiseF = c.createBiquadFilter(); + noiseF.type = "lowpass"; + noiseF.frequency.value = 260; + const noiseG = c.createGain(); + noiseG.gain.value = 0.5; + noise.connect(noiseF); + noiseF.connect(noiseG); + noiseG.connect(duckFilter); + + // Slow breathing on the noise bed (~0.08 Hz) so the room feels alive. + const lfo = c.createOscillator(); + lfo.frequency.value = 0.08; + const lfoG = c.createGain(); + lfoG.gain.value = 0.15; + lfo.connect(lfoG); + lfoG.connect(noiseG.gain); + + hum.start(); + hum2.start(); + noise.start(); + lfo.start(); + duckGain.gain.setTargetAtTime(AMBIENT_LEVEL, c.currentTime, 1.2); + ambient = { duckGain, duckFilter }; +} + +export function setAmbientDucked(ducked) { + if (!ambient) return; + const t = ctx.currentTime; + ambient.duckGain.gain.setTargetAtTime(ducked ? AMBIENT_DUCKED : AMBIENT_LEVEL, t, 0.25); + ambient.duckFilter.frequency.setTargetAtTime(ducked ? 300 : 18000, t, 0.25); +} + +function noiseBuffer(c, seconds) { + const n = (c.sampleRate * seconds) | 0; + const buf = c.createBuffer(1, n, c.sampleRate); + const d = buf.getChannelData(0); + for (let i = 0; i < n; i++) d[i] = Math.random() * 2 - 1; + return buf; +} + +// ── Materialize sweeps (phase-locked to the wireframe FX) ───────────── +// fx-wireframe.js runs two overlapping passes over totalS seconds (duck: +// 0.9 s): a wireframe scan line over the first 2/3 and a trailing +// solidify line over the last 2/3, BOTH driven by the same ease-out +// (1 - (1-x)^2): the line launches at full speed and decelerates into +// the top. The pitch of each layer follows that exact curve (sampled +// into setValueCurveAtTime), so the sweep rushes then settles exactly +// like the line the player watches - not a straight climb through it. +// +// scan [0 .. 2/3 T] square, 150 -> 1500 Hz along the fx ease +// solid [1/3 T .. T] triangle an octave down, same curve, trailing +// T resolve: sine drop thunk + soft high ping +// +// Props reuse the same voice via playPropSweep: their fx stretches the +// timeline by sqrt(size) (see fx-wireframe REF_SPAN), so the duration +// itself encodes the target's size - the sweep divides its pitch by +// that stretch, and big objects (arcade cabinet) materialize DEEPER +// and longer while small ones chirp through quickly. +const FX_EASE = (x) => 1 - (1 - x) * (1 - x); // fx-wireframe's ease() +const FX_BASE_S = 0.9; // fx TOTAL_S before size stretch + +function easedPitchCurve(f0, f1, n = 48) { + const arr = new Float32Array(n); + for (let i = 0; i < n; i++) arr[i] = f0 * (f1 / f0) ** FX_EASE(i / (n - 1)); + return arr; +} + +// One materialize voice. level scales every layer; pitchK divides the +// whole sweep's register (bigger target = lower); shimmer + ping are the +// duck's hero garnish, props skip them. +function materializeSweep(c, { totalS, level = 1, pitchK = 1, hero = true }) { + const T = Math.max(0.3, totalS); + const t0 = c.currentTime + 0.01; + const scanEnd = t0 + T * (2 / 3); + const solidStart = t0 + T * (1 / 3); + const tEnd = t0 + T; + const k = 1 / pitchK; + + const out = c.createGain(); + out.gain.value = level; + const tone = c.createBiquadFilter(); + tone.type = "lowpass"; + tone.frequency.value = 5200; // tame the squares' buzz, keep the bite + tone.connect(out); + out.connect(buses.sfx); + + // Static tick right as the scan cues. + const tick = c.createBufferSource(); + tick.buffer = noiseBuffer(c, 0.06); + const tickF = c.createBiquadFilter(); + tickF.type = "highpass"; + tickF.frequency.value = 2500; + const tickG = c.createGain(); + tickG.gain.setValueAtTime(0.1, t0); + tickG.gain.exponentialRampToValueAtTime(0.001, t0 + 0.06); + tick.connect(tickF); + tickF.connect(tickG); + tickG.connect(out); + tick.start(t0); + + // Scan pass: rising square riding the scan line's exact ease-out. + const scan = c.createOscillator(); + scan.type = "square"; + scan.frequency.setValueCurveAtTime( + easedPitchCurve(150 * k, 1500 * k), t0, T * (2 / 3), + ); + const scanG = c.createGain(); + scanG.gain.setValueAtTime(0, t0); + scanG.gain.linearRampToValueAtTime(0.14, t0 + 0.03); + scanG.gain.setValueAtTime(0.14, scanEnd - 0.05); + scanG.gain.exponentialRampToValueAtTime(0.001, scanEnd + 0.08); + scan.connect(scanG); + scanG.connect(tone); + scan.start(t0); + scan.stop(scanEnd + 0.1); + + // Solidify pass: same eased climb an octave down, trailing like the + // second line, swelling as the target fills in solid. + const solid = c.createOscillator(); + solid.type = "triangle"; + solid.frequency.setValueCurveAtTime( + easedPitchCurve(85 * k, 760 * k), solidStart, T * (2 / 3), + ); + const solidG = c.createGain(); + solidG.gain.setValueAtTime(0, solidStart); + solidG.gain.linearRampToValueAtTime(0.08, solidStart + 0.06); + solidG.gain.linearRampToValueAtTime(0.16, tEnd - 0.05); + solidG.gain.exponentialRampToValueAtTime(0.001, tEnd + 0.06); + solid.connect(solidG); + solidG.connect(tone); + solid.start(solidStart); + solid.stop(tEnd + 0.1); + + if (hero) { + // Hologram shimmer: airy bandpassed noise, centre frequency easing + // up with the reveal like everything else. + const shimmer = c.createBufferSource(); + shimmer.buffer = noiseBuffer(c, T); + const shimF = c.createBiquadFilter(); + shimF.type = "bandpass"; + shimF.frequency.setValueCurveAtTime( + easedPitchCurve(1800 * k, 5200 * k), t0, T, + ); + shimF.Q.value = 1.2; + const shimG = c.createGain(); + shimG.gain.setValueAtTime(0, t0); + shimG.gain.linearRampToValueAtTime(0.05, t0 + 0.1); + shimG.gain.setValueAtTime(0.05, tEnd - 0.15); + shimG.gain.linearRampToValueAtTime(0, tEnd); + shimmer.connect(shimF); + shimF.connect(shimG); + shimG.connect(out); + shimmer.start(t0); + } + + // Resolve: pitch-drop thunk right when the solidify line clears the + // top and the real materials land. Deeper for bigger targets. + const thunk = c.createOscillator(); + thunk.type = "sine"; + thunk.frequency.setValueAtTime(170 * k, tEnd); + thunk.frequency.exponentialRampToValueAtTime(62 * k, tEnd + 0.13); + const thunkG = c.createGain(); + thunkG.gain.setValueAtTime(hero ? 0.3 : 0.22, tEnd); + thunkG.gain.exponentialRampToValueAtTime(0.001, tEnd + 0.22); + thunk.connect(thunkG); + thunkG.connect(out); + thunk.start(tEnd); + thunk.stop(tEnd + 0.25); + + if (hero) { + const ping = c.createOscillator(); + ping.type = "sine"; + ping.frequency.value = 1320; + const pingG = c.createGain(); + pingG.gain.setValueAtTime(0.07, tEnd); + pingG.gain.exponentialRampToValueAtTime(0.001, tEnd + 0.3); + ping.connect(pingG); + pingG.connect(out); + ping.start(tEnd); + ping.stop(tEnd + 0.32); + ping.onended = () => out.disconnect(); + } else { + thunk.onended = () => out.disconnect(); + } +} + +// The duck's hero sweep (entrance and every respawn scan-up). +export function playEntranceSweep(totalS = 0.9) { + if (SOUND_DISABLED) return; + const c = audioCtx(); + if (c.state === "suspended") return; + materializeSweep(c, { totalS, level: 1, pitchK: 1, hero: true }); +} + +// One prop materializing (arcade cabinet, boombox...). The fx stretches +// its timeline by sqrt(size), so recover that stretch from the duration +// and drop the register by it: a 2.2 s cabinet sweeps ~2.5x deeper than +// the duck, a duck-sized prop sounds like a quieter duck. A tiny random +// detune keeps staggered props from phasing into one thick chord. +export function playPropSweep(totalS = 0.9) { + if (SOUND_DISABLED) return; + const c = audioCtx(); + if (c.state === "suspended") return; + const durK = Math.max(1, totalS / FX_BASE_S); + const detune = 2 ** ((Math.random() - 0.5) * 0.16); + materializeSweep(c, { + totalS, + level: 0.4, + pitchK: durK * detune, + hero: false, + }); +} + +// ── BIOS / menu one-shots (synthesized, retro POST language) ────────── +// All guarded on a suspended context: the BIOS replay only starts after +// the enter click (the unlock gesture), but a gamepad-only entry can +// leave the context locked - then these simply stay silent. + +// Single POST beep, the classic "one beep = all good". +export function playBiosBeep() { + if (SOUND_DISABLED) return; + const c = audioCtx(); + if (c.state === "suspended") return; + const t0 = c.currentTime + 0.01; + const osc = c.createOscillator(); + osc.type = "square"; + osc.frequency.value = 940; + const g = c.createGain(); + g.gain.setValueAtTime(0, t0); + g.gain.linearRampToValueAtTime(0.08, t0 + 0.008); + g.gain.setValueAtTime(0.08, t0 + 0.1); + g.gain.exponentialRampToValueAtTime(0.001, t0 + 0.16); + osc.connect(g); + g.connect(buses.sfx); + osc.start(t0); + osc.stop(t0 + 0.18); + osc.onended = () => g.disconnect(); +} + +// Teletype tick, one per printed POST line. Whisper-level. +export function playBiosTick() { + if (SOUND_DISABLED) return; + const c = audioCtx(); + if (c.state === "suspended") return; + const t0 = c.currentTime; + const osc = c.createOscillator(); + osc.type = "square"; + osc.frequency.value = 1750 + Math.random() * 350; + const g = c.createGain(); + g.gain.setValueAtTime(0.02, t0); + g.gain.exponentialRampToValueAtTime(0.001, t0 + 0.018); + osc.connect(g); + g.connect(buses.sfx); + osc.start(t0); + osc.stop(t0 + 0.02); + osc.onended = () => g.disconnect(); +} + +// Menu-confirm bloop (Waddle in / Resume / pad A): two rising square +// notes, C5 -> G5. This rides the very gesture that unlocks the context, +// so a suspended context gets one resume-then-play attempt. +export function playConfirmBloop() { + if (SOUND_DISABLED) return; + const c = audioCtx(); + if (c.state === "suspended") { + c.resume().then(() => confirmNow(c)).catch(() => {}); + return; + } + confirmNow(c); +} + +function confirmNow(c) { + const t0 = c.currentTime + 0.01; + const tone = c.createBiquadFilter(); + tone.type = "lowpass"; + tone.frequency.value = 4200; + tone.connect(buses.sfx); + const osc = c.createOscillator(); + osc.type = "square"; + osc.frequency.setValueAtTime(523, t0); + osc.frequency.setValueAtTime(784, t0 + 0.07); + const g = c.createGain(); + g.gain.setValueAtTime(0, t0); + g.gain.linearRampToValueAtTime(0.13, t0 + 0.01); + g.gain.setValueAtTime(0.13, t0 + 0.12); + g.gain.exponentialRampToValueAtTime(0.001, t0 + 0.2); + osc.connect(g); + g.connect(tone); + osc.start(t0); + osc.stop(t0 + 0.22); + osc.onended = () => tone.disconnect(); +} + +// ── Entrance line blips ─────────────────────────────────────────────── +// One tiny tick per grid/wall section line as it starts drawing in. `u` +// is the line's own draw jitter (0..1), reused as pitch variation so the +// flurry chirps instead of machine-gunning. Very low in the mix. +export function playLineBlip(u = 0.5) { + if (SOUND_DISABLED) return; + const c = audioCtx(); + if (c.state === "suspended") return; + const t0 = c.currentTime; + const osc = c.createOscillator(); + osc.type = "triangle"; + osc.frequency.value = 1400 * 2 ** (u * 0.9); // ~1.4-2.6 kHz across lines + const g = c.createGain(); + g.gain.setValueAtTime(0.05, t0); + g.gain.exponentialRampToValueAtTime(0.001, t0 + 0.05); + osc.connect(g); + g.connect(buses.sfx); + osc.start(t0); + osc.stop(t0 + 0.06); + osc.onended = () => g.disconnect(); +} + +// ── Roller rumble (synthesized rolling-noise loop) ──────────────────── +// Bandpassed noise on the duck emitter; gain and a slight pitch follow +// ground speed, silent at rest. Built lazily on first use. +let rumble = null; // { gain, src } + +export function setRumble(level, out = null) { + if (SOUND_DISABLED) return; + const c = audioCtx(); + if (!rumble) { + if (level <= 0) return; + const src = c.createBufferSource(); + src.buffer = noiseBuffer(c, 1.5); + src.loop = true; + const f = c.createBiquadFilter(); + f.type = "bandpass"; + f.frequency.value = 110; + f.Q.value = 0.8; + const g = c.createGain(); + g.gain.value = 0; + src.connect(f); + f.connect(g); + g.connect(out?.node ?? buses.sfx); + src.start(); + rumble = { gain: g, src }; + } + const t = c.currentTime; + rumble.gain.gain.setTargetAtTime(Math.min(1, level) * 0.22, t, 0.08); + rumble.src.playbackRate.setTargetAtTime(0.85 + 0.5 * Math.min(1, level), t, 0.12); +} diff --git a/app/src/game/ball-actor.js b/app/src/game/ball-actor.js new file mode 100644 index 0000000..62b1739 --- /dev/null +++ b/app/src/game/ball-actor.js @@ -0,0 +1,102 @@ +// Ball actor: physics stays in rl.js, this owns the mesh + wireframe FX. +// +// visual: +// hidden parked, mesh off +// live following qpos, optional appear scan playing +// ghost physics already parked; mesh frozen at last pose while the +// reverse scan peels it away +// +// spawn while live/ghost queues a pop: despawn finishes, then the caller +// places physics and appear()s. + +// Appear/disappear speed. The shared wireframe FX timeline lasts +// fx.TOTAL_S (0.9 s, tuned for the duck's ceremony); the ball plays the +// same timeline time-scaled to these snappier durations. +const BALL_APPEAR_S = 0.35; // spawn pop-in (scan up) +const BALL_DISAPPEAR_S = 0.25; // despawn/park peel-away (reverse scan) + +export function createBallActor({ THREE, scene, camera, renderer, fxModule, mesh, group }) { + const fx = fxModule.createWireframeFx(); + fx.init({ THREE, scene, root: group, camera, renderer, hidden: false }); + + let visual = "hidden"; // hidden | live | ghost + let ghost = null; + let pendingSpawn = false; + let fxPrev = null; + + function appear() { + visual = "live"; + ghost = null; + mesh.visible = true; + fx.start(); + fxPrev = performance.now(); + } + + function despawn({ cancelQueued = false, parkPhysics }) { + if (cancelQueued) pendingSpawn = false; + if (visual === "hidden") return; + if (visual === "live") { + ghost = { + pos: mesh.position.clone(), + quat: mesh.quaternion.clone(), + }; + visual = "ghost"; + } + parkPhysics(); + fx.startReverse(); + fxPrev = performance.now(); + } + + function queueRespawn() { + pendingSpawn = true; + } + + function poseFromQpos(qpos, adr) { + mesh.position.set(qpos[adr], qpos[adr + 1], qpos[adr + 2]); + mesh.quaternion.set(qpos[adr + 4], qpos[adr + 5], qpos[adr + 6], qpos[adr + 3]); + } + + function sync(qpos, adr, physicsLive) { + if (visual === "ghost" && ghost) { + mesh.visible = true; + mesh.position.copy(ghost.pos); + mesh.quaternion.copy(ghost.quat); + } else if (physicsLive) { + mesh.visible = true; + poseFromQpos(qpos, adr); + } else { + mesh.visible = false; + } + } + + function drive(onQueuedSpawn) { + if (fx.playing) { + const now = performance.now(); + if (fxPrev === null) fxPrev = now; + const dt = Math.min((now - fxPrev) / 1000, 0.25); + fxPrev = now; + // Time-scale the FX so the ball pops in/out at its own speed. + const speed = fx.TOTAL_S / (fx.reversing ? BALL_DISAPPEAR_S : BALL_APPEAR_S); + fx.update(dt * speed); + } + if (visual === "ghost" && fx.isDone()) { + mesh.visible = false; + visual = "hidden"; + ghost = null; + fx.restore(); + const queued = pendingSpawn; + pendingSpawn = false; + if (queued) onQueuedSpawn(); + } + } + + return { + appear, + despawn, + queueRespawn, + poseFromQpos, + sync, + drive, + get visual() { return visual; }, + }; +} diff --git a/app/src/game/ball-visual.js b/app/src/game/ball-visual.js new file mode 100644 index 0000000..0ecdea9 --- /dev/null +++ b/app/src/game/ball-visual.js @@ -0,0 +1,149 @@ +// Ball visuals: procedural soccer-ball texture + the render mesh, ported +// verbatim from the pre-React rl.js. +import * as THREE from "three"; +import { BALL_RADIUS } from "./constants.js"; + +// Soccer-ball look computed per pixel on the sphere itself, so there is +// no pole or seam special case by design. The truncated icosahedron is +// reconstructed as a spherical Voronoi diagram over 32 sites: the 12 +// icosahedron vertices (black pentagon centers, one sitting at each +// pole) and its 20 face centers (white hexagon centers). A pixel is +// black when its nearest site is a pentagon center and it sits clear of +// the cell boundary by a seam margin - which yields big flat-edged black +// pentagons separated from the white hexagons by thin seams, corners +// almost touching, exactly like the real panel layout. +function makeSoccerBallTexture(renderer) { + const W = 1024, H = 512; + const c = document.createElement("canvas"); + c.width = W; + c.height = H; + const ctx = c.getContext("2d"); + // 12 icosahedron vertices: 2 poles + two staggered rings of 5 at + // latitude +-atan(1/2) (~26.57 deg) - the pentagon centers. + const sites = []; + const addSite = (v, isPent) => { + const n = Math.hypot(v[0], v[1], v[2]); + sites.push({ x: v[0] / n, y: v[1] / n, z: v[2] / n, pent: isPent }); + }; + const verts = [[0, 0, 1], [0, 0, -1]]; + const latR = Math.atan(0.5), cr = Math.cos(latR), sr = Math.sin(latR); + for (let i = 0; i < 5; i++) { + const a = (i * 72 * Math.PI) / 180; + const b = ((i * 72 + 36) * Math.PI) / 180; + verts.push([cr * Math.cos(a), cr * Math.sin(a), sr]); + verts.push([cr * Math.cos(b), cr * Math.sin(b), -sr]); + } + for (const v of verts) addSite(v, true); + // 20 face centers (hexagon centers): normalized centroids of every + // mutually-adjacent vertex triple (adjacent pairs have dot = 1/sqrt(5)). + const adj = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2] > 0.3; + for (let i = 0; i < 12; i++) { + for (let j = i + 1; j < 12; j++) { + if (!adj(verts[i], verts[j])) continue; + for (let k = j + 1; k < 12; k++) { + if (adj(verts[i], verts[k]) && adj(verts[j], verts[k])) { + addSite([ + verts[i][0] + verts[j][0] + verts[k][0], + verts[i][1] + verts[j][1] + verts[k][1], + verts[i][2] + verts[j][2] + verts[k][2], + ], false); + } + } + } + } + // Seam half-width and anti-alias band, in radians of arc. + const SEAM = (1.6 * Math.PI) / 180; + const AA = (0.35 * Math.PI) / 180; + // Groove reach for the bump map: a touch wider than the painted seam so + // the recess shoulders catch light on both sides of the line. + const GROOVE = SEAM * 1.5; + const BG = [233, 231, 224], INK = [23, 23, 29], STITCH = [200, 197, 188]; + const img = ctx.createImageData(W, H); + const px = img.data; + // Height map sharing the same panel construction: seams become recessed + // grooves, plus a very fine leather/PVC grain over the whole surface. + const bc = document.createElement("canvas"); + bc.width = W; + bc.height = H; + const bctx = bc.getContext("2d"); + const bimg = bctx.createImageData(W, H); + const bpx = bimg.data; + for (let row = 0; row < H; row++) { + const lat = Math.PI / 2 - ((row + 0.5) / H) * Math.PI; + const cl = Math.cos(lat), sl = Math.sin(lat); + for (let col = 0; col < W; col++) { + const lon = ((col + 0.5) / W) * 2 * Math.PI - Math.PI; + const dx = cl * Math.cos(lon), dy = cl * Math.sin(lon), dz = sl; + let best = -2, second = -2, bestPent = false; + for (const s of sites) { + const d = dx * s.x + dy * s.y + dz * s.z; + if (d > best) { second = best; best = d; bestPent = s.pent; } + else if (d > second) second = d; + } + // Signed distance to the Voronoi cell boundary along the geodesic. + const halfGap = (Math.acos(Math.min(1, second)) - Math.acos(Math.min(1, best))) / 2; + // Black panel: inside a pentagon cell, clear of the seam margin. + const black = bestPent ? Math.min(1, Math.max(0, (halfGap - SEAM) / AA)) : 0; + // Subtle stitch line on every remaining cell boundary so the white + // hexagons read as panels too. + const stitch = Math.min(1, Math.max(0, 1 - halfGap / (SEAM * 0.6))) * (1 - black); + const o = (row * W + col) * 4; + for (let ch = 0; ch < 3; ch++) { + const base = BG[ch] + (STITCH[ch] - BG[ch]) * stitch; + px[o + ch] = base + (INK[ch] - base) * black; + } + px[o + 3] = 255; + // Bump: quadratic groove profile (soft shoulders, no golf-ball + // embossing) + grain noise. + const groove = Math.max(0, 1 - halfGap / GROOVE) ** 2; + const hgt = 205 - groove * 115 + (Math.random() - 0.5) * 14; + const h8 = Math.max(0, Math.min(255, hgt)); + bpx[o] = h8; bpx[o + 1] = h8; bpx[o + 2] = h8; + bpx[o + 3] = 255; + } + } + ctx.putImageData(img, 0, 0); + bctx.putImageData(bimg, 0, 0); + const finish = (canvas, srgb) => { + const tex = new THREE.CanvasTexture(canvas); + // The bump map stays linear; only the color map is sRGB. + if (srgb) tex.colorSpace = THREE.SRGBColorSpace; + // Texel footprints get extremely anamorphic near the UV poles; without + // anisotropy the cap edge visibly scallops at close range. + tex.anisotropy = renderer.capabilities.getMaxAnisotropy(); + return tex; + }; + return { map: finish(c, true), bumpMap: finish(bc, false) }; +} + +// Same Z-up -> Y-up trick as the duck rig: the group takes the axis fix, +// the mesh inside takes the raw MJCF free-joint pose. +export function createBallVisual(renderer) { + const group = new THREE.Group(); + group.rotation.x = -Math.PI / 2; + const tex = makeSoccerBallTexture(renderer); + const mesh = new THREE.Mesh( + // 48x32 segments: the coarser default makes the UV interpolation near + // the poles visibly scallop the round cap edge of the texture. + new THREE.SphereGeometry(BALL_RADIUS, 48, 32), + // Physical material for the waxed vintage-leather look: matte-ish base + // with a whisper of clearcoat so highlights ride the seam grooves. + new THREE.MeshPhysicalMaterial({ + map: tex.map, + bumpMap: tex.bumpMap, + bumpScale: 0.0012, + metalness: 0, + roughness: 0.55, + clearcoat: 0.2, + clearcoatRoughness: 0.35, + }), + ); + mesh.userData.meshName = "ball"; + // The 48x32 render sphere is far too dense for the wireframe scan (it + // reads as a solid glowing blob); the FX overlay uses this geodesic + // stand-in instead - 80 triangles, clean hologram lines. + mesh.userData.fxWireGeometry = new THREE.IcosahedronGeometry(BALL_RADIUS, 1); + mesh.visible = false; + group.add(mesh); + return { group, mesh }; +} diff --git a/app/src/game/ceremony.js b/app/src/game/ceremony.js new file mode 100644 index 0000000..81d7a4f --- /dev/null +++ b/app/src/game/ceremony.js @@ -0,0 +1,267 @@ +// Cutscene layer: page-load entrance and every later respawn. +// +// Physics (resetSim) snaps the duck to the stand keyframe; this module +// owns what the player sees around that snap. Two mutually exclusive +// timelines share the duck's wireframe FX: +// +// entrance (once) grid + walls draw in, then the duck scans up +// respawn (every kill / Space / loco switch) +// 0.00 duck clipped away, camera glides home from the kill view +// 0.80 camera almost settled -> duck scan-up cues +// 0.90 camera lands +// 1.70 scan done, inputs unlock +// +// rl.js injects the world (rig, grid, camera reset) and the lock/flash +// callbacks; this file never touches MuJoCo. + +import { entranceLineCues } from "./arena.js"; + +export const CAM_RESET_S = 0.9; +export const RESPAWN_SCAN_AT = 0.8; // cue scan-up at 80% of the camera glide + +const ENTRANCE_GRID_S = 1.1; +const ENTRANCE_WALL_DELAY_S = 0.35; +const ENTRANCE_WALL_S = 0.9; +const ENTRANCE_FX_START_S = 0.6; + +const clamp01 = (x) => Math.min(Math.max(x, 0), 1); + +export function createCeremony({ + THREE, scene, camera, renderer, fx, + getRig, grid, wallMats, + syncRig, startCameraReset, + setLocked, flashReset, + onScanCue = () => {}, + onLineCue = () => {}, + onPropCue = () => {}, +}) { + const ENTRANCE_TOTAL_S = Math.max( + ENTRANCE_GRID_S, + ENTRANCE_WALL_DELAY_S + ENTRANCE_WALL_S, + ENTRANCE_FX_START_S + fx.TOTAL_S, + ); + + // Per-line audio cues for the entrance draw-in: normalized reveal times + // from arena.js (exact same hashed stagger as the shaders), mapped onto + // this timeline's grid/wall reveal windows. Entrance-only: respawns + // never redraw the arena. + const cues = entranceLineCues(); + const lineCues = [ + ...cues.grid.map((c) => ({ at: c.at * ENTRANCE_GRID_S, u: c.u })), + ...cues.walls.map((c) => ({ + at: ENTRANCE_WALL_DELAY_S + c.at * ENTRANCE_WALL_S, u: c.u, + })), + ].sort((a, b) => a.at - b.at); + let lineCueIdx = lineCues.length; // parked until startEntrance + + let fxRig = null; + let fxPrev = null; + // Decorative props (addPropFx): each owns a wireframe FX bound to its + // own root. They cue whenever the duck's scan cues (entrance and every + // respawn), offset by their stagger, and drive on their OWN clock so a + // late-finishing prop never extends the input lock or the ceremony's + // completion checks. + const props = []; // { fx, delayS, at, started, prev } + let entranceT0 = null; + let entranceFxCued = false; + let entranceDone = false; + let respawn = null; // { t0, scanCued } | null + let entranceFinishedResolve; + const entranceFinished = new Promise((r) => { entranceFinishedResolve = r; }); + + function bind() { + const rig = getRig(); + if (fxRig === rig) return; + fx.dispose(); + fx.init({ THREE, scene, rig, camera, renderer }); + rig.placer.traverse((o) => { + if (o.isMesh && !o.userData.meshName) o.userData.fxOverlay = true; + }); + fxRig = rig; + } + + function fxStart() { + bind(); + fx.start(); + fxPrev = performance.now(); + propsCue(); + // Sound cue riding the same trigger as the visual scan; the duration + // lets the sweep span the materialize exactly. + onScanCue(fx.TOTAL_S); + } + function propsCue() { + const now = performance.now(); + for (const p of props) { + p.at = now + p.delayS * 1000; + p.started = false; + p.prev = null; + } + } + function propsHide() { + for (const p of props) { + p.fx.setProgress(0); + p.at = null; + p.started = false; + } + } + function propsFinish() { + for (const p of props) { + if (!p.started) p.fx.start(); + p.fx.update(1e3); + p.at = null; + } + } + // Deterministic screenshot/test hook (setFx): park every prop at the + // same scan progress as the duck, detached from the timed driver. + function propsSetProgress(v) { + for (const p of props) { + p.fx.setProgress(v); + p.at = null; + p.started = false; + } + } + function driveProps() { + const now = performance.now(); + for (const p of props) { + if (p.at === null || now < p.at) continue; + if (!p.started) { + p.fx.start(); + // Audio twin, cued the frame this prop's scan actually starts; + // TOTAL_S carries the size-stretched duration so the sound can + // match both length and register. + onPropCue(p.fx.TOTAL_S); + p.started = true; + p.prev = now; + continue; + } + if (p.fx.isDone()) continue; + const dt = Math.min((now - p.prev) / 1000, 0.25); + p.prev = now; + p.fx.update(dt); + } + } + function fxDrive() { + if (fxPrev === null || fx.isDone()) return; + const now = performance.now(); + const dt = Math.min((now - fxPrev) / 1000, 0.25); + fxPrev = now; + fx.update(dt); + } + function fxForceFinish() { + if (!fx.isDone()) fx.update(1e3); + } + + function startEntrance() { + if (entranceT0 !== null || entranceDone) return; + entranceT0 = performance.now(); + entranceFxCued = false; + lineCueIdx = 0; + grid.material.uniforms.uReveal.value = 0; + for (const m of wallMats) m.uniforms.uReveal.value = 0; + } + + function driveEntrance() { + if (entranceT0 === null) return; + const t = (performance.now() - entranceT0) / 1000; + // Fire the per-line blips as their lines start drawing in. + while (lineCueIdx < lineCues.length && lineCues[lineCueIdx].at <= t) { + onLineCue(lineCues[lineCueIdx].u); + lineCueIdx++; + } + grid.material.uniforms.uReveal.value = clamp01(t / ENTRANCE_GRID_S); + const wallR = clamp01((t - ENTRANCE_WALL_DELAY_S) / ENTRANCE_WALL_S); + for (const m of wallMats) m.uniforms.uReveal.value = wallR; + if (t >= ENTRANCE_FX_START_S && !entranceFxCued) { + entranceFxCued = true; + fxStart(); + } + fxDrive(); + if (t >= ENTRANCE_TOTAL_S) { + if (!fx.isDone() && t < ENTRANCE_TOTAL_S + 0.5) return; + fxForceFinish(); + entranceT0 = null; + entranceDone = true; + grid.material.uniforms.uReveal.value = 1; + for (const m of wallMats) m.uniforms.uReveal.value = 1; + setLocked(false); + entranceFinishedResolve(); + } + } + + function playRespawn() { + if (!entranceDone) return; + setLocked(true); + flashReset(); + bind(); + startCameraReset(); + syncRig(); + fx.setProgress(0); + propsHide(); + respawn = { t0: performance.now(), scanCued: false }; + } + + function driveRespawn() { + if (!respawn) return; + const u = (performance.now() - respawn.t0) / 1000 / CAM_RESET_S; + if (!respawn.scanCued && u >= RESPAWN_SCAN_AT) { + respawn.scanCued = true; + fxStart(); + } + if (respawn.scanCued) fxDrive(); + if (respawn.scanCued && fx.isDone()) { + respawn = null; + setLocked(false); + } + } + + function drive() { + driveEntrance(); + driveRespawn(); + driveProps(); + } + + function setReveal(floor, wall = floor) { + entranceT0 = null; + grid.material.uniforms.uReveal.value = floor; + for (const m of wallMats) m.uniforms.uReveal.value = wall; + } + + function setFx(p) { + entranceT0 = null; + respawn = null; + bind(); + if (p >= 1) { + fx.start(); + fxForceFinish(); + propsFinish(); + setLocked(false); + entranceFinishedResolve(); + } else { + fx.setProgress(p); + propsSetProgress(p); + } + } + + // Register a decorative prop's wireframe FX (already init'd on its own + // root, hidden). It materializes delayS after each duck scan cue. + function addPropFx(propFx, delayS = 0) { + props.push({ fx: propFx, delayS, at: null, started: false, prev: null }); + } + + // Boot hidden: clip parked below the feet from the first frame. + bind(); + + return { + CAM_RESET_S, + startEntrance, + playRespawn, + drive, + bind, + setReveal, + setFx, + addPropFx, + entranceFinished, + get entranceDone() { return entranceDone; }, + get respawnActive() { return respawn !== null; }, + }; +} diff --git a/app/src/game/constants.js b/app/src/game/constants.js new file mode 100644 index 0000000..88c901d --- /dev/null +++ b/app/src/game/constants.js @@ -0,0 +1,117 @@ +// Shared sim constants, lifted verbatim from the pre-React rl.js. + +export const POLICY_DIR = "./policies"; +export const POLICIES = { + walk: `${POLICY_DIR}/BEST_alpha_walking.onnx`, + sitstand: `${POLICY_DIR}/BEST_alpha_sitstand.onnx`, + roll: `${POLICY_DIR}/roulade.onnx`, + // Blind one-shot kicks (the operator aims the robot, no ball in obs): + // the runtime swaps these in for a 0.5 s window, commands zeroed. + kickL: `${POLICY_DIR}/ball_kick_left.onnx`, + kickR: `${POLICY_DIR}/ball_kick_right.onnx`, + // One-shot ground pick (runtime A button): peck the ground and stand + // back up, phase-driven via [cos, sin, 0] in the command vel slots. + groundpick: `${POLICY_DIR}/alpha_ground_pick.onnx`, + // Get-up policy for the automatic fall recovery (runtime --fall-detect): + // same 61D obs layout as the other alpha policies, commands all zeroed. + stand: `${POLICY_DIR}/BEST_alpha_stand.onnx`, + // Roller variant (lazy-loaded on first switch, never at boot): + // drive = velocity-tracking skating, crouch = one-shot crouch-glide + // driven by a phase encoding in the command slots (ground-pick style). + drive: `${POLICY_DIR}/BEST_roller.onnx`, + crouch: `${POLICY_DIR}/BEST_roller_crouch.onnx`, +}; + +// From the ONNX metadata (identical for all alpha policies) and the STAND +// keyframe in mjlab's scene_walk.xml. Order matches the actuators in +// the MJCF. +export const JOINT_NAMES = [ + "left_hip_yaw", "left_hip_roll", "left_hip_pitch", "left_knee", "left_ankle", + "neck_pitch", "head_pitch", "head_yaw", "head_roll", + "right_hip_yaw", "right_hip_roll", "right_hip_pitch", "right_knee", "right_ankle", +]; +export const DEFAULT_POSE = new Float32Array([ + 0, -0.08726646259971647, -0.457924, -0.004940, 0.452984, + 0.3490658503988659, 0.3490658503988659, 0, 0, + 0, 0.08726646259971647, 0.457924, 0.004940, -0.452984, +]); +export const NUM_JOINTS = 14; +export const OBS_SIZE = 61; +export const CMD_SIZE = 13; +export const ACTION_SCALE = 1.0; +export const TIMESTEP = 0.005; +export const DECIMATION = 4; +export const CTRL_DT = TIMESTEP * DECIMATION; // 50 Hz + +// Velocity command limits, same as infer_policy.py's keyboard mapping. +// No strafe input anymore: the lateral cmd slot stays zeroed for the obs. +export const VEL_FWD = 0.25, VEL_BACK = -0.2, VEL_ANG = 1.0; +// Roller mode limits, from the runtime's roller branch: asymmetric vx +// (0.6 push / 0.5 brake), no lateral. The real runtime launches rollers +// with --max-angular-vel 0.3: faster commanded turns tip the robot over, +// so the playground clamps wz the same way. +export const RVEL_FWD = 0.6, RVEL_BACK = -0.5, RVEL_ANG = 0.3; +// Crouch-glide one-shot: command = [cos(2pi*phase), sin(2pi*phase), 0], +// phase advancing at 1/CROUCH_PERIOD_S per second and the cycle exiting +// at 0.7 - exactly the runtime's ground-pick slot the policy was trained +// against (mjlab CROUCH_PERIOD = 5.0, cycle end 0.7 => 3.5 s gesture). +export const CROUCH_PERIOD_S = 5.0; +export const CROUCH_END_PHASE = 0.7; +// Ground-pick one-shot (legs): same phase encoding, from the runtime's +// defaults (--ground-pick-period 4.0, cycle exiting at 0.7 => ~2.8 s +// gesture, action scale and kP untouched at their 1.0 defaults). +export const GROUND_PICK_PERIOD_S = 4.0; +export const GROUND_PICK_END_PHASE = 0.7; + +// Kickable ball: radius and parking spot (far away = hidden by default). +export const BALL_RADIUS = 0.05; +export const BALL_PARK_POS = "50 0 0.05"; + +// Square arena boxing the play area: static walls at +-ARENA_HALF keep +// the ball (and the duck) inside. Tall enough that neither steps over. +export const ARENA_HALF = 1.5; // inner half-size, m +export const ARENA_WALL_H = 0.25; +export const ARENA_WALL_T = 0.05; +// Section grid: 5 cells across the 3 m arena (ODD, so a true middle +// column/row of cells exists; the lattice is shifted half a cell in the +// shaders so the walls land exactly on section lines). +export const GRID_SECTION = (2 * ARENA_HALF) / 5; // 0.6 m +// Arcade cabinet row: three cabinets side by side against the front (+X) +// wall, screens facing the arena. Consumed by the prop library (props.js +// "arcade" def - currently benched, enabled: false) for both the clone +// placements and the row's single static collision box. Proportions +// measured from the GLB's natural size (0.524 x 0.587 x 1.0 m, w x d x h). +// Slightly surreal scale: ~2.8x the 0.25 m duck (a real 1.73 m cabinet +// felt overwhelming in the 3 m arena). Big enough to read as oversized +// furniture, small enough that the row (~1.15 m wide, 0.41 m deep) +// leaves the play area open. +export const ARCADE_H = 0.7; // target height, m +export const ARCADE_W = ARCADE_H * 0.524; // footprint width, ~0.22 m +export const ARCADE_D = ARCADE_H * 0.5876; // footprint depth, ~0.247 m +export const ARCADE_GAP = 0.02; // gap between neighbouring cabinets +export const ARCADE_WALL_GAP = 0.01; // clearance between backs and the wall + +// Relief (prototype): gentle cosine bumps baked into the level itself. +// One shared analytic height function drives BOTH the physics (a MuJoCo +// heightfield covering the arena) and the visuals (vertex displacement +// of the grid floor shader), so the grid genuinely deforms instead of +// boxes popping out of it. Entries are [cx, cy, height, radius] in MJCF +// coords; slopes stay mild (max grade ~20%) so the blind walking policy +// has a chance, and the spawn cell + arcade row stay flat. +export const RELIEF_BUMPS = [ + [0.3, -0.9, 0.06, 0.55], + [-0.9, 0.75, 0.05, 0.5], + [0.6, 0.9, 0.07, 0.55], +]; +export const RELIEF_HMAX = 0.07; // tallest bump, scales the hfield z-size +export const RELIEF_GRID = 65; // hfield rows/cols over the 3x3 m arena +export const RELIEF_SINK = 0.003; // hfield geom buried below the floor +export const RELIEF_RATE = 0.6; // raise/sink rate, scale units per second + +// Spawn: center of the middle section cell in the SECOND ROW FROM THE +// BACK wall. The duck faces +X (identity freejoint quat, walks toward +// local +X), so "back" is the -X wall: row centers sit at x = -1.2, +// -0.6, 0, 0.6, 1.2 -> second row is -0.6; middle column is y = 0. +// MJCF coordinates (three.js: x -> x, y -> -z). +export const SPAWN_X = -ARENA_HALF + 1.5 * GRID_SECTION; // -0.6 +export const SPAWN_Y = 0; diff --git a/app/src/game/controls/controller.js b/app/src/game/controls/controller.js new file mode 100644 index 0000000..efe7136 --- /dev/null +++ b/app/src/game/controls/controller.js @@ -0,0 +1,194 @@ +// Controller: the video-game-style input core. Aggregates pluggable input +// SOURCES (keyboard, gamepad, later touch) into one game-facing surface: +// +// - a continuous COMMAND: the [vx, vy, wz] twist the policy tracks, plus +// auxiliary analog AXES (jaw 0..1, camera-orbit rates -1..1); +// - discrete ACTIONS: edge-triggered events (roll, kicks, ball spawn...) +// dispatched to subscribers the moment a source fires them; +// - HUD support: per-source pressed-state snapshots and activity info so +// the hint keycaps can light up per physical control and per device. +// +// The game code (rl.js) instantiates the sources, registers them here, +// calls update(dt) once per render frame, reads getCommand()/getAxes() +// where it builds the policy observation, and subscribes its trigger +// functions with on(action, cb). +// +// ── Source interface contract ──────────────────────────────────────────── +// Every input source module (keyboard.js, gamepad.js, a future touch.js +// with a virtual joystick + buttons) implements: +// +// id Unique string ("keyboard", "gamepad", "touch"...). Action +// subscribers receive it as meta.source, so game code can +// attribute HUD flashes / keycap lighting to the right device. +// connected Boolean hardware presence. Keyboard: always true. Gamepad: +// a pad is currently reported by navigator.getGamepads(). +// command Float32Array(3) [vx, vy, wz], ALREADY scaled to the game's +// velocity limits (sources take a getVelocityLimits() callback +// returning [fwd, back, ang], so limits can change at runtime, +// e.g. the legs <-> rollers switch). Must be a stable array +// reference updated in place: getCommand() hands it out +// without copying, and the control loop reads it between +// render frames. +// axes { jaw, orbitX, orbitY, ride } - auxiliary continuous +// channels. jaw in [0, 1] (mouth opening), orbit axes in +// [-1, 1] (camera orbit rate; the inertia/smoothing lives +// downstream in the camera code, sources report raw +// deflection), ride in [0, 1] (LT squeeze pressure, bends +// the wheee note's pitch). Stable object reference, updated +// in place. Channels a source does not drive may be omitted +// (merged as 0). +// pressed Plain object of booleans (stable reference) mirroring which +// physical controls are currently down. HUD highlighting +// only - never game logic. +// isActive() Whether the source currently claims authority over the +// continuous command. Keyboard: any move key held. Gamepad: +// stick deflected, and it keeps the claim until its smoothed +// command settles back to ~zero. +// init() Attach event listeners / hardware hooks. Called by +// Controller.init(), NOT at construction (rl.js constructs +// the sources early but arms the listeners at the same point +// in the boot where they historically went live). +// dispose() Detach everything init() attached. +// poll(dt) Per-frame tick (dt in seconds, clamped by the caller). +// Read the hardware, update command/axes/pressed in place, +// and fire edge-triggered actions via this.onAction(name). +// onAction (name, meta?) => void, assigned by the Controller at +// registration. Sources may call it from poll() (gamepad +// button edges) or straight from event handlers (keyboard: +// keeps the historical press-to-effect latency). +// +// ── Arbitration ────────────────────────────────────────────────────────── +// Continuous command: sources are registered in PRIORITY order (first = +// highest). Each frame the first source reporting isActive() owns the +// twist; when none is active the LAST registered source's command is used +// as the fallback (it reads zero when idle). With [gamepad, keyboard] this +// reproduces the historical `padActive ? padCmd : velCmd` exactly: live +// sticks win over held keys, and the keyboard takes back over once the +// pad's smoothed command has settled. +// Aux axes are merged across ALL sources regardless of who owns the twist +// (the pad triggers drive the jaw even while walking on the keyboard): +// jaw = max over sources, orbit = largest-magnitude value per axis. +// +// ── Actions ────────────────────────────────────────────────────────────── +// roll one-shot roll (crouch-glide in roller mode; game decides) +// groundPick one-shot ground pick cycle (pad A / keyboard G) +// kickL, kickR one-shot kicks, explicit foot +// alternateKick one-shot kick, feet alternated by the game +// spawnBall pop / respawn the kickable ball (no bound key; game/API) +// headToggle HEAD mode on/off (pad Y): sticks drive the head +// sitToggle sit <-> stand (game gates it to legs mode) +// locoToggle legs <-> rollers switch +// chaseToggle chase camera on/off +// reset full sim reset (Space) +// walk back to the walk/run mode (pad DpadUp short press) +// quack chirp + jaw flap (pad RT edge, Schmitt-triggered) +// +// ── Input lock ─────────────────────────────────────────────────────────── +// setLocked(true) zeroes getCommand() - the twist gate used while the +// entrance/respawn ceremony plays. Discrete actions still dispatch: each +// game trigger applies its own lock policy (e.g. Space-reset and the +// chase-cam toggle historically work while locked, kicks don't). + +const ZERO_CMD = new Float32Array(3); + +export class Controller { + #sources = []; + #listeners = new Map(); // action -> Set(cb) + #locked = false; + #axes = { jaw: 0, orbitX: 0, orbitY: 0, ride: 0 }; + + constructor({ sources = [] } = {}) { + for (const s of sources) this.addSource(s); + } + + // Register in priority order (first registered wins arbitration ties). + addSource(source) { + source.onAction = (action, meta) => + this.#dispatch(action, { source: source.id, ...meta }); + this.#sources.push(source); + } + + // Read-only source list, for advanced per-source queries the merged view + // can't answer (e.g. "is ANY source commanding a turn right now?"). + get sources() { + return this.#sources; + } + + // Arm every source's listeners/hardware hooks. + init() { + for (const s of this.#sources) s.init?.(); + } + + dispose() { + for (const s of this.#sources) s.dispose?.(); + } + + // Per-frame tick: poll every source (they fire their edge actions from + // inside poll), then merge the aux axes. + update(dt) { + for (const s of this.#sources) s.poll?.(dt); + let jaw = 0, ox = 0, oy = 0, ride = 0; + for (const s of this.#sources) { + const a = s.axes; + if (!a) continue; + jaw = Math.max(jaw, a.jaw ?? 0); + ride = Math.max(ride, a.ride ?? 0); + if (Math.abs(a.orbitX ?? 0) > Math.abs(ox)) ox = a.orbitX; + if (Math.abs(a.orbitY ?? 0) > Math.abs(oy)) oy = a.orbitY; + } + this.#axes.jaw = jaw; + this.#axes.orbitX = ox; + this.#axes.orbitY = oy; + this.#axes.ride = ride; + } + + setLocked(v) { + this.#locked = !!v; + } + + get locked() { + return this.#locked; + } + + // Merged continuous twist [vx, vy, wz] (see the arbitration notes above). + // Returns live source arrays without copying - treat as read-only. + getCommand() { + if (this.#locked) return ZERO_CMD; + for (const s of this.#sources) if (s.isActive()) return s.command; + const fallback = this.#sources[this.#sources.length - 1]; + return fallback ? fallback.command : ZERO_CMD; + } + + // Merged aux axes { jaw, orbitX, orbitY }, refreshed by update(). + getAxes() { + return this.#axes; + } + + // Any source claiming twist authority (HUD "user is driving" signal). + anyActive() { + return this.#sources.some((s) => s.isActive()); + } + + // Per-source pressed snapshots for HUD keycap highlighting: + // { keyboard: {...}, gamepad: {...} }. + getPressed() { + const out = {}; + for (const s of this.#sources) out[s.id] = s.pressed ?? {}; + return out; + } + + // Subscribe to a discrete action; cb(meta) with meta.source = source id. + // Returns an unsubscribe function. + on(action, cb) { + let set = this.#listeners.get(action); + if (!set) this.#listeners.set(action, (set = new Set())); + set.add(cb); + return () => set.delete(cb); + } + + #dispatch(action, meta) { + const set = this.#listeners.get(action); + if (!set) return; + for (const cb of set) cb(meta); + } +} diff --git a/app/src/game/controls/gamepad.js b/app/src/game/controls/gamepad.js new file mode 100644 index 0000000..a4256b7 --- /dev/null +++ b/app/src/game/controls/gamepad.js @@ -0,0 +1,250 @@ +// Gamepad input source (see controller.js for the source interface +// contract). Same mapping as the robot runtime (pollen-robotics/microduck): +// +// Left stick vertical = vx (asymmetric fwd/back), horizontal = turn, +// EMA-smoothed like the runtime's cmd_alpha. +// Right stick camera orbit rate (reported raw in axes.orbitX/Y; the +// velocity smoothing / coasting lives downstream in the +// camera code). R3 toggles the chase cam. +// A ground pick: one-shot pick-up-from-the-ground cycle +// (runtime-faithful; game gates it to walk mode) +// X sit <-> stand (crouch-glide in roller mode - game decides). +// The pad can no longer launch a roll at all. +// Y HEAD mode toggle (runtime-faithful). While the game sets +// `headMode`, locomotion is parked and BOTH sticks drive +// the head instead: left = head pitch/yaw, right = neck +// pitch/head roll (reported in `head`, deflections in +// [-1, 1], up/left positive). The right stick stops +// orbiting the camera for the duration. +// RB / LB right / left kick +// DpadDown sit <-> stand +// DpadUp short press = back to run; HOLD ~1 s = legs <-> rollers +// (like the robot's 3 s hold, shortened for the web) +// RT analog jaw + quack on the rising edge, through a +// Schmitt trigger (fire at >= 0.35, re-arm below 0.2 - a +// single threshold re-fires on jitter, which is how one +// squeeze used to quack several times). +// LT rides the looping "wheee": start on the rising edge, cut +// the instant it releases - same Schmitt hysteresis so +// jitter can't restart the ride. The analog pressure is +// reported continuously in `axes.ride` so the game can +// pick the note with the squeeze (pentatonic steps over +// one octave - the trigger is a tiny instrument). +// The two are mutually exclusive: an edge on one trigger +// is CONSUMED while the other is physically down, so one +// squeeze can never fire both sounds - even on pads that +// mirror a combined trigger channel onto both button +// slots (see the trigger block for the tie-break). + +const PAD_DEADZONE = 0.15; +const PAD_ALPHA = 0.12; // EMA smoothing toward the stick target +const dz = (v) => (Math.abs(v) < PAD_DEADZONE ? 0 : v); + +// Standard-mapping button indices. +const BTN_A = 0, BTN_X = 2, BTN_Y = 3, BTN_LB = 4, BTN_RB = 5, BTN_LT = 6, BTN_RT = 7; +const BTN_R3 = 11, BTN_DPAD_UP = 12, BTN_DPAD_DOWN = 13; + +const DPAD_UP_HOLD_MS = 1000; // hold-to-switch-loco duration + +// The one pad-picking rule, shared by poll() and the haptics engine +// (haptics.js): prefer a standard-mapping pad - the button indices above +// are only guaranteed by the "standard" layout - and fall back to +// whatever is connected. +export function pickPad() { + const pads = [...(navigator.getGamepads?.() ?? [])].filter((p) => p && p.connected); + return pads.find((p) => p.mapping === "standard") ?? pads[0]; +} + +export class GamepadSource { + id = "gamepad"; + connected = false; + command = new Float32Array(3); // [vx, 0, wz], EMA-smoothed + axes = { jaw: 0, orbitX: 0, orbitY: 0, ride: 0 }; + // Head-mode routing flag, owned by the game (mode state machine lives + // there); while true the sticks fill `head` instead of command/orbit. + headMode = false; + head = { neckPitch: 0, pitch: 0, yaw: 0, roll: 0 }; // stick deflections + pressed = { + a: false, x: false, y: false, rb: false, lb: false, r3: false, + dpadDown: false, dpadUp: false, + }; + onAction = () => {}; // assigned by the Controller at registration + + #getVelocityLimits; + #active = false; // owns twist authority (stick input, until EMA settles) + #dpadUpAt = 0; // wall-clock of the current DpadUp press + #dpadUpFired = false; // latch: one loco switch per hold + #rtDown = false; // RT physical Schmitt state (edge detection + gating) + #ltDown = false; // LT physical Schmitt state (edge detection + gating) + #ltRide = false; // wheee ride currently open (LT edge that wasn't blocked) + + constructor({ getVelocityLimits }) { + this.#getVelocityLimits = getVelocityLimits; + } + + init() {} // poll-based: nothing to attach + dispose() {} + + isActive() { + return this.#active; + } + + poll() { + const prev = this.pressed; + // A non-standard pad (mapping "") is a last-resort fallback in + // pickPad - its indices are firmware-defined and some mirror one + // combined trigger channel onto both trigger slots. + const gp = pickPad(); + this.connected = !!gp; + if (!gp) { + if (this.#active) { + this.#active = false; + this.command.fill(0); + this.axes.jaw = 0; + } + this.axes.orbitX = 0; + this.axes.orbitY = 0; + this.axes.ride = 0; + this.#zeroHead(); + // A pad yanked mid-ride must not leave the wheee looping forever. + if (this.#ltRide) { + this.#ltRide = false; + this.#ltDown = false; + this.onAction("wheeeStop"); + } + return; + } + const now = performance.now(); + + const lx = dz(gp.axes[0] ?? 0), ly = dz(gp.axes[1] ?? 0); + const rx = dz(gp.axes[2] ?? 0), ry = dz(gp.axes[3] ?? 0); + const [limF, limB, limA] = this.#getVelocityLimits(); + let target; + if (this.headMode) { + // HEAD mode: locomotion parks (EMA settles to zero), the camera + // orbit is frozen, and the sticks report head deflections instead + // (up/left positive; sign-to-joint mapping lives in the game). + target = [0, 0, 0]; + this.head.pitch = -ly; + this.head.yaw = -lx; + this.head.neckPitch = -ry; + this.head.roll = -rx; + this.axes.orbitX = 0; + this.axes.orbitY = 0; + } else { + // Left stick only: vertical = forward/back, horizontal = turn. + // (No strafe; the right stick doesn't drive movement.) + const up = -ly; // browser sticks report up as -1 + target = [ + up >= 0 ? up * limF : up * -limB, + 0, + -lx * limA, + ]; + this.#zeroHead(); + // Right stick: raw (deadzoned) orbit rate. Reported every frame - + // the downstream camera step needs the zeros too so a released + // stick coasts to a stop. + this.axes.orbitX = rx; + this.axes.orbitY = ry; + } + for (let i = 0; i < 3; i++) this.command[i] += PAD_ALPHA * (target[i] - this.command[i]); + // Sticks grab command authority on first input, release when back at + // rest (then the keyboard takes over again through the Controller's + // arbitration). In head mode the sticks belong to the head, so they + // never claim the twist. + const stickInput = !this.headMode && (lx !== 0 || ly !== 0); + if (stickInput) this.#active = true; + else if ( + this.#active && + Math.abs(this.command[0]) + Math.abs(this.command[1]) + Math.abs(this.command[2]) < 0.01 + ) { + this.#active = false; + this.command.fill(0); + } + + // R3 (right stick click): chase-cam toggle, gamepad twin of KeyC. + const r3 = !!gp.buttons[BTN_R3]?.pressed; + if (r3 && !prev.r3) this.onAction("chaseToggle"); + prev.r3 = r3; + + const a = !!gp.buttons[BTN_A]?.pressed; + if (a && !prev.a) this.onAction("groundPick"); + prev.a = a; + + const x = !!gp.buttons[BTN_X]?.pressed; + if (x && !prev.x) this.onAction("sitToggle"); + prev.x = x; + + const y = !!gp.buttons[BTN_Y]?.pressed; + if (y && !prev.y) this.onAction("headToggle"); + prev.y = y; + + const rb = !!gp.buttons[BTN_RB]?.pressed; + if (rb && !prev.rb) this.onAction("kickR"); + prev.rb = rb; + const lb = !!gp.buttons[BTN_LB]?.pressed; + if (lb && !prev.lb) this.onAction("kickL"); + prev.lb = lb; + + const dpadDown = !!gp.buttons[BTN_DPAD_DOWN]?.pressed; + if (dpadDown && !prev.dpadDown) this.onAction("sitToggle"); + prev.dpadDown = dpadDown; + + // DpadUp: short press = back to run; hold fires ONE loco switch. + const dpadUp = !!gp.buttons[BTN_DPAD_UP]?.pressed; + if (dpadUp && !prev.dpadUp) { + this.#dpadUpAt = now; + this.#dpadUpFired = false; + this.onAction("walk"); + } + if (dpadUp && !this.#dpadUpFired && now - this.#dpadUpAt >= DPAD_UP_HOLD_MS) { + this.#dpadUpFired = true; // latch: one switch per hold + this.onAction("locoToggle"); + } + prev.dpadUp = dpadUp; + + // Triggers. Both open the beak analogically - the duck sings the + // wheee with its mouth, wider with the squeeze (jaw is purely visual: + // no sound and no policy input ever reads it, so this can't re-open + // the cross-talk fixed below). Physical Schmitt edges are detected + // first - state must advance even for blocked edges, so releasing a + // blocker never retro-fires the suppressed action - then the actions + // are gated so the two triggers stay mutually exclusive. + const rt = gp.buttons[BTN_RT]?.value ?? 0; + const lt = gp.buttons[BTN_LT]?.value ?? 0; + this.axes.jaw = Math.max(rt, lt); + this.axes.ride = lt; // raw squeeze, consumed per-frame for the wheee pitch + const rtEdge = !this.#rtDown && rt >= 0.35; + if (rtEdge) this.#rtDown = true; + else if (this.#rtDown && rt < 0.2) this.#rtDown = false; + const ltEdge = !this.#ltDown && lt >= 0.3; + if (ltEdge) this.#ltDown = true; + else if (this.#ltDown && lt < 0.2) this.#ltDown = false; + // LT wheee ride first: blocked only if RT was already down BEFORE + // this frame. On pads that mirror one combined trigger channel onto + // both button slots a squeeze raises rt and lt together; treating the + // same-frame rt rise as "engaged" would hand the race to the quack + // (the old bug: LT presses fired RT's sound). The LT edge wins the + // tie deterministically; cut the ride the instant LT drops below the + // low rail. + const rtWasDown = this.#rtDown && !rtEdge; + if (ltEdge && !rtWasDown) { + this.#ltRide = true; + this.onAction("wheeeStart"); + } else if (this.#ltRide && !this.#ltDown) { + this.#ltRide = false; + this.onAction("wheeeStop"); + } + // RT quack: consumed while LT is down or the ride is open. In the + // mirrored case above the lt rise opened the ride and set #ltDown in + // the same frame, so the phantom rt edge always lands here. + if (rtEdge && !this.#ltDown && !this.#ltRide) this.onAction("quack"); + } + + #zeroHead() { + this.head.neckPitch = 0; + this.head.pitch = 0; + this.head.yaw = 0; + this.head.roll = 0; + } +} diff --git a/app/src/game/controls/keyboard.js b/app/src/game/controls/keyboard.js new file mode 100644 index 0000000..5bd7623 --- /dev/null +++ b/app/src/game/controls/keyboard.js @@ -0,0 +1,118 @@ +// Keyboard input source (see controller.js for the source interface +// contract). Hold-to-command movement keys plus one-shot action keys. +// +// e.code is the PHYSICAL key position, so one map covers QWERTY and AZERTY: +// arrows / WASD (ZQSD) run + turn. No strafe - vy stays 0. + +const KEYMAP = { + ArrowUp: "fwd", KeyW: "fwd", + ArrowDown: "back", KeyS: "back", + ArrowLeft: "turnl", KeyA: "turnl", + ArrowRight: "turnr", KeyD: "turnr", +}; + +// One-shot keys -> controller actions. Physical Q/E (A/E on AZERTY) are the +// explicit left / right kicks, mirroring the pad's LB / RB; F alternates. +// R sits (crouch-glide in roller mode - the game decides, same way the +// roll action used to). Nothing dispatches "roll" any more. +const ACTION_KEYS = { + KeyC: "chaseToggle", + KeyG: "groundPick", + KeyM: "locoToggle", + KeyR: "sitToggle", + KeyQ: "kickL", + KeyE: "kickR", + KeyF: "alternateKick", +}; + +export class KeyboardSource { + id = "keyboard"; + connected = true; // a keyboard is always assumed present + command = new Float32Array(3); // [vx, 0, wz], scaled to velocity limits + axes = { jaw: 0, orbitX: 0, orbitY: 0 }; // keyboard drives none of these + pressed = { fwd: false, back: false, turnl: false, turnr: false }; + onAction = () => {}; // assigned by the Controller at registration + + #held = new Set(); + #getVelocityLimits; + // Limits snapshot so poll() only re-maps held keys when they actually + // change (the legs <-> rollers switch); event handlers do the live work. + #lims = [NaN, NaN, NaN]; + #onKeyDown = null; + #onKeyUp = null; + #onBlur = null; + + constructor({ getVelocityLimits }) { + this.#getVelocityLimits = getVelocityLimits; + } + + init() { + this.#onKeyDown = (e) => { + if (e.repeat) return; + // Space always resets, and must not scroll the page. + if (e.code === "Space") { + e.preventDefault(); + this.onAction("reset"); + return; + } + const action = ACTION_KEYS[e.code]; + if (action) { + this.onAction(action); + return; + } + const move = KEYMAP[e.code]; + if (!move) return; + e.preventDefault(); + this.#held.add(move); + this.#refresh(); + }; + this.#onKeyUp = (e) => { + const move = KEYMAP[e.code]; + if (!move) return; + this.#held.delete(move); + this.#refresh(); + }; + // Losing window focus drops every held key (keyup events are missed). + this.#onBlur = () => { + this.#held.clear(); + this.#refresh(); + }; + window.addEventListener("keydown", this.#onKeyDown); + window.addEventListener("keyup", this.#onKeyUp); + window.addEventListener("blur", this.#onBlur); + } + + dispose() { + window.removeEventListener("keydown", this.#onKeyDown); + window.removeEventListener("keyup", this.#onKeyUp); + window.removeEventListener("blur", this.#onBlur); + } + + // Claims twist authority while any movement key is held. + isActive() { + return this.#held.size > 0; + } + + // The command is event-driven (recomputed on keydown/keyup/blur, so a + // press lands the same tick, not on the next frame); poll only re-maps + // held keys onto fresh velocity limits after a locomotion switch. + poll() { + const [limF, limB, limA] = this.#getVelocityLimits(); + if (limF !== this.#lims[0] || limB !== this.#lims[1] || limA !== this.#lims[2]) { + this.#refresh(); + } + } + + #refresh() { + const lims = this.#getVelocityLimits(); + const [limF, limB, limA] = lims; + this.#lims = lims; + const held = this.#held; + this.command[0] = held.has("fwd") ? limF : held.has("back") ? limB : 0; + this.command[2] = held.has("turnl") ? limA : held.has("turnr") ? -limA : 0; + this.pressed.fwd = held.has("fwd"); + this.pressed.back = held.has("back"); + this.pressed.turnl = held.has("turnl"); + this.pressed.turnr = held.has("turnr"); + } +} diff --git a/app/src/game/controls/touch.js b/app/src/game/controls/touch.js new file mode 100644 index 0000000..906b696 --- /dev/null +++ b/app/src/game/controls/touch.js @@ -0,0 +1,180 @@ +// Touch input source (see controller.js for the source interface +// contract). Game Boy layout, two thumbs: +// +// Left thumb FLOATING analog stick: the lower-left quadrant of the +// screen (#touch-zone) is the grab area, and the stick base +// (#touch-stick) re-anchors under the finger wherever it +// lands - so the thumb never has to find a fixed circle - +// then snaps back to its resting spot on release. Vertical +// = vx (asymmetric fwd/back limits), horizontal = turn. The +// nub tracks the finger clamped to the base circle; the +// command is EMA-smoothed like the gamepad's so releases +// don't snap. +// Right thumb two round caps: A (#touch-a) fires alternateKick - the +// game alternates feet; B (#touch-b) quacks on press and +// holds the beak open (axes.jaw = 1) while held. +// +// The overlay DOM lives in index.html (#touch-ui); this module only wires +// pointer events to it. `connected` (mirrored onto body.touch-mode by +// rl.js, which is what actually shows the overlay) arms two ways: +// - (pointer: coarse) matches: phones/tablets, before any touch; +// - OR the first real touch anywhere: catches DevTools device modes and +// hybrid laptops the media query misses. Latching, like a gamepad. + +const TOUCH_ALPHA = 0.18; // EMA smoothing toward the stick target +const TOUCH_DEADZONE = 0.12; // normalized deflection ignored around center + +export class TouchSource { + id = "touch"; + connected = false; + command = new Float32Array(3); // [vx, 0, wz], EMA-smoothed + axes = { jaw: 0, orbitX: 0, orbitY: 0 }; + pressed = { stick: false, a: false, b: false }; + onAction = () => {}; // assigned by the Controller at registration + + #getVelocityLimits; + #active = false; // owns twist authority (stick engaged, until EMA settles) + #target = [0, 0]; // normalized deflection [x, right+] [y, up+] + #mq = null; + #onMq = null; + #disposers = []; + + constructor({ getVelocityLimits }) { + this.#getVelocityLimits = getVelocityLimits; + } + + init() { + this.#mq = window.matchMedia("(pointer: coarse)"); + // Latching: once a device has proven it can touch, keep the thumbs. + // __microduckTouched carries a touch seen by the title page before + // this module booted. + if (window.__microduckTouched) this.connected = true; + this.#onMq = () => { this.connected = this.connected || this.#mq.matches; }; + this.#mq.addEventListener("change", this.#onMq); + this.#onMq(); + const armTouch = () => { this.connected = true; }; + window.addEventListener("touchstart", armTouch, { once: true, passive: true }); + this.#disposers.push(() => window.removeEventListener("touchstart", armTouch)); + + const zone = document.getElementById("touch-zone"); + const stick = document.getElementById("touch-stick"); + const nub = stick?.querySelector(".nub"); + if (zone && stick && nub) this.#bindStick(zone, stick, nub); + + this.#bindButton("touch-a", "a", () => this.onAction("alternateKick")); + this.#bindButton("touch-b", "b", () => this.onAction("quack")); + } + + dispose() { + this.#mq?.removeEventListener("change", this.#onMq); + for (const off of this.#disposers) off(); + this.#disposers = []; + } + + isActive() { + return this.#active; + } + + poll() { + const [x, y] = this.#target; + const [limF, limB, limA] = this.#getVelocityLimits(); + const tvx = y >= 0 ? y * limF : y * -limB; + const twz = -x * limA; + this.command[0] += TOUCH_ALPHA * (tvx - this.command[0]); + this.command[2] += TOUCH_ALPHA * (twz - this.command[2]); + // Same authority rule as the gamepad sticks: grab on input, release + // once the smoothed command has settled back to ~zero. + if (this.pressed.stick) this.#active = true; + else if (this.#active && Math.abs(this.command[0]) + Math.abs(this.command[2]) < 0.01) { + this.#active = false; + this.command.fill(0); + } + // B holds the beak open; quack itself fired on the press edge. + this.axes.jaw = this.pressed.b ? 1 : 0; + } + + #on(el, type, fn) { + el.addEventListener(type, fn); + this.#disposers.push(() => el.removeEventListener(type, fn)); + } + + #bindStick(zone, stick, nub) { + let pointerId = null; + let center = null; // stick center while grabbed, zone-local px + const setFrom = (e) => { + const zr = zone.getBoundingClientRect(); + const R = stick.offsetWidth / 2; + const travel = R * 0.62; // max nub travel inside the base circle + let dx = e.clientX - zr.left - center.x; + let dy = e.clientY - zr.top - center.y; + const d = Math.hypot(dx, dy); + if (d > travel) { dx *= travel / d; dy *= travel / d; } + nub.style.transform = `translate(${dx}px, ${dy}px)`; + const nx = dx / travel, ny = -dy / travel; // up is +y + const mag = Math.hypot(nx, ny); + const live = mag >= TOUCH_DEADZONE; + this.#target[0] = live ? nx : 0; + this.#target[1] = live ? ny : 0; + }; + const release = () => { + pointerId = null; + center = null; + this.pressed.stick = false; + stick.classList.remove("live"); + nub.style.transform = ""; + // Back to the CSS resting spot until the next grab. + stick.style.left = ""; + stick.style.top = ""; + stick.style.bottom = ""; + this.#target[0] = 0; + this.#target[1] = 0; + }; + this.#on(zone, "pointerdown", (e) => { + e.preventDefault(); + pointerId = e.pointerId; + // Anchor the base exactly under the finger - a clamped anchor would + // start the stick with a phantom deflection near the zone edges. The + // circle clipping off-screen there is the standard floating-stick + // look, and it takes no pointer events anyway. + const zr = zone.getBoundingClientRect(); + const R = stick.offsetWidth / 2; + center = { x: e.clientX - zr.left, y: e.clientY - zr.top }; + stick.style.left = `${center.x - R}px`; + stick.style.top = `${center.y - R}px`; + stick.style.bottom = "auto"; + this.pressed.stick = true; + stick.classList.add("live"); + setFrom(e); // zero deflection at grab + // Last: capture can throw on exotic pointers and must not eat the + // press state above. + try { zone.setPointerCapture(e.pointerId); } catch {} + }); + this.#on(zone, "pointermove", (e) => { + if (e.pointerId === pointerId) setFrom(e); + }); + this.#on(zone, "pointerup", (e) => { + if (e.pointerId === pointerId) release(); + }); + this.#on(zone, "pointercancel", (e) => { + if (e.pointerId === pointerId) release(); + }); + } + + #bindButton(elId, key, fire) { + const el = document.getElementById(elId); + if (!el) return; + this.#on(el, "pointerdown", (e) => { + e.preventDefault(); + this.pressed[key] = true; + el.classList.add("down"); + fire(); // on the press edge, not the release: arcade latency + try { el.setPointerCapture(e.pointerId); } catch {} + }); + const release = () => { + this.pressed[key] = false; + el.classList.remove("down"); + }; + this.#on(el, "pointerup", release); + this.#on(el, "pointercancel", release); + } +} diff --git a/app/src/game/controls/waypoint.js b/app/src/game/controls/waypoint.js new file mode 100644 index 0000000..4f005c9 --- /dev/null +++ b/app/src/game/controls/waypoint.js @@ -0,0 +1,153 @@ +// Waypoint input source (see controller.js for the source interface +// contract). PLAN.md Project 1 Phase A: click a point on the arena floor, +// the duck walks there. No new policy - this only turns a click into the +// same [vx, vy, wz] twist the walking policy already tracks. +// +// Click, not drag-follow: the mouse already drives OrbitControls (camera +// orbit) and the duck/ball grab-drag, so a live cursor-follow twist would +// fight both. A plain click (small movement, short hold) on empty floor +// is otherwise unclaimed input, and reads naturally as "go here" - the +// same gesture Project 5's tile grid uses. +// +// Arbitration: registered LAST in game.js's source list, so it is the +// Controller's fallback exactly like the keyboard source used to be - +// any keyboard/pad/touch input immediately preempts it (see +// controller.js's arbitration notes), and getManualOverride() cancels the +// pending target outright so releasing manual input doesn't snap the duck +// back onto a stale click. + +import * as THREE from "three"; +import { ARENA_HALF } from "../constants.js"; + +const WAYPOINT_ARRIVE_RADIUS = 0.12; // m, dead zone - commands zero inside it +const WAYPOINT_TURN_GAIN = 2.2; // rad/s commanded per rad of heading error, pre-clamp +const WAYPOINT_SMOOTH_ALPHA = 0.15; // EMA toward the steered command, per render frame +const WAYPOINT_CLICK_SLOP = 6; // px, pointerdown -> pointerup movement budget for a "click" +const WAYPOINT_CLICK_MS = 500; // ms, pointerdown -> pointerup duration budget + +const wrapPi = (a) => Math.atan2(Math.sin(a), Math.cos(a)); +// Three world (x, y, z) -> MJCF ground (x, -z); floor sits at three y = 0. +const FLOOR_PLANE = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0); + +export class WaypointSource { + id = "waypoint"; + connected = true; // a mouse is assumed present, like the keyboard + command = new Float32Array(3); // [vx, 0, wz], EMA-smoothed toward the target + axes = { jaw: 0, orbitX: 0, orbitY: 0 }; // drives none of these + pressed = {}; + onAction = () => {}; // assigned by the Controller at registration + + #camera; + #renderer; + #getVelocityLimits; + #getDuckPose; // () => [x, y, yaw] MJCF ground pose + #isSuppressed; // () => true while a click must not arm (grabbing, locked, wrong mode) + #getManualOverride; // () => true while another source is actively driving + #target = null; // [x, y] MJCF, or null when idle + #active = false; + #downAt = null; // { x, y, t } pointerdown snapshot, for the click-vs-drag check + #raycaster = new THREE.Raycaster(); + #ndc = new THREE.Vector2(); + #hit = new THREE.Vector3(); + #onDown = null; + #onUp = null; + + constructor({ camera, renderer, getVelocityLimits, getDuckPose, isSuppressed, getManualOverride }) { + this.#camera = camera; + this.#renderer = renderer; + this.#getVelocityLimits = getVelocityLimits; + this.#getDuckPose = getDuckPose; + this.#isSuppressed = isSuppressed; + this.#getManualOverride = getManualOverride; + } + + init() { + this.#onDown = (e) => { + if (e.pointerType !== "mouse" || e.button !== 0) return; + if (e.target !== this.#renderer.domElement) return; + if (this.#isSuppressed()) return; + this.#downAt = { x: e.clientX, y: e.clientY, t: performance.now() }; + }; + this.#onUp = (e) => { + if (!this.#downAt || e.pointerType !== "mouse" || e.button !== 0) { this.#downAt = null; return; } + const { x, y, t } = this.#downAt; + this.#downAt = null; + if (this.#isSuppressed()) return; + const moved = Math.hypot(e.clientX - x, e.clientY - y); + const held = performance.now() - t; + // A drag (orbit or grab) shows up as either more movement than a + // click budget allows, or a slow deliberate press - either way, not + // a click. + if (moved > WAYPOINT_CLICK_SLOP || held > WAYPOINT_CLICK_MS) return; + this.#setTargetFromEvent(e); + }; + window.addEventListener("pointerdown", this.#onDown); + window.addEventListener("pointerup", this.#onUp); + } + + dispose() { + window.removeEventListener("pointerdown", this.#onDown); + window.removeEventListener("pointerup", this.#onUp); + } + + isActive() { + return this.#active; + } + + // Current target in MJCF ground coords, or null - read by game.js to + // place the click marker. Read-only. + get target() { + return this.#target; + } + + // Cancel a pending target without walking it down (sim reset, mode + // change out from under it). + cancel() { + this.#target = null; + this.#active = false; + this.command.fill(0); + } + + poll() { + if (this.#target && this.#getManualOverride()) this.#target = null; + if (!this.#target) { + this.command.fill(0); + this.#active = false; + return; + } + const [px, py, yaw] = this.#getDuckPose(); + const dx = this.#target[0] - px, dy = this.#target[1] - py; + const dist = Math.hypot(dx, dy); + if (dist < WAYPOINT_ARRIVE_RADIUS) { + this.#target = null; + this.command.fill(0); + this.#active = false; + return; + } + const err = wrapPi(Math.atan2(dy, dx) - yaw); + const [limF, , limA] = this.#getVelocityLimits(); + const wz = Math.min(limA, Math.max(-limA, err * WAYPOINT_TURN_GAIN)); + // Forward speed falls off with heading error so the duck turns in + // place first rather than strafing (there is no strafe) toward a + // target that's behind it. + const vx = limF * Math.max(0, Math.cos(err)); + this.command[0] += WAYPOINT_SMOOTH_ALPHA * (vx - this.command[0]); + this.command[2] += WAYPOINT_SMOOTH_ALPHA * (wz - this.command[2]); + this.#active = true; + } + + #setTargetFromEvent(e) { + const r = this.#renderer.domElement.getBoundingClientRect(); + this.#ndc.set( + ((e.clientX - r.left) / r.width) * 2 - 1, + -((e.clientY - r.top) / r.height) * 2 + 1, + ); + this.#raycaster.setFromCamera(this.#ndc, this.#camera); + if (!this.#raycaster.ray.intersectPlane(FLOOR_PLANE, this.#hit)) return; + const lim = ARENA_HALF - 0.05; + this.#target = [ + Math.min(lim, Math.max(-lim, this.#hit.x)), + Math.min(lim, Math.max(-lim, -this.#hit.z)), // three -> MJCF + ]; + } +} diff --git a/app/src/game/custom-policy.js b/app/src/game/custom-policy.js new file mode 100644 index 0000000..dae77e8 --- /dev/null +++ b/app/src/game/custom-policy.js @@ -0,0 +1,365 @@ +// Community move loading: resolve a move ref (Hub repo id, Academy session +// ref or a direct .onnx URL) into a validated onnxruntime session (or a +// command script) the game can drop into one of its slots. Mirrors the +// official publish pipeline's smoke run: shape checks, a zeros inference +// and two noisy inferences that must produce finite, non-constant actions +// before the session ever touches the duck. +// +// Slots (manifest schema 2, Academy decision D7): +// kind "perpetual" (gait) -> "walk" (default) or "sitstand" (slot field) +// kind "episodic" (trick) -> "trick": a one-shot on the R key +// kind "script" -> "script": a 13-D command timeline played on +// the base walker while R is toggled on +// +// The module is deliberately framework-free (no game imports): the caller +// hands in the `ort` namespace it already booted, and pure helpers like +// manifestIncompatibility are reusable by standalone pages without pulling +// the game bundle in. + +import { OBS_SIZE, NUM_JOINTS, CMD_SIZE } from "./constants.js"; + +const HUB_BASE = "https://huggingface.co"; +// Same-origin Academy endpoints (backend/play_api.py) for private moves. +const PLAY_API = "/api/play"; + +export const SUPPORTED_KINDS = ["perpetual", "episodic", "script"]; +// Default one-shot length for an episodic trick without a duration claim. +const DEFAULT_TRICK_S = 5.0; + +// Game slot a manifest mounts into (see the header). A missing manifest is +// a plain walk policy, exactly like v1. +export function slotForManifest(manifest) { + const kind = manifest?.kind ?? "perpetual"; + if (kind === "script") return "script"; + if (kind === "episodic") return "trick"; + const slot = String(manifest?.slot ?? "walk").toLowerCase(); + return slot === "sitstand" || slot === "sit" ? "sitstand" : "walk"; +} + +// Manifest claims the sim cannot satisfy (schema 2). Only present-and-wrong +// claims reject: an absent field is trusted to match the microduck defaults. +// Returns a human-readable reason, or null when the manifest is acceptable. +export function manifestIncompatibility(manifest) { + if (!manifest || typeof manifest !== "object") return null; + if (Array.isArray(manifest.policies)) { + return "multi-policy set: not loadable in v1 (pick a single-policy repo)"; + } + if (manifest.model_api != null && manifest.model_api > 2) { + return `model_api ${manifest.model_api} is newer than this sim supports`; + } + const robotModel = manifest.robot?.model; + if (robotModel != null && robotModel !== "microduck") { + return `targets robot "${robotModel}", not microduck`; + } + const kind = manifest.kind ?? "perpetual"; + if (!SUPPORTED_KINDS.includes(kind)) { + return `"${manifest.kind}" policies are not supported (kinds: ${SUPPORTED_KINDS.join(", ")})`; + } + // A script drives the built-in walker: no network claims to check. + if (kind === "script") return null; + if (manifest.obs_len != null && manifest.obs_len !== OBS_SIZE) { + return `expects ${manifest.obs_len} observations (sim provides ${OBS_SIZE})`; + } + if (manifest.action_len != null && manifest.action_len !== NUM_JOINTS) { + return `outputs ${manifest.action_len} actions (sim drives ${NUM_JOINTS})`; + } + if (kind === "perpetual") { + const slot = manifest.slot != null ? String(manifest.slot).toLowerCase() : null; + if (slot != null && !["walk", "sitstand", "sit"].includes(slot)) { + return `perpetual slot "${manifest.slot}" is not supported (walk or sitstand)`; + } + const encoding = manifest.command?.encoding; + if (encoding != null && encoding !== "constant") { + return `command encoding "${encoding}" is not supported yet`; + } + if (manifest.mode != null && manifest.mode !== "walk" && slot !== "sitstand" && slot !== "sit") { + return `mode "${manifest.mode}" is not supported yet (walk-slot only)`; + } + } + // Episodic tricks: every slot (stand, roulade, kick_left, ground_pick, + // R, ...) mounts on the R key as a zero-command one-shot. + return null; +} + +// Parse the "session:[:]" ref form. Returns null when `r` is not +// a session ref. `round` is null when absent. +function parseSessionRef(r) { + const m = /^session:([\w.-]+)(?::([\w.-]+))?$/i.exec(r); + return m ? { id: m[1], round: m[2] ?? null } : null; +} + +// Build a same-origin Academy URL for a private session artifact. +function sessionApiUrl(endpoint, { id, round }, extra = {}) { + const q = new URLSearchParams({ session: id }); + if (round != null) q.set("round", String(round)); + for (const [k, v] of Object.entries(extra)) q.set(k, v); + return `${PLAY_API}/${endpoint}?${q}`; +} + +// A move ref is one of: +// "org/repo" a Hub move repo (manifest + policy.onnx) +// "session:[:]" a private Academy run, served same-origin +// "https://.../x.onnx" a direct URL (sibling manifest probed) +// Resolves to the URLs of the three artifacts the loader may need. +export function resolvePolicyRef(ref) { + const r = String(ref || "").trim(); + if (/^https?:\/\//i.test(r)) { + let manifestUrl = null; + let scriptUrl = null; + try { + const u = new URL(r); + const name = u.pathname.split("/").pop() || ""; + if (/\.onnx$/i.test(name)) { + const dir = u.pathname.slice(0, -name.length); + u.pathname = `${dir}manifest.json`; + manifestUrl = u.href; + u.pathname = `${dir}move_script.json`; + scriptUrl = u.href; + } + } catch { /* unparsable: no manifest probe */ } + return { + kind: "url", + name: r.split("/").pop()?.split("?")[0] || r, + author: null, + onnxUrl: r, + manifestUrl, + scriptUrl, + manifestOptional: true, + }; + } + const sess = parseSessionRef(r); + if (sess) { + return { + kind: "session", + name: sess.round != null ? `session ${sess.id} (round ${sess.round})` : `session ${sess.id}`, + author: null, + onnxUrl: sessionApiUrl("policy", sess), + manifestUrl: sessionApiUrl("manifest", sess), + scriptUrl: sessionApiUrl("file", sess, { path: "move_script.json" }), + manifestOptional: true, + }; + } + if (!/^[\w.-]+\/[\w.-]+$/.test(r)) { + throw new Error(`invalid move ref "${r}" (expected org/repo, session: or a .onnx URL)`); + } + return { + kind: "hub", + name: r, + author: r.split("/")[0], + repoId: r, + onnxUrl: `${HUB_BASE}/${r}/resolve/main/policy.onnx`, + manifestUrl: `${HUB_BASE}/${r}/resolve/main/manifest.json`, + scriptUrl: `${HUB_BASE}/${r}/resolve/main/move_script.json`, + }; +} + +// Manifest fetch for the loader (and any future policy-browsing page): +// 404 (no manifest) resolves to null, network/parse failures throw. +export async function fetchPolicyManifest(repoId) { + const res = await fetch(`${HUB_BASE}/${repoId}/resolve/main/manifest.json`); + if (res.status === 404) return null; + // The Hub answers 401 for repos that don't exist (or are private). + if (res.status === 401 || res.status === 403) { + throw new Error(`repo "${repoId}" not found on the Hub (or private)`); + } + if (!res.ok) throw new Error(`manifest fetch failed (HTTP ${res.status})`); + return res.json(); +} + +// Optional sibling manifest (direct URL / Academy session): 404 = none. +// A 401 from the Academy means the visitor is not signed in - that one is +// worth surfacing instead of silently playing nothing. +async function fetchOptionalManifest(url) { + let res; + try { + res = await fetch(url); + } catch { + return null; + } + if (res.status === 401) throw new Error("sign in to the Academy to play a private move"); + if (!res.ok) return null; + try { + return await res.json(); + } catch { + return null; + } +} + +// Command script (kind "script"): {duration_s, loop, keyframes:[{t, cmd[13]}]}. +// Keyframes are sorted by t and every cmd is padded/truncated to CMD_SIZE. +export function normalizeMoveScript(raw) { + if (!raw || typeof raw !== "object" || !Array.isArray(raw.keyframes) || !raw.keyframes.length) { + throw new Error("move_script.json has no keyframes"); + } + const keyframes = raw.keyframes.map((k, i) => { + const t = Number(k?.t); + if (!Number.isFinite(t) || t < 0) throw new Error(`keyframe ${i}: bad time`); + const src = Array.isArray(k?.cmd) ? k.cmd : []; + const cmd = new Float32Array(CMD_SIZE); + for (let c = 0; c < CMD_SIZE; c++) { + const v = Number(src[c] ?? 0); + if (!Number.isFinite(v)) throw new Error(`keyframe ${i}: non-finite command`); + cmd[c] = v; + } + return { t, cmd }; + }); + keyframes.sort((a, b) => a.t - b.t); + const last = keyframes[keyframes.length - 1].t; + const durationS = Number.isFinite(Number(raw.duration_s)) && Number(raw.duration_s) > 0 + ? Math.max(Number(raw.duration_s), last) + : Math.max(last, 0.02); + return { keyframes, durationS, loop: raw.loop !== false, description: raw.description || "" }; +} + +// Linearly interpolated command at time t (loop-aware), written into `out`. +export function scriptCommandAt(script, t, out) { + const { keyframes, durationS, loop } = script; + let tt = t; + if (loop && durationS > 0) tt = ((t % durationS) + durationS) % durationS; + if (tt <= keyframes[0].t) { out.set(keyframes[0].cmd); return out; } + for (let i = 0; i < keyframes.length - 1; i++) { + const a = keyframes[i], b = keyframes[i + 1]; + if (tt >= a.t && tt <= b.t) { + const u = (tt - a.t) / Math.max(b.t - a.t, 1e-6); + for (let c = 0; c < CMD_SIZE; c++) out[c] = (1 - u) * a.cmd[c] + u * b.cmd[c]; + return out; + } + } + out.set(keyframes[keyframes.length - 1].cmd); + return out; +} + +// Publish-pipeline smoke run: 1 input / 1 output, a zeros pass plus two +// small-noise passes; every output must be [1,14], finite, and the noisy +// passes must not produce identical actions (a constant net is a dud). +async function validateSession(ort, session) { + const { inputNames, outputNames } = session; + if (inputNames.length !== 1 || outputNames.length !== 1) { + throw new Error( + `expected 1 input / 1 output, got ${inputNames.length}/${outputNames.length}`, + ); + } + const runOnce = async (fill) => { + const buf = new Float32Array(OBS_SIZE); + if (fill) for (let i = 0; i < OBS_SIZE; i++) buf[i] = (Math.random() - 0.5) * 0.1; + const feeds = { [inputNames[0]]: new ort.Tensor("float32", buf, [1, OBS_SIZE]) }; + const out = (await session.run(feeds))[outputNames[0]]; + const dims = out.dims; + if (dims.length !== 2 || dims[0] !== 1 || dims[1] !== NUM_JOINTS) { + throw new Error(`bad output shape [${dims.join(",")}] (expected [1,${NUM_JOINTS}])`); + } + const act = out.data; + for (let j = 0; j < NUM_JOINTS; j++) { + if (!Number.isFinite(act[j])) throw new Error("non-finite actions in smoke run"); + } + return Float32Array.from(act); + }; + await runOnce(false); + const a = await runOnce(true); + const b = await runOnce(true); + let maxDiff = 0; + for (let j = 0; j < NUM_JOINTS; j++) maxDiff = Math.max(maxDiff, Math.abs(a[j] - b[j])); + if (maxDiff < 1e-9) throw new Error("constant output in smoke run (dead policy)"); +} + +async function fetchOrThrow(url, what) { + const res = await fetch(url); + if (!res.ok) { + if (res.status === 401) throw new Error("sign in to the Academy to play a private move"); + throw new Error( + res.status === 404 ? `no ${what} found at ${url}` : `${what} download failed (HTTP ${res.status})`, + ); + } + return res; +} + +// Load + validate a community move. Resolves to everything the game needs +// to mount it in its slot; throws with a clear message on any failure. +// onProgress receives coarse stages for the HUD loading line. +// +// Result: { kind, slot, name, title, author, academy, ref, actionScale, +// durationS, session?, inputName?, outputName?, script? } +export async function loadCustomPolicy(ref, { ort, onProgress = () => {} } = {}) { + const resolved = resolvePolicyRef(ref); + let name = resolved.name; + let author = resolved.author; + let actionScale = 1.0; + let manifest = null; + + if (resolved.manifestUrl) { + onProgress("manifest"); + if (resolved.manifestOptional) { + // Sibling manifest of a direct URL / session: 404 or a network error + // just means "no manifest" (a plain walk policy), exactly like before + // the probe existed. Only present-and-incompatible manifests reject. + manifest = await fetchOptionalManifest(resolved.manifestUrl); + } else { + try { + manifest = await fetchPolicyManifest(resolved.repoId); + } catch (e) { + // TypeError = the fetch itself failed (offline, CORS); anything else + // already carries a specific message (missing repo, bad status). + throw e instanceof TypeError ? new Error(`could not reach the Hub: ${e.message}`) : e; + } + } + if (manifest) { + const reason = manifestIncompatibility(manifest); + if (reason) throw new Error(reason); + if (typeof manifest.name === "string" && manifest.name) name = manifest.name; + if (Number.isFinite(manifest.action_scale)) actionScale = manifest.action_scale; + if (typeof manifest.academy?.author === "string" && manifest.academy.author) { + author = manifest.academy.author; + } + } + } + + const slot = slotForManifest(manifest); + const kind = manifest?.kind ?? "perpetual"; + const academy = manifest?.academy && typeof manifest.academy === "object" ? manifest.academy : null; + // HUD plate text: the Academy prompt when there is one, else the name + // (descriptions are paragraphs, too long for the chip). + const title = academy?.prompt || name; + const base = { kind, slot, name, title, author, academy, ref: String(ref), actionScale }; + + if (slot === "script") { + if (!resolved.scriptUrl) throw new Error("script moves need a manifest with a sibling move_script.json"); + onProgress("script"); + const res = await fetchOrThrow(resolved.scriptUrl, "move_script.json"); + let raw; + try { + raw = await res.json(); + } catch { + throw new Error("move_script.json is not valid JSON"); + } + const script = normalizeMoveScript(raw); + return { ...base, script, durationS: script.durationS }; + } + + onProgress("download"); + const res = await fetchOrThrow(resolved.onnxUrl, "policy.onnx"); + const bytes = new Uint8Array(await res.arrayBuffer()); + + onProgress("session"); + let session; + try { + session = await ort.InferenceSession.create(bytes, { executionProviders: ["wasm"] }); + } catch (e) { + throw new Error(`not a loadable ONNX model: ${e?.message || e}`); + } + + onProgress("validate"); + await validateSession(ort, session); + + const claimed = Number(manifest?.duration_s ?? manifest?.episode_s ?? manifest?.episode?.duration_s); + const durationS = slot === "trick" + ? (Number.isFinite(claimed) && claimed > 0 ? Math.min(claimed, 30) : DEFAULT_TRICK_S) + : null; + + return { + ...base, + session, + durationS, + inputName: session.inputNames[0], + outputName: session.outputNames[0], + }; +} diff --git a/app/src/game/duck.js b/app/src/game/duck.js new file mode 100644 index 0000000..be90213 --- /dev/null +++ b/app/src/game/duck.js @@ -0,0 +1,415 @@ +// Standalone JS port of microduck_app's src/duck/kinematics.ts. +// Loads kinematics.json (built from the MJCF by build_kinematics.py) and +// builds an Object3D tree with one Group per body. Joints become per-body +// local rotations driven by setJointAngles / setJoint. + +import * as THREE from "three"; +import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js"; +import { STLLoader } from "three/addons/loaders/STLLoader.js"; +import { mergeVertices, toCreasedNormals } from "three/addons/utils/BufferGeometryUtils.js"; + +// Cache-busting version appended to the GLB / kinematics / leftover STL +// fetches. Bump whenever microduck.glb is regenerated. +export const MESH_VERSION = "11"; + +// Default model directory: the complete mjlab export (converted from +// robot_walk.xml by tools/mjcf_to_kinematics.py). robot/v1.5/ and +// robot/alpha/ stay on disk for reference but the code no longer +// targets them. +export const MODEL_DIR = "./robot/mjlab"; + +// On a private HF Space, asset requests carry the ?__sign JWT (auth +// cookies may be blocked in the hub iframe). Identity everywhere else. +import { signed } from "./signed.js"; + +// Meshes fully occluded inside the shells at every demo camera angle, +// verified empirically by per-mesh pixel-diff (front 3/4, back, low +// front close-up): hiding each changes exactly 0 pixels. Skipped at +// load time so their bytes are never fetched. Load everything with +// `?all=1` for debugging. +const HIDDEN_MESHES = new Set([]); + +export async function loadKinematics(url) { + // Same cache-buster as the GLB: force-cache would otherwise keep + // serving a stale kinematics.json after the mesh list changes. + const r = await fetch(signed(`${url}?v=${MESH_VERSION}`), { cache: "force-cache" }); + if (!r.ok) throw new Error(`kinematics fetch ${r.status}`); + const k = await r.json(); + // The exported mesh_dir is root-absolute ("/robot/mjlab/meshes"), which + // breaks when the app is served under a prefix (/play/). Rebase it like + // every other asset URL (MODEL_DIR is "./robot/mjlab"). + if (typeof k.mesh_dir === "string" && k.mesh_dir.startsWith("/")) { + k.mesh_dir = `.${k.mesh_dir}`; + } + // Full-resolution meshes by default (the reduction will be redone + // interactively in Blender later). `?lite=1` opts into a decimated + // meshes-lite/ sibling if present. + if (new URLSearchParams(location.search).get("lite") === "1") { + k.mesh_dir = k.mesh_dir.replace(/\/meshes$/, "/meshes-lite"); + } + return k; +} + +// One GLB, named meshes matching kinematics geom.mesh (e.g. "left_shell.stl"). +// Positions are already welded (same 1e-4 m hash as mergeVertices). STL +// facet normals are omitted on purpose: creased normals are rebuilt here. +const GLB_URL = `${MODEL_DIR}/microduck.glb`; +const CREASE = Math.PI / 5; // 36 deg +let glbGeomsPromise = null; + +export function loadGlbGeometries() { + if (!glbGeomsPromise) { + glbGeomsPromise = new GLTFLoader() + .loadAsync(signed(`${GLB_URL}?v=${MESH_VERSION}`)) + .then((gltf) => { + const map = new Map(); + gltf.scene.traverse((o) => { + if (!o.isMesh || !o.geometry) return; + const name = o.userData.meshFile || o.name || o.geometry.name; + if (!name || map.has(name)) return; + const welded = o.geometry; + welded.deleteAttribute("normal"); + // toCreasedNormals hashes on a 0.01-unit grid. Meshes are in + // metres, so scale a clone to mm (10 um grid) then back. + const scaled = welded.clone(); + scaled.scale(1000, 1000, 1000); + const display = toCreasedNormals(scaled, CREASE); + display.scale(1e-3, 1e-3, 1e-3); + const entry = { display, welded }; + map.set(name, entry); + if (o.name && o.name !== name) map.set(o.name, entry); + }); + return map; + }); + } + return glbGeomsPromise; +} + +// MuJoCo's WASM compiler still wants binary STL in its VFS. Rebuild from +// the already-loaded GLB so the browser never re-downloads the mesh files. +export function geometryToBinaryStl(geometry) { + const pos = geometry.attributes.position; + const idx = geometry.index; + const triCount = (idx ? idx.count : pos.count) / 3; + const buf = new ArrayBuffer(84 + triCount * 50); + const view = new DataView(buf); + view.setUint32(80, triCount, true); + let off = 84; + const vx = (i) => { + const j = idx ? idx.getX(i) : i; + return [pos.getX(j), pos.getY(j), pos.getZ(j)]; + }; + for (let t = 0; t < triCount; t++) { + const a = vx(t * 3); + const b = vx(t * 3 + 1); + const c = vx(t * 3 + 2); + const nx = (b[1] - a[1]) * (c[2] - a[2]) - (b[2] - a[2]) * (c[1] - a[1]); + const ny = (b[2] - a[2]) * (c[0] - a[0]) - (b[0] - a[0]) * (c[2] - a[2]); + const nz = (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]); + const len = Math.hypot(nx, ny, nz) || 1; + view.setFloat32(off, nx / len, true); + view.setFloat32(off + 4, ny / len, true); + view.setFloat32(off + 8, nz / len, true); + view.setFloat32(off + 12, a[0], true); + view.setFloat32(off + 16, a[1], true); + view.setFloat32(off + 20, a[2], true); + view.setFloat32(off + 24, b[0], true); + view.setFloat32(off + 28, b[1], true); + view.setFloat32(off + 32, b[2], true); + view.setFloat32(off + 36, c[0], true); + view.setFloat32(off + 40, c[1], true); + view.setFloat32(off + 44, c[2], true); + view.setUint16(off + 48, 0, true); + off += 50; + } + return buf; +} + +// Materials are PBR (MeshStandardMaterial), same family as the Reachy +// mobile app's glb viewer. Optional silhouette outlines via three's +// OutlineEffect - see main.js. + +export async function buildRig(k, opts = {}) { + // placer holds world-space position + yaw (no axis-conversion). + const placer = new THREE.Group(); + placer.name = "duck_placer"; + // root applies the MJCF +Z up -> three.js +Y up convention fix. + const root = new THREE.Group(); + root.name = "duck_root"; + root.rotation.x = -Math.PI / 2; + placer.add(root); + + const bodies = new Map(); + const joints = new Map(); + const geomByName = await loadGlbGeometries(); + // Roller-only meshes (tire, rim, ...) are not in the shared landing GLB. + const extraStlCache = new Map(); + const loadMesh = (name) => { + const entry = geomByName.get(name); + if (entry) return Promise.resolve(entry); + if (!extraStlCache.has(name)) { + extraStlCache.set( + name, + new STLLoader().loadAsync(signed(`${k.mesh_dir}/${name}?v=${MESH_VERSION}`)).then((raw) => { + raw.deleteAttribute("normal"); + const welded = mergeVertices(raw, 1e-4); + welded.scale(1000, 1000, 1000); + const display = toCreasedNormals(welded, CREASE); + display.scale(1e-3, 1e-3, 1e-3); + welded.scale(1e-3, 1e-3, 1e-3); + return { display, welded }; + }), + ); + } + return extraStlCache.get(name); + }; + + for (const b of k.bodies) { + const g = new THREE.Group(); + g.name = b.name; + g.position.set(b.pos[0], b.pos[1], b.pos[2]); + g.quaternion.set(b.quat[1], b.quat[2], b.quat[3], b.quat[0]); + bodies.set(b.name, g); + } + for (const b of k.bodies) { + const g = bodies.get(b.name); + if (b.parent && bodies.has(b.parent)) bodies.get(b.parent).add(g); + else root.add(g); + } + for (const b of k.bodies) { + if (!b.joint || (b.joint.type && b.joint.type !== "hinge")) continue; + const g = bodies.get(b.name); + joints.set(b.joint.name, { + body: g, + axis: new THREE.Vector3(...b.joint.axis).normalize(), + baseQuat: g.quaternion.clone(), + range: b.joint.range ?? null, + }); + } + + // Cache materials by their resolved PBR props so identical parts share + // one GPU material instance. + const matCache = new Map(); + // Optional (meshName, bodyName, rgba) -> material spec hook. A spec is + // { color: [r,g,b], roughness, metalness, opacity? }; plain rgba arrays + // are also accepted for backwards compat. + const materialForMesh = opts.materialForMesh ?? null; + const matFor = (spec) => { + const color = spec.color; + const roughness = spec.roughness ?? 0.5; + const metalness = spec.metalness ?? 0.0; + const opacity = spec.opacity ?? 1; + const key = `${color.join(",")}|${roughness}|${metalness}|${opacity}`; + const cached = matCache.get(key); + if (cached) return cached; + const m = new THREE.MeshStandardMaterial({ + color: new THREE.Color(...color), + roughness, + metalness, + transparent: opacity < 1, + opacity, + }); + matCache.set(key, m); + return m; + }; + const toSpec = (v, fallbackRgba) => { + if (!v) return { color: fallbackRgba.slice(0, 3), opacity: fallbackRgba[3] ?? 1 }; + if (Array.isArray(v)) return { color: v.slice(0, 3), opacity: v[3] ?? 1 }; + return v; + }; + + // Optional interior ink lines: hard edges above the threshold angle + // drawn as line segments, comic style. Cached per mesh file. + const inkOpts = opts.inkEdges ?? null; + const inkMat = inkOpts + ? new THREE.LineBasicMaterial({ + color: inkOpts.color ?? 0x0a0a0e, + transparent: true, + opacity: inkOpts.opacity ?? 0.55, + }) + : null; + const edgeCache = new Map(); + const edgesFor = (name, welded) => { + if (!edgeCache.has(name)) { + edgeCache.set(name, new THREE.EdgesGeometry(welded, inkOpts.threshold ?? 40)); + } + return edgeCache.get(name); + }; + + const pending = []; + const loadAll = new URLSearchParams(location.search).get("all") === "1"; + // The MJCF lists a few geoms twice with identical transforms (visual + + // collision copies of power_support, soles, legs); drawing both would + // only z-fight, so exact duplicates are skipped. + const seenGeoms = new Set(); + for (const b of k.bodies) { + const g = bodies.get(b.name); + if (!g) continue; + for (const geom of b.geoms) { + if (geom.type && geom.type !== "mesh") continue; + if (!geom.mesh) continue; + if (!loadAll && HIDDEN_MESHES.has(geom.mesh)) continue; + const dupKey = `${b.name}|${geom.mesh}|${geom.pos}|${geom.quat}`; + if (seenGeoms.has(dupKey)) continue; + seenGeoms.add(dupKey); + pending.push( + loadMesh(geom.mesh).then(({ display, welded }) => { + const rgba = geom.color + ? [geom.color[0], geom.color[1], geom.color[2], geom.color[3] ?? 1] + : [0.85, 0.85, 0.85, 1]; + const spec = toSpec(materialForMesh?.(geom.mesh, b.name, rgba), rgba); + const m = new THREE.Mesh(display, matFor(spec)); + // Mesh filename tag so callers can re-skin materials in place + // (survives cloneRig: Object3D.copy deep-copies userData). + m.userData.meshName = geom.mesh; + if (geom.pos) m.position.set(...geom.pos); + if (geom.quat) m.quaternion.set(geom.quat[1], geom.quat[2], geom.quat[3], geom.quat[0]); + g.add(m); + if (inkMat) { + const lines = new THREE.LineSegments(edgesFor(geom.mesh, welded), inkMat); + lines.position.copy(m.position); + lines.quaternion.copy(m.quaternion); + g.add(lines); + } + }), + ); + } + } + await Promise.all(pending); + + const rig = { placer, root, bodies, joints }; + setupJawPivot(rig); + return rig; +} + +// ── Jaw hinge ─────────────────────────────────────────────────────────── +// The mjlab model has no passive jaw joints: jaw.stl / jaw_soft.stl are +// rigid geoms of the head body (named "jaw_soft" in the MJCF, it carries +// the head_roll joint). The quack re-creates the hinge in JS: both jaw +// meshes are reparented into a "jaw_pivot" group whose origin sits on the +// physical hinge, and setJawOpen rotates that pivot about the robot's +// left-right axis so the beak tip swings down. +const JAW_MESH_NAMES = new Set(["jaw.stl", "jaw_soft.stl"]); +export const JAW_MAX_OPEN = 0.32; // rad at openness 1 + +// The physical hinge: jaw.stl ends in a circular boss (8 mm ring with the +// axle hole at its center) on each side, hole axis along mesh-local X (the +// robot's left-right). Circle fitted offline on the STL's hole-wall +// vertices (RANSAC, 68 inliers, < 0.15 mm spread); x = 0 sits mid-way +// between the two bosses, on the hinge line. +const JAW_HINGE_LOCAL = new THREE.Vector3(0, 0.00004, 0.0075); + +function setupJawPivot(rig) { + const meshes = []; + rig.root.traverse((o) => { + if (o.isMesh && JAW_MESH_NAMES.has(o.userData.meshName)) meshes.push(o); + }); + if (!meshes.length) return; + const body = meshes[0].parent; + // The placer is still untransformed right after buildRig, so world + // coords == placer coords here: robot forward is +X, up is +Y. + rig.placer.updateWorldMatrix(true, true); + const jawMesh = meshes.find((m) => m.userData.meshName === "jaw.stl") ?? meshes[0]; + const hingeW = jawMesh.localToWorld(JAW_HINGE_LOCAL.clone()); + // +angle about -Z rotates the +X beak tip toward -Y (down). + const axisW = new THREE.Vector3(0, 0, -1); + const bodyQuatInv = body.getWorldQuaternion(new THREE.Quaternion()).invert(); + const hingeL = body.worldToLocal(hingeW.clone()); + const axisL = axisW.applyQuaternion(bodyQuatInv).normalize(); + const pivot = new THREE.Group(); + pivot.name = "jaw_pivot"; + pivot.position.copy(hingeL); + // Plain array so Object3D.copy's JSON userData clone preserves it. + pivot.userData.jawAxis = axisL.toArray(); + body.add(pivot); + for (const m of meshes) { + m.position.sub(hingeL); + pivot.add(m); + } +} + +// Open the beak: 0 = closed, 1 = fully open (JAW_MAX_OPEN rad). The pivot +// is resolved lazily by name so clones from cloneRig work transparently. +const _jawAxis = new THREE.Vector3(); +export function setJawOpen(rig, open) { + if (rig._jawPivot === undefined) { + rig._jawPivot = rig.placer.getObjectByName("jaw_pivot") ?? null; + } + const pivot = rig._jawPivot; + if (!pivot) return; + _jawAxis.fromArray(pivot.userData.jawAxis); + pivot.quaternion.setFromAxisAngle(_jawAxis, JAW_MAX_OPEN * open); +} + +// Set one named joint, clamped to its MJCF range when known. +export function setJoint(rig, name, angle) { + const j = rig.joints.get(name); + if (!j) return; + let a = angle; + if (j.range) a = Math.min(j.range[1], Math.max(j.range[0], a)); + const rot = _q.setFromAxisAngle(j.axis, a); + j.body.quaternion.copy(j.baseQuat).multiply(rot); +} +const _q = new THREE.Quaternion(); + +export function applyPose(rig, pose) { + for (const [name, ang] of Object.entries(pose)) setJoint(rig, name, ang); +} + +// Deep-clone a built rig without re-parsing the GLB: Object3D.clone +// shares geometry and materials, so N clones cost almost nothing on top of +// the first buildRig. The bodies/joints maps are rebuilt by looking up the +// cloned nodes by name (body names are unique in the MJCF). +export function cloneRig(rig) { + const placer = rig.placer.clone(true); + const root = placer.getObjectByName("duck_root"); + const bodies = new Map(); + for (const name of rig.bodies.keys()) { + bodies.set(name, placer.getObjectByName(name)); + } + const joints = new Map(); + for (const [name, j] of rig.joints) { + joints.set(name, { + body: placer.getObjectByName(j.body.name), + axis: j.axis, // read-only, safe to share + baseQuat: j.baseQuat.clone(), + range: j.range, + }); + } + return { placer, root, bodies, joints }; +} + +// Ground using the whole rig's bounding box (sitting pose folds the legs +// under the trunk, so the feet are not the lowest point). +const _box = new THREE.Box3(); +export function groundFullBody(rig, floorY = 0) { + rig.placer.updateWorldMatrix(true, true); + _box.setFromObject(rig.placer); + if (!Number.isFinite(_box.min.y)) return 0; + rig.placer.position.y += floorY - _box.min.y; + return floorY - _box.min.y; +} + +// "SIT" keyframe. The mjlab model shares alpha's conventions (same +// onshape-to-robot pipeline): neck_pitch range max is 1.0472, so +// neck_pitch sits just under it (headroom for the breathing oscillation, +// +-0.025) and head_pitch compensates to keep the head level-ish with a +// slight upward tilt toward the camera. NOTE: head_pitch sign is +// inverted vs v1.5 (positive = head down), so the compensation is +// positive here (verified visually). +export const SITTING_POSE = { + left_hip_yaw: 0.0, + left_hip_roll: 0.0, + left_hip_pitch: -0.5236, + left_knee: 1.0472, + left_ankle: 0.0, + neck_pitch: 1.02, + head_pitch: 0.9, + head_yaw: 0.0, + head_roll: 0.0, + right_hip_yaw: 0.0, + right_hip_roll: 0.0, + right_hip_pitch: 0.5236, + right_knee: -1.0472, + right_ankle: 0.0, +}; diff --git a/app/src/game/fx/demo-glitch.html b/app/src/game/fx/demo-glitch.html new file mode 100644 index 0000000..91b790d --- /dev/null +++ b/app/src/game/fx/demo-glitch.html @@ -0,0 +1,140 @@ + + + + + + fx demo - glitch materialization + + + + +
+ +
loading rig...
+ + + diff --git a/app/src/game/fx/demo-wireframe.html b/app/src/game/fx/demo-wireframe.html new file mode 100644 index 0000000..24d7dbb --- /dev/null +++ b/app/src/game/fx/demo-wireframe.html @@ -0,0 +1,113 @@ + + + + + + FX demo - holographic wireframe scan-up + + + + +
+
+ FX: HOLOGRAPHIC WIREFRAME SCAN-UP
+ +
+ + + diff --git a/app/src/game/fx/fx-glitch.js b/app/src/game/fx/fx-glitch.js new file mode 100644 index 0000000..085e500 --- /dev/null +++ b/app/src/game/fx/fx-glitch.js @@ -0,0 +1,311 @@ +// Cyberpunk 2077-style glitch materialization for the Microduck rig. +// +// The duck appears as stacked horizontal slices that flicker in and out +// with random screen-space horizontal offsets, converging to their true +// position. Chromatic aberration is faked with two additive silhouette +// ghosts (cyan / orange) offset left-right, digital noise blocks flash +// emissive or invert the surface colour, and a final warm flash "snaps" +// everything crisp. +// +// Implementation: onBeforeCompile injections on CACHED clones of the rig +// materials (same pattern and same program-cache trap as the entrance +// dissolve in rl.js: clones are cached per original material and reused +// on every replay, each with a unique customProgramCacheKey, otherwise +// three.js would reuse a compiled program without re-binding uniforms). +// All uniforms are shared singleton objects so one JS write per frame +// drives every material. + +export const name = "glitch"; + +const DURATION = 1.15; // seconds +const TICK_HZ = 30; // discrete glitch update rate (digital feel) +const SLICES = 24; + +// ── Shared uniforms (one instance drives all cloned materials) ────────── +const uP = { value: 0 }; // progress 0..1 (0 = invisible) +const uSeed = { value: 0 }; // discrete tick, drives all hashes +const uAmp = { value: 0 }; // slice offset amplitude (view-space meters) +const uFlash = { value: 0 }; // final snap flash intensity +const uGhostOff = { value: 0 }; // RGB-split ghost separation (meters) +const uB = { value: null }; // vec4(minY, height, sliceH, 0) world bounds + +let T = null; // injected THREE namespace +let rigRef = null; +let playing = false; +let scrubbed = false; +let done = true; +let elapsed = 0; + +// Deterministic JS-side hash, mirrors the GLSL one. +const jhash = (n) => { + const s = Math.sin(n * 127.1 + 311.7) * 43758.5453; + return s - Math.floor(s); +}; + +// ── GLSL injection ────────────────────────────────────────────────────── +const GLSL_HELPERS = /* glsl */ ` +varying vec3 vGlW; +uniform float uGlP, uGlSeed; +uniform vec4 uGlB; +float glHash2(vec2 q) { return fract(sin(dot(q, vec2(127.1, 311.7))) * 43758.5453); } +vec3 glHash3(vec2 q) { return vec3(glHash2(q), glHash2(q + 17.17), glHash2(q + 31.3)); } +`; + +function injectGlitch(shader, { signU = null, ghost = false } = {}) { + shader.uniforms.uGlP = uP; + shader.uniforms.uGlSeed = uSeed; + shader.uniforms.uGlAmp = uAmp; + shader.uniforms.uGlFlash = uFlash; + shader.uniforms.uGlGhostOff = uGhostOff; + shader.uniforms.uGlSign = signU ?? { value: 0 }; + shader.uniforms.uGlB = uB; + + shader.vertexShader = shader.vertexShader + .replace( + "#include ", + "#include \n" + GLSL_HELPERS + "uniform float uGlAmp, uGlSign, uGlGhostOff;\n", + ) + .replace( + "#include ", + /* glsl */ `#include +vec4 glWp = modelMatrix * vec4(transformed, 1.0); +vGlW = glWp.xyz; +if (uGlP < 1.0) { + float glSid = floor((glWp.y - uGlB.x) / uGlB.z); + // Fraction of moving slices shrinks as p rises: convergence. + float glMove = step(0.25 + 0.62 * uGlP, glHash2(vec2(glSid * 1.71 + 4.2, uGlSeed + 13.0))); + float glOff = (glHash2(vec2(glSid, uGlSeed)) - 0.5) * 2.0 * uGlAmp * glMove; + // Occasional whole-body frame jump for one tick. + if (glHash2(vec2(uGlSeed, 3.17)) > 0.86) { + glOff += (glHash2(vec2(uGlSeed, 9.91)) - 0.5) * 3.0 * uGlAmp; + } + glOff += uGlSign * uGlGhostOff; + // View-space X = screen-horizontal, the classic spawn-glitch axis. + mvPosition.x += glOff; + gl_Position = projectionMatrix * mvPosition; +}`, + ); + + const sliceDiscard = /* glsl */ ` +float glEdge = 0.0, glInvAmt = 0.0; +vec3 glAddC = vec3(0.0); +if (uGlP < 1.0) { + float glSid = floor((vGlW.y - uGlB.x) / uGlB.z); + float glH = glHash2(vec2(glSid, uGlSeed + 0.7)); + float glVis = smoothstep(0.02, 0.82, uGlP) * 1.35; + // Two-three full-silhouette pre-flashes right at the start. + float glPre = (uGlP > 0.015 && uGlP < 0.14 && glHash2(vec2(uGlSeed, 7.7)) > 0.72) ? 1.0 : 0.0; + glVis = max(glVis, glPre); + if (glH > glVis) discard; + glEdge = max(glPre * 0.7, (1.0 - smoothstep(0.0, 0.3, glVis - glH)) * (1.0 - uGlP)); +${ghost ? "" : /* glsl */ ` + // Digital noise blocks: world-space rectangular patches, re-seeded per + // tick. Some invert the surface colour, most flash emissive. + vec2 glBq = floor((vGlW.xy + vec2(vGlW.z * 0.7, vGlW.z * 0.3)) * 52.0 + + vec2(uGlSeed * 0.373, uGlSeed * 0.719)); + vec3 glBh = glHash3(glBq + uGlSeed); + float glBGate = (1.0 - uGlP) * 0.16; + if (glBh.x > 1.0 - glBGate) { + if (glBh.y < 0.3) glInvAmt = 1.0; + else glAddC += (glBh.z < 0.6 ? vec3(0.15, 1.3, 1.5) + : (glBh.z < 0.85 ? vec3(1.4) : vec3(1.6, 0.5, 0.06))) * (0.7 + glBh.y); + } + // Faint rolling scanline shimmer. + glAddC += vec3(0.05, 0.3, 0.35) * (1.0 - uGlP) * 0.18 + * step(0.6, fract(vGlW.y * 150.0 - uGlSeed * 0.21)); +`} +}`; + + const emissiveOut = ghost + ? "" // ghosts are pre-tinted additive silhouettes, no extra emissive + : /* glsl */ ` +gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(1.1) - gl_FragColor.rgb, glInvAmt); +gl_FragColor.rgb += glAddC; +gl_FragColor.rgb += glEdge * vec3(0.25, 1.15, 1.35); +gl_FragColor.rgb += uGlFlash * vec3(1.25, 0.7, 0.35);`; + + shader.fragmentShader = shader.fragmentShader + .replace( + "#include ", + "#include \n" + GLSL_HELPERS + "uniform float uGlFlash;\n", + ) + .replace("#include ", "#include " + sliceDiscard) + .replace("#include ", "#include " + emissiveOut); +} + +// ── Material clones (cached, never disposed between replays) ──────────── +const clones = new Map(); // original material uuid -> glitch clone +let cloneNonce = 0; +let saved = null; // Array<[mesh, originalMat, cloneMat]> while active + +function cloneFor(orig) { + let m = clones.get(orig.uuid); + if (m) return m; + m = orig.clone(); + m.onBeforeCompile = (shader) => injectGlitch(shader); + const key = `microduck-glitch-${cloneNonce++}`; + m.customProgramCacheKey = () => key; + m.needsUpdate = true; + clones.set(orig.uuid, m); + return m; +} + +function applyGlitchMats() { + if (saved) return; + saved = []; + rigRef.placer.traverse((o) => { + if (!o.isMesh || o.userData.glGhost) return; + const orig = o.material; + const m = cloneFor(orig); + saved.push([o, orig, m]); + o.material = m; + }); +} + +function restoreMats() { + if (!saved) return; + for (const [mesh, orig, clone] of saved) { + if (mesh.material === clone) mesh.material = orig; + } + saved = null; +} + +// ── RGB-split ghosts ──────────────────────────────────────────────────── +// Two additive unlit silhouette copies of every rig mesh (cyan right, +// orange left), sharing the slice-discard shader so their outline always +// matches the sliced duck. Added as children of each mesh: they inherit +// the full kinematic transform for free. +let ghostMats = []; +let ghostMeshes = []; + +function makeGhostMat(r, g, b, sign) { + const m = new T.MeshBasicMaterial({ + transparent: true, + opacity: 0, + depthWrite: false, + blending: T.AdditiveBlending, + }); + m.color.setRGB(r, g, b); + const signU = { value: sign }; + m.onBeforeCompile = (shader) => injectGlitch(shader, { signU, ghost: true }); + m.customProgramCacheKey = () => `microduck-glitch-ghost-${sign > 0 ? "r" : "l"}`; + return m; +} + +function buildGhosts() { + ghostMats = [makeGhostMat(0.0, 1.1, 1.3, +1), makeGhostMat(1.3, 0.35, 0.02, -1)]; + const hosts = []; + rigRef.placer.traverse((o) => { + if (o.isMesh && !o.userData.glGhost) hosts.push(o); + }); + for (const mesh of hosts) { + for (const mat of ghostMats) { + const gm = new T.Mesh(mesh.geometry, mat); + gm.userData.glGhost = true; + gm.renderOrder = 2; + gm.frustumCulled = false; + gm.visible = false; + mesh.add(gm); + ghostMeshes.push(gm); + } + } +} + +function setGhostsVisible(v) { + for (const gm of ghostMeshes) gm.visible = v; +} + +// ── Deterministic per-progress uniform state ──────────────────────────── +// Everything derives from p alone (tick included), so setProgress(p) gives +// reproducible frames for debugging/screenshots. +function setUniformsFor(p) { + uP.value = p; + const tick = Math.floor(p * DURATION * TICK_HZ); + uSeed.value = tick; + const h = uB.value.y; // duck height + const gate = 0.35 + 0.65 * jhash(tick + 3.7); + uAmp.value = p < 0.92 ? h * 0.3 * Math.pow(1 - p, 1.3) * gate : 0; + uGhostOff.value = + p > 0.04 && p < 0.9 ? (0.06 + 0.3 * jhash(tick + 11.1)) * (1 - p) * h : 0; + uFlash.value = p > 0.86 ? 1.5 * Math.exp(-16 * (p - 0.86) * DURATION) : 0; + const ghostOp = + p > 0.04 && p < 0.9 ? (0.05 + 0.32 * (1 - p)) * (0.4 + 0.6 * jhash(tick + 5.5)) : 0; + for (const m of ghostMats) m.opacity = ghostOp; +} + +function finish() { + uP.value = 1; + uFlash.value = 0; + setGhostsVisible(false); + restoreMats(); + playing = false; + done = true; +} + +// ── Public interface ──────────────────────────────────────────────────── +export function init({ THREE, scene, rig, camera, renderer }) { + T = THREE; + rigRef = rig; + rig.placer.updateWorldMatrix(true, true); + const box = new T.Box3().setFromObject(rig.placer); + const minY = box.min.y; + const height = Math.max(1e-3, box.max.y - minY); + uB.value = new T.Vector4(minY, height, height / SLICES, 0); + buildGhosts(); + // Duck starts invisible: p=0 discards every fragment. + uP.value = 0; + applyGlitchMats(); + done = true; + playing = false; +} + +export function start() { + applyGlitchMats(); + setGhostsVisible(true); + elapsed = 0; + playing = true; + scrubbed = false; + done = false; + setUniformsFor(0); +} + +export function update(dt, t) { + if (!playing || scrubbed) return; + elapsed += dt; + const p = Math.min(1, elapsed / DURATION); + setUniformsFor(p); + if (p >= 1) finish(); +} + +export function isDone() { + return done; +} + +export function dispose() { + restoreMats(); + for (const gm of ghostMeshes) gm.parent?.remove(gm); + ghostMeshes = []; + for (const m of ghostMats) m.dispose(); + ghostMats = []; + for (const m of clones.values()) m.dispose(); + clones.clear(); + playing = false; + done = true; + rigRef = null; +} + +// Debug hook: freeze the effect at an exact progress value (deterministic, +// used by the demo page for mid-effect screenshots). start() resumes +// normal playback. +export function setProgress(p) { + scrubbed = true; + if (p >= 1) { + finish(); + return; + } + playing = true; + done = false; + applyGlitchMats(); + setGhostsVisible(true); + setUniformsFor(Math.max(0, p)); +} diff --git a/app/src/game/fx/fx-wireframe.js b/app/src/game/fx/fx-wireframe.js new file mode 100644 index 0000000..bc88644 --- /dev/null +++ b/app/src/game/fx/fx-wireframe.js @@ -0,0 +1,339 @@ +// Holographic wireframe scan-up materialization effect. +// +// Sequence (~0.9 s, reversible): +// 1. An invisible scan height rises from the floor through the target; +// the boundary reads on the surface itself (bright wireframe band +// right under the scan height - no standalone disc geometry). +// 2. Below the scan line the target shows as a flickering additive +// wireframe hologram (scanline stripes, brightness boost near the +// scan line). +// 3. A second, fainter "solidify" line trails behind: fragments below +// it render the real PBR materials (world-Y clip injected via +// onBeforeCompile), with a hot edge right at the line. Once it +// clears the top the original materials are restored directly. +// +// Played backwards, the same timeline de-materializes (solid peel -> +// hologram -> gone). Used for the ball despawn; the duck only ever +// materializes. +// +// createWireframeFx() returns an independent instance (duck and ball +// scan at the same time without sharing uniforms). The module-level +// named exports wrap a singleton so demo-wireframe.html is unchanged. +// +// Instance interface: +// init({ THREE, scene, rig | root, camera, renderer, hidden? }) +// start() / startReverse() / update(dt) / isDone() / restore() / dispose() +// Extra: setProgress(p), playing, reversing, TOTAL_S. + +export const name = "wireframe"; + +// ── Timeline (seconds) ────────────────────────────────────────────────── +const SCAN_S = 0.6; // wireframe scan line: floor -> top +const SOLID_DELAY_S = 0.3; // solidify line starts this long after the scan +const SOLID_S = 0.6; // solidify line: floor -> top +export const TOTAL_S = SOLID_DELAY_S + SOLID_S; // 0.9 + +const clamp01 = (x) => Math.min(Math.max(x, 0), 1); +// Ease-out only: the rise starts at full speed the instant the scan cues +// (a smoothstep ease-in reads as a stall near the feet) and lands softly. +const ease = (x) => 1 - (1 - x) * (1 - x); + +// Deterministic pseudo-random flicker so setProgress(p) captures are +// reproducible (no Math.random). +const hash = (x) => { + const s = Math.sin(x * 127.1) * 43758.5453; + return s - Math.floor(s); +}; +const flickerAt = (time) => { + let f = 0.82 + 0.18 * hash(Math.floor(time * 60) + 0.5); + if (hash(Math.floor(time * 24) + 7.7) < 0.12) f *= 0.5; // dropouts + return f; +}; + +// Unique customProgramCacheKey values across every instance: a fresh +// clone of the same source material would otherwise reuse the compiled +// program without re-running onBeforeCompile, leaving clip uniforms +// unbound (see the dissolve comment in rl.js). +let clipNonce = 0; + +const BOTTOM_PAD = 0.025; + +// The band widths and timeline above are tuned for duck-sized targets +// (~0.35 m tall). Bigger props (the arcade cabinets) scale the spatial +// constants linearly and the duration by sqrt(scale), so the scan still +// reads as the same effect instead of a fast flash with hairline bands. +// Clamped at 1 so duck- and ball-sized targets are untouched. +const REF_SPAN = 0.35; + +export function createWireframeFx() { + // Per-instance uniforms: duck and ball must not share a scan height. + const uScanY = { value: -1e3 }; + const uSolidY = { value: -1e3 }; + const uFlicker = { value: 1 }; + const uTime = { value: 0 }; + const uSpanK = { value: 1 }; // size factor vs REF_SPAN (>= 1) + + let ctx = null; // { THREE, scene, root, camera, renderer } + let t = 0; + let dir = 1; // +1 materialize, -1 dematerialize + let playing = false; + let finished = false; + + let minY = 0; + let spanY = 0.3; + let durK = 1; // timeline stretch for big targets + const totalS = () => TOTAL_S * durK; + + const clipClones = new Map(); + let clipSaved = null; // Array<[mesh, originalMat, cloneMat]> while active + + let wireMat = null; + let wireMeshes = []; + + const isTargetMesh = (o) => o.isMesh && !o.userData.fxOverlay; + + function clipCloneFor(orig) { + let m = clipClones.get(orig.uuid); + if (m) return m; + m = orig.clone(); + m.onBeforeCompile = (shader) => { + shader.uniforms.uFxSolidY = uSolidY; + shader.uniforms.uFxSpanK = uSpanK; + shader.vertexShader = shader.vertexShader + .replace("#include ", "#include \nvarying vec3 vFxW;") + .replace( + "#include ", + "#include \nvFxW = (modelMatrix * vec4(transformed, 1.0)).xyz;", + ); + shader.fragmentShader = shader.fragmentShader + .replace( + "#include ", + "#include \nvarying vec3 vFxW;\nuniform float uFxSolidY;\nuniform float uFxSpanK;", + ) + .replace( + "#include ", + /* glsl */ `#include +float fxEdge = 0.0; +if (vFxW.y > uFxSolidY) discard; +fxEdge = 1.0 - smoothstep(0.002 * uFxSpanK, 0.018 * uFxSpanK, uFxSolidY - vFxW.y);`, + ) + .replace( + "#include ", + /* glsl */ `#include +gl_FragColor.rgb += fxEdge * vec3(0.95, 0.32, 0.05);`, + ); + }; + const key = `microduck-fx-wireframe-${clipNonce++}`; + m.customProgramCacheKey = () => key; + m.needsUpdate = true; + clipClones.set(orig.uuid, m); + return m; + } + + function applyClipMaterials() { + if (clipSaved) return; + clipSaved = []; + ctx.root.traverse((o) => { + if (!isTargetMesh(o)) return; + const orig = o.material; + const clone = clipCloneFor(orig); + clipSaved.push([o, orig, clone]); + o.material = clone; + }); + } + + function restoreClipMaterials() { + if (!clipSaved) return; + for (const [mesh, orig, clone] of clipSaved) { + if (mesh.material === clone) mesh.material = orig; + } + clipSaved = null; + } + + function makeWireMaterial(THREE) { + return new THREE.ShaderMaterial({ + uniforms: { uScanY, uSolidY, uFlicker, uTime, uSpanK }, + vertexShader: /* glsl */ ` + varying vec3 vW; + void main() { + vec4 wp = modelMatrix * vec4(position, 1.0); + vW = wp.xyz; + gl_Position = projectionMatrix * viewMatrix * wp; + }`, + fragmentShader: /* glsl */ ` + uniform float uScanY, uSolidY, uFlicker, uTime, uSpanK; + varying vec3 vW; + void main() { + if (vW.y > uScanY || vW.y < uSolidY) discard; + float lead = 1.0 - smoothstep(0.0, 0.06 * uSpanK, uScanY - vW.y); + float tail = smoothstep(0.0, 0.018 * uSpanK, vW.y - uSolidY); + float stripes = 0.7 + 0.3 * sin(vW.y * 900.0 / uSpanK - uTime * 45.0); + vec3 c = vec3(1.0, 0.34, 0.06) * (0.55 + 1.6 * lead); + float a = (0.10 + 0.40 * lead) * stripes * tail * uFlicker; + gl_FragColor = vec4(c, a); + }`, + wireframe: true, + transparent: true, + blending: THREE.AdditiveBlending, + depthWrite: false, + depthTest: true, + }); + } + + function buildWireOverlays(THREE, root) { + wireMat = makeWireMaterial(THREE); + root.traverse((o) => { + if (!isTargetMesh(o)) return; + // Child of the source mesh with identity transform so the overlay + // follows whatever pose the caller writes (duck joints or ball qpos). + // userData.fxWireGeometry substitutes a coarser geometry for the + // wireframe pass only (the ball's render sphere is too dense to read + // as a hologram); the solidify clip still runs on the real mesh. + const w = new THREE.Mesh(o.userData.fxWireGeometry ?? o.geometry, wireMat); + w.userData.fxOverlay = true; + w.renderOrder = 5; + w.visible = false; + o.add(w); + wireMeshes.push(w); + }); + } + + function applyAt(time) { + const scanP = ease(clamp01(time / (SCAN_S * durK))); + const solidP = ease(clamp01((time - SOLID_DELAY_S * durK) / (SOLID_S * durK))); + uFlicker.value = flickerAt(time); + uTime.value = time; + + const jitter = scanP > 0 && scanP < 1 ? (hash(time * 41.3) - 0.5) * 0.02 * spanY : 0; + uScanY.value = minY + spanY * scanP + jitter; + uSolidY.value = minY + spanY * solidP; + + const wiresOn = time > 0 && solidP < 1; + for (const w of wireMeshes) w.visible = wiresOn; + } + + function finish() { + // Forward: restore the real materials (fully solid). Reverse: leave + // the clip parked at t=0 (fully hidden) so restoring wouldn't flash + // the solid mesh for a frame; the caller hides the object then + // restore()s. + if (dir > 0) restoreClipMaterials(); + else applyAt(0); + for (const w of wireMeshes) w.visible = false; + finished = true; + playing = false; + } + + function computeRange() { + const { THREE, root } = ctx; + root.updateWorldMatrix(true, true); + const box = new THREE.Box3().setFromObject(root); + minY = Math.min(box.min.y, 0) - BOTTOM_PAD; + spanY = Math.max(box.max.y - minY, 0.04) * 1.06; + // Size adaptation: spatial constants scale linearly with the target's + // height, the timeline by sqrt (a 1.7 m cabinet scans in ~2 s, not + // 0.9 s at 6x the line speed). >= 1: duck/ball keep the original look. + uSpanK.value = Math.max(1, spanY / REF_SPAN); + durK = Math.min(Math.sqrt(uSpanK.value), 2.5); + } + + function arm(nextDir, resetT) { + dir = nextDir; + if (resetT) t = nextDir > 0 ? 0 : totalS(); + finished = false; + computeRange(); + applyClipMaterials(); + applyAt(t); + playing = true; + } + + function init({ THREE, scene, rig, root, camera, renderer, hidden = true }) { + const target = root ?? rig.placer; + ctx = { THREE, scene, root: target, camera, renderer }; + computeRange(); + buildWireOverlays(THREE, target); + t = 0; + dir = 1; + finished = false; + playing = false; + if (hidden) { + applyClipMaterials(); + applyAt(0); + } + } + + function start() { + // Mid-reverse: keep the current t and turn around. Fresh play: from 0. + arm(1, !playing); + } + + function startReverse() { + arm(-1, !playing); + } + + function update(dt) { + if (!playing || finished) return; + t += dir * dt; + if (dir > 0 && t >= totalS()) { + t = totalS(); + applyAt(t); + finish(); + return; + } + if (dir < 0 && t <= 0) { + t = 0; + applyAt(t); + finish(); + return; + } + applyAt(t); + } + + function isDone() { + return finished; + } + + function setProgress(p) { + playing = false; + finished = false; + dir = 1; + computeRange(); + applyClipMaterials(); + t = clamp01(p) * totalS(); + applyAt(t); + } + + function restore() { + restoreClipMaterials(); + } + + function dispose() { + restoreClipMaterials(); + for (const w of wireMeshes) w.parent?.remove(w); + wireMeshes = []; + wireMat?.dispose(); + wireMat = null; + ctx = null; + playing = false; + finished = false; + } + + return { + init, start, startReverse, update, isDone, setProgress, restore, dispose, + get playing() { return playing; }, + get reversing() { return playing && dir < 0; }, + get TOTAL_S() { return totalS(); }, + }; +} + +// Singleton for the duck (and the isolated demo page). New callers that +// need a second scan (the ball) go through createWireframeFx(). +const singleton = createWireframeFx(); +export const init = (...a) => singleton.init(...a); +export const start = (...a) => singleton.start(...a); +export const startReverse = (...a) => singleton.startReverse(...a); +export const update = (...a) => singleton.update(...a); +export const isDone = (...a) => singleton.isDone(...a); +export const setProgress = (...a) => singleton.setProgress(...a); +export const restore = (...a) => singleton.restore(...a); +export const dispose = (...a) => singleton.dispose(...a); diff --git a/app/src/game/fx/waypoint-marker.js b/app/src/game/fx/waypoint-marker.js new file mode 100644 index 0000000..3cfa392 --- /dev/null +++ b/app/src/game/fx/waypoint-marker.js @@ -0,0 +1,181 @@ +// Click-to-walk target reticle, drawn in the same art direction as the +// wireframe materialization (fx-wireframe.js): additive orange hairlines +// (1 px GL lines), deterministic hologram flicker, ease-out timing. +// +// Anatomy (flat on the floor, group-local XZ plane): +// - main ring: hairline LineLoop +// - 4 radial ticks, slowly rotating (the "alive" tell while idle) +// - center cross marking the exact click point +// - ping ring: one-shot expanding echo played on (re)acquire +// +// Lifecycle, driven by update(dt, target) where target is the MJCF [x, y] +// from WaypointSource (or null): +// click / re-click -> "in": the ring resolves from wide to tight while +// fading up, and the ping echoes outward +// arrival / cancel -> "out": quick collapse + fade, then hidden +// +// The MJCF -> three mapping (x, y) -> (x, -y) lives here so the caller +// can hand the source's target over untouched. + +import * as THREE from "three"; + +// Matches the scan color vec3(1.0, 0.34, 0.06) in fx-wireframe.js. +const COLOR = 0xff5710; + +const R = 0.06; // main ring radius (m) +const TICK_R0 = 0.08, TICK_R1 = 0.102; +const CROSS_R = 0.013; +const FLOOR_Y = 0.012; // sits just above the floor plane + +const IN_S = 0.35; // acquire: wide -> tight +const OUT_S = 0.22; // arrival/cancel: collapse + fade +const PING_S = 0.55; // echo ring lifetime +const PING_SCALE = 2.6; // echo end scale (relative to the main ring) + +const BODY_OPACITY = 0.85; +const TICK_SPIN = 0.7; // rad/s + +const clamp01 = (x) => Math.min(Math.max(x, 0), 1); +// Same ease-out as the scan: full speed on the cue, soft landing. +const ease = (x) => 1 - (1 - x) * (1 - x); + +// Deterministic hologram flicker, same recipe as fx-wireframe.js (no +// Math.random so captures are reproducible). +const hash = (x) => { + const s = Math.sin(x * 127.1) * 43758.5453; + return s - Math.floor(s); +}; +const flickerAt = (time) => { + let f = 0.86 + 0.14 * hash(Math.floor(time * 60) + 0.5); + if (hash(Math.floor(time * 24) + 7.7) < 0.08) f *= 0.55; // dropouts + return f; +}; + +function circleGeometry(r, n = 64) { + const pts = []; + for (let i = 0; i < n; i++) { + const a = (i / n) * Math.PI * 2; + pts.push(new THREE.Vector3(Math.cos(a) * r, 0, Math.sin(a) * r)); + } + return new THREE.BufferGeometry().setFromPoints(pts); +} + +function lineMaterial() { + return new THREE.LineBasicMaterial({ + color: COLOR, + transparent: true, + opacity: 0, + blending: THREE.AdditiveBlending, + depthWrite: false, + }); +} + +export function createWaypointMarker() { + const group = new THREE.Group(); + group.visible = false; + group.position.y = FLOOR_Y; + + const bodyMat = lineMaterial(); + const pingMat = lineMaterial(); + + const ringGeo = circleGeometry(R); + const ring = new THREE.LineLoop(ringGeo, bodyMat); + + // 4 radial ticks at the diagonals, rotated as one object while idle. + const tickPts = []; + for (let i = 0; i < 4; i++) { + const a = Math.PI / 4 + (i * Math.PI) / 2; + const c = Math.cos(a), s = Math.sin(a); + tickPts.push( + new THREE.Vector3(c * TICK_R0, 0, s * TICK_R0), + new THREE.Vector3(c * TICK_R1, 0, s * TICK_R1), + ); + } + const ticks = new THREE.LineSegments( + new THREE.BufferGeometry().setFromPoints(tickPts), + bodyMat, + ); + + const cross = new THREE.LineSegments( + new THREE.BufferGeometry().setFromPoints([ + new THREE.Vector3(-CROSS_R, 0, 0), new THREE.Vector3(CROSS_R, 0, 0), + new THREE.Vector3(0, 0, -CROSS_R), new THREE.Vector3(0, 0, CROSS_R), + ]), + bodyMat, + ); + + // One-shot expanding echo; shares the ring geometry, scale-animated. + const ping = new THREE.LineLoop(ringGeo, pingMat); + ping.visible = false; + + for (const o of [ring, ticks, cross, ping]) { + o.renderOrder = 5; // over the floor, same layer as the fx overlays + group.add(o); + } + + let phase = "hidden"; // hidden | in | idle | out + let tPhase = 0; + let tPing = Infinity; // >= PING_S means the echo is spent + let time = 0; // flicker clock + let px = 0, pz = 0; // shown position (three coords) + + function acquire(x, z) { + px = x; + pz = z; + group.position.set(px, FLOOR_Y, pz); + phase = "in"; + tPhase = 0; + tPing = 0; + group.visible = true; + } + + function update(dt, target) { + time += dt; + if (target) { + const tx = target[0], tz = -target[1]; // MJCF -> three + if (phase === "hidden" || phase === "out") acquire(tx, tz); + else if (Math.hypot(tx - px, tz - pz) > 1e-3) acquire(tx, tz); // re-click + } else if (phase === "in" || phase === "idle") { + phase = "out"; + tPhase = 0; + } + if (phase === "hidden") return; + + tPhase += dt; + tPing += dt; + ticks.rotation.y = time * TICK_SPIN; + + let scale = 1; + let alpha = BODY_OPACITY; + if (phase === "in") { + const k = ease(clamp01(tPhase / IN_S)); + scale = 1.6 - 0.6 * k; // resolves from wide to tight + alpha *= k; + if (tPhase >= IN_S) phase = "idle"; + } else if (phase === "idle") { + scale = 1 + 0.03 * Math.sin(time * 2.4); // subtle breathing + alpha *= flickerAt(time); + } else if (phase === "out") { + const k = ease(clamp01(tPhase / OUT_S)); + scale = 1 - 0.35 * k; + alpha *= 1 - k; + if (tPhase >= OUT_S) { + phase = "hidden"; + group.visible = false; + } + } + for (const o of [ring, ticks, cross]) o.scale.setScalar(scale); + bodyMat.opacity = alpha; + + if (tPing < PING_S) { + const p = ease(clamp01(tPing / PING_S)); + ping.visible = true; + ping.scale.setScalar(1 + (PING_SCALE - 1) * p); + pingMat.opacity = 0.9 * (1 - p); + } else { + ping.visible = false; + } + } + + return { group, update }; +} diff --git a/app/src/game/game.js b/app/src/game/game.js new file mode 100644 index 0000000..da73538 --- /dev/null +++ b/app/src/game/game.js @@ -0,0 +1,2311 @@ +// Microduck RL playground core: the REAL trained policies, not a procedural +// waddle. Framework-agnostic port of the pre-React rl.js. +// +// Physics runs in MuJoCo compiled to WebAssembly (the official +// @mujoco/mujoco bindings), stepping the same MJCF the policies were +// trained on (pollen-robotics/microduck_rl). The controller is one of the +// exported ONNX checkpoints from pollen-robotics/microduck, executed with +// onnxruntime-web at 50 Hz (timestep 0.005 s, decimation 4) - exactly the +// loop from microduck_rl/scripts/infer_policy.py. +// +// Obs layout (61D, "new-cmd-obs" flavor, from the ONNX metadata): +// [base_ang_vel(3), projected_gravity(3), joint_pos(14), joint_vel(14), +// last_action(14), command(13)] +// +// Integration contract with the React shell: +// - bootGame({ scene, camera, renderer }) is called once from inside the +// R3F canvas; it loads everything, wires inputs and starts the 50 Hz +// control loop. +// - frame(dt) is called by R3F's useFrame every animation frame; it does +// everything the old rAF loop did EXCEPT renderer.render (R3F renders). +// - UI state flows out through the zustand store (throttled), UI intents +// flow back in through gameApi. + +import * as THREE from "three"; +import { OrbitControls } from "three/addons/controls/OrbitControls.js"; +import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js"; +import { signed } from "./signed.js"; +import { + POLICIES, JOINT_NAMES, DEFAULT_POSE, NUM_JOINTS, OBS_SIZE, CMD_SIZE, + ACTION_SCALE, TIMESTEP, DECIMATION, CTRL_DT, + VEL_FWD, VEL_BACK, VEL_ANG, RVEL_FWD, RVEL_BACK, RVEL_ANG, + CROUCH_PERIOD_S, CROUCH_END_PHASE, + GROUND_PICK_PERIOD_S, GROUND_PICK_END_PHASE, + BALL_RADIUS, BALL_PARK_POS, ARENA_HALF, SPAWN_X, SPAWN_Y, + RELIEF_BUMPS, RELIEF_HMAX, RELIEF_GRID, RELIEF_SINK, RELIEF_RATE, +} from "./constants.js"; +import { loadProps, propColliders } from "./props.js"; +import { + buildRig, cloneRig, loadKinematics, setJoint, setJawOpen, MODEL_DIR, MESH_VERSION, + loadGlbGeometries, geometryToBinaryStl, +} from "./duck.js"; +import { + VARIANTS, materialHookFor, DEFAULT_VARIANT, applyVariant, +} from "./variants.js"; +import { Controller } from "./controls/controller.js"; +import { KeyboardSource } from "./controls/keyboard.js"; +import { GamepadSource } from "./controls/gamepad.js"; +import { haptics } from "./haptics.js"; +import { TouchSource } from "./controls/touch.js"; +import { WaypointSource } from "./controls/waypoint.js"; +import * as fx from "./fx/fx-wireframe.js"; +import { createWaypointMarker } from "./fx/waypoint-marker.js"; +import { createCeremony, CAM_RESET_S } from "./ceremony.js"; +import { + audioCtx, busNode, preloadSfx, playSfx, playUrl, updateListener, + createEmitter, startAmbient, setAmbientDucked, playEntranceSweep, + playPropSweep, playLineBlip, setRumble, +} from "./audio.js"; +import { createBallActor } from "./ball-actor.js"; +import { loadCustomPolicy as loadCustomPolicyModule, scriptCommandAt } from "./custom-policy.js"; +import { initGhosts } from "./ghosts.js"; +import { makeInfiniteGrid, makeArenaWalls } from "./arena.js"; +import { createBallVisual } from "./ball-visual.js"; +import { useGame, gameApi, bootLine, bootNote, bootHalt } from "../store.js"; + +// Physics + inference runtimes are vendored npm dependencies (no CDN): +// everything visitors execute is built from package-lock-verified +// tarballs and served from the Space itself, closing the jsDelivr +// supply-chain surface. The .wasm binaries ride the bundle as hashed +// assets via Vite ?url imports; the JS modules stay dynamic imports so +// they land in their own lazy chunks like before. +import mujocoWasmUrl from "@mujoco/mujoco/mujoco.wasm?url"; +import ortWasmUrl from "onnxruntime-web/ort-wasm-simd-threaded.wasm?url"; + +let bootStarted = false; + +// Trunk yaw from the freejoint quat (MuJoCo wxyz), Z-up so this is rotation +// about z. Shared by the chase cam and the waypoint follower - both need +// "which way is the duck facing" in MJCF ground coords. +function duckYaw(qpos) { + return Math.atan2( + 2 * (qpos[3] * qpos[6] + qpos[4] * qpos[5]), + 1 - 2 * (qpos[5] * qpos[5] + qpos[6] * qpos[6]), + ); +} + +// HMR teardown for the ghost session: invalidating this module (directly or +// via an edit to ghosts.js) used to stack a live 15 Hz broadcast interval +// plus a ghost room per reload (the historical "stale module" bug class). +const liveGhostSessions = new Set(); +if (import.meta.hot) { + import.meta.hot.dispose(() => { + for (const g of liveGhostSessions) g.destroy(); + liveGhostSessions.clear(); + }); +} + +export async function bootGame({ scene, camera, renderer }) { + if (bootStarted) return; + bootStarted = true; + try { + await boot({ scene, camera, renderer }); + } catch (err) { + console.error("[game] boot failed", err); + bootHalt(err?.message || String(err)); + } +} + +async function boot({ scene, camera, renderer }) { + const setStore = useGame.setState; + const store = useGame.getState; + + bootNote("Microduck BIOS v1.0"); + bootLine("MEMORY CHECK")("640K OK"); + bootLine("DUCK FIRMWARE")("PRESENT"); + + // Surface async boot failures in the BIOS halt screen. Gated on the boot + // still being in flight: post-boot async noise (ghost relay hiccups, + // audio autoplay rejections...) must NOT cue the halt screen. + const bootGuard = (e, msg) => { + if (!store().bootDone && !store().bootFailed) bootHalt(msg); + }; + window.addEventListener("unhandledrejection", (e) => { + console.error("[game] unhandled rejection", e.reason); + bootGuard(e, e.reason?.message || String(e.reason)); + }); + window.addEventListener("error", (e) => { + console.error("[game] window error", e.message); + bootGuard(e, e.message); + }); + + // Halting at the failure site: a rejected await inside this async boot + // would otherwise only surface through the caller's catch. + const traced = (label, p) => { + const done = bootLine(label); + return p.then( + (v) => { done("OK"); return v; }, + (err) => { + done("FAILED"); + console.error(`[game] ${label} FAILED`, err); + bootHalt(err?.message || String(err)); + throw err; + }, + ); + }; + + // ── Runtimes (vendored, lazy chunks) ───────────────────────────────── + const [{ default: loadMujocoFactory }, ort] = await traced( + "RUNTIME MODULES", + Promise.all([ + import("@mujoco/mujoco"), + // wasm-only build: the sessions only ever use the "wasm" execution + // provider, and the default entry would emit the 26 MB WebGPU (jsep) + // wasm into the dist for nothing. + import("onnxruntime-web/wasm"), + ]), + ); + // The bundler build embeds its JS loader; only the .wasm binary is + // fetched at runtime, from our own hashed asset. + ort.env.wasm.wasmPaths = { wasm: ortWasmUrl }; + ort.env.wasm.numThreads = 1; // static hosting sends no COOP/COEP headers + + // ── MJCF preparation ──────────────────────────────────────────────── + // robot_allcollisions.xml is what infer_policy.py's scene.xml includes: + // it carries body/shell collision geoms that robot_walk.xml lacks, which + // the sitstand policy needs (a sit rests the trunk on the ground). + // Visual meshes are irrelevant to the dynamics: every body carries an + // explicit , and visual geoms have contype=0 conaffinity=0. + // Stripping them means the MuJoCo VFS only needs the ~10 meshes + // referenced by collision geoms. Works for both variants. + async function buildPhysicsXml(xmlFile) { + const src = await (await fetch(signed(`${MODEL_DIR}/${xmlFile}`))).text(); + const doc = new DOMParser().parseFromString(src, "text/xml"); + for (const g of [...doc.querySelectorAll('geom[class="visual"]')]) g.remove(); + const usedMeshes = new Set( + [...doc.querySelectorAll("geom[mesh]")].map((g) => g.getAttribute("mesh")), + ); + for (const m of [...doc.querySelectorAll("asset > mesh")]) { + const name = m.getAttribute("name") ?? m.getAttribute("file").replace(/\.stl$/i, ""); + if (!usedMeshes.has(name)) m.remove(); + } + const root = doc.documentElement; + const el = (tag, attrs) => { + const e = doc.createElement(tag); + for (const [k, v] of Object.entries(attrs)) e.setAttribute(k, v); + return e; + }; + root.appendChild(el("option", { timestep: String(TIMESTEP) })); + doc.querySelector("worldbody").appendChild( + el("geom", { name: "floor", type: "plane", size: "0 0 0.05", pos: "0 0 0" }), + ); + // Arena walls: four static boxes (no joints, so no qpos/keyframe + // impact); default contype/conaffinity collides with ball and duck. + const ht = 0.05 / 2, hh = 0.25 / 2; + const off = ARENA_HALF + ht, span = ARENA_HALF + 0.05; + const walls = [ + { name: "wall_px", pos: `${off} 0 ${hh}`, size: `${ht} ${span} ${hh}` }, + { name: "wall_nx", pos: `${-off} 0 ${hh}`, size: `${ht} ${span} ${hh}` }, + { name: "wall_py", pos: `0 ${off} ${hh}`, size: `${span} ${ht} ${hh}` }, + { name: "wall_ny", pos: `0 ${-off} ${hh}`, size: `${span} ${ht} ${hh}` }, + ]; + for (const w of walls) { + doc.querySelector("worldbody").appendChild( + el("geom", { name: w.name, type: "box", pos: w.pos, size: w.size }), + ); + } + // Prop library colliders: one static box per enabled prop + // (declared in props.js next to the visual placement, optionally + // yawed via euler to match off-axis staging) so the duck and ball + // can't clip through the dressing. + for (const c of propColliders()) { + const attrs = { name: c.name, type: "box", pos: c.pos, size: c.size }; + if (c.euler) attrs.euler = c.euler; + doc.querySelector("worldbody").appendChild(el("geom", attrs)); + } + // Kickable ball: a light free sphere (beach-ball feel). MuJoCo has no + // restitution parameter - the bounce comes from solref damping < 1, and + // the rolling-friction term makes it come to rest. Appended AFTER the + // robot body so the trunk freejoint stays first in qpos. + const ballBody = el("body", { name: "ball", pos: BALL_PARK_POS }); + ballBody.appendChild(el("freejoint", { name: "ball_freejoint" })); + // condim 6 enables the torsional + rolling friction components; with + // the default condim 3 a rolling ball never decelerates. + ballBody.appendChild(el("geom", { + name: "ball_geom", type: "sphere", size: String(BALL_RADIUS), + mass: "0.03", friction: "0.4 0.01 0.003", solref: "0.03 0.4", condim: "6", + })); + doc.querySelector("worldbody").appendChild(ballBody); + // Relief terraces: one kinematically driven box per raisable grid + // cell, on a vertical slide joint (qpos written directly each control + // step, like the ball). q = 0 parks the box fully below the floor; + // q = h + RELIEF_EPS puts its top exactly at h. Appended after the + // ball so the keyframe layout stays robot + ball + relief. + // Relief heightfield: a static hfield over the whole arena, elevation + // data filled at runtime from the shared analytic bump function (see + // driveRelief). It compiles flat (no file/elevation = zeros) and has + // no joints, so qpos and the keyframe are untouched. The geom sits + // RELIEF_SINK below the floor so a near-zero z-size is fully buried; + // raising the terrain = scaling model.hfield_size z at runtime. + doc.querySelector("asset").appendChild(el("hfield", { + name: "terrain", nrow: String(RELIEF_GRID), ncol: String(RELIEF_GRID), + size: `${ARENA_HALF} ${ARENA_HALF} ${RELIEF_HMAX} 0.1`, + })); + doc.querySelector("worldbody").appendChild(el("geom", { + name: "terrain", type: "hfield", hfield: "terrain", + pos: `0 0 ${-RELIEF_SINK}`, + })); + // STAND keyframe from mjlab's scene_walk.xml. qpos must cover every + // joint in document order: the 14 actuated hinges take DEFAULT_POSE by + // name, anything else (the roller variant's passive wheels) starts at + // zero. The ball's 7 free-joint values MUST be appended or nq won't + // match; parked 50 m away = effectively absent. + const qposFree = `${SPAWN_X} ${SPAWN_Y} 0.12 1 0 0 0`; + const poseByName = new Map(JOINT_NAMES.map((n, i) => [n, DEFAULT_POSE[i]])); + const qposJoints = [...doc.querySelectorAll("body > joint")] + .map((j) => poseByName.get(j.getAttribute("name")) ?? 0) + .join(" "); + const pose14 = Array.from(DEFAULT_POSE).join(" "); + const kf = doc.createElement("keyframe"); + kf.appendChild(el("key", { + name: "STAND", + qpos: `${qposFree} ${qposJoints} ${BALL_PARK_POS} 1 0 0 0`, + ctrl: pose14, + })); + root.appendChild(kf); + const meshFiles = [...doc.querySelectorAll("asset > mesh")].map((m) => m.getAttribute("file")); + return { xml: new XMLSerializer().serializeToString(doc), meshFiles }; + } + + // ── Boot physics + policy in parallel with the render rig ──────────── + const [mujoco, { xml, meshFiles }, k] = await Promise.all([ + traced("MUJOCO WASM", loadMujocoFactory({ + // Emscripten sidecar resolution: point at the Vite-emitted asset + // instead of a path relative to the module's own URL. + locateFile: (p) => (p.endsWith(".wasm") ? mujocoWasmUrl : p), + })), + traced("PHYSICS MJCF", buildPhysicsXml("robot_allcollisions.xml")), + traced("KINEMATICS", loadKinematics(`${MODEL_DIR}/kinematics.json`)), + ]); + + const doneMeshes = bootLine("MESH ASSETS"); + const vfs = new mujoco.MjVFS(); + // One shared VFS for both variants; already-loaded files are skipped so + // the roller lazy-load only fetches its leftover meshes. + const vfsFiles = new Set(); + async function addMeshesToVfs(files) { + const geoms = await loadGlbGeometries(); + await Promise.all( + files.map(async (f) => { + if (vfsFiles.has(f)) return; + vfsFiles.add(f); + // Legs/body meshes live in the visual GLB: rebuild binary STL in + // memory so MuJoCo never triggers a second download. Roller-only + // files (not in the GLB) still fetch as STL. + const entry = geoms.get(f); + const buf = entry + ? geometryToBinaryStl(entry.welded) + : await (await fetch(signed(`${MODEL_DIR}/meshes/${f}?v=${MESH_VERSION}`), { cache: "force-cache" })).arrayBuffer(); + // meshdir="assets" in the MJCF, so the compiler looks up "assets/". + vfs.addBuffer(`assets/${f}`, new Uint8Array(buf)); + }), + ); + } + try { + await addMeshesToVfs(meshFiles); + } catch (err) { + doneMeshes("FAILED"); + bootHalt(err?.message || String(err)); + throw err; + } + doneMeshes(`${meshFiles.length} FILES`); + + const sessions = {}; + // Always boot on the classic (orange) colourway; the quickbar re-skins live. + let currentVariant = DEFAULT_VARIANT; + const rigPromise = (async () => { + const doneRig = bootLine("RENDER RIG"); + try { + const builtRig = await buildRig(k, { materialForMesh: materialHookFor(VARIANTS[currentVariant]) }); + doneRig("OK"); + return builtRig; + } catch (err) { + doneRig("FAILED"); + bootHalt(err?.message || String(err)); + throw err; + } + })(); + // Boot policies with a live [n/7] counter on the BIOS line. + const donePolicies = bootLine("LOADING POLICIES"); + const sessionOpts = { executionProviders: ["wasm"] }; + let policiesLoaded = 0; + const bootPolicy = (url) => + ort.InferenceSession.create(signed(url), sessionOpts).then((s) => { + donePolicies.progress(`${++policiesLoaded}/7`); + return s; + }); + try { + [sessions.walk, sessions.sitstand, sessions.roll, sessions.kickL, sessions.kickR, + sessions.groundpick, sessions.stand] = + await Promise.all([ + bootPolicy(POLICIES.walk), + bootPolicy(POLICIES.sitstand), + bootPolicy(POLICIES.roll), + bootPolicy(POLICIES.kickL), + bootPolicy(POLICIES.kickR), + bootPolicy(POLICIES.groundpick), + bootPolicy(POLICIES.stand), + ]); + } catch (err) { + donePolicies("FAILED"); + bootHalt(err?.message || String(err)); + throw err; + } + donePolicies("7/7"); + + // ── Community move slots ────────────────────────────────────────────── + // A validated move mounts according to its manifest (Academy D7): + // perpetual -> sessions.walk (default) or sessions.sitstand (R key) + // episodic -> sessions.roll, played as a one-shot "trick" on R + // script -> a 13-D command timeline on the walker, toggled by R + // Every other slot (recovery, kicks, rollers) stays official. The + // official sessions are pinned here so a swap is always reversible. + const officialWalk = sessions.walk; + const officialSitstand = sessions.sitstand; + const officialRoll = sessions.roll; + let customPolicy = null; // loadCustomPolicy result: { kind, slot, session?, script?, ... } + let scriptRun = null; // { t } while a kind "script" move drives the commands + // True while the custom session is the one producing this step's actions. + const customDriving = () => + !!(customPolicy?.session && activeSession() === customPolicy.session); + // Watchdog: abnormal-ending timestamps (recovery entries + solver + // explosions) while a custom policy drives the duck. 3 within a rolling + // 20 s window auto-reverts; ~10 s without a new event clears the slate + // so player-caused falls don't slowly accumulate into a revert. + const WATCHDOG_WINDOW_MS = 20000; + const WATCHDOG_LIMIT = 3; + const WATCHDOG_HEALTHY_MS = 10000; + let watchdogEvents = []; + + const actionScaleFor = (session) => + (customPolicy && session === customPolicy.session ? customPolicy.actionScale : ACTION_SCALE); + + function revertCustomPolicy(revertReason = null) { + if (!customPolicy) return; + const prev = customPolicy; + customPolicy = null; + scriptRun = null; + watchdogEvents = []; + sessions.walk = officialWalk; + sessions.sitstand = officialSitstand; + sessions.roll = officialRoll; + if (revertReason) { + console.warn(`[policy] reverted "${prev.name}": ${revertReason}`); + setStore({ + customPolicy: { ...storeMove(prev), status: "error", revertReason }, + }); + } else { + setStore({ customPolicy: null }); + } + } + + // Store projection of a loaded move (no session / script objects in React). + const storeMove = (m) => ({ + ref: m.ref, name: m.name, title: m.title ?? m.name, author: m.author ?? null, + kind: m.kind ?? "perpetual", slot: m.slot ?? "walk", academy: m.academy ?? null, + }); + + function watchdogAbnormalEnd(kind) { + if (!customPolicy) return; + const now = performance.now(); + watchdogEvents.push(now); + watchdogEvents = watchdogEvents.filter((t) => now - t < WATCHDOG_WINDOW_MS); + if (watchdogEvents.length >= WATCHDOG_LIMIT) { + revertCustomPolicy(`${watchdogEvents.length} ${kind === "exploded" ? "explosions/falls" : "falls"} in ${Math.round(WATCHDOG_WINDOW_MS / 1000)} s`); + } + } + + // One load at a time; a failure (or a bogus boot-time ?policy=) leaves + // the official walker untouched and surfaces the error in the store. + let policyLoadBusy = false; + async function loadCustomPolicyIntoGame(ref) { + if (policyLoadBusy) return; + policyLoadBusy = true; + setStore({ customPolicy: { ref: String(ref), name: String(ref), status: "loading" } }); + try { + const loaded = await loadCustomPolicyModule(ref, { ort }); + revertCustomPolicy(); // drop any previous custom move first + customPolicy = loaded; + watchdogEvents = []; + if (loaded.slot === "walk") sessions.walk = loaded.session; + else if (loaded.slot === "sitstand") sessions.sitstand = loaded.session; + else if (loaded.slot === "trick") sessions.roll = loaded.session; + // "script": nothing to swap, the R key starts the command player. + setStore({ customPolicy: { ...storeMove(loaded), status: "active" } }); + console.info(`[policy] custom ${loaded.kind} move active in slot ${loaded.slot}: ${loaded.name} (${loaded.ref})`); + } catch (e) { + const error = e?.message || String(e); + console.warn(`[policy] load failed for "${ref}":`, e); + setStore({ customPolicy: { ref: String(ref), name: String(ref), status: "error", error } }); + } finally { + policyLoadBusy = false; + } + } + + const doneCompile = bootLine("COMPILING PHYSICS"); + let model, data; + try { + model = mujoco.MjModel.from_xml_string(xml, vfs); + data = new mujoco.MjData(model); + } catch (err) { + doneCompile("FAILED"); + bootHalt(err?.message || String(err)); + throw err; + } + doneCompile("COMPILED"); + + // Addresses resolved once per compiled variant. qpos/qvel/sensordata + // views are re-read at each use: the WASM heap can grow and detach + // earlier TypedArray views. + const JOINT_SET = new Set(JOINT_NAMES); + function resolveAddrs(model, kin) { + return { + qposAdr: JOINT_NAMES.map((n) => model.jnt(n).qposadr), + dofAdr: JOINT_NAMES.map((n) => model.jnt(n).dofadr), + gyroAdr: model.sensor("imu_ang_vel").adr, + trunkId: mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_BODY.value, "trunk_base"), + standKeyId: mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_KEY.value, "STAND"), + ballQposAdr: model.jnt("ball_freejoint").qposadr, + ballDofAdr: model.jnt("ball_freejoint").dofadr, + // Foot bodies for the footstep audio heuristic (-1 when a variant + // has no ankles, e.g. if a future model renames them). + ankleIds: ["ankle_left", "ankle_right"].map( + (n) => mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_BODY.value, n)), + // Unactuated hinges (the roller variant's 4 passive wheels): not in + // the obs or ctrl, but synced to the render rig so the wheels spin. + extraJoints: kin.bodies + .filter((b) => b.joint && b.joint.type === "hinge" && !JOINT_SET.has(b.joint.name)) + .map((b) => ({ name: b.joint.name, adr: model.jnt(b.joint.name).qposadr })), + }; + } + // Active-variant address block, swapped wholesale by activateLoco. + let { qposAdr, dofAdr, gyroAdr, trunkId, standKeyId, ballQposAdr, ballDofAdr, extraJoints, + ankleIds } = resolveAddrs(model, k); + + // Locomotion variants stay resident once built (model + data + rig + + // addresses); legs is registered when its render rig resolves below. + const locos = {}; + let loco = "legs"; // "legs" | "rollers" + const velLims = () => (loco === "rollers" + ? [RVEL_FWD, RVEL_BACK, RVEL_ANG] + : [VEL_FWD, VEL_BACK, VEL_ANG]); + + const lastAction = new Float32Array(NUM_JOINTS); + const obs = new Float32Array(OBS_SIZE); + const cmd = new Float32Array(CMD_SIZE); // [vx, vy, wz, head(4), body(6)] + // Input controller: keyboard + gamepad + touch sources merged into one + // continuous command + discrete action surface, in priority order. + const kbSource = new KeyboardSource({ getVelocityLimits: () => velLims() }); + const padSource = new GamepadSource({ getVelocityLimits: () => velLims() }); + const touchSource = new TouchSource({ getVelocityLimits: () => velLims() }); + // Click-to-walk (PLAN.md Project 1 Phase A): reads zero until a floor + // click arms a target, so - like the keyboard before it - it doubles as + // the fallback. Any keyboard/pad/touch input preempts it by arbitration + // order alone; getManualOverride also cancels the pending target outright + // so releasing manual input doesn't snap the duck back onto a stale click. + const waypointSource = new WaypointSource({ + camera, renderer, + getVelocityLimits: () => velLims(), + getDuckPose: () => { + const qpos = data.qpos; + return [qpos[0], qpos[1], duckYaw(qpos)]; + }, + isSuppressed: () => inputLocked || headMode || mode !== "walk" || !!grab, + getManualOverride: () => padSource.isActive() || touchSource.isActive() || kbSource.isActive(), + }); + // Keyboard, pad and touch preempt by priority; waypoint is the fallback. + const controller = new Controller({ sources: [padSource, touchSource, kbSource, waypointSource] }); + // Right-stick camera state, read by the telemetry before the camera-orbit + // section below has evaluated. + let padOrbitLive = false; + // Robot input gate: twist commands, mode changes, rolls, kicks and ball + // spawns all stay inert until the entrance sequence has fully played out. + let inputLocked = true; + let ceremony = null; + let ball = null; + let stickers = null; // comic popups, currently disabled + + let mode = "walk"; // "walk" | "sitstand" | "roll" | "kickL" | "kickR" | "crouch" | "groundpick" + let sitFlag = 0; + const isKick = () => mode === "kickL" || mode === "kickR"; + + // HEAD mode (runtime-faithful, pad Y): locomotion is zeroed and both + // sticks drive the head command slots cmd[3..6] = [neck_pitch, + // head_pitch, head_yaw, head_roll]. Targets are stick * HEAD_MAX, + // EMA-smoothed at 50 Hz in buildObs like the runtime (alpha 0.2). + // Offsets PERSIST when leaving head mode; only a sim reset zeroes them. + let headMode = false; + const HEAD_MAX = 2.5; // rad at full deflection (runtime head_max) + const HEAD_ALPHA = 0.2; + // Stick-to-joint polarity (deflections come in up/left = +1), tuned + // visually in the sim: cmd + means UP for neck_pitch but DOWN for + // head_pitch, LEFT for head_yaw but RIGHT-tilt for head_roll - hence + // the mixed signs, so stick up = look up, stick left = turn/tilt left. + // Order matches cmd[3..6] = [neck_pitch, head_pitch, head_yaw, head_roll]. + const HEAD_SIGNS = new Float32Array([1, -1, 1, -1]); + const headTarget = new Float32Array(4); + const headSmooth = new Float32Array(4); + // Local-only kickable ball: false while parked at the keyframe spot + // (mesh hidden), true once popped in front of the duck. + let ballActive = false; + + // The twist the policy actually receives. Mid-roll every movement input + // is ignored (zero twist) until the roll hands back to walk on its own. + // HEAD mode also zeroes it: the runtime stops the robot while the + // sticks drive the head. + const ZERO_CMD = new Float32Array(3); + function effectiveCmd() { + if (inputLocked || headMode || mode === "roll" || mode === "crouch" || + mode === "groundpick" || isKick() || postKickLock > 0 || recovery) + return ZERO_CMD; + return controller.getCommand(); + } + let rollRun = null; + let crouchRun = null; + let pickRun = null; + let kickRun = null; + let KICK_STEPS = 25; + // Post-kick grace: keep commands zeroed for a beat after the kick window + // hands back to walk. Step-counted like everything else. + const POST_KICK_LOCK_STEPS = 20; // 0.4 s at 50 Hz + let postKickLock = 0; + + // Pending mode-transition timers (sit hand-over, stand-up hand-back). + let sitTimer = null; + let standTimer = null; + let fallenSince = null; + + // ── Automatic fall recovery (legs walk mode only) ──────────────────── + // Mirrors the runtime's --fall-detect state machine (main.rs ~3658): + // a debounced tip (gz > -0.5 for 0.2 s) freezes ctrl on the current + // pose for a short settle (the runtime goes limp), then hands the duck + // to the stand policy with all commands zeroed until it's been upright + // (gz < -0.85) for a full second. If it can't get up within 6 s, fall + // back to the old kill: resetSim + materialization. Rollers keep the + // plain kill (the runtime declares fall-detect roller-incompatible), + // and so do sit/roll/kick/crouch/groundpick and the entrance lock. + const FALL_DEBOUNCE_STEPS = 10; // 0.2 s of gz > -0.5 before triggering + const FALL_SETTLE_STEPS = 15; // 0.3 s ctrl freeze once triggered + const RECOVER_UPRIGHT_STEPS = 50; // 1 s of gz < -0.85 to declare recovered + const RECOVER_GIVEUP_STEPS = 300; // 6 s of stand attempts before reset + let recovery = null; // null | { state: "fallen"|"recovering", steps, uprightSteps } + let fallDebounce = 0; + + function clearModeTimers() { + clearTimeout(sitTimer); sitTimer = null; + clearTimeout(standTimer); standTimer = null; + } + + // ── Mouse grab, physics side (MuJoCo-viewer-style perturbation) ─────── + // While a grab is live, EVERY PHYSICS SUBSTEP writes a spring-damper + // force on the grabbed free body via xfrc_applied (world frame), + // pulling it toward the cursor target. Formula and gains mirror the + // native viewer's mjv_applyPerturbForce (engine_vis_interact.c): + // F = -stiffness*mass*(pos - ref) - sqrt(stiffness)*mass*vel + // with stiffness = m->vis.map.stiffness default (100) and the damping + // coefficient sqrt(stiffness) exactly as MuJoCo computes it. Two + // deliberate departures: mass is the subtree mass instead of the + // Jacobian-derived localmass (equivalent for a free body pulled at its + // root, and the bindings expose no mj_jac), and the force acts + // torque-free at the freejoint origin instead of at the picked point + // (the viewer adds moment_arm x F; skipping it avoids spinning the duck + // the walking policy would then fight). The early per-CONTROL-step + // version of this (50 Hz zero-order hold, damping on 4-substep-stale + // velocity) was the jitter the user felt: a stiff spring held over 20 ms + // limit-cycles. Per-substep application is what the viewer does. + // Pointer wiring (raycast pick, target plane, cursor) lives after the + // camera section below; this block stays above resetSim so the control + // loop and resets can reference it during boot. + const GRAB_STIFFNESS = 100; // MuJoCo vis.map.stiffness default + const GRAB_DAMPING = Math.sqrt(GRAB_STIFFNESS); // viewer's damping coefficient + const GRAB_MAX_ACC = 200; // safety clamp only - the viewer has none + let grab = null; // { bodyId, qAdr, dofAdr, mass, target: [x,y,z] MJCF } + let endGrabHook = () => {}; // reassigned by the pointer wiring + function applyGrabForce() { + if (!grab) return; + const qpos = data.qpos, qvel = data.qvel; + let fx = GRAB_STIFFNESS * (grab.target[0] - qpos[grab.qAdr]) - GRAB_DAMPING * qvel[grab.dofAdr]; + let fy = GRAB_STIFFNESS * (grab.target[1] - qpos[grab.qAdr + 1]) - GRAB_DAMPING * qvel[grab.dofAdr + 1]; + let fz = GRAB_STIFFNESS * (grab.target[2] - qpos[grab.qAdr + 2]) - GRAB_DAMPING * qvel[grab.dofAdr + 2]; + const n = Math.hypot(fx, fy, fz); + if (n > GRAB_MAX_ACC) { + const s = GRAB_MAX_ACC / n; + fx *= s; fy *= s; fz *= s; + } + // Fresh view each call: the WASM heap can grow and detach old ones. + const xfrc = data.xfrc_applied; + const a = grab.bodyId * 6; + xfrc[a] = grab.mass * fx; + xfrc[a + 1] = grab.mass * fy; + xfrc[a + 2] = grab.mass * fz; + } + function releaseGrabForce() { + if (!grab) return; + const xfrc = data.xfrc_applied; + const a = grab.bodyId * 6; + xfrc[a] = 0; xfrc[a + 1] = 0; xfrc[a + 2] = 0; + grab = null; + } + + function resetSim() { + // A live grab must not survive a reset: the per-step spring would + // immediately yank the respawned duck toward the stale cursor target. + endGrabHook(); + // Single reset path: Space, fall-kill, failed roll, loco switch. + clearModeTimers(); + rollRun = null; + scriptRun = null; + kickRun = null; + crouchRun = null; + pickRun = null; + postKickLock = 0; + fallenSince = null; + recovery = null; + fallDebounce = 0; + mode = "walk"; + // Head mode exits and its offsets DO reset here (the one place). + headMode = false; + padSource.headMode = false; + headTarget.fill(0); + headSmooth.fill(0); + mujoco.mj_resetDataKeyframe(model, data, standKeyId); + mujoco.mj_forward(model, data); + lastAction.fill(0); + sitFlag = 0; + // Park the ball in physics immediately; if it was on screen, the + // reverse scan peels it away at its last pose. A queued B-respawn is + // cancelled: a reset means no ball. + ball?.despawn({ cancelQueued: true, parkPhysics: parkBallPhysics }); + ballActive = false; + syncButtons(); + ceremony?.playRespawn(); + } + resetSim(); + + function parkBallPhysics() { + const qpos = data.qpos, qvel = data.qvel; + qpos[ballQposAdr] = 50; + qpos[ballQposAdr + 1] = 0; + qpos[ballQposAdr + 2] = BALL_RADIUS; + qpos[ballQposAdr + 3] = 1; + qpos[ballQposAdr + 4] = 0; + qpos[ballQposAdr + 5] = 0; + qpos[ballQposAdr + 6] = 0; + for (let i = 0; i < 6; i++) qvel[ballDofAdr + i] = 0; + mujoco.mj_forward(model, data); + ballActive = false; + } + + // Pop / respawn the ball ~0.35 m in front of the duck, with a small + // random heading + distance jitter. If the ball is already on screen, + // peel it away first (reverse scan) and pop the new one when that + // finishes - same appear/disappear pair as the duck's wireframe ceremony. + function spawnBall(opts = {}) { + if (inputLocked && !opts.fromQueue) return; + if (!ball) return; + if (ball.visual !== "hidden") { + ball.queueRespawn(); + ball.despawn({ parkPhysics: parkBallPhysics }); + return; + } + const qpos = data.qpos, qvel = data.qvel; + const yaw = Math.atan2( + 2 * (qpos[3] * qpos[6] + qpos[4] * qpos[5]), + 1 - 2 * (qpos[5] * qpos[5] + qpos[6] * qpos[6]), + ); + const heading = yaw + (Math.random() - 0.5) * 0.7; + const dist = 0.35 + (Math.random() - 0.5) * 0.1; + const lim = ARENA_HALF - BALL_RADIUS - 0.05; + const clamp = (v) => Math.min(lim, Math.max(-lim, v)); + qpos[ballQposAdr] = clamp(qpos[0] + Math.cos(heading) * dist); + qpos[ballQposAdr + 1] = clamp(qpos[1] + Math.sin(heading) * dist); + qpos[ballQposAdr + 2] = BALL_RADIUS + 0.02; + qpos[ballQposAdr + 3] = 1; + qpos[ballQposAdr + 4] = 0; + qpos[ballQposAdr + 5] = 0; + qpos[ballQposAdr + 6] = 0; + for (let i = 0; i < 6; i++) qvel[ballDofAdr + i] = 0; + mujoco.mj_forward(model, data); + ballActive = true; + // Snap the mesh to the new pose BEFORE the scan starts: the FX + // recomputes its bbox from the live mesh. + ball.poseFromQpos(qpos, ballQposAdr); + ball.appear(); + stickers?.pop("spawn"); + } + + // ── Observation ───────────────────────────────────────────────────── + const _q = new THREE.Quaternion(); + const _g = new THREE.Vector3(); + + function buildObs() { + const qpos = data.qpos, qvel = data.qvel, sens = data.sensordata; + let i = 0; + for (let a = 0; a < 3; a++) obs[i++] = sens[gyroAdr + a]; + // projected gravity: world -z rotated into the trunk frame + const xq = data.body(trunkId).xquat; // [w, x, y, z] + _q.set(xq[1], xq[2], xq[3], xq[0]).conjugate(); + _g.set(0, 0, -1).applyQuaternion(_q); + obs[i++] = _g.x; obs[i++] = _g.y; obs[i++] = _g.z; + for (let j = 0; j < NUM_JOINTS; j++) obs[i++] = qpos[qposAdr[j]] - DEFAULT_POSE[j]; + for (let j = 0; j < NUM_JOINTS; j++) obs[i++] = qvel[dofAdr[j]]; + for (let j = 0; j < NUM_JOINTS; j++) obs[i++] = lastAction[j]; + // command: walking/drive use the twist; sitstand uses cmd[0] as the + // posture flag; the crouch-glide one-shot carries its phase encoding in + // the vel slots (ground-pick convention: [cos, sin, 0]). + cmd.fill(0, 0, 3); + if (mode === "sitstand") { + cmd[0] = sitFlag; + } else if (mode === "crouch" && crouchRun) { + const a = 2 * Math.PI * crouchRun.phase; + cmd[0] = Math.cos(a); + cmd[1] = Math.sin(a); + } else if (mode === "groundpick" && pickRun) { + const a = 2 * Math.PI * pickRun.phase; + cmd[0] = Math.cos(a); + cmd[1] = Math.sin(a); + } else { + const c = effectiveCmd(); + cmd[0] = c[0]; cmd[1] = c[1]; cmd[2] = c[2]; + } + // Head slots cmd[3..6]: EMA toward the stick targets at 50 Hz (this + // runs once per control step), exactly the runtime's smoothing. Kept + // filled outside head mode too - offsets persist like on the robot. + for (let h = 0; h < 4; h++) headSmooth[h] += HEAD_ALPHA * (headTarget[h] - headSmooth[h]); + // Ground pick parity: the runtime zero-pads the head (and body) slots + // for its obs (mjlab's zero_command_padding), so persisted head + // offsets must not leak into the pick policy's command buffer. Fall + // recovery zeroes them too: the stand policy gets an all-zero command. + const gpZero = mode === "groundpick" || recovery !== null; + cmd[3] = gpZero ? 0 : headSmooth[0]; cmd[4] = gpZero ? 0 : headSmooth[1]; + cmd[5] = gpZero ? 0 : headSmooth[2]; cmd[6] = gpZero ? 0 : headSmooth[3]; + // Command script (kind "script" move): the timeline owns the whole + // 13-D command vector while it plays on the walker. Movement input is + // ignored until R stops it (or the script ends, when it doesn't loop). + if (scriptRun && mode === "walk" && !recovery && customPolicy?.script) { + scriptCommandAt(customPolicy.script, scriptRun.t, cmd); + } + for (let c = 0; c < CMD_SIZE; c++) obs[i++] = cmd[c]; + return obs; + } + + // The ONNX session for the current mode: in the roller variant the main + // velocity mode runs the drive (skating) policy instead of the walker, + // and the fall-recovery state machine overrides everything with the + // get-up policy while it owns the duck. + const activeSession = () => { + if (recovery?.state === "recovering") return sessions.stand; + return sessions[loco === "rollers" && mode === "walk" ? "drive" : mode]; + }; + + // ── Control loop (50 Hz, async because ONNX inference is async) ────── + let ctrlHz = 0; + + // Fresh projected-gravity z straight from the trunk pose (buildObs is + // skipped during the fall-recovery settle, so obs[5] can go stale). + function projGravZ() { + const xq = data.body(trunkId).xquat; // [w, x, y, z] + _q.set(xq[1], xq[2], xq[3], xq[0]).conjugate(); + _g.set(0, 0, -1).applyQuaternion(_q); + return _g.z; + } + + // Dead pose: "fallen" = trunk tilted past ~60 deg or sunk below the + // floor. NaN/Inf is a solver explosion: no grace, reset on the spot. + // In legs walk mode a debounced fall now goes to the recovery state + // machine instead of the kill; everywhere else (rollers, sit, one-shots, + // entrance lock) the old grace-then-reset behavior stands. + function poseIsDead() { + const z = data.qpos[2]; + const gz = projGravZ(); + if (!Number.isFinite(z) || !Number.isFinite(gz)) return "exploded"; + if (gz > -0.5 || z < 0.02) return "fallen"; + return null; + } + + // ── Sim-driven audio (footsteps / roller rumble / ball impacts) ────── + // Footsteps use a per-foot height heuristic instead of MuJoCo contacts + // (the WASM bindings expose no contact array): each ankle's height + // RELATIVE to the lower ankle (the planted foot approximates the local + // ground, so the measure self-calibrates on the relief terrain), with + // lift/contact hysteresis and a per-foot debounce. Tap gain scales with + // the landing speed. Rollers get a speed-following rumble loop instead, + // and the ball thumps on velocity deltas between control steps. + const STEP_LIFT = 0.012; // m above the planted foot = foot in swing + const STEP_CONTACT = 0.005; // m: dropping below this while in swing = step + const STEP_DEBOUNCE_MS = 130; + const stepFeet = [ + { air: false, prevZ: 0, lastAt: 0 }, + { air: false, prevZ: 0, lastAt: 0 }, + ]; + const duckEmitter = createEmitter({ refDistance: 0.5 }); + const ballEmitter = createEmitter({ refDistance: 0.5 }); + const ballPrevV = [0, 0, 0]; + let ballPrevValid = false; + let ballThumpAt = 0; + // Body bumps: trunk velocity deltas gated on obstacle proximity (walls + // or prop collider footprints) so the walking gait's own accelerations + // (comparable in magnitude to a slow wall hit) never false-trigger. + // Duller than the ball thumps: same samples pitched way down. + const BUMP_DV = 0.35; // m/s per control step + const BUMP_DEBOUNCE_MS = 300; // rubbing a wall must not machine-gun + const BUMP_WALL_PAD = 0.16; // trunk half-width-ish reach to a wall + const bumpZones = propColliders().map((c) => { + const [px, py] = c.pos.split(" ").map(Number); + const [sx, sy] = c.size.split(" ").map(Number); + return { x: px, y: py, r: Math.hypot(sx, sy) + 0.14 }; + }); + const bumpPrevV = [0, 0, 0]; + let bumpPrevValid = false; + let bumpAt = 0; + function nearObstacle(x, y) { + if (Math.max(Math.abs(x), Math.abs(y)) > ARENA_HALF - BUMP_WALL_PAD) return true; + for (const z of bumpZones) { + if (Math.hypot(x - z.x, y - z.y) < z.r) return true; + } + return false; + } + + function stepAudioSim() { + const now = performance.now(); + if (loco === "legs" && !inputLocked && ankleIds[0] >= 0 && ankleIds[1] >= 0) { + const xpos = data.xpos; + const zL = xpos[ankleIds[0] * 3 + 2]; + const zR = xpos[ankleIds[1] * 3 + 2]; + const ground = Math.min(zL, zR); + for (let i = 0; i < 2; i++) { + const f = stepFeet[i]; + const z = i === 0 ? zL : zR; + const rel = z - ground; + const vz = (z - f.prevZ) / CTRL_DT; + f.prevZ = z; + if (rel > STEP_LIFT) { + f.air = true; + } else if (f.air && rel < STEP_CONTACT && vz < -0.02 && + now - f.lastAt > STEP_DEBOUNCE_MS) { + f.air = false; + f.lastAt = now; + const u = Math.min(1, Math.abs(vz) / 0.35); + playSfx("step", { + gain: 0.12 + 0.14 * u, + rate: 0.9 + Math.random() * 0.25, + out: duckEmitter.node, + }); + } + } + } + // Roller rumble: gain and slight pitch follow ground speed - and the + // pad's haptic bed mirrors it (texture on the weak motor). + const speed = Math.hypot(data.qvel[0], data.qvel[1]); + const rollLevel = loco === "rollers" && !inputLocked ? Math.min(1, speed / 0.5) : 0; + setRumble(rollLevel, duckEmitter); + haptics.setBed(rollLevel); + // Body bumps: trunk |dv| against a nearby wall/prop. The proximity + // gate keeps gait/kick jerks (which rival slow wall hits) silent. + if (!inputLocked) { + const v = data.qvel; + if (bumpPrevValid) { + const dv = Math.hypot(v[0] - bumpPrevV[0], v[1] - bumpPrevV[1], v[2] - bumpPrevV[2]); + if (dv > BUMP_DV && now - bumpAt > BUMP_DEBOUNCE_MS && + nearObstacle(data.qpos[0], data.qpos[1])) { + bumpAt = now; + const u = Math.min(1, (dv - BUMP_DV) / 1.5); + playSfx("thump", { + gain: 0.12 + 0.3 * u, + rate: 0.55 + 0.15 * u + Math.random() * 0.06, // way below the ball's range + out: duckEmitter.node, + }); + haptics.pulse("bump", 0.5 + 0.5 * u); // shove felt in the hands + } + } + bumpPrevV[0] = v[0]; bumpPrevV[1] = v[1]; bumpPrevV[2] = v[2]; + bumpPrevValid = true; + } else { + bumpPrevValid = false; + } + // Ball impacts: |dv| between control steps. Gravity alone accounts for + // ~0.2 m/s per 20 ms step; the 0.5 threshold clears it and rolling noise. + if (ballActive) { + const v = data.qvel; + const b = ballDofAdr; + if (ballPrevValid) { + const dv = Math.hypot( + v[b] - ballPrevV[0], v[b + 1] - ballPrevV[1], v[b + 2] - ballPrevV[2]); + if (dv > 0.5 && now - ballThumpAt > 90) { + ballThumpAt = now; + const u = Math.min(1, (dv - 0.5) / 3.5); // full at kick-grade hits + playSfx("thump", { + gain: 0.14 + 0.4 * u, + rate: 1.25 - 0.45 * u + Math.random() * 0.08, + out: ballEmitter.node, + }); + // Haptics only when the duck plausibly caused/received the hit: + // a far bounce off a wall shouldn't shake the hands. + const bq = ballQposAdr; + const dBall = Math.hypot( + data.qpos[bq] - data.qpos[0], data.qpos[bq + 1] - data.qpos[1]); + if (dBall < 0.6) haptics.pulse("ballHit", 0.4 + 0.6 * u); + } + } + ballPrevV[0] = v[b]; ballPrevV[1] = v[b + 1]; ballPrevV[2] = v[b + 2]; + ballPrevValid = true; + } else { + ballPrevValid = false; + } + // Haptic channel scheduler: keeps the roller bed alive between pulses + // and cuts the motors when it falls silent. 50 Hz, like everything here. + haptics.tick(); + } + + async function controlStep() { + driveRelief(CTRL_DT); // kinematic terrain, written before the physics steps + // Settle phase: ctrl frozen on the pose held at the fall (approximates + // the runtime's limp beat), physics keeps stepping, no inference. + if (recovery?.state !== "fallen") { + // Tensor names come from the session itself (community exports don't + // all use obs/actions), and the action scale is per-session (official + // policies stay at ACTION_SCALE = 1). + const session = activeSession(); + const feeds = { + [session.inputNames[0]]: new ort.Tensor("float32", buildObs(), [1, OBS_SIZE]), + }; + const out = await session.run(feeds); + const act = out[session.outputNames[0]].data; + let finite = true; + for (let j = 0; j < NUM_JOINTS; j++) { + if (!Number.isFinite(act[j])) { finite = false; break; } + } + if (!finite) { + // Never write a NaN/Inf into ctrl. A custom policy producing one is + // instantly reverted; ctrl holds the previous step's targets. + if (customPolicy && session === customPolicy.session) { + revertCustomPolicy("non-finite action tensor"); + } + } else { + const scale = actionScaleFor(session); + lastAction.set(act); + const ctrl = data.ctrl; + for (let j = 0; j < NUM_JOINTS; j++) ctrl[j] = DEFAULT_POSE[j] + act[j] * scale; + } + } + for (let s = 0; s < DECIMATION; s++) { + applyGrabForce(); // mouse perturbation, fresh velocity every substep + mujoco.mj_step(model, data); + } + stepAudioSim(); // footsteps / rumble / ball thumps off the fresh state + + // Command script clock: 50 Hz like everything here. A non-looping + // script ends on its own; a looping one runs until R (or a reset). + if (scriptRun) { + scriptRun.t += CTRL_DT; + const sc = customPolicy?.script; + if (!sc || (!sc.loop && scriptRun.t >= sc.durationS)) { + scriptRun = null; + syncButtons(); + } + } + + // Watchdog housekeeping: a healthy stretch (no abnormal ending for + // ~10 s) forgives earlier events, so player-caused falls spread over + // a session never accumulate into a revert. + if (customPolicy && watchdogEvents.length && + performance.now() - watchdogEvents[watchdogEvents.length - 1] > WATCHDOG_HEALTHY_MS) { + watchdogEvents = []; + } + + const death = poseIsDead(); + if (death === "exploded") { + haptics.pulse("explode"); + // Solver explosions only implicate the custom policy while it is the + // one driving (its slot: walk, sitstand or the trick one-shot); + // official one-shots and rollers never count. + if (loco === "legs" && customDriving()) watchdogAbnormalEnd("exploded"); + resetSim(); + } else if (recovery) { + // Recovery state machine owns the duck: settle -> stand policy -> + // hysteresis exit (upright for a full second) or 6 s give-up reset. + recovery.steps++; + if (recovery.state === "fallen") { + if (recovery.steps >= FALL_SETTLE_STEPS) { + recovery = { state: "recovering", steps: 0, uprightSteps: 0 }; + lastAction.fill(0); + syncButtons(); + } + } else { + recovery.uprightSteps = projGravZ() < -0.85 ? recovery.uprightSteps + 1 : 0; + if (recovery.uprightSteps >= RECOVER_UPRIGHT_STEPS) { + recovery = null; + mode = "walk"; + lastAction.fill(0); + haptics.pulse("recover"); // back on its feet: light double tap + syncButtons(); + } else if (recovery.steps >= RECOVER_GIVEUP_STEPS) { + resetSim(); + } + } + } else if (death === "fallen") { + const recoverable = loco === "legs" && mode === "walk" && + !inputLocked && postKickLock === 0 && !standTimer; + if (recoverable) { + fallenSince = null; + if (++fallDebounce >= FALL_DEBOUNCE_STEPS) { + fallDebounce = 0; + exitHeadMode(); + // Recovery entry = one abnormal ending for the custom-policy + // watchdog (the rolling window absorbs player-caused falls). + watchdogAbnormalEnd("fallen"); + recovery = { state: "fallen", steps: 0 }; + // Haptic thud on the confirmed fall (one-shot: this transition + // fires once per fall, the recovery machine owns the duck after). + haptics.pulse("fall"); + syncButtons(); + } + } else { + fallDebounce = 0; + const now = performance.now(); + const graceMs = mode === "roll" ? 5000 : 1000; + // First frame of a non-recoverable fall (rollers, sit, one-shots): + // same haptic thud, once - fallenSince latches until reset/upright. + if (fallenSince == null) haptics.pulse("fall"); + fallenSince ??= now; + if (now - fallenSince > graceMs) { + // A custom sit / trick that floors the duck counts for the + // watchdog exactly like a recovery entry does for a walker. + if (loco === "legs" && customDriving()) watchdogAbnormalEnd("fallen"); + resetSim(); + } + } + } else { + fallDebounce = 0; + fallenSince = null; + } + + // Ball respawn watchdog: outside the arena bounds means "escaped + // through a solver glitch", bring it back near the duck. + if (ballActive) { + const q = data.qpos; + const escaped = + Math.abs(q[ballQposAdr]) > ARENA_HALF + 0.1 || + Math.abs(q[ballQposAdr + 1]) > ARENA_HALF + 0.1; + if (escaped) spawnBall(); + } + + if (postKickLock > 0 && mode === "walk") postKickLock--; + + // One-shot kick: fixed 0.5 s window like the robot runtime, then + // straight back to walking. lastAction is NOT zeroed on either swap. + if (isKick() && kickRun) { + kickRun.steps++; + if (kickRun.steps >= KICK_STEPS) { + kickRun = null; + mode = "walk"; + postKickLock = POST_KICK_LOCK_STEPS; + syncButtons(); + } + } + + // Crouch-glide one-shot: advance the trained phase clock and hand back + // to the drive policy at the runtime's cycle end. + if (mode === "crouch" && crouchRun) { + crouchRun.phase += CTRL_DT / CROUCH_PERIOD_S; + if (crouchRun.phase >= CROUCH_END_PHASE) { + crouchRun = null; + mode = "walk"; + syncButtons(); + } + } + + // Ground-pick one-shot: same phase-clock pattern as the crouch, ending + // at the runtime's cycle end (phase 0.7 of a 4 s period, ~2.8 s). + if (mode === "groundpick" && pickRun) { + pickRun.phase += CTRL_DT / GROUND_PICK_PERIOD_S; + if (pickRun.phase >= GROUND_PICK_END_PHASE) { + pickRun = null; + mode = "walk"; + syncButtons(); + } + } + + // One-shot roll, step-counted like the robot runtime: hand back to + // walking once the trunk has tipped over and is upright again, or + // after a hard window if the roll never initiated. + if (mode === "roll" && rollRun) { + rollRun.steps++; + if (obs[5] > -0.3) rollRun.tipped = true; + const upright = obs[5] < -0.85; + const done = rollRun.tipped && upright && rollRun.steps >= 40; + // 3 s for the official roll (it should long be over); a custom + // trick runs for its manifest duration instead. + const expired = rollRun.steps >= rollRun.maxSteps; + if (done || expired) { + const wasCustom = rollRun.custom; + rollRun = null; + mode = "walk"; + lastAction.fill(0); + // Timed out mid-roll: don't hand a tipped duck to the walking + // policy (it has no get-up skill). + if (!upright) { + if (wasCustom) watchdogAbnormalEnd("fallen"); + resetSim(); + } else haptics.pulse("land"); // rolled through and stuck the landing + syncButtons(); + } + } + } + + // ── Relief (prototype: the level itself gains gentle slopes) ──────── + // One analytic height function (cosine bumps, RELIEF_BUMPS) drives both + // surfaces: the MuJoCo heightfield gets it sampled into hfield_data + // once per compiled model, and the grid floor shader displaces its + // vertices with the same function (uTopoScale uniform). Raising or + // sinking the terrain = ramping one scalar that scales the hfield + // z-size and the shader uniform together, so physics and visuals stay + // the same surface at every moment of the transition. Trigger for now: + // window.rl.setRelief(bool) (prototype - no UI yet). + let reliefOn = false; + let reliefScale = 0; + let reliefGridMat = null; // assigned at scene wiring (grid built below) + const reliefFilled = new WeakSet(); + function topoH(x, y) { + let H = 0; + for (const [cx, cy, h, r] of RELIEF_BUMPS) { + const u = Math.hypot(x - cx, y - cy) / r; + if (u < 1) H += h * (0.5 + 0.5 * Math.cos(Math.PI * u)); + } + return H; + } + function fillHfield(m) { + if (reliefFilled.has(m)) return; + // Re-read the view on every fill: heap growth detaches TypedArrays. + const n = RELIEF_GRID, hdata = m.hfield_data; + for (let r = 0; r < n; r++) { + const y = -ARENA_HALF + (2 * ARENA_HALF * r) / (n - 1); + for (let c = 0; c < n; c++) { + const x = -ARENA_HALF + (2 * ARENA_HALF * c) / (n - 1); + hdata[r * n + c] = topoH(x, y) / RELIEF_HMAX; + } + } + reliefFilled.add(m); + } + function driveRelief(dt) { + fillHfield(model); // no-op once per compiled model (legs / rollers) + const target = reliefOn ? 1 : 0; + if (reliefScale !== target) { + const d = Math.max(-RELIEF_RATE * dt, Math.min(RELIEF_RATE * dt, target - reliefScale)); + reliefScale += d; + } + // z-size scales every bump; the floor keeps it strictly positive and, + // combined with the geom's RELIEF_SINK offset, fully buried when off. + model.hfield_size[2] = Math.max(reliefScale * RELIEF_HMAX, 1e-4); + if (reliefGridMat) reliefGridMat.uniforms.uTopoScale.value = reliefScale; + } + let running = true; + (async function controlLoop() { + let next = performance.now(); + let count = 0, hzT0 = next; + while (running) { + await controlStep(); + count++; + const now = performance.now(); + if (now - hzT0 > 500) { + ctrlHz = (count * 1000) / (now - hzT0); + count = 0; hzT0 = now; + } + next += CTRL_DT * 1000; + const wait = next - performance.now(); + if (wait > 0) await new Promise((r) => setTimeout(r, wait)); + else next = performance.now(); // fell behind: don't spiral + } + })(); + + // ── Scene wiring (grid, walls, rig, ball, arcade row) ──────────────── + // The grid/walls carry ceremony-driven uReveal uniforms and per-frame + // focus updates, so the game owns them; lights and environment live in + // the R3F layer. + const grid = makeInfiniteGrid(); + scene.add(grid); + reliefGridMat = grid.material; // relief drive mirrors uTopoScale into it + const { wallMats, wallMeshes } = makeArenaWalls(); + for (const m of wallMeshes) scene.add(m); + + let rig = await rigPromise; + scene.add(rig.placer); + let trunkGroup = rig.bodies.get("trunk_base"); + locos.legs = { + model, data, rig, trunkGroup, + qposAdr, dofAdr, gyroAdr, trunkId, standKeyId, ballQposAdr, ballDofAdr, extraJoints, + }; + + // ── Locomotion variant switching (legs <-> rollers) ────────────────── + // The roller stack (XML + 5 extra meshes + kinematics + 2 ONNX policies) + // is lazy-loaded on the first switch, then kept resident. + let rollersLoading = null; + function ensureRollers() { + rollersLoading ??= (async () => { + const [{ xml: rXml, meshFiles: rMeshFiles }, rk] = await Promise.all([ + buildPhysicsXml("robot_allcollisions_rollers.xml"), + loadKinematics(`${MODEL_DIR}/kinematics_rollers.json`), + ]); + const [rRig, sDrive, sCrouch] = await Promise.all([ + buildRig(rk, { materialForMesh: materialHookFor(VARIANTS[currentVariant]) }), + ort.InferenceSession.create(signed(POLICIES.drive), sessionOpts), + ort.InferenceSession.create(signed(POLICIES.crouch), sessionOpts), + addMeshesToVfs(rMeshFiles), + ]); + sessions.drive = sDrive; + sessions.crouch = sCrouch; + const rModel = mujoco.MjModel.from_xml_string(rXml, vfs); + const rData = new mujoco.MjData(rModel); + locos.rollers = { + model: rModel, data: rData, rig: rRig, trunkGroup: rRig.bodies.get("trunk_base"), + ...resolveAddrs(rModel, rk), + }; + })(); + return rollersLoading; + } + + // Ghost-only roller rig: kinematics + THREE meshes, no physics model and + // no ONNX sessions - just enough to render roller-mode PEERS correctly + // for a visitor who never leaves legs mode (ensureRollers' full stack + // stays lazy). Kept resident once built; if the player later switches + // for real, getRigFor prefers the live locos.rollers rig and this one + // quietly remains as a clone source. + let ghostRollerRig = null; + let ghostRollerRigLoading = null; + function ensureGhostRollerRig() { + if (locos.rollers || ghostRollerRig || rollersLoading) return; + ghostRollerRigLoading ??= (async () => { + const rk = await loadKinematics(`${MODEL_DIR}/kinematics_rollers.json`); + ghostRollerRig = await buildRig(rk, { + materialForMesh: materialHookFor(VARIANTS[currentVariant]), + }); + })().catch((e) => { + ghostRollerRigLoading = null; // next roller peer retries the load + console.warn("[ghosts] roller ghost rig load failed", e); + }); + } + + function activateLoco(name) { + const L = locos[name]; + loco = name; + scene.remove(rig.placer); + ({ model, data, rig, trunkGroup, qposAdr, dofAdr, gyroAdr, trunkId, + standKeyId, ballQposAdr, ballDofAdr, extraJoints, ankleIds } = L); + // The rig may have been built (or last shown) under another colourway. + applyVariant(rig, currentVariant); + scene.add(rig.placer); + setStore({ loco: name }); + resetSim(); + } + + let locoSwitching = false; + async function setLoco(name, { force = false } = {}) { + if (name !== "legs" && name !== "rollers") return; + if (loco === name || locoSwitching) return; + if (!force && (inputLocked || rollRun || kickRun || crouchRun || pickRun || + standTimer || recovery)) return; + locoSwitching = true; + setStore({ locoSwitching: true }); + try { + if (name === "rollers" && !locos.rollers) { + setStore({ rollersLoading: true }); + await ensureRollers(); + } + activateLoco(name); + } catch (e) { + rollersLoading = null; + console.error("[game] roller switch failed", e); + } finally { + setStore({ rollersLoading: false, locoSwitching: false }); + locoSwitching = false; + } + } + + async function toggleLoco() { + const next = loco === "legs" ? "rollers" : "legs"; + setStore({ locoWant: next }); + await setLoco(next); + } + + // Quickbar loco intent: reconcile locoWant -> actual, retrying until the + // game allows the switch (mid-roll, respawn ceremony, ...). Replaces the + // old index.html reconciler that polled window.rl. + let locoReconciler = null; + function reconcileLoco() { + const want = store().locoWant; + if (want === loco) { + if (locoReconciler) { clearInterval(locoReconciler); locoReconciler = null; } + return; + } + if (want === "rollers") ensureRollers().catch(() => {}); + if (!locoSwitching) setLoco(want); + locoReconciler ??= setInterval(reconcileLoco, 250); + } + useGame.subscribe((s) => s.locoWant, reconcileLoco); + + // ── Cutscenes (entrance + respawn) ────────────────────────────────── + ceremony = createCeremony({ + THREE, scene, camera, renderer, fx, + getRig: () => rig, + grid, wallMats, + syncRig, startCameraReset, + setLocked: (v) => { + inputLocked = v; + controller.setLocked(v); + // A ball is always in play: pop one the moment the entrance or a + // respawn ceremony hands control back. + if (!v && ball && !ballActive) spawnBall({ fromQueue: true }); + }, + flashReset: () => {}, + // Audio twins of the wireframe materialize FX (entrance and respawns): + // the duck's hero sweep spans the FX's exact duration and follows its + // ease-out; each prop's scan gets its own smaller, size-pitched sweep + // the frame it starts; each arena line drawing in gets a tiny blip. + onScanCue: (durS) => playEntranceSweep(durS), + onPropCue: (durS) => playPropSweep(durS), + onLineCue: (u) => playLineBlip(u), + }); + + // ── Ambient bed lifecycle ───────────────────────────────────────────── + // The Waddle-in click latches `entered` and doubles as the unlock + // gesture; the hum starts there and ducks whenever the pause/title + // overlay comes back up. fireImmediately covers ?boot=1 (already + // entered by the time the game boots). + useGame.subscribe((s) => s.entered, (entered) => { + if (!entered) return; + audioCtx(); + preloadSfx(); + startAmbient(); + }, { fireImmediately: true }); + useGame.subscribe((s) => s.menuOpen, (open) => setAmbientDucked(open), + { fireImmediately: true }); + + const { group: ballGroup, mesh: ballMesh } = createBallVisual(renderer); + scene.add(ballGroup); + ball = createBallActor({ + THREE, scene, camera, renderer, fxModule: fx, mesh: ballMesh, group: ballGroup, + }); + + // ── Prop library (wall/corner dressing + entrance FX) ──────────────── + // Every enabled def in props.js: loaded, real-size scaled, floor + // snapped, wireframe-materialized with the ceremony (staggered after + // the duck's scan cue). Physics-side, buildPhysicsXml planted one + // static box per declared collider. + const propGroups = await loadProps({ + THREE, GLTFLoader, signed, scene, camera, renderer, fx, ceremony, + }); + + // ── Camera: orbit controls + chase cam + reset glide ───────────────── + const controls = new OrbitControls(camera, renderer.domElement); + controls.target.set(SPAWN_X, 0, -SPAWN_Y); // orbit around the spawn cell + controls.enableDamping = true; + controls.dampingFactor = 0.08; + controls.minDistance = 0.25; + controls.maxDistance = 3; + controls.maxPolarAngle = Math.PI / 2 - 0.03; + + // Chase cam (default ON): each frame the camera eases toward a point + // behind the duck's heading at the current orbit distance, while the + // orbit target keeps easing to the trunk in syncRig. Implemented by + // overwriting camera.position AFTER controls.update() so we never fight + // OrbitControls' own spherical bookkeeping. + let chaseCam = true; + const CHASE_PITCH = 0.42; // rad above horizontal, keeps the floor in view + const CHASE_EASE = 0.05; + const _chasePos = new THREE.Vector3(); + const _chaseDir = new THREE.Vector3(); + // During one-shot rolls and kicks the trunk tumbles: hold the last + // healthy yaw for the whole one-shot. + let chaseHeldYaw = 0; + // Heading hysteresis (Schmitt trigger): the walking gait wiggles the + // trunk yaw ~±14 deg per step; two-layer EMA + engage/release thresholds + // keep the camera steady while walking straight but responsive on turns. + let chaseYawSmooth = 0; + let chaseYawFollow = 0; + let chaseYawTracking = false; + const CHASE_YAW_SMOOTH_EASE = 0.04; + const CHASE_YAW_ENGAGE = 0.17; + const CHASE_YAW_RELEASE = 0.03; + const CHASE_YAW_EASE = 0.10; + const CHASE_YAW_EASE_TURN = 0.5; + const wrapPi = (a) => Math.atan2(Math.sin(a), Math.cos(a)); + function updateChaseCam() { + // Reset glide: one clean tween from wherever the camera is back to the + // home framing. Runs instead of the chase logic and hands control back + // to it on landing. + if (camResetT0 !== null) { + if (!chaseCam) { camResetT0 = null; return; } + const t = (performance.now() - camResetT0) / 1000 / CAM_RESET_S; + const e = t >= 1 ? 1 : t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2; + camera.position.lerpVectors(_camFrom, _camTo, e); + controls.target.lerpVectors(_tgtFrom, _tgtTo, e); + camera.lookAt(controls.target); + if (t >= 1) camResetT0 = null; + return; + } + // Head mode: the camera freezes where it is. It keeps looking at the + // duck for free - syncRig translates camera and target by the same + // delta, and the duck isn't walking anyway (twist zeroed). + if (headMode) return; + if (!chaseCam) return; + const qpos = data.qpos; + let rawYaw; + if (mode === "roll" || isKick()) { + rawYaw = chaseHeldYaw; + } else { + rawYaw = duckYaw(qpos); + chaseHeldYaw = rawYaw; + } + // "turning" reads the raw per-source wz commands (not the locked/merged + // view) so an intentional turn engages on the first frame. + const turning = controller.sources.some((s) => Math.abs(s.command[2]) > 0.05); + chaseYawSmooth = wrapPi( + chaseYawSmooth + + wrapPi(rawYaw - chaseYawSmooth) * (turning ? CHASE_YAW_EASE_TURN : CHASE_YAW_SMOOTH_EASE), + ); + const yawErr = wrapPi(chaseYawSmooth - chaseYawFollow); + if (turning || Math.abs(yawErr) > CHASE_YAW_ENGAGE) chaseYawTracking = true; + if (chaseYawTracking) { + chaseYawFollow = wrapPi( + chaseYawFollow + yawErr * (turning ? CHASE_YAW_EASE_TURN : CHASE_YAW_EASE), + ); + if (!turning && Math.abs(yawErr) < CHASE_YAW_RELEASE) chaseYawTracking = false; + } + const yaw = chaseYawFollow; + const dist = camera.position.distanceTo(controls.target); + const horiz = dist * Math.cos(CHASE_PITCH); + const vert = dist * Math.sin(CHASE_PITCH); + // Duck forward in MJCF is (cos yaw, sin yaw, 0); Z-up -> Y-up maps it + // to three-space (cos yaw, 0, -sin yaw). Behind = minus that. + _chasePos.set( + controls.target.x - Math.cos(yaw) * horiz, + controls.target.y + vert, + controls.target.z + Math.sin(yaw) * horiz, + ); + camera.position.lerp(_chasePos, CHASE_EASE); + // Re-project onto the orbit sphere: lerping between two points at the + // same radius cuts the chord, which would slowly zoom the camera in + // during large swings. + _chaseDir.copy(camera.position).sub(controls.target); + const len = _chaseDir.length(); + if (len > 1e-6) camera.position.copy(controls.target).addScaledVector(_chaseDir, dist / len); + camera.lookAt(controls.target); + } + renderer.domElement.addEventListener("pointerdown", () => { chaseCam = false; }); + + // Camera reset glide (owned by the respawn ceremony): back to the + // page-load framing - the chase cam's ideal point behind the duck's + // spawn heading, at the boot orbit distance. + const CAM_HOME_DIST = camera.position.distanceTo(controls.target); + let camResetT0 = null; + const _camFrom = new THREE.Vector3(), _camTo = new THREE.Vector3(); + const _tgtFrom = new THREE.Vector3(), _tgtTo = new THREE.Vector3(); + function startCameraReset() { + const qpos = data.qpos; + const yaw = duckYaw(qpos); + chaseHeldYaw = yaw; + chaseYawSmooth = yaw; + chaseYawFollow = yaw; + chaseYawTracking = false; + _tgtTo.set(qpos[0], qpos[2], -qpos[1]); // trunk at spawn, MJCF -> three + const horiz = CAM_HOME_DIST * Math.cos(CHASE_PITCH); + const vert = CAM_HOME_DIST * Math.sin(CHASE_PITCH); + _camTo.set( + _tgtTo.x - Math.cos(yaw) * horiz, + _tgtTo.y + vert, + _tgtTo.z + Math.sin(yaw) * horiz, + ); + _camFrom.copy(camera.position); + _tgtFrom.copy(controls.target); + camResetT0 = performance.now(); + chaseCam = true; // reset always re-attaches the chase cam + } + + // ── Mouse grab, pointer side (pick + drag target + cursor) ──────────── + // Pointer-down on the duck (or the live ball) grabs it; anywhere else + // falls through to OrbitControls untouched. The pick is a three.js + // raycast against the render rig (the WASM bindings expose no + // mjv_select, and the rig IS the duck's collision-accurate silhouette + // for mouse purposes). While dragging, the cursor is projected on a + // camera-facing plane through the grab point - horizontal AND vertical + // drags both work, so the duck can be lifted - and the target is + // clamped inside the arena walls and to a sane height band. Desktop + // mouse only: the touch overlay keeps its own controls. + const GRAB_TARGET_ZMIN = 0.02, GRAB_TARGET_ZMAX = 0.45; + const _grabRaycaster = new THREE.Raycaster(); + const _grabNdc = new THREE.Vector2(); + const _grabPlane = new THREE.Plane(); + const _grabHit = new THREE.Vector3(); + const _grabCamDir = new THREE.Vector3(); + function grabRayFrom(e) { + const r = renderer.domElement.getBoundingClientRect(); + _grabNdc.set( + ((e.clientX - r.left) / r.width) * 2 - 1, + -((e.clientY - r.top) / r.height) * 2 + 1, + ); + _grabRaycaster.setFromCamera(_grabNdc, camera); + } + function grabPick() { + const duckHit = _grabRaycaster.intersectObject(rig.placer, true)[0]; + const ballHit = ballActive ? _grabRaycaster.intersectObject(ballMesh, true)[0] : undefined; + if (duckHit && (!ballHit || duckHit.distance <= ballHit.distance)) { + return { kind: "duck", point: duckHit.point }; + } + return ballHit ? { kind: "ball", point: ballHit.point } : null; + } + function updateGrabTarget() { + if (!_grabRaycaster.ray.intersectPlane(_grabPlane, _grabHit)) return; + const lim = ARENA_HALF - 0.05; + // three (x, y, z) -> MJCF (x, -z, y), Z-up. + grab.target[0] = Math.min(lim, Math.max(-lim, _grabHit.x)); + grab.target[1] = Math.min(lim, Math.max(-lim, -_grabHit.z)); + grab.target[2] = Math.min(GRAB_TARGET_ZMAX, Math.max(GRAB_TARGET_ZMIN, _grabHit.y)); + } + function endGrab() { + if (!grab) return; + releaseGrabForce(); + controls.enabled = true; + renderer.domElement.style.cursor = ""; + } + endGrabHook = endGrab; + // Capture phase on window: runs before OrbitControls' pointerdown on the + // canvas, so the orbit can be disabled for the whole drag. The canvas's + // own chase-detach listener still fires afterward (grabbing detaches the + // chase cam exactly like an orbit drag does). + window.addEventListener("pointerdown", (e) => { + if (e.target !== renderer.domElement || e.pointerType !== "mouse" || e.button !== 0) return; + if (grab || inputLocked) return; + grabRayFrom(e); + const pick = grabPick(); + if (!pick) return; + // Any duck mesh grabs the trunk: the freejoint root carries the whole + // body, and pulling the CoM is what the viewer perturbation feels like. + const g = pick.kind === "duck" + ? { bodyId: trunkId, qAdr: 0, dofAdr: 0, mass: model.body(trunkId).subtreemass } + : { + bodyId: mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_BODY.value, "ball"), + qAdr: ballQposAdr, dofAdr: ballDofAdr, + mass: model.body(mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_BODY.value, "ball")).mass, + }; + camera.getWorldDirection(_grabCamDir); + _grabPlane.setFromNormalAndCoplanarPoint(_grabCamDir.negate(), pick.point); + grab = { ...g, target: [0, 0, 0] }; + updateGrabTarget(); + controls.enabled = false; + renderer.domElement.style.cursor = "grabbing"; + try { renderer.domElement.setPointerCapture(e.pointerId); } catch { /* capture unsupported */ } + }, true); + let grabHoverAt = 0; + window.addEventListener("pointermove", (e) => { + if (grab) { + grabRayFrom(e); + updateGrabTarget(); + return; + } + // Hover affordance: grab cursor over anything grabbable. Throttled - + // a full-rig raycast per mousemove event would be wasteful - and + // skipped mid-orbit (buttons held) so the cursor doesn't flicker. + if (e.target !== renderer.domElement || e.pointerType !== "mouse" || e.buttons || inputLocked) return; + const now = performance.now(); + if (now - grabHoverAt < 80) return; + grabHoverAt = now; + grabRayFrom(e); + const clickable = mode === "walk" && !headMode; + renderer.domElement.style.cursor = grabPick() ? "grab" : (clickable ? "crosshair" : ""); + }); + window.addEventListener("pointerup", endGrab); + window.addEventListener("pointercancel", endGrab); + + // Waypoint marker: hairline tron reticle at the clicked floor point + // (fx/waypoint-marker.js), with acquire/arrive animations. Driven each + // frame in frame() from waypointSource.target. + const waypointMarker = createWaypointMarker(); + scene.add(waypointMarker.group); + + // Pause: while the menu is up over a live game, keys belong to the menu. + const setInputLock = (v) => { inputLocked = v; controller.setLocked(v); }; + useGame.subscribe( + (s) => s.menuOpen, + (open) => { + if (!ceremony.entranceDone) return; + if (open) setInputLock(true); + else if (!ceremony.respawnActive) setInputLock(false); + }, + ); + + // The rig's root already applies the MJCF Z-up -> three Y-up fix, so the + // trunk group can take the freejoint pose in raw MJCF coordinates. + const _target = new THREE.Vector3(); + const _follow = new THREE.Vector3(); + function syncRig() { + const qpos = data.qpos; + trunkGroup.position.set(qpos[0], qpos[1], qpos[2]); + trunkGroup.quaternion.set(qpos[4], qpos[5], qpos[6], qpos[3]); + for (let j = 0; j < NUM_JOINTS; j++) setJoint(rig, JOINT_NAMES[j], qpos[qposAdr[j]]); + // Passive hinges (roller wheels): purely visual, driven straight from qpos. + for (const ej of extraJoints) setJoint(rig, ej.name, qpos[ej.adr]); + // Ball: live follows qpos; ghost freeze is owned by the ball actor. + if (ball) ball.sync(qpos, ballQposAdr, ballActive); + // Follow cam: ease the orbit target toward the trunk and translate the + // camera by the same delta, so the camera-to-duck distance and viewing + // angle stay constant while the duck walks. Paused while the reset + // glide owns the camera. + if (camResetT0 === null) { + _target.set(qpos[0], qpos[2], -qpos[1]); + _follow.copy(_target).sub(controls.target); + // Horizontal follow at the usual rate; vertical much slower so the + // per-step gait bob doesn't nod the frame. + _follow.x *= 0.06; + _follow.z *= 0.06; + _follow.y *= 0.015; + controls.target.add(_follow); + camera.position.add(_follow); + } + // Keep the grid plane (and its fade center) under the action; the wall + // grids share the same radial fade focus. + grid.position.set(controls.target.x, 0, controls.target.z); + grid.material.uniforms.uFocus.value.copy(controls.target); + for (const m of wallMats) m.uniforms.uFocus.value.copy(controls.target); + } + + // ── Quack: jaw + chirp ──────────────────────────────────────────────── + // The jaw isn't a MuJoCo joint (duck.js re-creates the hinge in JS), so + // this is purely cosmetic and can't upset the policy. Voice banks from + // the robot runtime: each colourway gets its own bank and every quack + // draws a random chirp take from it. + const QUACK_MS = 480; + let quackAt = -Infinity; + let padJaw = 0; + const CHIRP_TAKES = "abcdefghijkl"; + const VOICE_BANK = { classic: "duck1", charcoal: "duck2", purple: "duck3", blue: "duck4" }; + function playChirp() { + const bank = VOICE_BANK[currentVariant] ?? "duck1"; + const take = CHIRP_TAKES[(Math.random() * CHIRP_TAKES.length) | 0]; + // Decoded through the shared context on the voice bus (used to be a + // bare HTMLAudio element outside the master gain). + playUrl(signed(`./assets/voices/${bank}/chirp_${take}.wav`), { gain: 0.7 }); + } + const quackLoud = () => { + quackAt = performance.now(); + playChirp(); + stickers?.pop("quack"); + }; + // Ground-pick jaw: on the robot the pick policy drives the mouth itself + // (mouth is part of its action space); the sim's ONNX exports have no + // mouth channel (all heads are 14 actions), so the peck is re-created + // here on the same phase clock. Keyed to the measured cycle: the beak + // reaches the ground ~phase 0.16-0.42 and the head scoops back up + // 0.40-0.50 - open on approach, snap shut on the scoop (the grab). + const PICK_JAW_KEYS = [[0.10, 0], [0.20, 1], [0.40, 1], [0.50, 0]]; + function pickJawNow() { + const phase = mode === "groundpick" ? pickRun?.phase : null; + if (phase == null) return 0; + const K = PICK_JAW_KEYS; + if (phase <= K[0][0] || phase >= K[K.length - 1][0]) return 0; + for (let i = 1; i < K.length; i++) { + if (phase > K[i][0]) continue; + const [p0, v0] = K[i - 1]; + const [p1, v1] = K[i]; + const t = (phase - p0) / (p1 - p0); + return v0 + (v1 - v0) * (1 - Math.cos(Math.PI * t)) / 2; // eased + } + return 0; + } + function jawOpenNow() { + const t = (performance.now() - quackAt) / QUACK_MS; + const flap = t >= 0 && t < 1 ? Math.sin(Math.PI * t) : 0; + // Runtime mouth-mode rule (main.rs: motor_targets[MOUTH] += offset): + // the policy's jaw is the BASE and the trigger/quack opening is an + // additive offset on top, clamped - it never fights the pick motion. + return Math.min(1, pickJawNow() + Math.max(flap, padJaw)); + } + function syncJaw() { + setJawOpen(rig, jawOpenNow()); + } + + // ── Wheee: LT-held playable note (sim behavior) ─────────────────────── + // The ride plays the voice bank's LOOP segment only (crossfade-authored + // to wrap sample-exactly), faded in over ~20 ms, and the LT analog + // pressure PICKS ITS NOTE: major-pentatonic steps over one octave via + // playbackRate, glided with setTargetAtTime so per-frame updates and + // step changes never zipper or click. The runtime has no pitch feature + // (raw PCM through aplay) - this is the sim's own instrument. + // + // The authored start segment is deliberately NOT played: it is 0.8-0.9 s + // long and cannot be pitch-modulated without breaking the sample-accurate + // start→loop handoff, so with it the first second of every squeeze was + // stuck at base pitch - pressure read as a volume change (the attack's + // own crescendo), not as notes. + // + // Release CUTS the ride and plays nothing else - the runtime kills the + // streaming aplay on the LT falling edge (its end segment never plays on + // the gamepad path), and the sim's old end-segment playback re-attacked + // a note on release, which read as a retriggered sound. A short gain + // ramp stands in for the process kill so Web Audio doesn't click. The + // gain is otherwise CONSTANT - pressure must never track loudness. + const WHEEE_TAKES = "ab"; + // Major pentatonic anchored one octave BELOW the sample's natural pitch: + // full squeeze reaches the natural note, casual play sits clearly lower + // (the natural pitch alone read as too shrill). -12 st = playbackRate 0.5. + const WHEEE_SCALE = [-12, -10, -8, -5, -3, 0]; // semitones vs natural pitch + const WHEEE_DEADZONE = 0.05; // squeeze below this is stick noise, maps to the root + const WHEEE_GAIN = 0.7; + let wheeeCtx = null; + const wheeeBufCache = new Map(); + let wheeeRide = null; // current ride, null while the trigger is up + function wheeeBuffer(url) { + let p = wheeeBufCache.get(url); + if (!p) { + p = fetch(url) + .then((r) => r.arrayBuffer()) + .then((ab) => wheeeCtx.decodeAudioData(ab)); + wheeeBufCache.set(url, p); + } + return p; + } + async function startWheee() { + stopWheee({ silent: true }); // a re-press replaces the current ride + wheeeCtx ??= audioCtx(); // shared game context, ride lands on the voice bus + if (wheeeCtx.state === "suspended") wheeeCtx.resume().catch(() => {}); + const bank = VOICE_BANK[currentVariant] ?? "duck1"; + const take = WHEEE_TAKES[(Math.random() * WHEEE_TAKES.length) | 0]; + const ride = { loopSrc: null, gain: null }; + wheeeRide = ride; + let loopBuf; + try { + loopBuf = await wheeeBuffer(signed(`./assets/voices/${bank}/wheee_loop_${take}.wav`)); + } catch { + return; // asset missing / fetch failed: ride silently never starts + } + if (wheeeRide !== ride) return; // released (or replaced) during decode + const gain = wheeeCtx.createGain(); + gain.connect(busNode("voice")); + const t0 = wheeeCtx.currentTime + 0.02; + // The loop is steady-state audio (no authored attack): a ~20 ms fade-in + // makes a clean note onset instead of a click. Constant gain after that. + gain.gain.setValueAtTime(0, t0); + gain.gain.linearRampToValueAtTime(WHEEE_GAIN, t0 + 0.02); + const loopSrc = wheeeCtx.createBufferSource(); + loopSrc.buffer = loopBuf; + loopSrc.loop = true; + loopSrc.connect(gain); + loopSrc.start(t0); + Object.assign(ride, { loopSrc, gain }); + } + function stopWheee({ silent = false } = {}) { + const ride = wheeeRide; + if (!ride) return; + wheeeRide = null; + // Nothing audible yet (released mid-decode) or replaced by a re-press: + // hard stop is inaudible and frees the nodes immediately. + if (silent || !ride.gain) { + try { ride.loopSrc?.stop(); } catch { /* already ended */ } + ride.gain?.disconnect(); + return; + } + // Release: cut the ride, retrigger nothing (runtime kills its player + // here). ~50 ms fade instead of a hard stop so the cut doesn't click. + const t = wheeeCtx.currentTime; + ride.gain.gain.setTargetAtTime(0, t, 0.05); + const stopAt = t + 0.3; // > 5 time constants: fully silent by then + try { ride.loopSrc?.stop(stopAt); } catch { /* already ended */ } + const gain = ride.gain; + setTimeout(() => gain.disconnect(), 400); + } + + // Per-frame note picking: the full LT travel (above a small deadzone) + // spans the pentatonic scale, one octave below natural pitch at rest up + // to the natural pitch at full squeeze. Quantized to scale steps so + // squeezing plays NOTES, not a siren; the ~40 ms setTargetAtTime glide + // smooths both the per-frame updates and the step jumps (portamento + // instead of clicks). Digital 0/1 triggers simply play the top note + // (the natural pitch). Gain never tracks pressure. + function driveWheeePitch(pressure) { + const ride = wheeeRide; + if (!ride?.loopSrc) return; + const u = Math.min(1, Math.max(0, (pressure - WHEEE_DEADZONE) / (1 - WHEEE_DEADZONE))); + const semis = WHEEE_SCALE[Math.round(u * (WHEEE_SCALE.length - 1))]; + ride.loopSrc.playbackRate.setTargetAtTime(2 ** (semis / 12), wheeeCtx.currentTime, 0.04); + } + + // ── Telemetry (throttled into the store) ───────────────────────────── + // FPS EMA is per-frame; the store write is 4 Hz so React re-renders + // stay far away from frame rate. Odometer integrates horizontal trunk + // travel; teleport-sized jumps (resets, loco swaps) don't count. + let fpsEma = 60; + let fpsLastT = performance.now(); + let odoM = 0; + let odoX = null, odoY = null; + let telemetryLastPush = 0; + function renderTelemetry() { + const now = performance.now(); + const dtF = (now - fpsLastT) / 1000; + fpsLastT = now; + if (dtF > 0 && dtF < 0.5) fpsEma += (1 / dtF - fpsEma) * 0.05; + const stepD = (odoX === null) ? 0 : Math.hypot(data.qpos[0] - odoX, data.qpos[1] - odoY); + if (stepD < 0.05) odoM += stepD; // plausible per-frame travel only + odoX = data.qpos[0]; + odoY = data.qpos[1]; + if (now - telemetryLastPush < 250) return; + telemetryLastPush = now; + setStore({ + telemetry: { + fps: Math.round(fpsEma), + ctrlHz: Math.round(ctrlHz), + speed: Math.hypot(data.qvel[0], data.qvel[1]), + odo: odoM, + peers: ghosts?.peerCount() ?? 0, + }, + }); + } + + // ── Right-stick camera orbit (inertia downstream of the controller) ── + // The stick steers an angular VELOCITY that eases toward the stick's + // target rate, so pushing ramps up gently and releasing coasts to a stop + // over ~0.3 s. Vertical is flight-style inverted. + const PAD_ORBIT_SPEED = 2.4; // rad/s at full deflection + const PAD_ORBIT_SMOOTH = 8; // 1/s response rate (~95% in 0.37 s) + const padOrbitVel = { az: 0, el: 0 }; + const _padSph = new THREE.Spherical(); + const _padOff = new THREE.Vector3(); + function padOrbitStep(rx, ry, dt) { + padOrbitLive = rx !== 0 || ry !== 0; + if (padOrbitLive) chaseCam = false; // detach, same as a mouse grab + const k = 1 - Math.exp(-PAD_ORBIT_SMOOTH * dt); + padOrbitVel.az += (rx * PAD_ORBIT_SPEED - padOrbitVel.az) * k; + padOrbitVel.el += (-ry * PAD_ORBIT_SPEED * 0.75 - padOrbitVel.el) * k; + if (chaseCam) { padOrbitVel.az = 0; padOrbitVel.el = 0; return; } + if (Math.abs(padOrbitVel.az) < 1e-3 && Math.abs(padOrbitVel.el) < 1e-3) return; + _padOff.copy(camera.position).sub(controls.target); + _padSph.setFromVector3(_padOff); + _padSph.theta -= padOrbitVel.az * dt; + _padSph.phi += padOrbitVel.el * dt; + _padSph.phi = Math.min(controls.maxPolarAngle, Math.max(0.08, _padSph.phi)); + _padSph.makeSafe(); + camera.position.setFromSpherical(_padSph).add(controls.target); + camera.lookAt(controls.target); + } + + // Multiplayer ghosts, initialised asynchronously at the end of the boot. + let ghosts = null; + + // ── Per-frame drive, called by R3F's useFrame ──────────────────────── + let padWasConnected = null; + let touchWasConnected = null; + function frame(dt) { + controller.update(dt); + padJaw = controller.getAxes().jaw; + driveWheeePitch(controller.getAxes().ride); // no-op while no ride is open + if (padSource.connected !== padWasConnected) { + padWasConnected = padSource.connected; + setStore({ padConnected: padSource.connected }); + } + if (touchSource.connected !== touchWasConnected) { + touchWasConnected = touchSource.connected; + setStore({ touchMode: touchSource.connected }); + } + // Head mode: sticks steer the head targets (stick * HEAD_MAX, signed + // per joint); the EMA toward them runs in buildObs at 50 Hz. Without + // a pad the targets stay put (and are debug-writable via window.rl). + if (headMode && padSource.connected) { + const h = padSource.head; + headTarget[0] = HEAD_SIGNS[0] * h.neckPitch * HEAD_MAX; + headTarget[1] = HEAD_SIGNS[1] * h.pitch * HEAD_MAX; + headTarget[2] = HEAD_SIGNS[2] * h.yaw * HEAD_MAX; + headTarget[3] = HEAD_SIGNS[3] * h.roll * HEAD_MAX; + } + // Camera orbit runs every frame while a pad is present (the coasting + // needs the zero-deflection frames too); without a pad, park the + // state. Head mode parks it too: the right stick belongs to the head + // and the camera must freeze in place (no leftover coasting). + if (padSource.connected && !headMode) { + padOrbitStep(controller.getAxes().orbitX, controller.getAxes().orbitY, dt); + } else { + padOrbitLive = false; + padOrbitVel.az = 0; + padOrbitVel.el = 0; + } + syncRig(); + syncJaw(); + ghosts?.update(); + // Spatial audio follows the movers: listener on the camera, emitters + // on the duck trunk and the ball (MJCF Z-up -> three Y-up). + updateListener(camera); + duckEmitter.setPosition(data.qpos[0], data.qpos[2], -data.qpos[1]); + if (ballActive) { + const q = data.qpos; + ballEmitter.setPosition(q[ballQposAdr], q[ballQposAdr + 2], -q[ballQposAdr + 1]); + } + controls.update(); + updateChaseCam(); + ceremony.drive(); + ball.drive(() => spawnBall({ fromQueue: true })); + waypointMarker.update(dt, waypointSource.target); + renderTelemetry(); + } + + // ── Input wiring: arm the controller sources, bind actions ─────────── + controller.init(); + + // Keyboard F alternates kicking feet; only advance the alternation on + // kicks that actually launched (triggerKick reports that). + let kbKickFoot = "left"; + const srcTag = (source) => (source === "gamepad" ? "pad" : "kb"); + + controller.on("reset", () => resetSim()); + controller.on("reset", () => waypointSource.cancel()); + controller.on("spawnBall", () => spawnBall()); + controller.on("headToggle", () => toggleHeadMode()); + controller.on("chaseToggle", () => { chaseCam = !chaseCam; }); + controller.on("locoToggle", () => toggleLoco()); + controller.on("roll", ({ source }) => triggerRoll(srcTag(source))); + controller.on("groundPick", ({ source }) => triggerGroundPick(srcTag(source))); + controller.on("kickL", ({ source }) => triggerKick("left", srcTag(source))); + controller.on("kickR", ({ source }) => triggerKick("right", srcTag(source))); + controller.on("alternateKick", ({ source }) => { + if (triggerKick(kbKickFoot, srcTag(source))) { + kbKickFoot = kbKickFoot === "left" ? "right" : "left"; + } + }); + // Sit is the legs-only skill; on rollers the same button hands over to + // the crouch-glide, exactly as the (now unbound) roll action did. + controller.on("sitToggle", ({ source } = {}) => { + if (loco !== "legs") return triggerCrouch(srcTag(source)); + // A community trick / script takes over the R key while it is mounted + // (a custom sitstand keeps the sit toggle: it IS the sit policy). + if (customPolicy?.slot === "trick") return triggerRoll(srcTag(source)); + if (customPolicy?.slot === "script") return toggleScript(); + const sitting = mode === "sitstand" && sitFlag === 1; + setMode(sitting ? "walk" : "sit"); + }); + // Pad DpadUp short press: straight back to running (ignored mid-roll / + // mid-crouch: those hand back to walk on their own). + controller.on("walk", () => { + if (mode !== "walk" && mode !== "roll" && mode !== "crouch") setMode("walk"); + }); + controller.on("quack", () => quackLoud()); + controller.on("wheeeStart", () => startWheee()); + controller.on("wheeeStop", () => stopWheee()); + + // Leaving head mode keeps the head offsets (runtime behavior): only + // resetSim zeroes headTarget/headSmooth. + function exitHeadMode() { + if (!headMode) return; + headMode = false; + padSource.headMode = false; + syncButtons(); + } + + function toggleHeadMode() { + if (headMode) return exitHeadMode(); + // Enterable from walk or sit only - never during one-shots (roll / + // kick / crouch), the post-kick grace, a stand-up hand-back, a fall + // recovery, or while the entrance/respawn lock holds the inputs. + if (inputLocked || (mode !== "walk" && mode !== "sitstand") || postKickLock > 0 || + standTimer || recovery) + return; + headMode = true; + padSource.headMode = true; + syncButtons(); + } + + function setMode(next, { force = false } = {}) { + if (!force && inputLocked) return; + // No policy switching mid-roll or mid-kick: both end on their own and + // return to walk - switching now would floor the duck. Same while the + // fall-recovery state machine owns the duck. + if (recovery) return; + if ((mode === "roll" && rollRun) || (isKick() && kickRun) || + (mode === "crouch" && crouchRun) || (mode === "groundpick" && pickRun)) return; + if (next === "sit" && loco === "rollers") return; + exitHeadMode(); // posture changes exit head mode (offsets kept) + clearModeTimers(); + rollRun = null; + crouchRun = null; + pickRun = null; + if (next !== "sit") { + // Leaving a sit: let the sitstand policy stand the duck back up first. + if (mode === "sitstand" && sitFlag === 1) { + sitFlag = 0; + standTimer = setTimeout(() => { + standTimer = null; + mode = next; + lastAction.fill(0); + syncButtons(); + }, 2000); + syncButtons(); + return; + } + mode = next; + lastAction.fill(0); + } else { + // Hand over gently: hold the stand under the sitstand policy for a + // moment before commanding the sit, or the abrupt session switch + // knocks the duck over. + mode = "sitstand"; + sitFlag = 0; + lastAction.fill(0); + sitTimer = setTimeout(() => { + sitTimer = null; + if (mode === "sitstand") { sitFlag = 1; syncButtons(); } + }, 800); + } + syncButtons(); + } + + // One roll, then straight back to running. lastAction is deliberately + // NOT zeroed: the runtime keeps one continuous action history across + // policy switches, and the roll initiates more reliably mid-gait. + function triggerRoll(source = "kb") { + if (loco === "rollers") return triggerCrouch(source); + if (inputLocked || mode !== "walk" || standTimer || recovery) return; + exitHeadMode(); + clearModeTimers(); + mode = "roll"; + sitFlag = 0; + // A custom episodic trick lives in the roll slot and runs for its own + // duration (loadCustomPolicy clamps it); the official roulade keeps + // its 3 s hard window. + const custom = customPolicy?.slot === "trick" && sessions.roll === customPolicy.session; + const maxSteps = custom ? Math.max(10, Math.round((customPolicy.durationS ?? 5) / CTRL_DT)) : 150; + rollRun = { steps: 0, tipped: false, custom, maxSteps }; + syncButtons(); + stickers?.pop("roll"); + } + + // Kind "script" move: R toggles the command timeline on the walker. + function toggleScript() { + if (!customPolicy?.script) return; + if (scriptRun) { + scriptRun = null; + syncButtons(); + return; + } + if (inputLocked || mode !== "walk" || standTimer || recovery || loco !== "legs") return; + exitHeadMode(); + scriptRun = { t: 0 }; + syncButtons(); + } + + // Roller-only one-shot: crouch, glide low, stand back up (phase-driven). + function triggerCrouch(source = "kb") { + if (inputLocked || mode !== "walk" || locoSwitching || recovery) return; + exitHeadMode(); + clearModeTimers(); + mode = "crouch"; + crouchRun = { phase: 0 }; + syncButtons(); + stickers?.pop("roll"); + } + + // One-shot ground pick (runtime A button): peck the ground and stand + // back up, phase-driven like the roller crouch (same cos/sin encoding in + // the command vel slots). Legs-only, from walk, and never during another + // one-shot / a stand-up hand-back / the entrance lock. + function triggerGroundPick(source = "kb") { + if (loco !== "legs") return; + if (inputLocked || mode !== "walk" || standTimer || recovery) return; + exitHeadMode(); + clearModeTimers(); + mode = "groundpick"; + sitFlag = 0; + pickRun = { phase: 0 }; + syncButtons(); + } + + // One blind kick (the duck can't see any ball - it's a scripted boot). + // Returns whether the kick actually launched so the keyboard's foot + // alternation only advances on real kicks. + function triggerKick(foot, source = "kb") { + if (loco === "rollers") return false; + if (inputLocked || mode !== "walk" || standTimer || recovery) return false; + exitHeadMode(); + clearModeTimers(); + mode = foot === "left" ? "kickL" : "kickR"; + sitFlag = 0; + kickRun = { steps: 0 }; + haptics.pulse("kick"); // swing launch; ball contact adds ballHit + syncButtons(); + stickers?.pop("kick"); + return true; + } + + function syncButtons() { + const sitting = mode === "sitstand" && sitFlag === 1; + const label = + recovery ? "Recovery" + : mode === "roll" ? (rollRun?.custom ? "Trick" : "Roll") + : scriptRun ? "Script" + : mode === "crouch" ? "Crouch" + : mode === "groundpick" ? "Pick" + : isKick() ? "Kick" + : headMode ? "Head" + : sitting ? "Sit" + : loco === "rollers" ? "Drive" + : "Run"; + if (store().modeLabel !== label) setStore({ modeLabel: label }); + if (store().ballActive !== ballActive) setStore({ ballActive }); + } + + // ── Public surface for the React UI ────────────────────────────────── + Object.assign(gameApi, { + frame, + setVariant: (name) => { + if (!VARIANTS[name] || name === currentVariant) return; + currentVariant = name; + applyVariant(rig, name); + setStore({ variant: name }); + }, + requestLoco: (name) => { + if (name !== "legs" && name !== "rollers") return; + setStore({ locoWant: name }); + reconcileLoco(); + }, + resetSim, + spawnBall: () => spawnBall(), + startEntrance: () => ceremony.startEntrance(), + loadCustomPolicy: (ref) => loadCustomPolicyIntoGame(ref), + clearCustomPolicy: () => revertCustomPolicy(), + }); + + // Deterministic hooks for automated verification (rAF pauses in + // background tabs, and the control loop is async). + window.rl = { + get model() { return model; }, + get data() { return data; }, + mujoco, camera, controls, + get mode() { return mode; }, + get sitFlag() { return sitFlag; }, + buildObs, cmd, + velCmd: kbSource.command, lastAction, resetSim, + controller, kbSource, padSource, + spawnBall, triggerKick, triggerRoll, sessions, ort, + loadCustomPolicy: loadCustomPolicyIntoGame, + clearCustomPolicy: revertCustomPolicy, + get customPolicy() { return customPolicy; }, + get scriptRun() { return scriptRun; }, + toggleScript, + get watchdogEvents() { return watchdogEvents.slice(); }, + get loco() { return loco; }, + get locoSwitching() { return locoSwitching; }, + toggleLoco, setLoco, ensureRollers, + triggerCrouch, + get crouchPhase() { return crouchRun?.phase ?? null; }, + triggerGroundPick, + get groundPickPhase() { return pickRun?.phase ?? null; }, + get kickSteps() { return KICK_STEPS; }, + set kickSteps(v) { KICK_STEPS = v; }, + get recovery() { return recovery?.state ?? null; }, + // Debug shove for fall-recovery testing: an instantaneous trunk + // velocity kick (free-joint dofs are qvel[0..5]). + debugPush: (vx = 0, vy = 0, vz = 0, wx = 0, wy = 0, wz = 0) => { + const qvel = data.qvel; + qvel[0] += vx; qvel[1] += vy; qvel[2] += vz; + qvel[3] += wx; qvel[4] += wy; qvel[5] += wz; + }, + get headMode() { return headMode; }, + toggleHeadMode, headTarget, headSmooth, + get ballActive() { return ballActive; }, + get ballQposAdr() { return ballQposAdr; }, + get chaseCam() { return chaseCam; }, + set chaseCam(v) { chaseCam = !!v; }, + get props() { return propGroups; }, + get relief() { return reliefOn; }, + setRelief: (v) => { reliefOn = !!v; }, + get camResetActive() { return camResetT0 !== null; }, + get respawnActive() { return ceremony?.respawnActive ?? false; }, + get camPose() { + return { + pos: camera.position.toArray(), + target: controls.target.toArray(), + }; + }, + get chaseYaw() { return { follow: chaseYawFollow, smooth: chaseYawSmooth, held: chaseHeldYaw, tracking: chaseYawTracking }; }, + padOrbitStep, + jawOpenNow, + step: async (n = 1) => { for (let i = 0; i < n; i++) await controlStep(); }, + render: () => { syncRig(); renderer.render(scene, camera); }, + frame: (dt = 1 / 60) => frame(dt), + get ghosts() { return ghosts; }, + get inputLocked() { return inputLocked; }, + entrance: { + start: () => ceremony.startEntrance(), + setReveal: (floor, wall) => ceremony.setReveal(floor, wall), + setFx: (p) => ceremony.setFx(p), + }, + }; + + // Boot complete: the sim/HUD go live immediately. The BIOS readout (if + // the user already waddled in, or when they do) sees bootDone and closes + // with READY. + fade on its own. + setStore({ bootDone: true }); + + // ?move= / ?policy= / ?session= (parsed in App.jsx into the + // store): load the community move now that the sim is up. Fire-and-forget + // - a bad ref surfaces its error in the HUD while the official walker + // keeps the duck alive. + const requestedPolicy = store().customPolicy; + if (requestedPolicy?.status === "loading" && requestedPolicy.ref) { + loadCustomPolicyIntoGame(requestedPolicy.ref); + } + + // ── Multiplayer ghosts (WebRTC, serverless signaling) ──────────────── + // Broadcast this duck's pose and render up to 3 other visitors live as + // translucent ducks. Fire-and-forget: any failure just means no ghosts. + const r3 = (x) => Math.round(x * 1000) / 1000; + try { + // Ghosts only join once the entrance has fully played: the world (and + // this duck) must stay hidden until then, translucent peers included. + await ceremony.entranceFinished; + ghosts = await initGhosts({ + scene, rig, cloneRig, setJoint, setJawOpen, applyVariant, + jointNames: JOINT_NAMES, + // Payload sanitizing: ghosts.js coerces unknown peer variants to the + // default instead of letting applyVariant throw on a bad key. + variantNames: Object.keys(VARIANTS), + defaultVariant: DEFAULT_VARIANT, + // Ghost rig per locomotion flag: roller peers clone the live roller + // rig when this tab has it, else the lightweight ghost-only roller + // rig. hasRigFor/prepareRigFor let ghosts.js render legs as a + // stopgap while lazily loading the real thing, then rebuild. + getRigFor: (l) => + (l ? (locos.rollers?.rig ?? ghostRollerRig ?? locos.legs.rig) : locos.legs.rig), + hasRigFor: (l) => !l || !!(locos.rollers || ghostRollerRig), + prepareRigFor: (l) => { if (l) ensureGhostRollerRig(); }, + // Ghost ball visual: shares the local ball's geometry and clones its + // material (ghosts.js makes it translucent). Same Z-up group trick + // as createBallVisual - the mesh takes the raw MJCF free-joint pose. + makeGhostBall: () => { + const group = new THREE.Group(); + group.rotation.x = -Math.PI / 2; + const mesh = new THREE.Mesh(ballMesh.geometry, ballMesh.material.clone()); + group.add(mesh); + return { group, mesh }; + }, + getLocalState: () => { + const qpos = data.qpos; + const j = new Array(NUM_JOINTS); + for (let i = 0; i < NUM_JOINTS; i++) j[i] = r3(qpos[qposAdr[i]]); + const st = { + p: [r3(qpos[0]), r3(qpos[1]), r3(qpos[2]), r3(qpos[3]), r3(qpos[4]), r3(qpos[5]), r3(qpos[6])], + j, + w: r3(jawOpenNow()), + v: currentVariant, + l: loco === "rollers" ? 1 : 0, + }; + // Ball free-joint pose, only while a ball is in play (old clients + // ignore the extra field; absent = no ball on this peer's field). + if (ballActive) { + const a = ballQposAdr; + st.b = [r3(qpos[a]), r3(qpos[a + 1]), r3(qpos[a + 2]), r3(qpos[a + 3]), r3(qpos[a + 4]), r3(qpos[a + 5]), r3(qpos[a + 6])]; + } + return st; + }, + }); + liveGhostSessions.add(ghosts); + if (ghosts.room) ghosts.room.onPeerJoin = () => stickers?.pop("hi"); + } catch (e) { + window.__ghostErr = String((e && e.stack) || e); + console.warn("ghosts disabled:", e); + } +} diff --git a/app/src/game/ghosts.js b/app/src/game/ghosts.js new file mode 100644 index 0000000..12f1020 --- /dev/null +++ b/app/src/game/ghosts.js @@ -0,0 +1,601 @@ +// Live multiplayer ghosts: every open tab of the sandbox broadcasts its +// duck state over WebRTC and renders the other visitors as translucent +// ducks. There is no backend - this is a static Space - so peer discovery +// uses Trystero's serverless signaling over public Nostr relays. Payloads +// are tiny (22 floats + a variant name at SEND_HZ), and at most MAX_GHOSTS +// ghosts are instantiated regardless of how many peers are in the room. +// +// This module deliberately imports nothing from duck.js / variants.js: +// on the private Space those need the ?__sign JWT that only rl.js knows +// how to append, so all rig helpers arrive through init parameters. + +const APP_ID = "microduck-sandbox"; +const ROOM = "lobby"; +// Explicit relay list instead of Trystero's default appId-seeded pick. +// The deterministic subset that "microduck-sandbox" draws from the default +// pool rotted away (2026-09 audit: 3 relays dead, 1 rejecting ephemeral +// events, 1 rate-limiting), which silently killed ghost discovery in prod. +// These were verified live to accept AND route Trystero's ephemeral +// events; the warnOnRelayFailure path logs any that decay later. +const RELAY_URLS = [ + "wss://relay.damus.io", + "wss://nos.lol", + "wss://nostr.tegila.com.br", + "wss://staging.yabu.me", + "wss://social.amanah.eblessing.co", + "wss://relay-rpi.edufeed.org", + "wss://strfry.shock.network", +]; +const MAX_GHOSTS = 3; +const SEND_HZ = 15; +const GHOST_OPACITY = 0.35; +// Snapshot interpolation: each ghost renders in the past, lerping between +// the two buffered snapshots that bracket the render time (timed by local +// ARRIVAL, so no clock sync and no payload change - old clients +// interoperate). This replaces the old exponential chase toward the +// latest packet, whose move-then-stall rhythm read as micro-stutter. +// +// The playback delay is ADAPTIVE per ghost: it tracks the measured +// snapshot arrival cadence (fast-attack / slow-release, like a jitter +// buffer), so a healthy 15 Hz peer keeps the ~150 ms floor while a +// background-throttled 1 Hz sender is replayed as continuous slow motion +// ~1.3 s in the past instead of the old sprint-then-freeze (a fixed +// 150 ms delay replayed each 1 s packet gap as a 150 ms dash). The delay +// is slew-rate limited so rate changes (tab hidden <-> shown) glide - +// render time never runs backward and never pops. Arrival stamps are +// also de-jittered: bursts delivered back-to-back by the reliable +// ordered channel (head-of-line blocking) are re-spaced to at least half +// the nominal send interval, so a burst replays as motion instead of a +// teleport. Nobody synchronizes on ghosts, so the latency is invisible. +const INTERP_DELAY_MS = 150; // floor, ~2.25 send intervals at 15 Hz +const INTERP_DELAY_MAX_MS = 2000; // cap for stalled senders +const RESPACE_MIN_MS = 1000 / SEND_HZ / 2; // de-jitter floor between stamps +const GAP_RELEASE = 0.15; // per-packet EWMA rate when arrivals speed up +const DELAY_SLEW = 0.5; // max delay change per ms of real time +const BUF_MAX = 40; // snapshots kept per ghost (~2.5 s at 15 Hz) +// Floor between legs<->rollers ghost rebuilds for one peer: a rebuild +// clones a full rig, so the rate is capped against flag-flapping peers. +const LOCO_SWAP_MIN_MS = 500; +// Hopeless-stream gate: a ghost whose snapshots arrive too sparsely to +// interpolate smoothly (peer tab throttled to ~1 Hz, bad network) is +// faded out entirely instead of shown as a stuttering slow-motion puppet. +// Health is judged on max(gapAvg, time since last packet) with hysteresis: +// sustained above HIDE_GAP_MS hides, sustained below SHOW_GAP_MS shows, +// and the band between the two keeps the current state so the boundary +// never flickers. The sustain windows also ride out one-off hiccups +// (gapAvg fast-attacks on a single late packet but releases within a few +// packets, well inside HIDE_SUSTAIN_MS). Fading drives the cloned ghost +// materials' opacity (same path as GHOST_OPACITY), the ghost ball, and +// the mapDots minimap feed; ghosts have no name tags or audio emitters, +// so there is nothing else to mute. +const HIDE_GAP_MS = 700; // sustained arrival interval that hides a ghost +const SHOW_GAP_MS = 350; // sustained interval that shows it again +const HIDE_SUSTAIN_MS = 1500; // how long the gap must stay bad to hide +const SHOW_SUSTAIN_MS = 700; // how long it must stay good to show +const FADE_MS = 400; // opacity ramp duration for hide/show + +// Idle visitors stay invisible: a ghost is only shown once its peer has +// strayed from the pose of its first state message (everyone spawns at +// the arena center). Once revealed it stays visible for the whole peer +// session, so a reset teleporting the duck back to center doesn't blink +// the ghost out. +const REVEAL_DIST = 0.2; // m, horizontal distance from spawn +const REVEAL_YAW = 0.4; // rad (~23deg), turning in place also reveals + +// state.p is raw MuJoCo qpos[0..6]: [x, y, z, qw, qx, qy, qz], Z-up. +const yawOf = (p) => + Math.atan2(2 * (p[3] * p[6] + p[4] * p[5]), 1 - 2 * (p[5] * p[5] + p[6] * p[6])); +const hasMoved = (spawn, p) => { + const dx = p[0] - spawn.x, dy = p[1] - spawn.y; + if (dx * dx + dy * dy > REVEAL_DIST * REVEAL_DIST) return true; + const dyaw = yawOf(p) - spawn.yaw; + return Math.abs(Math.atan2(Math.sin(dyaw), Math.cos(dyaw))) > REVEAL_YAW; +}; + +// Instances not yet destroyed, so a dev-server hot swap of this module can +// tear down the previous one's interval/room instead of stacking them. +const liveInstances = new Set(); +if (import.meta.hot) { + import.meta.hot.dispose(() => { + for (const g of [...liveInstances]) g.destroy(); + }); +} + +export async function initGhosts(env) { + const noop = { + update() {}, peerCount: () => 0, ghostCount: () => 0, debug: () => [], + mapDots: () => [], destroy() {}, injectState: () => false, + setSendHz: () => {}, + }; + let room; + try { + // Vendored npm dep (was esm.run); dynamic so it stays a lazy chunk + // loaded only when the ghost session actually starts. + const { joinRoom } = await import("trystero/nostr"); + room = joinRoom({ appId: APP_ID, relayConfig: { urls: RELAY_URLS } }, ROOM); + } catch (e) { + console.warn("ghosts disabled (signaling unavailable):", e); + return noop; + } + + const { scene, cloneRig, setJoint, setJawOpen, applyVariant, jointNames, getLocalState } = env; + // Variant whitelist supplied by the host (this module imports nothing from + // variants.js, see header). Unknown names from remote peers are coerced to + // the default so applyVariant never sees a key it can't resolve. + const knownVariants = env.variantNames ? new Set(env.variantNames) : null; + const defaultVariant = env.defaultVariant ?? env.variantNames?.[0]; + // Locomotion-variant rig source: state.l 1 = rollers, 0/absent = legs + // (old clients never send it). The host may not have the wanted rig yet + // (the roller stack is lazy): servedLoco says which flavor a ghost + // actually gets right now, and prepareRigFor warms the missing one in + // the background so a later packet can rebuild onto the real thing. + const rigFor = (l) => (env.getRigFor ? env.getRigFor(l ?? 0) : env.rig); + const servedLoco = (l) => { + const want = l ?? 0; + return env.hasRigFor && !env.hasRigFor(want) ? 0 : want; + }; + // trystero 0.25 (backed by @trystero-p2p): makeAction returns + // { send, onMessage, onReceiveProgress } where onMessage is a SETTER - + // the receive handler is registered by assignment, not by calling it. + const act = room.makeAction("s"); + // send() rejects when a peer's channel drops mid-transfer; that peer will + // be swept anyway, so failures are non-events. + const sendState = (data) => act.send(data).catch(() => {}); + + // Ghosts share geometry with the local rig (cloneRig), but get their own + // transparent material clones so repainting them never touches the + // visitor's own duck (variants.js caches materials globally). + // + // Rendering: a ghost reads as ONE translucent shell, not ~70 individually + // transparent meshes (through which every internal motor/PCB used to show). + // Classic depth-prepass silhouette, kept inside the transparent pass so the + // grid floor/walls (transparent ShaderMaterials at renderOrder 0) still + // draw behind ghosts instead of being depth-rejected: + // PREPASS (renderOrder 1): every ghost mesh duplicated as a color-less + // twin (colorWrite off, depthWrite on) -> the depth buffer ends up + // holding the nearest ghost surface per pixel. + // BEAUTY (renderOrder 2): the real meshes, transparent + depthWrite off; + // the default LessEqual depth test then rejects everything except the + // fragment matching the prepass depth, so internals and back shell + // layers are skipped and each pixel is shaded exactly once. + // Orders are shared by all ghosts (not per-ghost pairs): every beauty pass + // tests against every ghost's prepass depth, so overlapping ghosts occlude + // each other like solids instead of double-blending. + const PREPASS_ORDER = 1; + const BEAUTY_ORDER = 2; + const ghostify = (rig) => { + // Collect first: twins are added below and must not be re-traversed. + const meshes = []; + rig.root.traverse((o) => { if (o.isMesh) meshes.push(o); }); + const cache = new Map(); + let depthMat = null; + for (const o of meshes) { + // Materialization-FX wire overlays cloned along with the local rig: + // drop them, they share the LIVE scan shader material and would + // flash on this ghost every time the local duck re-materializes. + if (o.userData.fxOverlay) { o.parent?.remove(o); continue; } + if (o.userData.ghostPrepass) continue; // twin from a previous ghostify + let m = cache.get(o.material.uuid); + if (!m) { + m = o.material.clone(); + m.transparent = true; + m.opacity = GHOST_OPACITY; + m.depthWrite = false; + cache.set(o.material.uuid, m); + } + o.material = m; + o.renderOrder = BEAUTY_ORDER; + if (!o.userData.hasGhostTwin) { + if (!depthMat) { + // Depth-only material: cloned (no THREE import here) and muted. + // transparent stays true so the twin sorts into the transparent + // pass, after the grid but before the beauty meshes. + depthMat = m.clone(); + depthMat.colorWrite = false; + depthMat.depthWrite = true; + } + // Twin as an identity-transform child: follows joints for free. No + // userData.meshName, so applyVariant never repaints it. + const twin = new o.constructor(o.geometry, depthMat); + twin.renderOrder = PREPASS_ORDER; + twin.userData.ghostPrepass = true; + o.userData.hasGhostTwin = true; + o.add(twin); + } + } + }; + + const ghosts = new Map(); // peerId -> ghost + let destroyed = false; // set by destroy(): drops any late messages + // Interpolation snapshot: the pose parts of a state message, stamped + // with the local arrival time, de-jittered: a snapshot never lands + // closer than RESPACE_MIN_MS after the previous one, so a burst of + // queued packets spreads into playable motion (the future-dated stamps + // stay behind the delayed render time). + const snapOf = (state, prevAt = -Infinity) => ({ + p: state.p, j: state.j, w: state.w ?? 0, + b: state.b ?? null, // ball free-joint pose, or null while none in play + at: Math.max(performance.now(), prevAt + RESPACE_MIN_MS), + }); + const makeGhost = (state) => { + // g.loco records the rig the ghost actually GOT (the served flavor), + // not the peer's flag: while the roller rig is still loading the ghost + // walks on legs, and the mismatch on later packets drives the rebuild. + const served = servedLoco(state.l); + if (served !== (state.l ?? 0)) env.prepareRigFor?.(state.l); + const rig = cloneRig(rigFor(served)); + applyVariant(rig, state.v); + ghostify(rig); + scene.add(rig.placer); + const trunk = rig.bodies.get("trunk_base"); + // Snap straight to the first received pose: no fly-in from the origin. + trunk.position.set(state.p[0], state.p[1], state.p[2]); + trunk.quaternion.set(state.p[4], state.p[5], state.p[6], state.p[3]); + return { + rig, trunk, buf: [snapOf(state)], + variant: state.v, loco: served, + ball: null, // { group, mesh } lazily built on the first ball pose + gapAvg: 1000 / SEND_HZ, // measured arrival cadence, ms + delay: INTERP_DELAY_MS, // current playback delay, ms + // Stream-health fade (see HIDE_GAP_MS block): fade is the current + // opacity factor, fadeTarget the hysteresis verdict (0 or 1), and + // appliedFade what the materials last received (fresh ghostify + // clones start at full GHOST_OPACITY, i.e. factor 1). + fade: 1, fadeTarget: 1, appliedFade: 1, + hideSince: null, showSince: null, + }; + }; + + const removeGhost = (peerId) => { + const g = ghosts.get(peerId); + if (!g) return; + scene.remove(g.rig.placer); + const seen = new Set(); + g.rig.root.traverse((o) => { + if (o.isMesh && !seen.has(o.material.uuid)) { + seen.add(o.material.uuid); + o.material.dispose(); + } + }); + if (g.ball) { + scene.remove(g.ball.group); + g.ball.mesh.material.dispose(); // cloned per ghost; geometry is shared + } + ghosts.delete(peerId); + }; + + // The lobby is public over Nostr relays, so any peer can send anything: + // validate the payload shape before touching it, and never let a hostile + // or buggy message throw out of the handler. + const finiteArray = (a, n) => Array.isArray(a) && a.length === n && a.every(Number.isFinite); + const validState = (state) => + typeof state === "object" && state !== null && + finiteArray(state.p, 7) && + finiteArray(state.j, jointNames.length) && + (state.w == null || Number.isFinite(state.w)) && + (state.b == null || finiteArray(state.b, 7)) && // ball pose, optional + typeof state.v === "string"; + const warnedPeers = new Set(); // one malformed-payload warn per peer + + // Handler signature in this build: (payload, context) where context is + // { peerId } - NOT the bare peerId string of classic trystero. + const handleState = (state, peerId) => { + if (destroyed) return; + if (!validState(state)) { + if (!warnedPeers.has(peerId)) { + warnedPeers.add(peerId); + console.warn("ghosts: dropping malformed state from peer", peerId); + } + return; + } + // Sanitize the free-form fields in place (state is a fresh deserialized + // object, never shared): unknown variant -> default, loco flag -> 0|1. + if (knownVariants && !knownVariants.has(state.v)) state.v = defaultVariant; + state.l = state.l ? 1 : 0; + let g = ghosts.get(peerId); + if (!g) { + if (ghosts.size >= MAX_GHOSTS) return; // room stays open, rendering capped + // Nostr relays replay recent events, so states from already-dead + // sessions can arrive right after joining: only ghost live peers. + if (!(peerId in room.getPeers())) return; + g = makeGhost(state); + // Idle-visitor gate: remember where this peer first appeared and keep + // its rig invisible until it strays from there (see hasMoved above). + g.spawn = { x: state.p[0], y: state.p[1], yaw: yawOf(state.p) }; + g.revealed = false; + g.rig.placer.visible = false; + ghosts.set(peerId, g); + g.lastSeen = performance.now(); + return; + } + g.lastSeen = performance.now(); + const prevAt = g.buf[g.buf.length - 1]?.at; + const snap = snapOf(state, prevAt); + if (prevAt !== undefined) { + // Arrival cadence, fast attack / slow release: one late packet bumps + // the estimate (and thus the playback delay) immediately, a resumed + // fast sender eases it back down over ~a second of packets. + const gap = snap.at - prevAt; + g.gapAvg = gap > g.gapAvg ? gap : g.gapAvg + (gap - g.gapAvg) * GAP_RELEASE; + } + g.buf.push(snap); + if (g.buf.length > BUF_MAX) g.buf.shift(); + if (!g.revealed && hasMoved(g.spawn, state.p)) { + g.revealed = true; // latched for the rest of this peer session + g.rig.placer.visible = true; + } + // Peer switched legs <-> rollers, or the rig its mode needs just + // finished lazy-loading: rebuild the ghost on the right rig (cheap - + // cloneRig shares geometry). The snapshot buffer carries over so the + // interpolated motion stays continuous across the swap. While the + // wanted rig is still loading, keep warming it and stay on legs. + // Rate-limited per peer: the lobby is public, so a hostile peer + // flapping the flag at packet rate must not turn into a 15 Hz + // teardown/rebuild loop on every viewer's tab (a real switch takes a + // ~1 s button hold, so legit swaps are never this close together). + if (state.l !== g.loco) { + const now = performance.now(); + if (servedLoco(state.l) !== state.l) { + env.prepareRigFor?.(state.l); + } else if (now - (g.locoSwapAt ?? 0) >= LOCO_SWAP_MIN_MS) { + const { lastSeen, spawn, revealed, buf, gapAvg, delay, + fade, fadeTarget, hideSince, showSince } = g; + removeGhost(peerId); + g = makeGhost(state); + // appliedFade stays 1 (fresh rig materials): update() re-applies + // the carried fade on the next frame if it differs. + Object.assign(g, { lastSeen, spawn, revealed, buf, gapAvg, delay, + fade, fadeTarget, hideSince, showSince, locoSwapAt: now }); + g.rig.placer.visible = revealed; + ghosts.set(peerId, g); + return; + } + } + if (state.v !== g.variant) { + g.variant = state.v; + applyVariant(g.rig, state.v); + ghostify(g.rig); + g.appliedFade = 1; // repaint recloned materials at full GHOST_OPACITY + } + }; + const onState = (state, { peerId }) => { + try { + handleState(state, peerId); + } catch (e) { + // Shape-valid but still poisonous payload, or an internal error: drop + // the message, keep the handler alive for the next one. + if (!warnedPeers.has(peerId)) { + warnedPeers.add(peerId); + console.warn("ghosts: error handling state from peer", peerId, e); + } + } + }; + act.onMessage = onState; + + // Same setter-style registration as onMessage. + room.onPeerLeave = (peerId) => removeGhost(peerId); + + // Graceful exit so other tabs drop this ghost immediately... + const onPagehide = () => { + try { room.leave(); } catch {} + }; + window.addEventListener("pagehide", onPagehide); + // ...and a staleness sweep for peers that vanished without leaving + // (crashed tab, dropped connection): 5 s without a state packet means + // the peer is gone, not just lagging (even background-throttled tabs + // still send at ~1 Hz). + const STALE_MS = 5000; + + // Broadcast + stale sweep on a Web Worker clock: hidden tabs clamp + // main-thread timers (and rAF) to >= 1 s, which used to degrade a hidden + // tab's ghost to 1 Hz stepping in everyone else's view. Dedicated-worker + // timers are exempt, and the postMessage task still runs on the hidden + // main thread (only timers are throttled), so a backgrounded tab keeps + // broadcasting at the nominal SEND_HZ. Inline via blob URL - no extra + // file, no bundler config; falls back to a plain (throttled) interval + // if workers or blob URLs are unavailable (strict CSP). + const tick = () => { + const s = getLocalState(); + if (s) sendState(s); + const now = performance.now(); + for (const [peerId, g] of [...ghosts]) { + if (now - g.lastSeen > STALE_MS) removeGhost(peerId); + } + }; + let tickWorker = null; + let tickId = null; + // Broadcast ticker, restartable so the QA hook below can emulate a + // throttled sender (there is no other way to reach the worker's + // interval from the console once it is running). + const startTicker = (hz) => { + tickWorker?.terminate(); + tickWorker = null; + if (tickId !== null) { clearInterval(tickId); tickId = null; } + try { + const url = URL.createObjectURL(new Blob( + [`setInterval(() => postMessage(0), ${1000 / hz});`], + { type: "text/javascript" }, + )); + tickWorker = new Worker(url); + URL.revokeObjectURL(url); // the worker resolved the URL synchronously + tickWorker.onmessage = tick; + } catch { + tickId = setInterval(tick, 1000 / hz); + } + }; + startTicker(SEND_HZ); + + // Scratch THREE.Quaternions without importing three: slerp needs real + // instances, cloned here from any node of the already-built local rig. + const _qa = env.rig.placer.quaternion.clone(); + const _qb = env.rig.placer.quaternion.clone(); + + // Ghost ball: the peer's soccer ball as the same translucent shell as + // its duck. Built lazily on the first snapshot carrying a ball pose + // (env.makeGhostBall shares the local ball's geometry and clones its + // material), shown only while the ghost itself is revealed, hidden the + // moment the peer's ball despawns (b turns null in the stream). Poses + // interpolate like the trunk; on a spawn/despawn edge where only one + // bracketing snapshot has a ball, it snaps to that pose instead of + // lerping from nowhere. A single convex mesh needs no depth-prepass + // twin - plain transparent blending reads fine on a sphere. + const driveBall = (g, ab, bb, u) => { + if (!ab && !bb) { + if (g.ball) g.ball.group.visible = false; + return; + } + if (!g.ball) { + if (!env.makeGhostBall) return; // host without ball support + const ball = env.makeGhostBall(); + const m = ball.mesh.material; + m.transparent = true; + m.opacity = GHOST_OPACITY; + m.depthWrite = false; + ball.mesh.renderOrder = BEAUTY_ORDER; + scene.add(ball.group); + g.ball = ball; + } + g.ball.group.visible = g.revealed && g.fade > 0; + const mesh = g.ball.mesh; + if (ab && bb) { + mesh.position.set( + ab[0] + (bb[0] - ab[0]) * u, + ab[1] + (bb[1] - ab[1]) * u, + ab[2] + (bb[2] - ab[2]) * u, + ); + _qa.set(ab[4], ab[5], ab[6], ab[3]); // MJCF wxyz -> THREE xyzw + _qb.set(bb[4], bb[5], bb[6], bb[3]); + mesh.quaternion.copy(_qa.slerp(_qb, u)); + } else { + const s = ab ?? bb; + mesh.position.set(s[0], s[1], s[2]); + mesh.quaternion.set(s[4], s[5], s[6], s[3]); + } + }; + // Push the ghost's current fade factor into its cloned materials (beauty + // meshes + ghost ball; prepass twins are colorWrite-off so opacity is + // irrelevant, and the whole rig is hidden via placer.visible at fade 0). + // Called only on frames where the fade actually moved. + const applyFade = (g) => { + const seen = new Set(); + g.rig.root.traverse((o) => { + if (!o.isMesh || o.userData.ghostPrepass || seen.has(o.material.uuid)) return; + seen.add(o.material.uuid); + o.material.opacity = GHOST_OPACITY * g.fade; + }); + if (g.ball) g.ball.mesh.material.opacity = GHOST_OPACITY * g.fade; + g.appliedFade = g.fade; + }; + let lastUpdateAt = performance.now(); // update() frame clock for the delay slew + const api = { + room, + // Full teardown: without it, every HMR reload of this module stacked a + // live 15 Hz interval plus a ghost room that kept broadcasting. + destroy() { + if (destroyed) return; + destroyed = true; + liveInstances.delete(api); + tickWorker?.terminate(); + if (tickId !== null) clearInterval(tickId); + window.removeEventListener("pagehide", onPagehide); + try { room.leave(); } catch {} + for (const peerId of [...ghosts.keys()]) removeGhost(peerId); + }, + // Debug/test hook: feed a payload through the exact same guarded path + // as a network message (console QA of the validation layer). + injectState: (state, peerId = "__debug") => onState(state, { peerId }), + // QA hook: rebuild the broadcast ticker at a different rate, to + // emulate a background-throttled / bad-network sender (drives the + // receiving side's sparse-stream fade, see HIDE_GAP_MS block). + setSendHz: (hz = SEND_HZ) => startTicker(hz), + peerCount: () => Object.keys(room.getPeers()).length, + ghostCount: () => ghosts.size, + // Minimap feed: revealed ghosts' arena positions in raw MJCF coords + // (trunk.position is set from qpos before the root's Z-up fix). + mapDots: () => + [...ghosts.values()] + .filter((g) => g.revealed && g.fade > 0) // fade-hidden ghosts drop off the map too + .map((g) => ({ x: g.trunk.position.x, y: g.trunk.position.y })), + debug: () => [...ghosts.entries()].map(([peerId, g]) => { + let meshes = 0, visible = 0, op = null, twins = 0; + g.rig.root.traverse((o) => { + if (!o.isMesh) return; + if (o.userData.ghostPrepass) { twins++; return; } + meshes++; if (o.visible) visible++; op ??= o.material.opacity; + }); + const w = g.trunk.getWorldPosition(g.trunk.position.clone()); + const ball = g.ball + ? { visible: g.ball.group.visible, p: g.ball.mesh.position.toArray() } + : null; + return { peerId, p: g.trunk.position.toArray(), world: w.toArray(), inScene: !!g.rig.placer.parent, revealed: g.revealed, meshes, visible, twins, op, v: g.variant, l: g.loco, ball, gapAvg: g.gapAvg, delay: g.delay, bufLen: g.buf.length, fade: g.fade, fadeTarget: g.fadeTarget, lastSeen: g.lastSeen }; + }), + update() { + const now = performance.now(); + // Frame delta for the delay slew; capped so a long-occluded tab's + // first frame back just snaps the delay while nobody was watching. + const dt = Math.min(250, now - lastUpdateAt); + lastUpdateAt = now; + for (const g of ghosts.values()) { + // Stream-health verdict with hysteresis (see HIDE_GAP_MS block): + // judge on the measured cadence AND the live silence since the + // last packet, so a sender that stopped entirely starts fading + // before the 5 s stale sweep removes it. + const sparse = Math.max(g.gapAvg, now - g.lastSeen); + if (sparse > HIDE_GAP_MS) { + g.showSince = null; + if (g.hideSince === null) g.hideSince = now; + else if (now - g.hideSince >= HIDE_SUSTAIN_MS) g.fadeTarget = 0; + } else if (sparse < SHOW_GAP_MS) { + g.hideSince = null; + if (g.showSince === null) g.showSince = now; + else if (now - g.showSince >= SHOW_SUSTAIN_MS) g.fadeTarget = 1; + } else { + g.hideSince = g.showSince = null; // dead band: hold current state + } + if (g.fade !== g.fadeTarget) { + const step = dt / FADE_MS; + g.fade += Math.min(step, Math.max(-step, g.fadeTarget - g.fade)); + } + if (g.fade !== g.appliedFade) applyFade(g); + g.rig.placer.visible = g.revealed && g.fade > 0; + // Adaptive playback delay: track the measured arrival cadence with + // margin, floored at the healthy-peer delay. Slew-limited to half + // real time so render time never runs backward while the delay + // grows (slow-motion instead of reverse) and only gently + // fast-forwards (x1.5) while it shrinks back. + const target = Math.min( + INTERP_DELAY_MAX_MS, + Math.max(INTERP_DELAY_MS, g.gapAvg * 1.25 + 50), + ); + const slew = dt * DELAY_SLEW; + g.delay += Math.min(slew, Math.max(-slew, target - g.delay)); + const renderT = now - g.delay; + const buf = g.buf; + // Drop snapshots fully in the past; keep [0] and [1] bracketing + // renderT (or the two newest, if renderT has caught up). + while (buf.length > 2 && buf[1].at <= renderT) buf.shift(); + const a = buf[0]; + const b = buf.length > 1 ? buf[1] : a; + // Clamped: before the segment -> a, past the newest -> hold b. + const span = b.at - a.at; + const u = span > 0 ? Math.min(1, Math.max(0, (renderT - a.at) / span)) : 1; + // Trunk pose in raw MJCF coords: the cloned root applies Z-up -> Y-up. + g.trunk.position.set( + a.p[0] + (b.p[0] - a.p[0]) * u, + a.p[1] + (b.p[1] - a.p[1]) * u, + a.p[2] + (b.p[2] - a.p[2]) * u, + ); + _qa.set(a.p[4], a.p[5], a.p[6], a.p[3]); // THREE order x,y,z,w + _qb.set(b.p[4], b.p[5], b.p[6], b.p[3]); + g.trunk.quaternion.copy(_qa.slerp(_qb, u)); + for (let i = 0; i < jointNames.length; i++) { + setJoint(g.rig, jointNames[i], a.j[i] + (b.j[i] - a.j[i]) * u); + } + setJawOpen(g.rig, a.w + (b.w - a.w) * u); + driveBall(g, a.b, b.b, u); + } + }, + }; + liveInstances.add(api); + return api; +} diff --git a/app/src/game/haptics.js b/app/src/game/haptics.js new file mode 100644 index 0000000..5b9882e --- /dev/null +++ b/app/src/game/haptics.js @@ -0,0 +1,139 @@ +// Gamepad haptics engine: named one-shot pulses plus a continuous rumble +// bed, multiplexed onto the single dual-rumble channel the Gamepad API +// exposes per pad (playEffect always REPLACES the running effect - there +// is no hardware mixing, so the mixing policy lives here). +// +// Model (the usual game-feel split): +// strongMagnitude = heavy low-frequency motor -> mass, impacts, thuds +// weakMagnitude = light high-frequency motor -> texture, ticks +// +// Pulses are named presets with a priority: while one is playing, a +// lower-priority pulse is dropped (a wall bump can never eat the fall +// thud) and an equal/higher one takes the channel. `scale` multiplies +// both magnitudes so impact-style cues can ride the physics (ball |dv|, +// bump strength). Presets may be sequences (multi-tap patterns) - taps +// are scheduled with timeouts and cancelled wholesale if another pulse +// takes over mid-pattern. +// +// The bed is a 0..1 level written every control step (roller ground +// speed); it keeps the motors alive between pulses by re-issuing a short +// overlapping effect, yields the instant a pulse fires, and resumes when +// the pulse expires. Everything is fire-and-forget and safe without a +// pad or actuator (Safari, some Firefox/driver stacks): silent no-op. + +import { pickPad } from "./controls/gamepad.js"; + +// Kill switch, mirroring SOUND_DISABLED in audio.js: flip to true and +// every entry point below early-returns. +const HAPTICS_DISABLED = false; + +// One-shot presets. d/gap in ms, s/w = strong/weak magnitudes (0..1 +// before scale), prio decides who wins the single channel. +const EFFECTS = { + // Confirmed fall (recovery entry or non-recoverable tip-over). + fall: { prio: 3, seq: [{ d: 450, s: 1.0, w: 0.7 }] }, + // Solver explosion -> instant reset: the hardest hit in the game. + explode: { prio: 4, seq: [{ d: 550, s: 1.0, w: 1.0 }] }, + // Barrel roll finished upright: landing thump. + land: { prio: 2, seq: [{ d: 170, s: 0.7, w: 0.35 }] }, + // Kick swing launch (the ball contact rides ballHit on top). + kick: { prio: 1, seq: [{ d: 90, s: 0.5, w: 0.2 }] }, + // Ball impact felt through the body - scaled by the hit's |dv|. + ballHit: { prio: 2, seq: [{ d: 120, s: 0.85, w: 0.4 }] }, + // Trunk bump against a wall or prop - scaled by |dv|. + bump: { prio: 1, seq: [{ d: 130, s: 0.55, w: 0.25 }] }, + // Recovery success (the duck got back up): light double tap. + recover: { prio: 2, seq: [{ d: 70, s: 0.3, w: 0.45 }, { gap: 90 }, { d: 100, s: 0.5, w: 0.65 }] }, +}; + +// Bed tuning: texture-forward (weak motor), a whisper of mass underneath. +const BED_REFRESH_MS = 240; // re-issue cadence; duration overlaps 2x +const BED_STRONG = 0.12; +const BED_WEAK = 0.4; +const BED_FLOOR = 0.03; // below this the bed is considered off + +let current = { until: 0, prio: 0 }; // the pulse owning the channel +let seqGen = 0; // generation token: bumping it cancels pending seq taps +let bedLevel = 0; +let bedIssuedAt = 0; +let bedActive = false; + +const actuator = () => pickPad()?.vibrationActuator ?? null; + +const play = (act, step, scale) => { + act + .playEffect("dual-rumble", { + duration: step.d, + strongMagnitude: Math.min(1, step.s * scale), + weakMagnitude: Math.min(1, step.w * scale), + }) + .catch(() => {}); +}; + +function pulse(name, scale = 1) { + if (HAPTICS_DISABLED) return; + const fx = EFFECTS[name]; + if (!fx) return; + const act = actuator(); + if (!act?.playEffect) return; + const now = performance.now(); + if (now < current.until && fx.prio < current.prio) return; + seqGen++; // cancel any in-flight sequence from the previous pulse + const gen = seqGen; + let at = 0; + let total = 0; + for (const step of fx.seq) total += (step.gap ?? 0) + (step.d ?? 0); + current = { until: now + total, prio: fx.prio }; + bedActive = false; // the pulse owns the channel; tick() resumes the bed + for (const step of fx.seq) { + at += step.gap ?? 0; + if (!step.d) continue; + if (at === 0) { + play(act, step, scale); + } else { + setTimeout(() => { + if (gen !== seqGen) return; // a newer pulse took the channel + const a = actuator(); // pad may have been yanked meanwhile + if (a?.playEffect) play(a, step, scale); + }, at); + } + at += step.d; + } +} + +// Continuous rumble level (0..1), meant to be written every control step +// (it only becomes motion through tick()). +function setBed(level) { + bedLevel = HAPTICS_DISABLED ? 0 : Math.max(0, Math.min(1, level)); +} + +// Channel scheduler, called once per control step: re-issues the bed +// while it's on and no pulse owns the channel, and cuts the motors when +// the bed falls silent (playEffect would otherwise finish the last +// overlap on its own, a ~0.5 s tail). +function tick() { + if (HAPTICS_DISABLED) return; + const now = performance.now(); + if (now < current.until) return; + const act = actuator(); + if (!act) return; + if (bedLevel > BED_FLOOR) { + if (now - bedIssuedAt >= BED_REFRESH_MS) { + bedIssuedAt = now; + bedActive = true; + act + .playEffect?.("dual-rumble", { + duration: BED_REFRESH_MS * 2, + strongMagnitude: Math.min(1, BED_STRONG * bedLevel), + weakMagnitude: Math.min(1, BED_WEAK * bedLevel), + }) + .catch(() => {}); + } + } else if (bedActive) { + bedActive = false; + bedIssuedAt = 0; + try { act.reset?.()?.catch?.(() => {}); } catch { /* older impls throw sync */ } + } +} + +export const haptics = { pulse, setBed, tick }; diff --git a/app/src/game/props.js b/app/src/game/props.js new file mode 100644 index 0000000..1cd8a2d --- /dev/null +++ b/app/src/game/props.js @@ -0,0 +1,338 @@ +// Prop library: every decorative GLB the arena can dress itself with. +// +// Each entry is fully declarative; adding a prop = dropping a GLB in +// public/assets/props/ and appending a def here, removing one from the +// scene = enabled: false (the asset stays in the repo - that's the +// library). The scene loads every enabled prop, snaps it to the floor, +// gives it a wireframe materialization FX and registers it with the +// entrance/respawn ceremony. +// +// Def shape: +// id unique key (also the group key in the loaded map) +// glb file under ./assets/props/ (cache-bust with ?v=N) +// enabled false = stays in the library, never touches the scene +// size { axis: "x"|"y"|"z"|"max", m } - the NATURAL bbox extent +// along that axis is scaled to m meters (three.js axes: +// y up). Robust to re-exported assets of any raw size. +// rotation [rx, ry, rz] euler (rad) applied to the model +// rotationOrder optional three.js euler order (default "XYZ") +// position [x, z] floor coords; y is auto-snapped so the posed +// bbox rests on the floor +// lift optional extra y (m) on top of the floor snap, for +// props staged on top of another prop (boombox on the +// skateboard deck) +// fxDelay seconds after the duck's scan cue (see ceremony.addPropFx) +// wireNode optional mesh name inside the GLB used as a coarser +// stand-in for the hologram pass (fxWireGeometry escape +// hatch, see fx-wireframe.js) +// instances optional [{ position, rotation?, fxDelay? }] to place +// several clones sharing geometry/materials (arcade row) +// collider optional static MJCF box(es) so the duck/ball can't +// clip through: { pos: [x,y,z], size: [hx,hy,hz], +// euler?: [rx,ry,rz] } in MJCF coords (z up, radians; +// three.js z = -mjcf y, three.js yaw = mjcf z-yaw) or +// an array +// +// World context for placements (see constants.js): 3 x 3 m arena, +// walls at +-1.5 m and only 0.25 m tall, duck spawns at (-0.6, 0) +// facing +X, relief bumps at MJCF (0.3,-0.9) (-0.9,0.75) (0.6,0.9) +// r ~0.55. Props are REAL-WORLD size on purpose: the 0.25 m duck lives +// in a 90s kid's room among human-scale objects. +// +// NOTE: skateboard/crt-tv/boombox/lavalamp/sneakers/segaconsole GLBs +// were remodeled in Blender to the arcade cabinet's quality bar +// (~3-9k tris each, chunky bevels, same orange/mint/cream palette; +// Tripo still had no credits - scripts in microduck-props/scripts/). +// Each GLB embeds a coarse _wire mesh (~500 tris) used via +// wireNode for the hologram pass, like arcade_wire. The walkman was +// remodeled separately (low-poly, palette-matched). + +import { ARCADE_H, ARCADE_W, ARCADE_D } from "./constants.js"; + +// Master switch: false = the whole library stays benched (no prop in the +// scene, no prop collider), regardless of per-def `enabled` flags. +export const PROPS_ENABLED = false; + +// ── Vignette anchors ────────────────────────────────────────────────── +// "Someone parked their music ride": skateboard flat on its wheels in +// the back-left pocket (three.js [-1.08, 1.02], clear of the duck spawn +// at [-0.6, 0] and of every relief bump), yawed ~26 deg off the back +// wall, with the boombox resting on the deck facing the arena center. +const BOARD_POS = [-1.08, 1.02]; // three.js [x, z] +const BOARD_YAW = Math.PI / 2 + 0.45; // ~26 deg off the -X wall axis +const BOOMBOX_YAW = BOARD_YAW + 0.05; // slightly askew, still on the deck +// Deck surface height measured from the GLB (flat between the kicktails +// for |x| < 0.28 m scaled - the 0.55 m boombox fits exactly) after the +// 0.79 m size normalization: wheels on the floor, deck top at 0.118 m. +const DECK_TOP = 0.118; +// CRT corner-ish on the front wall, screen swivelled toward the center. +const TV_YAW = -Math.PI / 2 + 0.28; // GLB fronts +Z; -PI/2 faces -X +// Arcade cabinet anchoring the front-south corner at 45 deg, jukebox +// style (no jukebox GLB in the library; the cabinet plays that role). +const ARCADE_YAW = -3 * (Math.PI / 4); // front +Z toward the arena center + +export const PROP_DEFS = [ + { + // Back from the bench: a single cabinet anchoring the front-south + // corner like a jukebox (the 3-cabinet row stays retired). + id: "arcade", + glb: "arcade.glb?v=1", + enabled: true, + size: { axis: "y", m: ARCADE_H }, + wireNode: "arcade_wire", + rotation: [0, ARCADE_YAW, 0], + position: [1.13, 1.13], + fxDelay: 0.85, + collider: { + pos: [1.13, -1.13, ARCADE_H / 2], + size: [ARCADE_W / 2, ARCADE_D / 2, ARCADE_H / 2], + euler: [0, 0, ARCADE_YAW], + }, + }, + { + // Real-size board (~0.79 m) flat on its wheels in the back-left + // pocket, casually yawed off the wall grid - the boombox's ride. + id: "skateboard", + glb: "skateboard.glb?v=3", + enabled: true, + size: { axis: "x", m: 0.79 }, + wireNode: "skateboard_wire", + rotation: [0, BOARD_YAW, 0], + position: BOARD_POS, + fxDelay: 0.25, + // Main box tops out at the flat deck (0.118 m); the kicktails rise + // to ~0.16 m over local |x| 0.32-0.395, so each tail gets its own + // small box. The boombox stack is untouched: its visual lift and + // its own static collider both key off DECK_TOP, not these boxes. + collider: [ + { + pos: [BOARD_POS[0], -BOARD_POS[1], 0.059], + size: [0.395, 0.166, 0.059], + euler: [0, 0, BOARD_YAW], + }, + ...[1, -1].map((side) => ({ + pos: [ + BOARD_POS[0] + side * 0.357 * Math.cos(BOARD_YAW), + -BOARD_POS[1] + side * 0.357 * Math.sin(BOARD_YAW), + 0.138, + ], + size: [0.038, 0.15, 0.022], + euler: [0, 0, BOARD_YAW], + })), + ], + }, + { + // Benched to the library (scene declutter): parked ON the skateboard + // deck (lift = deck surface height), speakers facing the arena. + id: "boombox", + glb: "boombox.glb?v=2", + enabled: false, + size: { axis: "x", m: 0.55 }, + wireNode: "boombox_wire", + rotation: [0, BOOMBOX_YAW, 0], // GLB fronts +Z; face the center + position: BOARD_POS, + lift: DECK_TOP, + fxDelay: 0.55, + collider: { + pos: [BOARD_POS[0], -BOARD_POS[1], DECK_TOP + 0.17], + size: [0.275, 0.098, 0.17], + euler: [0, 0, BOOMBOX_YAW], + }, + }, + { + // Benched to the library (scene declutter): 90s CRT near the front + // wall, swivelled toward the center like it's watching the duck. + id: "crt-tv", + glb: "crt-tv.glb?v=3", + enabled: false, + size: { axis: "x", m: 0.45 }, + wireNode: "crt_tv_wire", + rotation: [0, TV_YAW, 0], + position: [1.23, -0.42], + fxDelay: 0.7, + // Body top measured at 0.426 m world (0.416 raw x 0.45/0.44 scale); + // the antenna (up to 0.61 m) stays out on purpose - decorative. + collider: { + pos: [1.23, 0.42, 0.213], + size: [0.225, 0.211, 0.213], + euler: [0, 0, TV_YAW], + }, + }, + { + // Casually dropped on its back next to the lava lamp in the + // front-left corner, window facing the ceiling. YXZ order: lie + // flat (x +90 deg) first, then yaw in the floor plane. Natural + // bbox 0.096 x 0.124 x 0.054 -> lying footprint ~0.10 x 0.135, + // 0.059 m thick once normalized to 0.135 m tall. + id: "walkman", + glb: "walkman.glb?v=4", + enabled: true, + size: { axis: "y", m: 0.135 }, + rotation: [Math.PI / 2, 0.6, 0], + rotationOrder: "YXZ", + position: [1.22, -1.0], + fxDelay: 0.4, + collider: { + pos: [1.22, 1.0, 0.03], + size: [0.055, 0.07, 0.03], + euler: [0, 0, 0.6], + }, + }, + { + // Classic 45 cm board, palette-remapped sectors (dark/cream + // singles, orange/mint rings), 3 darts stuck in. Not hung yet: + // resting on the floor, leaning against the left (-Z) wall in the + // FRONT corner. That's the only pose the boot chase-cam can see: + // it pitches 24 deg down at the duck with a 20 deg vertical + // half-FOV, so wall points above ~0.37 m are always clipped - + // a duck-height mount can never be in the boot frame. Visible + // left-wall window at boot: x in [1.03, 1.5], y < 0.37 m. GLB + // fronts +Z; x-tilt -0.12 leans the top into the wall, floor + // snap keeps the bottom rim grounded. On the floor the ball can + // reach it, so it gets a thin box collider (upright: the 7 deg + // lean offset is ~1 cm at ball height, not worth an euler). + id: "dartboard", + glb: "dartboard.glb?v=1", + enabled: true, + size: { axis: "x", m: 0.47 }, + wireNode: "dartboard_wire", + rotation: [-0.12, 0, 0], + position: [1.2, -1.42], + fxDelay: 0.6, + collider: { + pos: [1.2, 1.42, 0.235], + size: [0.235, 0.06, 0.235], + }, + }, + { + // Mood light in the FRONT-LEFT corner of the arena: mint hourglass + // base and dome cap, translucent orange vessel with baked emissive + // lava blobs (concept prop-lava-lamp-concept-v2). 0.25 m off both + // walls, clear of the (0.6, -0.9) relief bump. 0.377 m tall. + id: "lavalamp", + glb: "lavalamp.glb?v=2", + enabled: true, + size: { axis: "y", m: 0.38 }, + wireNode: "lavalamp_wire", + rotation: [0, 0, 0], + position: [1.25, -1.25], + fxDelay: 0.9, + collider: { pos: [1.25, 1.25, 0.19], size: [0.072, 0.072, 0.19] }, + }, + { + // Benched to the library (scene declutter): orange canvas high-top + // pair, one upright, one tipped on its side (poses baked in the + // GLB). Cream laces/toe caps/sole, mint eyelets + foxing stripe, + // generic 4-point-star ankle patch - no trademark art (concept + // prop-sneakers-concept-v2). Each shoe ~0.28 m long. + id: "sneakers", + glb: "sneakers.glb?v=2", + enabled: false, + size: { axis: "x", m: 0.41 }, + wireNode: "sneakers_wire", + rotation: [0, 2.35, 0], + position: [-1.22, -0.22], + fxDelay: 0.35, + collider: { + pos: [-1.22, 0.22, 0.09], + size: [0.205, 0.15, 0.09], + euler: [0, 0, 2.35], + }, + }, + { + // Benched to the library (scene declutter, like its CRT): Genesis + // -like 16-bit console with two wired mint pads (concept + // prop-console-concept-v2b, no logos). Collider covers the 0.30 m + // body slab only - pads, cables and plinth stay decorative. + id: "segaconsole", + glb: "segaconsole.glb?v=2", + enabled: false, + size: { axis: "x", m: 0.3 }, + wireNode: "segaconsole_wire", + rotation: [0, TV_YAW, 0], + position: [0.87, -0.38], + fxDelay: 0.5, + collider: { + pos: [0.87, 0.38, 0.031], + size: [0.15, 0.105, 0.031], + euler: [0, 0, TV_YAW], + }, + }, +]; + +// Static MJCF collision boxes for every enabled prop, consumed by +// buildPhysicsXml. Purely declarative: no GLB needs to be loaded. +export function propColliders() { + if (!PROPS_ENABLED) return []; + const out = []; + for (const def of PROP_DEFS) { + if (!def.enabled || !def.collider) continue; + const boxes = Array.isArray(def.collider) ? def.collider : [def.collider]; + boxes.forEach((c, i) => { + out.push({ + name: boxes.length > 1 ? `prop_${def.id}_${i}` : `prop_${def.id}`, + pos: c.pos.join(" "), + size: c.size.join(" "), + euler: c.euler?.join(" "), + }); + }); + } + return out; +} + +// Load every enabled prop into the scene and register its wireframe +// materialization with the ceremony. Returns { id: [group, ...] }. +// Props are decorative: a missing/broken GLB never halts the boot. +export async function loadProps({ + THREE, GLTFLoader, signed, scene, camera, renderer, fx, ceremony, +}) { + if (!PROPS_ENABLED) return {}; + const loader = new GLTFLoader(); + const groups = {}; + await Promise.all(PROP_DEFS.filter((d) => d.enabled).map(async (def) => { + try { + const gltf = await loader.loadAsync(signed(`./assets/props/${def.glb}`)); + const proto = gltf.scene; + const wire = def.wireNode ? proto.getObjectByName(def.wireNode) : null; + wire?.removeFromParent(); + const nat = new THREE.Box3().setFromObject(proto); + const natSize = nat.getSize(new THREE.Vector3()); + const extent = def.size.axis === "max" + ? Math.max(natSize.x, natSize.y, natSize.z) + : natSize[def.size.axis]; + proto.scale.setScalar(def.size.m / extent); + const instances = def.instances + ?? [{ position: def.position, rotation: def.rotation }]; + groups[def.id] = instances.map((inst, i) => { + // clone(true) shares geometry/materials; userData doesn't + // survive Object3D.copy, so the wire tag is applied per clone. + const node = i === 0 ? proto : proto.clone(true); + if (wire) { + node.traverse((o) => { + if (o.isMesh) o.userData.fxWireGeometry = wire.geometry; + }); + } + const rot = inst.rotation ?? def.rotation ?? [0, 0, 0]; + node.quaternion.setFromEuler( + new THREE.Euler(...rot, def.rotationOrder ?? "XYZ"), + ); + const group = new THREE.Group(); + group.add(node); + // Floor snap: whatever the GLB's pivot, the posed bbox rests + // on the ground at the declared floor coords; `lift` raises it + // on top of another prop (boombox on the skateboard deck). + const posed = new THREE.Box3().setFromObject(group); + const lift = inst.lift ?? def.lift ?? 0; + group.position.set(inst.position[0], -posed.min.y + lift, inst.position[1]); + scene.add(group); + const propFx = fx.createWireframeFx(); + propFx.init({ THREE, scene, root: group, camera, renderer, hidden: true }); + ceremony.addPropFx(propFx, inst.fxDelay ?? def.fxDelay ?? 0.3); + return group; + }); + } catch (err) { + console.warn(`[props] "${def.id}" disabled:`, err); + } + })); + return groups; +} diff --git a/app/src/game/signed.js b/app/src/game/signed.js new file mode 100644 index 0000000..7c59a06 --- /dev/null +++ b/app/src/game/signed.js @@ -0,0 +1,13 @@ +// Private HF Space auth: the hub iframe URL carries a ?__sign JWT, but +// subresource requests normally rely on a *.static.hf.space cookie that +// browsers often block inside the iframe (third-party cookie blocking), +// which 401s every same-origin fetch. Appending the JWT to each request +// authenticates them regardless of cookie policy. No-op locally. +// +// Only ASSET requests (meshes, policies, XML, audio, images) go through +// this now: application code ships in the Vite bundle, which the page load +// itself already authenticated. +const HF_SIGN = new URLSearchParams(location.search).get("__sign"); + +export const signed = (url) => + HF_SIGN ? `${url}${url.includes("?") ? "&" : "?"}__sign=${encodeURIComponent(HF_SIGN)}` : url; diff --git a/app/src/game/stickers.js b/app/src/game/stickers.js new file mode 100644 index 0000000..79ad61d --- /dev/null +++ b/app/src/game/stickers.js @@ -0,0 +1,222 @@ +// Comic sticker popups: on notable game events (kick, quack, roll, ball +// spawn, ghost peer joining) a die-cut sticker or a comic onomatopoeia pops +// at a semi-random spot on screen, overshoots in, then fades out. Pure +// CSS animations, no dependencies. +// +// Fully self-contained and OPTIONAL: this module owns its DOM layer and its +// +
+

Microduck Soundboard

+

+ A/B: current runtime implementation vs ZzFX candidate. First click unlocks audio. +

+ +
+ +
+
+ SoundCategoryCurrentZzFX candidate +
+ {rows.map((r) => ( +
+ + {r.name} + {r.note} + + {r.cat} + + + + + {r.zz + ? r.zz.map(([label, params]) => ( + + )) + : n/a (voice reference)} + +
+ ))} +
+ +

Loops

+
+ {loops.map((l) => ( +
+ + {l.name} + {l.note} + + {l.cat} + + + + n/a +
+ ))} +
+ + ); +} + +const CSS = ` +/* The game's index.html pins body { overflow: hidden } for the canvas; + this page is a document, so re-enable normal scrolling. */ +html, body { height: auto; overflow: auto; } +#root { height: auto; } +.sb-root { + min-height: 100vh; + background: #faf8f2; + color: #101018; + font: 15px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; + padding: 2.2rem clamp(1rem, 5vw, 4rem) 4rem; +} +.sb-head h1 { + font-family: 'Anton', 'Arial Narrow', Impact, sans-serif; + font-size: clamp(2rem, 5vw, 3.2rem); + text-transform: uppercase; + letter-spacing: 0.02em; + margin: 0; + color: #101018; + -webkit-text-stroke: 1px #101018; +} +.sb-sub { margin: 0.3rem 0 1.2rem; opacity: 0.75; } +.sb-vol { + display: inline-flex; align-items: center; gap: 0.7rem; + border: 2px solid #101018; background: #fff; + padding: 0.5rem 0.9rem; box-shadow: 4px 4px 0 #101018; + margin-bottom: 1.6rem; font-weight: 700; +} +.sb-vol input { accent-color: #ff7a2f; width: 200px; } +.sb-h2 { + font-family: 'Anton', 'Arial Narrow', Impact, sans-serif; + text-transform: uppercase; margin: 2rem 0 0.6rem; +} +.sb-grid { border: 2px solid #101018; background: #fff; box-shadow: 6px 6px 0 #101018; } +.sb-row { + display: grid; + grid-template-columns: minmax(220px, 1.6fr) 110px 130px minmax(160px, 1fr); + align-items: center; gap: 0.8rem; + padding: 0.55rem 0.9rem; + border-bottom: 1px solid rgba(16, 16, 24, 0.18); +} +.sb-row:last-child { border-bottom: none; } +.sb-row-head { + font-weight: 700; text-transform: uppercase; font-size: 12px; + background: #101018; color: #faf8f2; +} +.sb-name { display: flex; flex-direction: column; font-weight: 700; } +.sb-name small { font-weight: 400; opacity: 0.6; font-size: 11px; } +.sb-cat { + font-style: normal; font-size: 11px; font-weight: 700; + text-transform: uppercase; padding: 2px 7px; border: 1.5px solid #101018; +} +.sb-cat-sampled { background: #ffe9db; } +.sb-cat-synth { background: #e5eeff; } +.sb-cat-voice { background: #fff3b0; } +.sb-btn { + font: inherit; font-weight: 700; text-transform: uppercase; font-size: 12px; + border: 2px solid #101018; padding: 0.35rem 0.9rem; cursor: pointer; + box-shadow: 3px 3px 0 #101018; background: #faf8f2; color: #101018; + margin: 2px 6px 2px 0; +} +.sb-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #101018; } +.sb-btn:focus-visible { outline: 3px solid #ff7a2f; outline-offset: 2px; } +.sb-btn-zz { background: #ff7a2f; color: #101018; } +.sb-btn-cur.sb-on { background: #101018; color: #faf8f2; } +.sb-na { opacity: 0.5; font-size: 12px; } +@media (max-width: 700px) { + .sb-row { grid-template-columns: 1fr; gap: 0.3rem; } + .sb-row-head { display: none; } +} +`; diff --git a/app/src/ui/TitleMenu.jsx b/app/src/ui/TitleMenu.jsx new file mode 100644 index 0000000..c579860 --- /dev/null +++ b/app/src/ui/TitleMenu.jsx @@ -0,0 +1,751 @@ +// Title / pause overlay: a full-page ink screen printed in the landing's +// comic DA - big Anton title with the ink-drop + cyan/magenta aberration +// treatment, a comic-block CTA on an acid plate, and an orange halftone +// ramp pooling in the top-left corner. Colour and locomotion live in the +// in-game HUD quickbar, so the intro's only action is Waddle in. +// +// The first "Waddle in" cues the BIOS; later Esc / the in-game Back button +// reopen the overlay as pause ("Resume"). The ?boot=1 bypass lives in +// App.jsx and never mounts this component. +import { useEffect, useRef, useState } from "react"; +import Box from "@mui/material/Box"; +import Typography from "@mui/material/Typography"; +import { keyframes, styled } from "@mui/material/styles"; +import { useGame } from "../store.js"; +import { signed } from "../game/signed.js"; +import { playConfirmBloop } from "../game/audio.js"; +import { INK, ORANGE, MONO } from "../theme.js"; +import { ComicButton, ComicTitle, HalftoneRamp, ANTON, CREAM } from "./comic.jsx"; +import MenuDuck, { preloadMenuDuck, isMenuDuckReady } from "./MenuDuck.jsx"; +import { PreorderButton } from "./Hud.jsx"; +import { readLayoutMap, resolveKeycaps } from "./keyboard-layout.js"; + +const rowIn = keyframes` + from { transform: translateY(12px); opacity: 0; } + to { transform: none; opacity: 1; } +`; +const brandIn = keyframes` + from { transform: translateY(10px) scale(0.94); opacity: 0; } + to { transform: none; opacity: 1; } +`; +// Title-screen blink for the "press Enter" prompt - a soft pulse, not a +// hard arcade strobe, so it invites rather than nags. +const promptPulse = keyframes` + from { opacity: 0.8; } + to { opacity: 0.18; } +`; +const spin = keyframes` + to { transform: rotate(360deg); } +`; +// One soft ease, small travel, ~80 ms between rows - staged, not showy. +const row = (delay, name = rowIn) => ({ + animation: `${name} 0.55s cubic-bezier(0.22, 1, 0.36, 1) both`, + animationDelay: `${delay}s`, + "@media (prefers-reduced-motion: reduce)": { animation: "none" }, +}); + +const Kbd = styled("kbd")(({ round }) => ({ + display: "inline-flex", + alignItems: "center", + justifyContent: "center", + minWidth: round ? "1.9rem" : "1.65rem", + height: "1.65rem", + padding: "0 0.45rem", + font: "inherit", + fontSize: "0.68rem", + fontWeight: 600, + color: "#fff", + background: "#14141c", + border: `2px solid ${INK}`, + borderRadius: round ? "50%" : 8, + boxShadow: "0 0 0 2px rgba(255, 255, 255, 0.82)", +})); + +// Arcade-style cheat strip pinned at the bottom of the title screen: one +// keycap group + label per move, scannable in a second. The CTA is the +// screen's centre of gravity - players enter first and learn in game. +// Controls bind physical KeyboardEvent.code positions, so letter keycaps +// carry `codes` and get their printed label resolved for the active layout +// (QWERTY fallback where the Keyboard Map API is unavailable). +const SHORTCUTS = { + kb: [ + { caps: ["\u2191\u2190\u2193\u2192"], name: "Move" }, + { codes: ["KeyQ", "KeyE"], name: "Kick" }, + { codes: ["KeyR"], name: "Sit" }, + { codes: ["KeyG"], name: "Pick up" }, + { codes: ["KeyC"], name: "Camera" }, + { caps: ["Space"], name: "Reset" }, + ], + pad: [ + { caps: ["LS"], name: "Move" }, + { caps: ["LB", "RB"], name: "Kick" }, + { caps: ["Y"], name: "Head" }, + { caps: ["RS"], name: "Camera" }, + { caps: ["X", "\u2193"], name: "Sit" }, + ], + touch: [ + { caps: ["Stick"], name: "Move" }, + { caps: ["A"], round: true, name: "Kick" }, + { caps: ["B"], round: true, name: "Quack" }, + ], +}; +// kb's hint is built at render time from the resolved layout (see kbHint). +const HINTS = { + pad: "A ground pick \u00b7 RT quack \u00b7 hold LT wheee \u00b7 R3 chase", + touch: "drag to orbit \u00b7 pinch to zoom", +}; + +// Per-colourway screen accent: the title fill and the halftone pool +// follow the duck on stage. Cream keeps the landing's brand orange (the +// classic duck's trim colour); lavender and sky use the press-kit swatch +// hexes (shared with the vitrine picker); graphite's swatch is too dark +// for type on ink, so it wears the palette's light warm gray instead. +const VARIANT_ACCENTS = { + classic: ORANGE, + charcoal: "#b9b5ae", + purple: "#bfa9cf", + blue: "#a9dbe8", +}; + +// #rrggbb -> rgba() at the halftone's alpha. +const tint = (hex, a) => + `rgba(${parseInt(hex.slice(1, 3), 16)}, ${parseInt(hex.slice(3, 5), 16)}, ${parseInt(hex.slice(5, 7), 16)}, ${a})`; + +const KB_CODES = SHORTCUTS.kb.flatMap((t) => t.codes ?? []); + +function useKeycaps(enabled) { + const [keycaps, setKeycaps] = useState(() => resolveKeycaps(KB_CODES, null)); + + useEffect(() => { + if (!enabled) return; + let cancelled = false; + let latest = 0; + const read = async () => { + const ticket = ++latest; + const map = await readLayoutMap(); + // Overlapping reads can settle out of order; only the newest paints. + if (!cancelled && ticket === latest) setKeycaps(resolveKeycaps(KB_CODES, map)); + }; + read(); + const keyboard = navigator.keyboard; + keyboard?.addEventListener?.("layoutchange", read); + return () => { + cancelled = true; + keyboard?.removeEventListener?.("layoutchange", read); + }; + }, [enabled]); + + return keycaps; +} + +function closeMenu() { + useGame.setState({ menuOpen: false }); + if (!useGame.getState().entered) useGame.setState({ entered: true }); + // Menu-confirm bloop. On the first entry the `entered` latch above has + // just created the shared AudioContext inside this very gesture, so the + // bloop rides the unlock (the synth resume-retries if still suspended). + playConfirmBloop(); +} + +export default function TitleMenu() { + const menuOpen = useGame((s) => s.menuOpen); + const entered = useGame((s) => s.entered); + const padConnected = useGame((s) => s.padConnected); + const touchMode = useGame((s) => s.touchMode); + const variant = useGame((s) => s.variant); + const bootDone = useGame((s) => s.bootDone); + const bootFailed = useGame((s) => s.bootFailed); + const [closing, setClosing] = useState(false); + const prevOpen = useRef(menuOpen); + // A plugged-in gamepad wins over the touch tutorial. + const tutorialVariant = padConnected ? "pad" : touchMode ? "touch" : "kb"; + const { labels, moveHint } = useKeycaps(tutorialVariant === "kb"); + + // Touch devices and narrow (mobile-sized) screens skip the 3D stage + // entirely: no duck column, and the GLB is never even downloaded. The + // width check matches the layout's md breakpoint, so the stage never + // renders where the column would stack under the text anyway. Everyone + // else holds a spinner until the stage's assets are in, so the content + // reveal and the duck's entrance scan cue together. The stage is a + // module singleton, so pause reopens resolve instantly (no second + // spinner). + const [wide, setWide] = useState( + () => window.matchMedia("(min-width: 900px)").matches, + ); + useEffect(() => { + const mq = window.matchMedia("(min-width: 900px)"); + const onChange = () => setWide(mq.matches); + mq.addEventListener("change", onChange); + return () => mq.removeEventListener("change", onChange); + }, []); + const showDuck = !touchMode && wide; + const [duckReady, setDuckReady] = useState(isMenuDuckReady); + useEffect(() => { + if (!showDuck || duckReady) return; + let on = true; + preloadMenuDuck() + .catch(() => {}) + .then(() => { if (on) setDuckReady(true); }); + return () => { on = false; }; + }, [showDuck, duckReady]); + + // The display face too: Anton is the screen's voice (title, CTA, + // strip) and would otherwise FOUT in after the reveal. It loads + // lazily on first use, so nudge it explicitly - the content is gated + // and would never request it. Timeout so a stuck font never wedges + // the menu behind the spinner. + const [fontsReady, setFontsReady] = useState( + () => !!document.fonts?.check?.("1rem Anton"), + ); + useEffect(() => { + if (fontsReady) return; + let on = true; + const done = () => { if (on) setFontsReady(true); }; + const anton = document.fonts?.load + ? document.fonts.load("1rem Anton") + : Promise.resolve(); + const allFonts = document.fonts?.ready ?? Promise.resolve(); + Promise.all([anton, allFonts]).then(done, done); + const t = setTimeout(done, 4000); + return () => { on = false; clearTimeout(t); }; + }, [fontsReady]); + + // The brand lockup images too (formerly the preboot veil's job): the + // corner chrome is part of the gated reveal, so the logo must not pop + // in after it. Capped so a broken asset never wedges the menu. + const [brandReady, setBrandReady] = useState(false); + useEffect(() => { + if (brandReady) return; + let on = true; + const done = () => { if (on) setBrandReady(true); }; + const load = (src) => + new Promise((res) => { + const img = new Image(); + img.src = signed(src); + if (img.complete && img.naturalWidth) res(); + else { + img.addEventListener("load", res, { once: true }); + img.addEventListener("error", res, { once: true }); + } + }); + Promise.all([ + load("./assets/duck-head-mark.webp"), + load("./assets/duck-head-mark-open.webp"), + ]).then(done, done); + const t = setTimeout(done, 2500); + return () => { on = false; clearTimeout(t); }; + }, [brandReady]); + + // The game core too: it boots eagerly behind the title screen (MuJoCo + // WASM, scene geometry, policy sessions), saturating the main thread + // in ~10-40 ms chunks for a couple of seconds. Revealing the menu + // mid-boot made the duck's entrance scan stutter (profiled: the scan + // window sat inside the boot's busy region), so the spinner holds + // until the boot settles - the reveal then animates on a free thread + // and Waddle-in is instant. bootFailed releases the gate: the halt + // screen owns the viewport at that point. + const ready = + (duckReady || !showDuck) && + fontsReady && + brandReady && + (bootDone || bootFailed); + + // Keep the overlay mounted through the 0.35 s closing fade. + useEffect(() => { + const was = prevOpen.current; + prevOpen.current = menuOpen; + if (was && !menuOpen) { + setClosing(true); + const t = setTimeout(() => setClosing(false), 380); + return () => clearTimeout(t); + } + }, [menuOpen]); + + // Enter enters / resumes; Esc toggles the pause menu (never over the + // BIOS readout). + useEffect(() => { + const onKey = (e) => { + const s = useGame.getState(); + if (e.code === "Enter" && s.menuOpen) { + if (e.target instanceof HTMLButtonElement && e.target.dataset.cta !== "1") return; + e.preventDefault(); + closeMenu(); + return; + } + if (e.code !== "Escape") return; + if (s.biosVisible) return; + if (s.menuOpen) { + if (s.entered) closeMenu(); + return; + } + if (s.entered) useGame.setState({ menuOpen: true }); + }; + window.addEventListener("keydown", onKey); + return () => window.removeEventListener("keydown", onKey); + }, []); + + // Gamepad twin of the handler above: A (button 0) enters / resumes + // through the same closeMenu() as the CTA click; Start (9) or Select (8) + // reopens the overlay in-game, like Escape. Polled with a light rAF loop + // because the game's own gamepad source only exists once the core has + // booted (and its actions are game-facing). Edge state persists across + // the open/close transition, so one press fires exactly one action. + useEffect(() => { + const prev = { enter: false, menu: false }; + // The A press that closes the menu is applied one frame LATE on + // purpose: closing unlocks the game inputs synchronously, and the + // in-game gamepad source polls in the same rAF round - if it sees the + // press only after the unlock, its own A edge fires (groundPick). The + // one-frame delay guarantees it polls the press at least once while + // the pause lock still gates it, so by the unlock frame its edge + // state already knows the button is down and the entering press is + // swallowed. + let enterPending = false; + let raf; + const poll = () => { + raf = requestAnimationFrame(poll); + if (enterPending) { + enterPending = false; + if (useGame.getState().menuOpen) closeMenu(); + } + // Same pad preference as controls/gamepad.js: standard mapping first. + const pads = [...(navigator.getGamepads?.() ?? [])].filter((p) => p && p.connected); + const gp = pads.find((p) => p.mapping === "standard") ?? pads[0]; + if (!gp) { + prev.enter = false; + prev.menu = false; + return; + } + const enter = !!gp.buttons[0]?.pressed; + const menu = !!(gp.buttons[9]?.pressed || gp.buttons[8]?.pressed); + const enterEdge = enter && !prev.enter; + const menuEdge = menu && !prev.menu; + prev.enter = enter; + prev.menu = menu; + const s = useGame.getState(); + if (enterEdge && s.menuOpen) { + enterPending = true; + return; + } + if (menuEdge && !s.menuOpen && s.entered && !s.biosVisible) + useGame.setState({ menuOpen: true }); + }; + raf = requestAnimationFrame(poll); + return () => cancelAnimationFrame(raf); + }, []); + + if (!menuOpen && !closing) return null; + + // Letter keycaps resolved for the active layout (QWERTY fallback). + const shortcuts = + tutorialVariant === "kb" + ? SHORTCUTS.kb.map((t) => + t.codes ? { ...t, caps: t.codes.map((code) => labels[code]) } : t, + ) + : SHORTCUTS[tutorialVariant]; + // The strip's footnote names the letter movement cluster for the active + // layout too ("ZQSD works too" reads wrong on QWERTY and Dvorak). + const kbHint = `${moveHint.replace(/^arrows or /, "")} works too \u00b7 drag to orbit \u00b7 scroll to zoom`; + const ctaLabel = entered ? "Resume" : "Waddle in"; + // Blinking key prompt under the CTA; touch has no key to press. + const enterHint = padConnected ? "press A" : touchMode ? null : "press Enter"; + const accent = VARIANT_ACCENTS[variant] ?? ORANGE; + + return ( + + {/* Theme-orange halftone pooling in the top-left corner, dots + growing toward it - the landing's screen-tone on ink ground. */} + + + {/* Corner chrome, shared grammar with the vitrine header (drawn + duck head, top-left) and the in-game HUD (pre-order, top-right): + the title screen wears the same screen furniture as the game. + Gated with the rest of the reveal so the loading state is a + single centered spinner on bare ink. */} + {ready && ( + + + + {/* The open frame's canvas (460x333) is a hair wider/taller + than the closed one (454x269); offsets pin the head while + the jaw hangs below. */} + + + + Microduck + + + )} + + {/* The in-game HUD's shop plate, verbatim: same component, same + fixed spot, so pausing never swaps it for a lookalike. */} + {ready && } + + {/* Loading gate: one centered spinner on bare ink until logo, + fonts, the duck stage's assets and the game boot are all in - + then the whole composition (corner chrome included) reveals at + once (row stagger + entrance scan). */} + {!ready && ( + + + + Loading + + + )} + + {/* Split title screen: brand + CTA column on the left, the live + duck stage on the right (stacked on narrow screens). The row + stretches to fill the space between the corner chrome and the + bottom strip, so the duck stands ON the strip's rule - the + screen has a floor instead of elements floating mid-air. */} + {ready && ( + <> + + + {/* The landing hero's mistracked-VHS treatment: orange fill with + ink drop + chroma ghosts, hollow echo line below. */} + + + + The exact same trained policies that drive the real robot, + live in your browser. + + + {/* CTA + key prompt travel as one block so the prompt stays + centred under the button whatever the column's alignment. */} + + + {/* Pad prompt: ink circle with the A face button, shown while a + gamepad is connected - it mirrors the A-to-enter binding of + the poll loop above. Decorative; the text label carries the + meaning. */} + {padConnected && ( + + A + + )} + {ctaLabel} + + + {enterHint && ( + + + {enterHint} + + + )} + + + + {/* Right column: the duck's simulated twin, live - head follows the + pointer, click quacks. Its colourway tracks the in-game duck. No + backdrop, no fake shadow: the render alone, standing on the + bottom strip's rule like a character select. Touch devices skip + the stage entirely (no column, no GLB download). */} + {showDuck && ( + + + + )} + + + {/* Bottom cheat strip: every move on one wrapping line, arcade + instruction-card style. Reference material, not the main event - + it sits at the screen's bottom edge, out of the CTA's way. */} + + + {shortcuts.map((s) => ( + + + {/* Index keys: exotic layouts can print the same glyph twice. */} + {s.caps.map((c, i) => ( + {c} + ))} + + + {s.name} + + + ))} + + + + {tutorialVariant === "kb" ? kbHint : HINTS[tutorialVariant]} + + + + )} + + ); +} diff --git a/app/src/ui/TouchOverlay.jsx b/app/src/ui/TouchOverlay.jsx new file mode 100644 index 0000000..a47c6fa --- /dev/null +++ b/app/src/ui/TouchOverlay.jsx @@ -0,0 +1,128 @@ +// Touch overlay: Game Boy thumbs. Left thumb = floating virtual stick +// (the whole lower-left quadrant grabs it, the base re-anchors under the +// finger), right thumb = A/B caps on the classic diagonal. +// +// The DOM here is deliberately plain and keyed by ids: controls/touch.js +// binds pointer events to #touch-zone / #touch-stick / #touch-a / #touch-b +// at controller init and toggles the .live/.down classes itself. React +// only owns the wrapper's visibility, so it never fights those mutations - +// which is also why this component must stay mounted at all times. +import Box from "@mui/material/Box"; +import { useGame } from "../store.js"; +import { INK, ORANGE } from "../theme.js"; + +export default function TouchOverlay() { + const touchMode = useGame((s) => s.touchMode); + const entered = useGame((s) => s.entered); + const menuOpen = useGame((s) => s.menuOpen); + const visible = touchMode && entered && !menuOpen; + + return ( + +
+
+
+
+
+
+
+ + Kick +
+
+ + Quack +
+
+ + ); +} diff --git a/app/src/ui/comic.jsx b/app/src/ui/comic.jsx new file mode 100644 index 0000000..74ca56b --- /dev/null +++ b/app/src/ui/comic.jsx @@ -0,0 +1,277 @@ +// Comic-DA primitives, ported from the pollen-website Microduck landing +// (ComicButton.tsx / FancyTitle.tsx): brutal print blocks - a flat face, +// a thick ink keyline and a hard offset plate - plus the Anton display +// voice with the mistracked-VHS title treatment. Lightweight JSX +// reimplementation for the sim; no code is shared across repos on purpose. +import Box from "@mui/material/Box"; + +export const COMIC_INK = "#101018"; +export const CREAM = "#faf8f2"; +export const COMIC_ORANGE = "#FF7A2F"; +export const COMIC_YELLOW = "#FFD23F"; +// The MTV experiment's acid plate colours: on ink grounds the offset plate +// swaps to these so it still reads (ink on ink would vanish). +export const ACID_MAGENTA = "#FF2FA8"; +export const ACID_CYAN = "#2FF0E6"; +export const ANTON = "'Anton', 'Arial Narrow', Impact, sans-serif"; + +// Colour presets, same tuning as the landing: `bg` face, `text` label, +// `edge` keyline, `shadow` plate on paper grounds, `shadowOnDark` the acid +// swap for ink grounds. +const SCHEMES = { + orange: { bg: COMIC_ORANGE, text: COMIC_INK, edge: COMIC_INK, shadow: COMIC_INK, shadowOnDark: ACID_MAGENTA }, + yellow: { bg: COMIC_YELLOW, text: COMIC_INK, edge: COMIC_INK, shadow: COMIC_INK, shadowOnDark: ACID_CYAN }, + ink: { bg: COMIC_INK, text: CREAM, edge: COMIC_INK, shadow: COMIC_ORANGE, shadowOnDark: COMIC_ORANGE }, + paper: { bg: CREAM, text: COMIC_INK, edge: COMIC_INK, shadow: COMIC_INK, shadowOnDark: COMIC_ORANGE }, +}; + +// One size step below the landing's "medium": the sim's HUD and modal run +// tighter than a marketing page. "xs" is for persistent HUD controls. +const METRICS = { + xs: { fontSize: "0.78rem", padding: "7px 14px", border: 2, shadow: 4, hoverShadow: 6 }, + small: { fontSize: "0.92rem", padding: "9px 20px", border: 3, shadow: 5, hoverShadow: 7 }, + medium: { fontSize: "1.15rem", padding: "13px 30px", border: 4, shadow: 7, hoverShadow: 10 }, +}; + +/** + * The landing's CTA button: flat face, thick ink keyline, hard offset + * plate. Hover lifts the face off the plate; pressing sinks it flat onto + * it. `variant="outline"` is the ghost tier - a bare keyline that earns + * its fill and plate on hover. Set `onDark` on ink grounds so the plate + * swaps to the scheme's acid colour. + */ +export function ComicButton({ + children, + href, + target, + rel, + onClick, + variant = "filled", + scheme = "orange", + size = "small", + onDark = false, + sx, + ...rest +}) { + const colors = SCHEMES[scheme]; + const metrics = METRICS[size]; + const plate = onDark ? colors.shadowOnDark : colors.shadow; + const isOutline = variant === "outline"; + + const restShadow = `${metrics.shadow}px ${metrics.shadow}px 0 ${plate}`; + const hoverShadow = `${metrics.hoverShadow}px ${metrics.hoverShadow}px 0 ${plate}`; + const pressedShadow = `0px 0px 0 ${plate}`; + + const rootSx = { + position: "relative", + display: "inline-flex", + alignItems: "center", + justifyContent: "center", + gap: "0.5em", + boxSizing: "border-box", + fontFamily: ANTON, + fontWeight: 400, + fontSize: metrics.fontSize, + lineHeight: 1.15, + whiteSpace: "nowrap", + letterSpacing: "0.07em", + textTransform: "uppercase", + textDecoration: "none", + textAlign: "center", + padding: metrics.padding, + border: `${metrics.border}px solid`, + borderRadius: 0, + cursor: "pointer", + WebkitTapHighlightColor: "transparent", + userSelect: "none", + transition: + "transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease, color 0.12s ease", + ...(isOutline + ? { + background: "transparent", + color: colors.bg, + borderColor: colors.bg, + boxShadow: "none", + "&:hover": { + background: colors.bg, + color: colors.text, + borderColor: colors.edge, + transform: "translate(-2px, -2px)", + boxShadow: restShadow, + }, + "&:active": { + background: colors.bg, + color: colors.text, + borderColor: colors.edge, + transform: "translate(2px, 2px)", + boxShadow: pressedShadow, + }, + } + : { + background: colors.bg, + color: colors.text, + borderColor: colors.edge, + boxShadow: restShadow, + "&:hover": { + transform: "translate(-2px, -2px)", + boxShadow: hoverShadow, + }, + "&:active": { + transform: `translate(${metrics.shadow}px, ${metrics.shadow}px)`, + boxShadow: pressedShadow, + }, + }), + "&:focus-visible": { + outline: `3px dashed ${onDark ? CREAM : COMIC_INK}`, + outlineOffset: "5px", + }, + "@media (prefers-reduced-motion: reduce)": { transition: "none" }, + }; + + const combinedSx = [rootSx, ...(Array.isArray(sx) ? sx : sx ? [sx] : [])]; + + return href ? ( + + {children} + + ) : ( + + {children} + + ); +} + +// The MTV stack's knocked-askew per-line rotation cycle, in degrees. +const ROTATIONS = [-1.5, 0.75, -1]; + +/** + * FancyTitle, compressed: stacked Anton lines with the landing's two + * recipes. `tone="light"` (the cartridge label's cream ground) prints ink + * fill over a hard accent drop plate, outline echoes in bare ink; + * `tone="dark"` adds the cyan/magenta chromatic ghosts. Lines: + * `{ text, variant: "fill" | "outline", color?, scale? }` or plain strings. + */ +export function ComicTitle({ component = "h2", tone = "light", accent = COMIC_ORANGE, fontSize = "2.4rem", lines, sx }) { + const list = lines.map((l) => (typeof l === "string" ? { text: l } : l)); + const lineSx = (line, i) => { + const rotate = ROTATIONS[i % ROTATIONS.length]; + const outline = line.variant === "outline"; + if (tone === "dark") { + return outline + ? { + color: "transparent", + WebkitTextStroke: `0.032em ${line.color ?? "#ffffff"}`, + textShadow: `-0.03em 0 0 ${ACID_MAGENTA}`, + transform: `rotate(${rotate}deg)`, + } + : { + color: line.color ?? accent, + textShadow: `0.06em 0.06em 0 ${COMIC_INK}, -0.035em 0 0 ${ACID_CYAN}, 0.035em 0 0 ${ACID_MAGENTA}`, + transform: `rotate(${rotate}deg)`, + }; + } + return outline + ? { + color: "transparent", + WebkitTextStroke: `0.03em ${line.color ?? COMIC_INK}`, + transform: `rotate(${rotate}deg)`, + } + : { + color: line.color ?? COMIC_INK, + textShadow: `0.05em 0.05em 0 ${accent}`, + transform: `rotate(${rotate}deg)`, + }; + }; + return ( + + {list.map((line, i) => ( + + {line.text} + + ))} + + ); +} + +// Where the ink pools: the ramp runs from that corner/edge toward the +// opposite one (gradient start = densest dots). +const RAMP_DIRECTIONS = { + top: "to bottom", + bottom: "to top", + "top-left": "to bottom right", + "top-right": "to bottom left", + "bottom-left": "to top right", + "bottom-right": "to top left", +}; + +/** + * Halftone dot ramp, ported from the landing's HalftoneBackdrop: one layer + * per dot size, each masked by a triangle band centred on its own slice of + * the ramp, so the screen frequency never changes - only the dots grow + * toward the `corner`. Decorative only: absolutely positioned over its + * nearest positioned ancestor, pointer-transparent. + */ +export function HalftoneRamp({ + color = "rgba(16, 16, 24, 0.06)", + size = 14, + corner = "bottom", + reach = 55, + dots = [3.1, 2.55, 2.05, 1.6, 1.15, 0.7], + sx, +}) { + const towards = RAMP_DIRECTIONS[corner]; + const band = reach / dots.length; + return ( + + {dots.map((radius, i) => { + const centre = band * i; + const mask = + i === 0 + ? `linear-gradient(${towards}, #000 0%, transparent ${centre + band}%)` + : `linear-gradient(${towards}, transparent ${centre - band}%, #000 ${centre}%, transparent ${centre + band}%)`; + return ( + + ); + })} + + ); +} diff --git a/app/src/ui/keyboard-layout.js b/app/src/ui/keyboard-layout.js new file mode 100644 index 0000000..ee0e798 --- /dev/null +++ b/app/src/ui/keyboard-layout.js @@ -0,0 +1,44 @@ +// Controls use physical KeyboardEvent.code positions; getLayoutMap() provides +// the characters printed on those keys for the active layout. +const MOVEMENT_CODES = ["KeyW", "KeyA", "KeyS", "KeyD"]; +const MOVEMENT_FALLBACK_HINT = "arrows or WASD"; + +function keycap(value) { + if (typeof value !== "string") return null; + const glyph = value.trim(); + if ([...glyph].length !== 1 || /[\p{M}\p{C}\p{Z}]/u.test(glyph)) return null; + const upper = glyph.toUpperCase(); + return [...upper].length === 1 ? upper : glyph; // "ß" must not become "SS" +} + +export function resolveKeycaps(codes, layoutMap) { + const required = [...new Set([...MOVEMENT_CODES, ...codes])]; + const labels = {}; + let complete = true; + for (const code of required) { + let label = null; + try { + label = keycap(layoutMap?.get?.(code)); + } catch { + label = null; + } + if (!label) complete = false; + labels[code] = label; + } + if (!complete) { + for (const code of required) labels[code] = code.replace(/^Key/, ""); + return { labels, moveHint: MOVEMENT_FALLBACK_HINT }; + } + return { + labels, + moveHint: `arrows or ${MOVEMENT_CODES.map((code) => labels[code]).join("")}`, + }; +} + +export async function readLayoutMap(nav = globalThis.navigator) { + try { + return (await nav?.keyboard?.getLayoutMap?.()) ?? null; + } catch { + return null; + } +} diff --git a/app/test/keyboard-layout.test.js b/app/test/keyboard-layout.test.js new file mode 100644 index 0000000..7f05211 --- /dev/null +++ b/app/test/keyboard-layout.test.js @@ -0,0 +1,81 @@ +import test from "node:test"; +import assert from "node:assert/strict"; + +import { readLayoutMap, resolveKeycaps } from "../src/ui/keyboard-layout.js"; + +const AZERTY = new Map( + Object.entries({ KeyW: "z", KeyA: "q", KeyS: "s", KeyD: "d", KeyQ: "a", KeyE: "e" }), +); +const QWERTY = new Map( + Object.entries({ KeyW: "w", KeyA: "a", KeyS: "s", KeyD: "d", KeyQ: "q", KeyE: "e" }), +); +const DVORAK = new Map( + Object.entries({ KeyW: ",", KeyA: "a", KeyS: "o", KeyD: "e", KeyQ: "'", KeyE: "." }), +); + +const CODES = ["KeyQ", "KeyE"]; + +test("resolves caps and the movement hint from the active layout", () => { + assert.deepEqual(resolveKeycaps(CODES, QWERTY), { + labels: { KeyW: "W", KeyA: "A", KeyS: "S", KeyD: "D", KeyQ: "Q", KeyE: "E" }, + moveHint: "arrows or WASD", + }); + const azerty = resolveKeycaps(CODES, AZERTY); + assert.deepEqual(azerty.labels, { + KeyW: "Z", KeyA: "Q", KeyS: "S", KeyD: "D", KeyQ: "A", KeyE: "E", + }); + assert.equal(azerty.moveHint, "arrows or ZQSD"); + + const dvorak = resolveKeycaps(CODES, DVORAK); + assert.equal(dvorak.labels.KeyQ, "'"); + assert.equal(dvorak.moveHint, "arrows or ,AOE"); +}); + +test("falls back to QWERTY labels without a map", () => { + assert.deepEqual(resolveKeycaps(CODES, null), { + labels: { KeyW: "W", KeyA: "A", KeyS: "S", KeyD: "D", KeyQ: "Q", KeyE: "E" }, + moveHint: "arrows or WASD", + }); + assert.equal(resolveKeycaps(["KeyX"], null).labels.KeyX, "X"); +}); + +const ALL_QWERTY = { + labels: { KeyW: "W", KeyA: "A", KeyS: "S", KeyD: "D", KeyQ: "Q", KeyE: "E" }, + moveHint: "arrows or WASD", +}; + +test("falls back entirely to QWERTY when the map misses a movement key", () => { + const partial = new Map([["KeyW", "z"], ["KeyA", "q"], ["KeyS", "s"]]); + assert.deepEqual(resolveKeycaps(CODES, partial), ALL_QWERTY); +}); + +test("falls back entirely to QWERTY when the map misses a requested key", () => { + const partial = new Map([...AZERTY].filter(([code]) => code !== "KeyE")); + assert.deepEqual(resolveKeycaps(CODES, partial), ALL_QWERTY); +}); + +test("rejects layout values that cannot sit on a keycap", () => { + const junk = new Map( + Object.entries({ KeyQ: "", KeyE: " ", KeyW: "Dead", KeyA: "́", KeyS: 7 }), + ); + assert.deepEqual(resolveKeycaps(CODES, junk), ALL_QWERTY); +}); + +test("a throwing map cannot break the menu", () => { + const hostile = { get: () => { throw new Error("nope"); } }; + assert.deepEqual(resolveKeycaps(CODES, hostile), ALL_QWERTY); +}); + +test("readLayoutMap yields null when the API is absent or refuses", async () => { + assert.equal(await readLayoutMap({}), null); + assert.equal(await readLayoutMap({ keyboard: {} }), null); + const rejects = { keyboard: { getLayoutMap: () => Promise.reject(new Error("blocked")) } }; + assert.equal(await readLayoutMap(rejects), null); + const throws = { keyboard: { getLayoutMap: () => { throw new Error("framed"); } } }; + assert.equal(await readLayoutMap(throws), null); +}); + +test("readLayoutMap returns the map where the API is supported", async () => { + const nav = { keyboard: { getLayoutMap: async () => AZERTY } }; + assert.equal(await readLayoutMap(nav), AZERTY); +}); diff --git a/app/vite.config.js b/app/vite.config.js new file mode 100644 index 0000000..1cd9534 --- /dev/null +++ b/app/vite.config.js @@ -0,0 +1,24 @@ +import { defineConfig } from "vite"; +import react from "@vitejs/plugin-react"; + +export default defineConfig({ + // Deploy prefix: "/" standalone (the HF Space), "/play/" when the bundle + // is served under the Microduck Academy (VITE_BASE=/play/ npm run build). + // Runtime asset URLs are base-relative ("./assets", "./policies") so + // only the bundle references in index.html depend on this. + base: process.env.VITE_BASE || "/", + plugins: [react()], + // MuJoCo WASM and onnxruntime-web stay on the CDN (dynamic import with + // @vite-ignore in game/boot.js), exactly like the pre-Vite app: their + // .wasm sidecars resolve relative to the CDN URL and never touch the + // bundle. + server: { + port: 5173, + }, + build: { + // Keep the JS/CSS bundle out of dist/assets/: the game's static assets + // (public/assets/) land there and must keep their historical URLs. + assetsDir: "bundle", + chunkSizeWarningLimit: 1500, + }, +});