multimodalart HF Staff commited on
Commit
cd5cd45
·
verified ·
1 Parent(s): 37a733b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -3
app.py CHANGED
@@ -403,6 +403,16 @@ CONTROL_INPUT_JS = """
403
  triggerUpdate();
404
  }
405
  }
 
 
 
 
 
 
 
 
 
 
406
 
407
  // Mobile: show toggle button and enable controls on tap
408
  if (isMobile) {
@@ -647,7 +657,7 @@ def create_app():
647
 
648
  Interactive frame-by-frame world generation on ZeroGPU.
649
 
650
- **Controls:** Click "Start Game" → Click game window to capture inputs → WASD to move • Mouse to look • ESC to release
651
  """)
652
 
653
  with gr.Row(elem_classes=["main-row"]):
@@ -716,6 +726,9 @@ def create_app():
716
 
717
  def on_start(selected_url, uploaded_image, prompt):
718
  """Start GPU session - generator that shows loading then first frame."""
 
 
 
719
  # Show loading state immediately
720
  loading_img = create_loading_image(text="Generating World ...")
721
  yield (
@@ -849,6 +862,7 @@ def create_app():
849
  inputs=[selected_seed_url, seed_image_upload, prompt_input],
850
  outputs=[session_state, latest_frame, latest_frame_count,
851
  video_output, frame_display, start_btn, stop_btn],
 
852
  )
853
 
854
  stop_btn.click(
@@ -875,14 +889,20 @@ def create_app():
875
  outputs=[latest_frame, latest_frame_count, video_output, frame_display],
876
  )
877
 
878
- # Pointer lock JS
879
  demo.load(fn=None, js="""
880
  () => {
881
  const insertButton = () => {
882
  const output = document.querySelector('#video-output');
883
  if (!output) { setTimeout(insertButton, 100); return; }
884
  output.style.cursor = 'pointer';
885
- output.onclick = () => document.body.requestPointerLock();
 
 
 
 
 
 
886
  };
887
  insertButton();
888
  }
 
403
  triggerUpdate();
404
  }
405
  }
406
+
407
+ // Expose setCapturing globally so we can trigger it from Start Game button
408
+ window.worldEngineSetCapturing = setCapturing;
409
+ window.worldEngineRequestPointerLock = () => {
410
+ if (!isMobile) {
411
+ document.body.requestPointerLock();
412
+ } else {
413
+ setCapturing(true);
414
+ }
415
+ };
416
 
417
  // Mobile: show toggle button and enable controls on tap
418
  if (isMobile) {
 
657
 
658
  Interactive frame-by-frame world generation on ZeroGPU.
659
 
660
+ **Controls:** Click "Start Game" → WASD to move • Mouse to look • Press ESC to release controls
661
  """)
662
 
663
  with gr.Row(elem_classes=["main-row"]):
 
726
 
727
  def on_start(selected_url, uploaded_image, prompt):
728
  """Start GPU session - generator that shows loading then first frame."""
729
+ # Show info about controls
730
+ gr.Info("Controls locked! Press ESC to release mouse/keyboard capture.", duration=5)
731
+
732
  # Show loading state immediately
733
  loading_img = create_loading_image(text="Generating World ...")
734
  yield (
 
862
  inputs=[selected_seed_url, seed_image_upload, prompt_input],
863
  outputs=[session_state, latest_frame, latest_frame_count,
864
  video_output, frame_display, start_btn, stop_btn],
865
+ js="() => { setTimeout(() => { if (window.worldEngineRequestPointerLock) window.worldEngineRequestPointerLock(); }, 500); }",
866
  )
867
 
868
  stop_btn.click(
 
889
  outputs=[latest_frame, latest_frame_count, video_output, frame_display],
890
  )
891
 
892
+ # Pointer lock JS - also allows clicking the game window
893
  demo.load(fn=None, js="""
894
  () => {
895
  const insertButton = () => {
896
  const output = document.querySelector('#video-output');
897
  if (!output) { setTimeout(insertButton, 100); return; }
898
  output.style.cursor = 'pointer';
899
+ output.onclick = () => {
900
+ if (window.worldEngineRequestPointerLock) {
901
+ window.worldEngineRequestPointerLock();
902
+ } else {
903
+ document.body.requestPointerLock();
904
+ }
905
+ };
906
  };
907
  insertButton();
908
  }