Spaces:
Running
Running
Update js_scripts/index.js
Browse files- js_scripts/index.js +30 -23
js_scripts/index.js
CHANGED
@@ -379,26 +379,36 @@ const currentScriptTag = document.currentScript;
|
|
379 |
}
|
380 |
});
|
381 |
|
382 |
-
// ---
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
389 |
|
390 |
-
|
391 |
-
|
392 |
-
const sensitivity = cameraEntity.script.orbitCameraInputMouse.distanceSensitivity || 0.4;
|
393 |
-
const distance = cameraEntity.script.orbitCamera.distance;
|
394 |
-
cameraEntity.script.orbitCamera.distance -= event.deltaY * 0.01 * sensitivity * (distance * 0.1);
|
395 |
} else {
|
396 |
-
|
397 |
-
const orthoHeight = cameraEntity.script.orbitCamera.orthoHeight;
|
398 |
-
cameraEntity.script.orbitCamera.orthoHeight -= event.deltaY * 0.01 * sensitivity * (orthoHeight * 0.1);
|
399 |
}
|
|
|
|
|
400 |
}
|
401 |
-
}
|
|
|
|
|
|
|
|
|
402 |
|
403 |
// --- Initialize the 3D PLY Viewer using PlayCanvas ---
|
404 |
async function initializeViewer() {
|
@@ -421,8 +431,8 @@ const currentScriptTag = document.currentScript;
|
|
421 |
// Create app
|
422 |
const createOptions = new pc.AppOptions();
|
423 |
createOptions.graphicsDevice = device;
|
424 |
-
createOptions.mouse = new pc.Mouse(document.body
|
425 |
-
createOptions.touch = new pc.TouchDevice(document.body
|
426 |
createOptions.componentSystems = [
|
427 |
pc.RenderComponentSystem,
|
428 |
pc.CameraComponentSystem,
|
@@ -541,7 +551,7 @@ const currentScriptTag = document.currentScript;
|
|
541 |
}
|
542 |
});
|
543 |
|
544 |
-
// Create input controllers but don't add mouse wheel handling - we handle that
|
545 |
cameraEntity.script.create('orbitCameraInputMouse', {
|
546 |
attributes: {
|
547 |
orbitSensitivity: isMobile ? 0.6 : 0.3,
|
@@ -551,10 +561,7 @@ const currentScriptTag = document.currentScript;
|
|
551 |
|
552 |
// Disable wheel event in the orbit camera input
|
553 |
if (cameraEntity.script.orbitCameraInputMouse) {
|
554 |
-
//
|
555 |
-
const originalOnWheel = cameraEntity.script.orbitCameraInputMouse.onMouseWheel;
|
556 |
-
|
557 |
-
// Replace with empty function - we handle wheel at document level
|
558 |
cameraEntity.script.orbitCameraInputMouse.onMouseWheel = function() {};
|
559 |
}
|
560 |
|
|
|
379 |
}
|
380 |
});
|
381 |
|
382 |
+
// --- Prevent app from hijacking all wheel events ---
|
383 |
+
const handleWheel = function(event) {
|
384 |
+
// Check if mouse is over the viewer
|
385 |
+
if (!isMouseOverViewer) {
|
386 |
+
// Allow normal page scrolling
|
387 |
+
return true;
|
388 |
+
}
|
389 |
+
|
390 |
+
// Otherwise apply zooming, but prevent default only for viewer area
|
391 |
+
event.stopPropagation();
|
392 |
+
|
393 |
+
if (cameraEntity && cameraEntity.script && cameraEntity.script.orbitCamera) {
|
394 |
+
const camera = cameraEntity.camera;
|
395 |
+
const orbitCamera = cameraEntity.script.orbitCamera;
|
396 |
+
const sensitivity = cameraEntity.script.orbitCameraInputMouse ?
|
397 |
+
cameraEntity.script.orbitCameraInputMouse.distanceSensitivity || 0.4 : 0.4;
|
398 |
|
399 |
+
if (camera.projection === pc.PROJECTION_PERSPECTIVE) {
|
400 |
+
orbitCamera.distance -= event.deltaY * 0.01 * sensitivity * (orbitCamera.distance * 0.1);
|
|
|
|
|
|
|
401 |
} else {
|
402 |
+
orbitCamera.orthoHeight -= event.deltaY * 0.01 * sensitivity * (orbitCamera.orthoHeight * 0.1);
|
|
|
|
|
403 |
}
|
404 |
+
|
405 |
+
event.preventDefault();
|
406 |
}
|
407 |
+
};
|
408 |
+
|
409 |
+
// --- Listen for wheel events at the viewer level, not document level ---
|
410 |
+
viewerContainer.addEventListener('wheel', handleWheel, { passive: false });
|
411 |
+
canvas.addEventListener('wheel', handleWheel, { passive: false });
|
412 |
|
413 |
// --- Initialize the 3D PLY Viewer using PlayCanvas ---
|
414 |
async function initializeViewer() {
|
|
|
431 |
// Create app
|
432 |
const createOptions = new pc.AppOptions();
|
433 |
createOptions.graphicsDevice = device;
|
434 |
+
createOptions.mouse = new pc.Mouse(canvas); // Use canvas, not document.body
|
435 |
+
createOptions.touch = new pc.TouchDevice(canvas); // Use canvas, not document.body
|
436 |
createOptions.componentSystems = [
|
437 |
pc.RenderComponentSystem,
|
438 |
pc.CameraComponentSystem,
|
|
|
551 |
}
|
552 |
});
|
553 |
|
554 |
+
// Create input controllers but don't add mouse wheel handling - we handle that separately
|
555 |
cameraEntity.script.create('orbitCameraInputMouse', {
|
556 |
attributes: {
|
557 |
orbitSensitivity: isMobile ? 0.6 : 0.3,
|
|
|
561 |
|
562 |
// Disable wheel event in the orbit camera input
|
563 |
if (cameraEntity.script.orbitCameraInputMouse) {
|
564 |
+
// Override mouse wheel to do nothing - we handle wheel events separately
|
|
|
|
|
|
|
565 |
cameraEntity.script.orbitCameraInputMouse.onMouseWheel = function() {};
|
566 |
}
|
567 |
|