From 56f4576a52a54e19d5c62b9c79c6cf09f5e4fa64 Mon Sep 17 00:00:00 2001 From: yushiang Date: Sun, 5 May 2024 17:53:46 +0800 Subject: [PATCH] enhance: simulator can't change sensor position, viewer can. --- src/Simulator.jsx | 2 -- src/Viewer.jsx | 9 +++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Simulator.jsx b/src/Simulator.jsx index 3121fe9..a2301ca 100644 --- a/src/Simulator.jsx +++ b/src/Simulator.jsx @@ -117,12 +117,10 @@ const Simulator = () => { }; window.addEventListener("resize", core.resizeCanvas); - canvas.addEventListener("pointerdown", core.onSelectSensor); canvas.addEventListener("pointerup", onPointerUp); return () => { window.removeEventListener("resize", core.resizeCanvas); - canvas.addEventListener("pointerdown", core.onSelectSensor); canvas.removeEventListener("pointerup", onPointerUp); }; }, [core, isTeleport, isPause]); diff --git a/src/Viewer.jsx b/src/Viewer.jsx index af15bb0..071dd80 100644 --- a/src/Viewer.jsx +++ b/src/Viewer.jsx @@ -12,6 +12,7 @@ const Viewer = () => { const threeApp = new ThreeApp(canvas); window.addEventListener("resize", threeApp.resizeCanvas); + canvas.addEventListener("pointerdown", threeApp.onSelectSensor); let prevPosition = [0, 0, 0]; const timer = setInterval(() => { @@ -41,8 +42,11 @@ const Viewer = () => { sensorPositions.map((v) => v.toArray()), sensorDistance ); - threeApp.setCamera(prevPosition, result); - prevPosition = [...result]; + + if (JSON.stringify(prevPosition) !== JSON.stringify(result)) { + threeApp.setCamera(prevPosition, result); + prevPosition = [...result]; + } }); }, 2e2); @@ -50,6 +54,7 @@ const Viewer = () => { clearInterval(timer); threeApp.animator.dispose(); window.removeEventListener("resize", threeApp.resizeCanvas); + canvas.addEventListener("pointerdown", threeApp.onSelectSensor); }; }, []);