Skip to content

Commit

Permalink
Merge pull request #71 from yushiang-demo/fix-editor-camera-constraint
Browse files Browse the repository at this point in the history
Fix: enable camera rotation and zooming in editors.
  • Loading branch information
tsengyushiang authored Dec 17, 2023
2 parents ebc87fd + e58298f commit bd6da28
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The format is based on [Keep a Changelog](https://github.com/olivierlacan/keep-a

### Fixed

- Fix don't camera rotation and zooming in editors. (https://github.com/yushiang-demo/pano-to-mesh/pull/71)

### Removed

## [2.0.0] - 2023-12-16
Expand Down
23 changes: 21 additions & 2 deletions packages/three/core/helpers/CameraControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ function CameraControls(camera, domElement) {
};

let constraintPanEvent = null;
const focus = (object, constraintPan = true) => {
const focus = (
object,
constraintZoom = true,
constraintPan = true,
constraintRotate = true
) => {
if (!object) return;
const { origin, distance, boundingBox } = getFocusSettings(
object,
Expand All @@ -106,7 +111,21 @@ function CameraControls(camera, domElement) {
controls.minDistance = 0;
controls.update();

setMode(MODE.TOP_VIEW, object);
if (constraintZoom) {
const { distance: minDistance } = getFocusSettings(object, 1.0);
const { distance: maxDistance } = getFocusSettings(object, 0.5);
controls.maxDistance = maxDistance;
controls.minDistance = minDistance;
controls.update();
}

if (constraintRotate) {
controls.maxPolarAngle = Math.PI / 2;
controls.minPolarAngle = 0;
controls.maxAzimuthAngle = Infinity;
controls.minAzimuthAngle = -Infinity;
controls.update();
}

if (constraintPan) {
const checkTarget = () => {
Expand Down

0 comments on commit bd6da28

Please sign in to comment.