Skip to content

Commit

Permalink
Merge branch 'master' into np/point-cloud-filter-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
nilscognite authored Aug 2, 2024
2 parents 445f507 + b755327 commit 5f24ec6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion react-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cognite/reveal-react-components",
"version": "0.55.0",
"version": "0.55.1",
"exports": {
".": {
"import": "./dist/index.js",
Expand Down
20 changes: 19 additions & 1 deletion react-components/src/hooks/useSceneDefaultCamera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,25 @@ export const useSceneDefaultCamera = (

return {
fitCameraToSceneDefault: () => {
viewer.cameraManager.setCameraState({ position, target });
const initialCameraState = viewer.cameraManager.getCameraState();

// Preserve pivot point if user has already set a pivot point
// If not, set the pivot point near the center of the scene
// When moving Scene to system space, we will extend the data
// model to store pos, rot and pivot
if (
initialCameraState.target.x === 0 &&
initialCameraState.target.y === 0 &&
initialCameraState.target.z === 0
) {
viewer.cameraManager.setCameraState({ position, target });
} else {
const direction = new Vector3().subVectors(position, target).normalize();
const rotation = new Euler().setFromVector3(direction);
const quaternion = new Quaternion().setFromEuler(rotation);

viewer.cameraManager.setCameraState({ position, rotation: quaternion });
}
},
isFetched: true
};
Expand Down
6 changes: 0 additions & 6 deletions react-components/stories/SceneContainer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
useSceneDefaultCamera,
withSuppressRevealEvents
} from '../src';
import { type DefaultCameraManager } from '@cognite/reveal';
import { ToolBar } from '@cognite/cogs.js';
import styled from 'styled-components';

Expand Down Expand Up @@ -79,11 +78,6 @@ const SceneContainerStoryContent = ({
const { fitCameraToSceneDefault } = useSceneDefaultCamera(sceneExternalId, sceneSpaceId);

useEffect(() => {
(reveal.cameraManager as DefaultCameraManager).setCameraControlsOptions({
changeCameraTargetOnClick: true,
mouseWheelAction: 'zoomToCursor'
});

fitCameraToSceneDefault();
}, [reveal, fitCameraToSceneDefault]);
return (
Expand Down

0 comments on commit 5f24ec6

Please sign in to comment.