hwihwalab commited on
Commit
4c8a2eb
·
verified ·
1 Parent(s): 2785e52

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

Browse files
Files changed (2) hide show
  1. app.js +175 -170
  2. index.html +2 -2
app.js CHANGED
@@ -354,6 +354,175 @@ let staticCoinCounter = 0;
354
  let staticClawMagnet = false;
355
  let staticSurvivalTime = 0.0;
356
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
357
  // ============================================================================
358
  // 🔊 Kawaii Web Audio API Synthesizer (0 바이트 다운로드, 브라우저 순수 합성음)
359
  // ============================================================================
@@ -676,12 +845,12 @@ async function initApp() {
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
  }
@@ -847,170 +1016,6 @@ function cycleCamera() {
847
  // ============================================================================
848
  // 🚀 WASM Real-Time Physics Engine Controller (Singleton Promise)
849
  // ============================================================================
850
- class EngineLoadingManager {
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
-
881
- getOverlay() {
882
- if (!this.overlay) this.overlay = document.getElementById("engineLoadingOverlay");
883
- return this.overlay;
884
- }
885
-
886
- setMessage(msgKo, msgEn) {
887
- const el = document.getElementById("engineLoadingMsg");
888
- if (!el) return;
889
- const isKo = (typeof currentLang !== "undefined" ? currentLang : "ko") === "ko";
890
- el.textContent = isKo ? msgKo : msgEn;
891
- }
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(() => {
933
- const elapsed = performance.now() - this.startTime;
934
- const timeRatio = Math.min(1.0, elapsed / this.minDurationMs);
935
-
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
-
952
- const bar = document.getElementById("miniProgressBar");
953
- const pct = document.getElementById("loadingPercent");
954
- const rounded = Math.round(this.currentVal);
955
-
956
- if (bar) bar.style.width = `${rounded}%`;
957
- if (pct) pct.textContent = `${rounded}%`;
958
-
959
- // When reaching 100% after readiness signal
960
- if (this.isReady && this.currentVal >= 99.5) {
961
- this.currentVal = 100;
962
- if (bar) bar.style.width = "100%";
963
- if (pct) {
964
- pct.textContent = "100%";
965
- pct.style.color = "#10b981"; // Vibrant Emerald Green
966
- pct.style.transform = "scale(1.12)";
967
- }
968
- this.setMessage("🎉 100% 준비 완료! 게임을 시작합니다!", "🎉 100% Ready! Starting 3D Arena!");
969
- clearInterval(this.timer);
970
- this.timer = null;
971
- this._dismissWithHold();
972
- }
973
- }, 25);
974
- }
975
-
976
- complete() {
977
- if (this.isReady) return;
978
- this.isReady = true;
979
- this.targetVal = 100;
980
- this._startTicker();
981
- }
982
-
983
- _dismissWithHold() {
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;
991
-
992
- // Step 1: Smooth opacity fade-out (0.4s ease)
993
- ov.classList.add("fade-out");
994
-
995
- // Step 2: Clean DOM removal after fade-out transition finishes
996
- setTimeout(() => {
997
- ov.classList.add("is-hidden");
998
- ov.style.setProperty("display", "none", "important");
999
- ov.style.setProperty("opacity", "0", "important");
1000
- ov.style.setProperty("visibility", "hidden", "important");
1001
- ov.style.setProperty("pointer-events", "none", "important");
1002
- try { ov.remove(); } catch (e) {}
1003
- }, 420);
1004
- }, this.holdDurationMs);
1005
- }
1006
- }
1007
-
1008
- const engineLoadingMgr = new EngineLoadingManager();
1009
- window.__engineLoadingMgr = engineLoadingMgr;
1010
- function dismissEngineLoadingOverlay() {
1011
- engineLoadingMgr.complete();
1012
- }
1013
- window.__dismissLoadingOverlay = dismissEngineLoadingOverlay;
1014
 
1015
  let wasmInitPromise = null;
