bilca commited on
Commit
859f705
·
verified ·
1 Parent(s): e1a9a34

Update index_2.js

Browse files
Files changed (1) hide show
  1. index_2.js +40 -4
index_2.js CHANGED
@@ -291,7 +291,12 @@
291
  document.exitFullscreen();
292
  }
293
  }
294
- widgetContainer.classList.remove('fake-fullscreen');
 
 
 
 
 
295
  viewerContainer.style.display = 'none';
296
  gifPreview.style.display = 'block';
297
  });
@@ -302,6 +307,8 @@
302
  widgetContainer.classList.add('fake-fullscreen');
303
  } else {
304
  widgetContainer.classList.remove('fake-fullscreen');
 
 
305
  }
306
  fullscreenToggle.textContent = widgetContainer.classList.contains('fake-fullscreen') ? '⇲' : '⇱';
307
  } else {
@@ -323,11 +330,13 @@
323
  }
324
  });
325
 
 
326
  document.addEventListener('fullscreenchange', function() {
327
  if (document.fullscreenElement === widgetContainer) {
328
  fullscreenToggle.textContent = '⇲';
329
  } else {
330
  fullscreenToggle.textContent = '⇱';
 
331
  }
332
  });
333
 
@@ -336,9 +345,9 @@
336
  menuContent.style.display = (menuContent.style.display === 'block') ? 'none' : 'block';
337
  });
338
 
339
- // Modified reset button: re-creates the OrbitControls with the original parameters.
340
- resetCameraBtn.addEventListener('click', async function() {
341
- console.log("Reset camera button clicked.");
342
  if (cameraInstance && initialCameraPosition && initialCameraRotation) {
343
  // Reset camera position and rotation.
344
  cameraInstance.position = initialCameraPosition.clone();
@@ -372,6 +381,33 @@
372
  controlsInstance.panSpeed = isMobile ? 0.5 : 1.2;
373
  controlsInstance.update();
374
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375
  });
376
 
377
  // --- Initialize the 3D PLY Viewer ---
 
291
  document.exitFullscreen();
292
  }
293
  }
294
+ if (widgetContainer.classList.contains('fake-fullscreen')) {
295
+ widgetContainer.classList.remove('fake-fullscreen');
296
+ fullscreenToggle.textContent = '⇱';
297
+ // For fake-fullscreen, reset camera immediately.
298
+ resetCamera();
299
+ }
300
  viewerContainer.style.display = 'none';
301
  gifPreview.style.display = 'block';
302
  });
 
307
  widgetContainer.classList.add('fake-fullscreen');
308
  } else {
309
  widgetContainer.classList.remove('fake-fullscreen');
310
+ // Reset camera when exiting fake-fullscreen.
311
+ resetCamera();
312
  }
313
  fullscreenToggle.textContent = widgetContainer.classList.contains('fake-fullscreen') ? '⇲' : '⇱';
314
  } else {
 
330
  }
331
  });
332
 
333
+ // Listen for native fullscreen changes. When exiting fullscreen, reset camera.
334
  document.addEventListener('fullscreenchange', function() {
335
  if (document.fullscreenElement === widgetContainer) {
336
  fullscreenToggle.textContent = '⇲';
337
  } else {
338
  fullscreenToggle.textContent = '⇱';
339
+ resetCamera();
340
  }
341
  });
342
 
 
345
  menuContent.style.display = (menuContent.style.display === 'block') ? 'none' : 'block';
346
  });
347
 
348
+ // --- Camera Reset Function ---
349
+ function resetCamera() {
350
+ console.log("Resetting camera to initial position.");
351
  if (cameraInstance && initialCameraPosition && initialCameraRotation) {
352
  // Reset camera position and rotation.
353
  cameraInstance.position = initialCameraPosition.clone();
 
381
  controlsInstance.panSpeed = isMobile ? 0.5 : 1.2;
382
  controlsInstance.update();
383
  }
384
+ }
385
+
386
+ // Modified reset button now calls the resetCamera function.
387
+ resetCameraBtn.addEventListener('click', async function() {
388
+ console.log("Reset camera button clicked.");
389
+ resetCamera();
390
+ });
391
+
392
+ // --- Add keydown listener to exit fullscreen with Esc (or Echap) ---
393
+ document.addEventListener('keydown', function(e) {
394
+ if (e.key === 'Escape' || e.key === 'Esc') {
395
+ let wasFullscreen = false;
396
+ if (document.fullscreenElement === widgetContainer) {
397
+ wasFullscreen = true;
398
+ if (document.exitFullscreen) {
399
+ document.exitFullscreen();
400
+ }
401
+ }
402
+ if (widgetContainer.classList.contains('fake-fullscreen')) {
403
+ wasFullscreen = true;
404
+ widgetContainer.classList.remove('fake-fullscreen');
405
+ fullscreenToggle.textContent = '⇱';
406
+ }
407
+ if (wasFullscreen) {
408
+ resetCamera();
409
+ }
410
+ }
411
  });
412
 
413
  // --- Initialize the 3D PLY Viewer ---