hwihwalab commited on
Commit
2785e52
ยท
verified ยท
1 Parent(s): 57f9310

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

Browse files
Files changed (3) hide show
  1. app.js +68 -10
  2. index.html +2 -2
  3. mujoco_wasm_player.js +15 -11
app.js CHANGED
@@ -676,8 +676,16 @@ async function initApp() {
676
  safeStep("translations", applyTranslations);
677
  safeStep("actionButtons", updateActionButtons);
678
  safeStep("gameStateUI", () => updateGameStateUI());
679
- // 6s safety net only in case of catastrophic network hang
680
- setTimeout(() => { if (typeof engineLoadingMgr !== 'undefined') engineLoadingMgr.complete(); }, 6000);
 
 
 
 
 
 
 
 
681
  }
682
  window.__jellyInitApp = initApp;
683
 
@@ -843,13 +851,30 @@ class EngineLoadingManager {
843
  constructor() {
844
  this.currentVal = 6;
845
  this.targetVal = 20;
 
 
 
846
  this.isReady = false;
847
  this.isDismissed = false;
848
  this.startTime = performance.now();
849
- this.minDurationMs = 1800; // Minimum 1.8s pacing so users can comfortably perceive milestones
850
- this.holdDurationMs = 650; // Hold at 100% for 650ms so user clearly perceives completion
851
  this.timer = null;
852
  this.overlay = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
853
  this._startTicker();
854
  }
855
 
@@ -867,12 +892,41 @@ class EngineLoadingManager {
867
 
868
  setProgress(target, msgKo = null, msgEn = null) {
869
  if (this.isReady) return;
870
- this.targetVal = Math.max(this.targetVal, Math.min(94, target));
871
  if (msgKo && msgEn) {
872
  this.setMessage(msgKo, msgEn);
873
  }
874
  }
875
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
876
  _startTicker() {
877
  if (this.timer) return;
878
  this.timer = setInterval(() => {
@@ -882,16 +936,16 @@ class EngineLoadingManager {
882
  // Desired progress based on minimum pacing and actual milestone
883
  let desired = this.targetVal;
884
  if (!this.isReady) {
885
- // Smoothly pace progress up to 92% until physical engine is 100% ready
886
  desired = Math.min(92, Math.max(this.targetVal, timeRatio * 90));
887
  } else {
888
- // Once engine is ready, glide smoothly all the way to 100%
889
  desired = 100;
890
  }
891
 
892
  if (this.currentVal < desired) {
893
  // Steady, comfortable step so numbers are clearly readable (never jump wildly)
894
- const step = Math.min(1.6, Math.max(0.4, (desired - this.currentVal) * 0.09));
895
  this.currentVal = Math.min(desired, this.currentVal + step);
896
  }
897
 
@@ -930,7 +984,7 @@ class EngineLoadingManager {
930
  if (this.isDismissed) return;
931
  this.isDismissed = true;
932
 
933
- // Hold at 100% for 550ms so user perceives completion before fade-out begins
934
  setTimeout(() => {
935
  const ov = this.getOverlay();
936
  if (!ov) return;
@@ -977,7 +1031,7 @@ async function initWasmEngine() {
977
  try {
978
  if (!MujocoWasmPlayer) {
979
  engineLoadingMgr.setProgress(50, "๐Ÿ“ฆ MuJoCo WebAssembly ๋ชจ๋“ˆ ๋กœ๋”ฉ ์ค‘...", "๐Ÿ“ฆ Loading MuJoCo WASM Module...");
980
- const mod = await import(withSign("./mujoco_wasm_player.js?v=20261107_v23"));
981
  MujocoWasmPlayer = mod.MujocoWasmPlayer;
982
  }
983
  wasmPlayer = new MujocoWasmPlayer(container);
@@ -1095,6 +1149,10 @@ async function loadExamples() {
1095
  updateActionButtons();
1096
  updateGameStateUI();
1097
 
 
 
 
 
1098
  // 2. ๐Ÿš€ MuJoCo WebAssembly ์‹ค์‹œ๊ฐ„ ๋ฌผ๋ฆฌ ์—”์ง„ ์ฆ‰์‹œ ๊ฐ€๋™
1099
  useWasm = true;
1100
  try {
 
676
  safeStep("translations", applyTranslations);
677
  safeStep("actionButtons", updateActionButtons);
678
  safeStep("gameStateUI", () => updateGameStateUI());
679
+ if (typeof engineLoadingMgr !== 'undefined') {
680
+ engineLoadingMgr.notifyUiReady();
681
+ }
682
+ // Catastrophic 40s timeout: warn user rather than abruptly hiding loading screen while elements are missing
683
+ setTimeout(() => {
684
+ if (typeof engineLoadingMgr !== 'undefined' && !engineLoadingMgr.isReady) {
685
+ console.warn("[initApp] 40s timeout reached without stable scene rendering.");
686
+ engineLoadingMgr.setMessage("โš ๏ธ ๋„คํŠธ์›Œํฌ ๋กœ๋”ฉ ์ง€์—ฐ ์ค‘... ์ž ์‹œ ํ›„ ๋‹ค์‹œ ์‹œ๋„ํ•ด ์ฃผ์„ธ์š”.", "โš ๏ธ Network delay... Please refresh if needed.");
687
+ }
688
+ }, 40000);
689
  }
690
  window.__jellyInitApp = initApp;
691
 
 
851
  constructor() {
852
  this.currentVal = 6;
853
  this.targetVal = 20;
854
+ this.isSceneStable = false;
855
+ this.isUiReady = false;
856
+ this.isFontsReady = false;
857
  this.isReady = false;
858
  this.isDismissed = false;
859
  this.startTime = performance.now();
860
+ this.minDurationMs = 1600; // Pacing so users can comfortably perceive milestones
861
+ this.holdDurationMs = 500; // Hold at 100% for 500ms so user clearly perceives completion
862
  this.timer = null;
863
  this.overlay = null;
864
+
865
+ // Web Fonts loading check
866
+ if (typeof document !== "undefined" && document.fonts && document.fonts.ready) {
867
+ document.fonts.ready.then(() => {
868
+ this.isFontsReady = true;
869
+ this._checkReadiness();
870
+ }).catch(() => {
871
+ this.isFontsReady = true;
872
+ this._checkReadiness();
873
+ });
874
+ } else {
875
+ this.isFontsReady = true;
876
+ }
877
+
878
  this._startTicker();
879
  }
880
 
 
892
 
893
  setProgress(target, msgKo = null, msgEn = null) {
894
  if (this.isReady) return;
895
+ this.targetVal = Math.max(this.targetVal, Math.min(95, target));
896
  if (msgKo && msgEn) {
897
  this.setMessage(msgKo, msgEn);
898
  }
899
  }
900
 
901
+ notifyUiReady() {
902
+ this.isUiReady = true;
903
+ this.setProgress(70, "๐ŸŽจ UI ๋ฐ ๊ฒŒ์ž„ ํŒŒ๋ผ๋ฏธํ„ฐ ๋กœ๋”ฉ ์™„๋ฃŒ", "๐ŸŽจ UI & Parameters Initialized");
904
+ this._checkReadiness();
905
+ }
906
+
907
+ notifySceneStable() {
908
+ this.isSceneStable = true;
909
+ this.setProgress(96, "โœจ 3D ๊ทธ๋ž˜ํ”ฝ ๋ฐ ๋ฌผ๋ฆฌ ๋ Œ๋”๋ง ๊ฒ€์ฆ ์™„๋ฃŒ", "โœจ 3D Graphics & Physics Verified");
910
+ this._checkReadiness();
911
+ }
912
+
913
+ _checkReadiness() {
914
+ if (this.isReady) return;
915
+
916
+ // Check all physical and visual DOM criteria
917
+ const listEl = document.getElementById("brickList");
918
+ const hasGameList = listEl && listEl.children.length >= 10;
919
+ const titleEl = document.getElementById("activeTitle");
920
+ const hasHeader = titleEl && titleEl.textContent.trim().length > 0;
921
+ const canvas = document.querySelector(".screen-wrapper canvas");
922
+ const hasCanvas = canvas && canvas.clientWidth > 0 && canvas.clientHeight > 0;
923
+
924
+ // All screen elements, web fonts, and 3D frames must be 100% verified!
925
+ if (this.isSceneStable && this.isFontsReady && hasGameList && hasHeader && hasCanvas) {
926
+ this.complete();
927
+ }
928
+ }
929
+
930
  _startTicker() {
931
  if (this.timer) return;
932
  this.timer = setInterval(() => {
 
936
  // Desired progress based on minimum pacing and actual milestone
937
  let desired = this.targetVal;
938
  if (!this.isReady) {
939
+ // Smoothly pace progress up to 92% until all physical and visual screen elements are 100% ready
940
  desired = Math.min(92, Math.max(this.targetVal, timeRatio * 90));
941
  } else {
942
+ // Once engine and all elements are ready, glide smoothly all the way to 100%
943
  desired = 100;
944
  }
945
 
946
  if (this.currentVal < desired) {
947
  // Steady, comfortable step so numbers are clearly readable (never jump wildly)
948
+ const step = Math.min(1.8, Math.max(0.4, (desired - this.currentVal) * 0.12));
949
  this.currentVal = Math.min(desired, this.currentVal + step);
950
  }
951
 
 
984
  if (this.isDismissed) return;
985
  this.isDismissed = true;
986
 
987
+ // Hold at 100% for 500ms so user perceives completion before fade-out begins
988
  setTimeout(() => {
989
  const ov = this.getOverlay();
990
  if (!ov) return;
 
1031
  try {
1032
  if (!MujocoWasmPlayer) {
1033
  engineLoadingMgr.setProgress(50, "๐Ÿ“ฆ MuJoCo WebAssembly ๋ชจ๋“ˆ ๋กœ๋”ฉ ์ค‘...", "๐Ÿ“ฆ Loading MuJoCo WASM Module...");
1034
+ const mod = await import(withSign("./mujoco_wasm_player.js?v=20261107_v24"));
1035
  MujocoWasmPlayer = mod.MujocoWasmPlayer;
1036
  }
1037
  wasmPlayer = new MujocoWasmPlayer(container);
 
1149
  updateActionButtons();
1150
  updateGameStateUI();
1151
 
1152
+ if (typeof engineLoadingMgr !== 'undefined') {
1153
+ engineLoadingMgr.notifyUiReady();
1154
+ }
1155
+
1156
  // 2. ๐Ÿš€ MuJoCo WebAssembly ์‹ค์‹œ๊ฐ„ ๋ฌผ๋ฆฌ ์—”์ง„ ์ฆ‰์‹œ ๊ฐ€๋™
1157
  useWasm = true;
1158
  try {
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_v19">
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_v23";
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_v24">
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_v24";
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
@@ -259,7 +259,8 @@ export class MujocoWasmPlayer {
259
  this.resetGame();
260
  this.updateCameraView();
261
  this.isGameLoaded = true;
262
- this._firstFrameRendered = false;
 
263
  }
264
 
265
  buildThreeGeoms() {
@@ -1064,16 +1065,6 @@ export class MujocoWasmPlayer {
1064
  renderLoop(time) {
1065
  if (!this.isRunning) return;
1066
 
1067
- // โ˜… ์‹ค์ œ 3D ๊ฒŒ์ž„ ๋ฉ”์‰ฌ๊ฐ€ ์”ฌ์— ๋ฐฐ์น˜๋˜๊ณ  ์ฒซ ์œ ํšจ ํ”„๋ ˆ์ž„์ด ๋ Œ๋”๋ง๋œ ์ˆœ๊ฐ„์—๋งŒ ์™„๋ฃŒ ์‹ ํ˜ธ ์ „๋‹ฌ
1068
- if (!this._firstFrameRendered && this.isGameLoaded && this.model && this.geomMeshes.length > 0) {
1069
- this._firstFrameRendered = true;
1070
- if (typeof window !== "undefined" && window.__engineLoadingMgr) {
1071
- window.__engineLoadingMgr.complete();
1072
- } else if (typeof window !== "undefined" && typeof window.__dismissLoadingOverlay === "function") {
1073
- window.__dismissLoadingOverlay();
1074
- }
1075
- }
1076
-
1077
  const dt = Math.min(0.05, (time - this.lastFrameTime) / 1000.0);
1078
  this.lastFrameTime = time;
1079
 
@@ -1082,6 +1073,19 @@ export class MujocoWasmPlayer {
1082
 
1083
  if (this.renderer && this.scene && this.camera) {
1084
  this.renderer.render(this.scene, this.camera);
 
 
 
 
 
 
 
 
 
 
 
 
 
1085
  }
1086
 
1087
  if (this.onTelemetryUpdate) {
 
259
  this.resetGame();
260
  this.updateCameraView();
261
  this.isGameLoaded = true;
262
+ this._sceneFullyRendered = false;
263
+ this._renderedFrames = 0;
264
  }
265
 
266
  buildThreeGeoms() {
 
1065
  renderLoop(time) {
1066
  if (!this.isRunning) return;
1067
 
 
 
 
 
 
 
 
 
 
 
1068
  const dt = Math.min(0.05, (time - this.lastFrameTime) / 1000.0);
1069
  this.lastFrameTime = time;
1070
 
 
1073
 
1074
  if (this.renderer && this.scene && this.camera) {
1075
  this.renderer.render(this.scene, this.camera);
1076
+ this._renderedFrames = (this._renderedFrames || 0) + 1;
1077
+ }
1078
+
1079
+ // โ˜… ์‹ค์ œ 3D ๊ฒŒ์ž„ ๋ฉ”์‰ฌ๊ฐ€ ์”ฌ์— ๋ฐฐ์น˜๋˜๊ณ  ์ตœ์†Œ 15ํ”„๋ ˆ์ž„ ์ด์ƒ GPU ๋ Œ๋”๋ง์ด ์•ˆ์ •ํ™”๋œ ์ˆœ๊ฐ„์—๋งŒ ์™„๋ฃŒ ์‹ ํ˜ธ ์ „๋‹ฌ!
1080
+ if (!this._sceneFullyRendered && this._renderedFrames >= 15 && this.isGameLoaded && this.model && this.geomMeshes.length > 0) {
1081
+ this._sceneFullyRendered = true;
1082
+ if (typeof window !== "undefined" && window.__engineLoadingMgr && typeof window.__engineLoadingMgr.notifySceneStable === "function") {
1083
+ window.__engineLoadingMgr.notifySceneStable();
1084
+ } else if (typeof window !== "undefined" && window.__engineLoadingMgr) {
1085
+ window.__engineLoadingMgr.complete();
1086
+ } else if (typeof window !== "undefined" && typeof window.__dismissLoadingOverlay === "function") {
1087
+ window.__dismissLoadingOverlay();
1088
+ }
1089
  }
1090
 
1091
  if (this.onTelemetryUpdate) {