diff --git a/src/lib/resetCameraPosition.ts b/src/lib/resetCameraPosition.ts index 3cf531708..612de1f67 100644 --- a/src/lib/resetCameraPosition.ts +++ b/src/lib/resetCameraPosition.ts @@ -1,6 +1,11 @@ import { DEFAULT_DEFAULT_LENGTH_UNIT } from '@src/lib/constants' import { isPlaywright } from '@src/lib/isPlaywright' -import { engineCommandManager, kclManager } from '@src/lib/singletons' +import { + engineCommandManager, + kclManager, + sceneInfra, + settingsActor, +} from '@src/lib/singletons' import { engineStreamZoomToFit, engineViewIsometricWithoutGeometryPresent, @@ -22,6 +27,15 @@ export async function resetCameraPosition() { if (isPlaywright()) { await engineStreamZoomToFit({ engineCommandManager, padding }) } else { + // Get user camera projection + const cameraProjection = + settingsActor.getSnapshot().context.modeling.cameraProjection.current + + // We need to keep the users projection setting when resetting their camera + if (cameraProjection === 'perspective') { + await sceneInfra.camControls.usePerspectiveCamera() + } + // If the scene is empty you cannot use view_isometric, it will not move the camera if (kclManager.isAstBodyEmpty(kclManager.ast)) { await engineViewIsometricWithoutGeometryPresent({ @@ -29,6 +43,7 @@ export async function resetCameraPosition() { unit: kclManager.fileSettings.defaultLengthUnit || DEFAULT_DEFAULT_LENGTH_UNIT, + cameraProjection, }) } else { await engineViewIsometricWithGeometryPresent({ diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 14b4c0b46..0b96bbf21 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -12,6 +12,7 @@ import type { CameraViewState_type, UnitLength_type, } from '@kittycad/lib/dist/types/src/models' +import type { CameraProjectionType } from '@rust/kcl-lib/bindings/CameraProjectionType' export const uuidv4 = v4 @@ -622,9 +623,11 @@ export async function engineViewIsometricWithGeometryPresent({ export async function engineViewIsometricWithoutGeometryPresent({ engineCommandManager, unit, + cameraProjection, }: { engineCommandManager: EngineCommandManager unit?: UnitLength_type + cameraProjection: CameraProjectionType }) { // If you load an empty scene with any file unit it will have an eye offset of this const MAGIC_ENGINE_EYE_OFFSET = 1378.0057 @@ -644,8 +647,8 @@ export async function engineViewIsometricWithoutGeometryPresent({ eye_offset: MAGIC_ENGINE_EYE_OFFSET, fov_y: 45, ortho_scale_factor: 1.4063792, - is_ortho: true, - ortho_scale_enabled: true, + is_ortho: cameraProjection !== 'perspective', + ortho_scale_enabled: cameraProjection !== 'perspective', world_coord_system: 'right_handed_up_z', } await engineCommandManager.sendSceneCommand({