Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react-components): Preserve camera pivot point on Reset to Home #4686

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 7 additions & 0 deletions react-components/src/hooks/useSceneDefaultCamera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ export const useSceneDefaultCamera = (

return {
fitCameraToSceneDefault: () => {
const initialCameraState = viewer.cameraManager.getCameraState();

viewer.cameraManager.setCameraState({ position, target });

// Keep the camera target (pivot) in the same position
viewer.cameraManager.setCameraState({
target: initialCameraState.target
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialCameraState.target value be at origin when the scene is loaded for the first time, it would set the pivot point to origin when scene loaded for the first time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, that would be an issue if the models are really far away from origin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for camera being in origin in ea7034a

});
},
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
Loading