1016
  async function initWasmEngine() {
@@ -1031,7 +1036,7 @@ async function initWasmEngine() {
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,8 +1154,8 @@ async function loadExamples() {
1149
  updateActionButtons();
1150
  updateGameStateUI();
1151
 
1152
- if (typeof engineLoadingMgr !== 'undefined') {
1153
- engineLoadingMgr.notifyUiReady();
1154
  }
1155
 
1156
  // 2. 🚀 MuJoCo WebAssembly 실시간 물리 엔진 즉시 가동
 
354
  let staticClawMagnet = false;
355
  let staticSurvivalTime = 0.0;
356
 
357
+ // ============================================================================
358
+ // 🚀 WASM Real-Time Physics Engine Controller (Singleton Promise)
359
+ // ============================================================================
360
+ class EngineLoadingManager {
361
+ constructor() {
362
+ this.currentVal = 6;
363
+ this.targetVal = 20;
364
+ this.isSceneStable = false;
365
+ this.isUiReady = false;
366
+ this.isFontsReady = false;
367
+ this.isReady = false;
368
+ this.isDismissed = false;
369
+ this.startTime = performance.now();
370
+ this.minDurationMs = 1600; // Pacing so users can comfortably perceive milestones
371
+ this.holdDurationMs = 500; // Hold at 100% for 500ms so user clearly perceives completion
372
+ this.timer = null;
373
+ this.overlay = null;
374
+
375
+ // Web Fonts loading check
376
+ if (typeof document !== "undefined" && document.fonts && document.fonts.ready) {
377
+ document.fonts.ready.then(() => {
378
+ this.isFontsReady = true;
379
+ this._checkReadiness();
380
+ }).catch(() => {
381
+ this.isFontsReady = true;
382
+ this._checkReadiness();
383
+ });
384
+ } else {
385
+ this.isFontsReady = true;
386
+ }
387
+
388
+ this._startTicker();
389
+ }
390
+
391
+ getOverlay() {
392
+ if (!this.overlay) this.overlay = document.getElementById("engineLoadingOverlay");
393
+ return this.overlay;
394
+ }
395
+
396
+ setMessage(msgKo, msgEn) {
397
+ const el = document.getElementById("engineLoadingMsg");
398
+ if (!el) return;
399
+ const isKo = (typeof currentLang !== "undefined" ? currentLang : "ko") === "ko";
400
+ el.textContent = isKo ? msgKo : msgEn;
401
+ }
402
+
403
+ setProgress(target, msgKo = null, msgEn = null) {
404
+ if (this.isReady) return;
405
+ this.targetVal = Math.max(this.targetVal, Math.min(95, target));
406
+ if (msgKo && msgEn) {
407
+ this.setMessage(msgKo, msgEn);
408
+ }
409
+ }
410
+
411
+ notifyUiReady() {
412
+ this.isUiReady = true;
413
+ this.setProgress(70, "🎨 UI 및 게임 파라미터 로딩 완료", "🎨 UI & Parameters Initialized");
414
+ this._checkReadiness();
415
+ }
416
+
417
+ notifySceneStable() {
418
+ this.isSceneStable = true;
419
+ this.setProgress(96, "✨ 3D 그래픽 및 물리 렌더링 검증 완료", "✨ 3D Graphics & Physics Verified");
420
+ this._checkReadiness();
421
+ }
422
+
423
+ _checkReadiness() {
424
+ if (this.isReady) return;
425
+
426
+ // Check all physical and visual DOM criteria
427
+ const listEl = document.getElementById("brickList");
428
+ const hasGameList = listEl && listEl.children.length >= 10;
429
+ const titleEl = document.getElementById("activeTitle");
430
+ const hasHeader = titleEl && titleEl.textContent.trim().length > 0;
431
+ const canvas = document.querySelector(".screen-wrapper canvas");
432
+ const hasCanvas = canvas && canvas.clientWidth > 0 && canvas.clientHeight > 0;
433
+
434
+ // All screen elements, web fonts, and 3D frames must be 100% verified!
435
+ if (this.isSceneStable && this.isFontsReady && hasGameList && hasHeader && hasCanvas) {
436
+ this.complete();
437
+ }
438
+ }
439
+
440
+ _startTicker() {
441
+ if (this.timer) return;
442
+ this.timer = setInterval(() => {
443
+ const elapsed = performance.now() - this.startTime;
444
+ const timeRatio = Math.min(1.0, elapsed / this.minDurationMs);
445
+
446
+ // Desired progress based on minimum pacing and actual milestone
447
+ let desired = this.targetVal;
448
+ if (!this.isReady) {
449
+ // Smoothly pace progress up to 92% until all physical and visual screen elements are 100% ready
450
+ desired = Math.min(92, Math.max(this.targetVal, timeRatio * 90));
451
+ } else {
452
+ // Once engine and all elements are ready, glide smoothly all the way to 100%
453
+ desired = 100;
454
+ }
455
+
456
+ if (this.currentVal < desired) {
457
+ // Steady, comfortable step so numbers are clearly readable (never jump wildly)
458
+ const step = Math.min(1.8, Math.max(0.4, (desired - this.currentVal) * 0.12));
459
+ this.currentVal = Math.min(desired, this.currentVal + step);
460
+ }
461
+
462
+ const bar = document.getElementById("miniProgressBar");
463
+ const pct = document.getElementById("loadingPercent");
464
+ const rounded = Math.round(this.currentVal);
465
+
466
+ if (bar) bar.style.width = `${rounded}%`;
467
+ if (pct) pct.textContent = `${rounded}%`;
468
+
469
+ // When reaching 100% after readiness signal
470
+ if (this.isReady && this.currentVal >= 99.5) {
471
+ this.currentVal = 100;
472
+ if (bar) bar.style.width = "100%";
473
+ if (pct) {
474
+ pct.textContent = "100%";
475
+ pct.style.color = "#10b981"; // Vibrant Emerald Green
476
+ pct.style.transform = "scale(1.12)";
477
+ }
478
+ this.setMessage("🎉 100% 준비 완료! 게임을 시작합니다!", "🎉 100% Ready! Starting 3D Arena!");
479
+ clearInterval(this.timer);
480
+ this.timer = null;
481
+ this._dismissWithHold();
482
+ }
483
+ }, 25);
484
+ }
485
+
486
+ complete() {
487
+ if (this.isReady) return;
488
+ this.isReady = true;
489
+ this.targetVal = 100;
490
+ this._startTicker();
491
+ }
492
+
493
+ _dismissWithHold() {
494
+ if (this.isDismissed) return;
495
+ this.isDismissed = true;
496
+
497
+ // Hold at 100% for 500ms so user perceives completion before fade-out begins
498
+ setTimeout(() => {
499
+ const ov = this.getOverlay();
500
+ if (!ov) return;
501
+
502
+ // Step 1: Smooth opacity fade-out (0.4s ease)
503
+ ov.classList.add("fade-out");
504
+
505
+ // Step 2: Clean DOM removal after fade-out transition finishes
506
+ setTimeout(() => {
507
+ ov.classList.add("is-hidden");
508
+ ov.style.setProperty("display", "none", "important");
509
+ ov.style.setProperty("opacity", "0", "important");
510
+ ov.style.setProperty("visibility", "hidden", "important");
511
+ ov.style.setProperty("pointer-events", "none", "important");
512
+ try { ov.remove(); } catch (e) {}
513
+ }, 420);
514
+ }, this.holdDurationMs);
515
+ }
516
+ }
517
+
518
+ const engineLoadingMgr = new EngineLoadingManager();
519
+ window.__engineLoadingMgr = engineLoadingMgr;
520
+ function dismissEngineLoadingOverlay() {
521
+ engineLoadingMgr.complete();
522
+ }
523
+ window.__dismissLoadingOverlay = dismissEngineLoadingOverlay;
524
+
525
+
526
  // ============================================================================
527
  // 🔊 Kawaii Web Audio API Synthesizer (0 바이트 다운로드, 브라우저 순수 합성음)
528
  // ============================================================================
 
845
  safeStep("translations", applyTranslations);
846
  safeStep("actionButtons", updateActionButtons);
847
  safeStep("gameStateUI", () => updateGameStateUI());
848
+ if (typeof window !== 'undefined' && window.__engineLoadingMgr) {
849
+ window.__engineLoadingMgr.notifyUiReady();
850
  }
851
  // Catastrophic 40s timeout: warn user rather than abruptly hiding loading screen while elements are missing
852
  setTimeout(() => {
853
+ if (typeof window !== 'undefined' && window.__engineLoadingMgr && !window.__engineLoadingMgr.isReady) {
854
  console.warn("[initApp] 40s timeout reached without stable scene rendering.");
855
  engineLoadingMgr.setMessage("⚠️ 네트워크 로딩 지연 중... 잠시 후 다시 시도해 주세요.", "⚠️ Network delay... Please refresh if needed.");
856
  }
 
1016
  // ============================================================================
1017
  // 🚀 WASM Real-Time Physics Engine Controller (Singleton Promise)
1018
  // ============================================================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1019
 
1020
  let wasmInitPromise = null;
1021
  async function initWasmEngine() {
 
1036
  try {
1037
  if (!MujocoWasmPlayer) {
1038
  engineLoadingMgr.setProgress(50, "📦 MuJoCo WebAssembly 모듈 로딩 중...", "📦 Loading MuJoCo WASM Module...");
1039
+ const mod = await import(withSign("./mujoco_wasm_player.js?v=20261107_v25"));
1040
  MujocoWasmPlayer = mod.MujocoWasmPlayer;
1041
  }
1042
  wasmPlayer = new MujocoWasmPlayer(container);
 
1154
  updateActionButtons();
1155
  updateGameStateUI();
1156
 
1157
+ if (typeof window !== 'undefined' && window.__engineLoadingMgr) {
1158
+ window.__engineLoadingMgr.notifyUiReady();
1159
  }
1160
 
1161
  // 2. 🚀 MuJoCo WebAssembly 실시간 물리 엔진 즉시 가동
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_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,7 +360,7 @@
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 · 젤리빈 볼풀장 & 핀볼 플리퍼"],
 
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_v25">
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_v25";
364
  var GAMES = [
365
  [1, "BEAN PARTY", "Jelly Bean Skydiving Party", "01 · 젤리빈 스카이다이빙 파티"],
366
  [2, "BALL POOL", "Jelly Bean Ball Pool Pinball", "02 · 젤리빈 볼풀장 & 핀볼 플리퍼"],