hwihwalab commited on
Commit
53285d4
ยท
verified ยท
1 Parent(s): 84101f0

feat(wasm): deploy real 60FPS MuJoCo WebAssembly physics engine (Zero Docker, Zero GIFs)

Browse files
Files changed (3) hide show
  1. app.js +6 -2
  2. index.html +2 -2
  3. mujoco_wasm_player.js +26 -13
app.js CHANGED
@@ -1042,7 +1042,7 @@ async function initWasmEngine() {
1042
  try {
1043
  if (!MujocoWasmPlayer) {
1044
  engineLoadingMgr.setProgress(50, "๐Ÿ“ฆ MuJoCo WebAssembly ๋ชจ๋“ˆ ๋กœ๋”ฉ ์ค‘...", "๐Ÿ“ฆ Loading MuJoCo WASM Module...");
1045
- const mod = await import(withSign("./mujoco_wasm_player.js?v=20261107_v29"));
1046
  MujocoWasmPlayer = mod.MujocoWasmPlayer;
1047
  }
1048
  wasmPlayer = new MujocoWasmPlayer(container);
@@ -1626,7 +1626,11 @@ async function sendAction(actionType, value = 0.0) {
1626
  } else {
1627
  playBoing();
1628
  }
1629
- wasmPlayer.applyAction(actionType, value);
 
 
 
 
1630
  currentGameState = wasmPlayer.gameState;
1631
  updateGameStateUI();
1632
  return;
 
1042
  try {
1043
  if (!MujocoWasmPlayer) {
1044
  engineLoadingMgr.setProgress(50, "๐Ÿ“ฆ MuJoCo WebAssembly ๋ชจ๋“ˆ ๋กœ๋”ฉ ์ค‘...", "๐Ÿ“ฆ Loading MuJoCo WASM Module...");
1045
+ const mod = await import(withSign("./mujoco_wasm_player.js?v=20261107_v30"));
1046
  MujocoWasmPlayer = mod.MujocoWasmPlayer;
1047
  }
1048
  wasmPlayer = new MujocoWasmPlayer(container);
 
1626
  } else {
1627
  playBoing();
1628
  }
1629
+ try {
1630
+ wasmPlayer.applyAction(actionType, value);
1631
+ } catch (err) {
1632
+ console.warn("wasmPlayer.applyAction suppressed error:", err);
1633
+ }
1634
  currentGameState = wasmPlayer.gameState;
1635
  updateGameStateUI();
1636
  return;
index.html CHANGED
@@ -6,7 +6,7 @@
6
  <title>Jelly Bean PlayEngine ยท 10 Pop Physics | HWIHWA LAB</title>
7
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
8
  <link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&family=Jua&family=Noto+Sans+KR:wght@400;500;700&family=Nunito:wght@600;700;800;900&family=JetBrains+Mono:wght@600;700&display=swap" rel="stylesheet">
9
- <link rel="stylesheet" href="style.css?v=20261107_v29">
10
  <!-- Three.js WebGL Engine for 60 FPS Client-Side Real-time Simulation -->
11
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.min.js"></script>
12
  </head>
@@ -360,7 +360,7 @@
360
  ================================================================ -->
361
  <script>
362
  (function () {
363
- var VER = "20261107_v29";
364
  var GAMES = [
365
  [1, "BEAN PARTY", "Jelly Bean Skydiving Party", "01 ยท ์ ค๋ฆฌ๋นˆ ์Šค์นด์ด๋‹ค์ด๋น™ ํŒŒํ‹ฐ"],
366
  [2, "BALL POOL", "Jelly Bean Ball Pool Pinball", "02 ยท ์ ค๋ฆฌ๋นˆ ๋ณผํ’€์žฅ & ํ•€๋ณผ ํ”Œ๋ฆฌํผ"],
 
6
  <title>Jelly Bean PlayEngine ยท 10 Pop Physics | HWIHWA LAB</title>
7
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
8
  <link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&family=Jua&family=Noto+Sans+KR:wght@400;500;700&family=Nunito:wght@600;700;800;900&family=JetBrains+Mono:wght@600;700&display=swap" rel="stylesheet">
9
+ <link rel="stylesheet" href="style.css?v=20261107_v30">
10
  <!-- Three.js WebGL Engine for 60 FPS Client-Side Real-time Simulation -->
11
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.min.js"></script>
12
  </head>
 
360
  ================================================================ -->
361
  <script>
362
  (function () {
363
+ var VER = "20261107_v30";
364
  var GAMES = [
365
  [1, "BEAN PARTY", "Jelly Bean Skydiving Party", "01 ยท ์ ค๋ฆฌ๋นˆ ์Šค์นด์ด๋‹ค์ด๋น™ ํŒŒํ‹ฐ"],
366
  [2, "BALL POOL", "Jelly Bean Ball Pool Pinball", "02 ยท ์ ค๋ฆฌ๋นˆ ๋ณผํ’€์žฅ & ํ•€๋ณผ ํ”Œ๋ฆฌํผ"],
mujoco_wasm_player.js CHANGED
@@ -183,12 +183,10 @@ export class MujocoWasmPlayer {
183
  this.isRunning = true;
184
  this.isReady = true;
185
 
186
- // ๋Œ€๊ธฐ ์ค‘์ด๋˜ ๊ฒŒ์ž„์ด ์žˆ์œผ๋ฉด ์ฆ‰์‹œ ๋กœ๋“œ!
187
- if (this.pendingGameId) {
188
- const pId = this.pendingGameId;
189
- this.pendingGameId = null;
190
- this.loadGame(pId);
191
- }
192
 
193
  requestAnimationFrame((t) => this.renderLoop(t));
194
  return true;
@@ -207,6 +205,7 @@ export class MujocoWasmPlayer {
207
 
208
  loadGame(exampleId) {
209
  this.currentId = parseInt(exampleId);
 
210
 
211
  // ์•„์ง WASM ๋ฌผ๋ฆฌ ์—”์ง„์ด ์ค€๋น„๋˜์ง€ ์•Š์•˜์œผ๋ฉด ํ์— ์ €์žฅ ํ›„ ์•ˆ์ „ ๋ฆฌํ„ด (Cannot read properties of null ๋ฐฉ์–ด!)
212
  if (!this.mujoco || !this.isReady) {
@@ -448,6 +447,7 @@ export class MujocoWasmPlayer {
448
  }
449
 
450
  resetGame() {
 
451
  this.mujoco.mj_resetData(this.model, this.data);
452
  this.gameState = 'ready';
453
  this.controlMode = 'manual';
@@ -525,6 +525,7 @@ export class MujocoWasmPlayer {
525
  }
526
 
527
  startGame() {
 
528
  this.gameState = 'playing';
529
  this.victoryBanner = null;
530
  this.survivalTime = 0.0;
@@ -553,6 +554,7 @@ export class MujocoWasmPlayer {
553
  }
554
 
555
  applyAction(actionType, value = 0) {
 
556
  if (actionType === 'start') { this.startGame(); return; }
557
  if (actionType === 'reset') { this.resetGame(); return; }
558
  if (actionType === 'set_mode') {
@@ -678,6 +680,7 @@ export class MujocoWasmPlayer {
678
  }
679
 
680
  dropExtraBean() {
 
681
  this.beansDropped++;
682
  const b = (this.beansDropped - 1) % 4;
683
  if (this.model.nq >= (b + 1) * 7) {
@@ -711,6 +714,7 @@ export class MujocoWasmPlayer {
711
  }
712
 
713
  updatePhysics(duration) {
 
714
  if (this.gameState !== 'playing' && this.gameState !== 'victory') return;
715
  const dt = this.model.opt.timestep;
716
  const steps = Math.max(1, Math.round(duration / dt));
@@ -1074,10 +1078,19 @@ export class MujocoWasmPlayer {
1074
 
1075
  renderLoop(time) {
1076
  if (!this.isRunning) return;
 
1077
 
1078
  const dt = Math.min(0.05, (time - this.lastFrameTime) / 1000.0);
1079
  this.lastFrameTime = time;
1080
 
 
 
 
 
 
 
 
 
1081
  this.updatePhysics(dt);
1082
  this.updateMeshPositions();
1083
 
@@ -1100,32 +1113,32 @@ export class MujocoWasmPlayer {
1100
  }
1101
 
1102
  if (this.onTelemetryUpdate) {
 
 
1103
  this.onTelemetryUpdate({
1104
  example_id: this.currentId,
1105
  game_state: this.gameState,
1106
  survival_time: this.survivalTime,
1107
  best_score: this.bestScore,
1108
- pole_angle: this.currentId === 7 ? (this.data.qpos[1] * 180 / Math.PI) : 0,
1109
- pole_angle_deg: this.currentId === 7 ? (this.data.qpos[1] * 180 / Math.PI).toFixed(1) : "0.0",
1110
  coins_collected: this.coinsCollected,
1111
  demolition_rate: this.demolitionRate,
1112
  beans_landed: this.beansLanded,
1113
  beans_dropped: this.beansDropped,
1114
  pinball_score: this.pinballScore,
1115
  domino_cleared: this.dominoCleared,
1116
- swing_angle: this.currentId === 4 ? (this.data.qpos[0] * 180 / Math.PI) : 0,
1117
- swing_angle_deg: this.currentId === 4 ? (this.data.qpos[0] * 180 / Math.PI).toFixed(1) : "0.0",
1118
  swing_loops: this.swingLoops,
1119
  somersault_count: this.somersaultCount,
1120
  race_winner: this.raceWinner,
1121
  race_leader: this.raceLeaderText,
1122
- claw_height: this.currentId === 9 ? (this.data.xpos ? 0.35 : 0) : 0,
1123
  victory_banner: this.victoryBanner,
1124
  rank: this.survivalTime > 15 ? 'S+' : (this.survivalTime > 10 ? 'A' : 'B')
1125
  });
1126
  }
1127
-
1128
- requestAnimationFrame((t) => this.renderLoop(t));
1129
  }
1130
  }
1131
 
 
183
  this.isRunning = true;
184
  this.isReady = true;
185
 
186
+ // ๋Œ€๊ธฐ ์ค‘์ด๋˜ ๊ฒŒ์ž„์ด ์žˆ์œผ๋ฉด ์ฆ‰์‹œ ๋กœ๋“œ, ์—†์œผ๋ฉด ๊ธฐ๋ณธ ๊ฒŒ์ž„(currentId=7) ์ฆ‰์‹œ ๋กœ๋“œ!
187
+ const pId = this.pendingGameId || this.currentId || 7;
188
+ this.pendingGameId = null;
189
+ this.loadGame(pId);
 
 
190
 
191
  requestAnimationFrame((t) => this.renderLoop(t));
192
  return true;
 
205
 
206
  loadGame(exampleId) {
207
  this.currentId = parseInt(exampleId);
208
+ this.isGameLoaded = false;
209
 
210
  // ์•„์ง WASM ๋ฌผ๋ฆฌ ์—”์ง„์ด ์ค€๋น„๋˜์ง€ ์•Š์•˜์œผ๋ฉด ํ์— ์ €์žฅ ํ›„ ์•ˆ์ „ ๋ฆฌํ„ด (Cannot read properties of null ๋ฐฉ์–ด!)
211
  if (!this.mujoco || !this.isReady) {
 
447
  }
448
 
449
  resetGame() {
450
+ if (!this.data || !this.model) return;
451
  this.mujoco.mj_resetData(this.model, this.data);
452
  this.gameState = 'ready';
453
  this.controlMode = 'manual';
 
525
  }
526
 
527
  startGame() {
528
+ if (!this.data || !this.model) return;
529
  this.gameState = 'playing';
530
  this.victoryBanner = null;
531
  this.survivalTime = 0.0;
 
554
  }
555
 
556
  applyAction(actionType, value = 0) {
557
+ if (!this.data || !this.model) return;
558
  if (actionType === 'start') { this.startGame(); return; }
559
  if (actionType === 'reset') { this.resetGame(); return; }
560
  if (actionType === 'set_mode') {
 
680
  }
681
 
682
  dropExtraBean() {
683
+ if (!this.data || !this.model) return;
684
  this.beansDropped++;
685
  const b = (this.beansDropped - 1) % 4;
686
  if (this.model.nq >= (b + 1) * 7) {
 
714
  }
715
 
716
  updatePhysics(duration) {
717
+ if (!this.data || !this.model || !this.isGameLoaded) return;
718
  if (this.gameState !== 'playing' && this.gameState !== 'victory') return;
719
  const dt = this.model.opt.timestep;
720
  const steps = Math.max(1, Math.round(duration / dt));
 
1078
 
1079
  renderLoop(time) {
1080
  if (!this.isRunning) return;
1081
+ requestAnimationFrame((t) => this.renderLoop(t));
1082
 
1083
  const dt = Math.min(0.05, (time - this.lastFrameTime) / 1000.0);
1084
  this.lastFrameTime = time;
1085
 
1086
+ // โ˜… ๋กœ๋”ฉ ์ค‘ ๋˜๋Š” ๋ฐ์ดํ„ฐ ๋ฏธ์ค€๋น„ ์ƒํƒœ์—์„œ๋Š” ์•ˆ์ „ํ•˜๊ฒŒ ๋ Œ๋”๋ง๋งŒ ์œ ์ง€ํ•˜๊ณ  ๋ฌผ๋ฆฌ/ํ…”๋ ˆ๋ฉ”ํŠธ๋ฆฌ ์—ฐ์‚ฐ ์ค‘๋‹จ
1087
+ if (!this.data || !this.model || !this.isGameLoaded) {
1088
+ if (this.renderer && this.scene && this.camera) {
1089
+ this.renderer.render(this.scene, this.camera);
1090
+ }
1091
+ return;
1092
+ }
1093
+
1094
  this.updatePhysics(dt);
1095
  this.updateMeshPositions();
1096
 
 
1113
  }
1114
 
1115
  if (this.onTelemetryUpdate) {
1116
+ const hasQpos = !!(this.data && this.data.qpos);
1117
+ const hasXpos = !!(this.data && this.data.xpos);
1118
  this.onTelemetryUpdate({
1119
  example_id: this.currentId,
1120
  game_state: this.gameState,
1121
  survival_time: this.survivalTime,
1122
  best_score: this.bestScore,
1123
+ pole_angle: (this.currentId === 7 && hasQpos) ? (this.data.qpos[1] * 180 / Math.PI) : 0,
1124
+ pole_angle_deg: (this.currentId === 7 && hasQpos) ? (this.data.qpos[1] * 180 / Math.PI).toFixed(1) : "0.0",
1125
  coins_collected: this.coinsCollected,
1126
  demolition_rate: this.demolitionRate,
1127
  beans_landed: this.beansLanded,
1128
  beans_dropped: this.beansDropped,
1129
  pinball_score: this.pinballScore,
1130
  domino_cleared: this.dominoCleared,
1131
+ swing_angle: (this.currentId === 4 && hasQpos) ? (this.data.qpos[0] * 180 / Math.PI) : 0,
1132
+ swing_angle_deg: (this.currentId === 4 && hasQpos) ? (this.data.qpos[0] * 180 / Math.PI).toFixed(1) : "0.0",
1133
  swing_loops: this.swingLoops,
1134
  somersault_count: this.somersaultCount,
1135
  race_winner: this.raceWinner,
1136
  race_leader: this.raceLeaderText,
1137
+ claw_height: (this.currentId === 9 && hasXpos) ? 0.35 : 0,
1138
  victory_banner: this.victoryBanner,
1139
  rank: this.survivalTime > 15 ? 'S+' : (this.survivalTime > 10 ? 'A' : 'B')
1140
  });
1141
  }
 
 
1142
  }
1143
  }
1144