Skip to content

Commit

Permalink
enhance: simulator can't change sensor position, viewer can.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsengyushiang committed May 5, 2024
1 parent 7b9c105 commit 56f4576
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/Simulator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
9 changes: 7 additions & 2 deletions src/Viewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -41,15 +42,19 @@ 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);

return () => {
clearInterval(timer);
threeApp.animator.dispose();
window.removeEventListener("resize", threeApp.resizeCanvas);
canvas.addEventListener("pointerdown", threeApp.onSelectSensor);
};
}, []);

Expand Down

0 comments on commit 56f4576

Please sign in to comment.