Skip to content

Commit b23fc9f

Browse files
authored
Make the Reset View button do the same view_isometric behavior as load (#6934)
* Make the Reset View button do the same view_isometric behavior as load Just copying some logic from the EngineStream code to make that button behave the same way: old initial camera position while in Playwright, isometric view for normal users. * Move duplicate code into shared `resetCameraPosition` function * Fix lints
1 parent 5c2dfb8 commit b23fc9f

File tree

3 files changed

+44
-33
lines changed

3 files changed

+44
-33
lines changed

src/components/EngineStream.tsx

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,9 @@ import { useSelector } from '@xstate/react'
2929
import type { MouseEventHandler } from 'react'
3030
import { useEffect, useRef, useState } from 'react'
3131
import { useRouteLoaderData } from 'react-router-dom'
32-
import { isPlaywright } from '@src/lib/isPlaywright'
33-
import {
34-
engineStreamZoomToFit,
35-
engineViewIsometricWithGeometryPresent,
36-
engineViewIsometricWithoutGeometryPresent,
37-
} from '@src/lib/utils'
38-
import { DEFAULT_DEFAULT_LENGTH_UNIT } from '@src/lib/constants'
3932
import { createThumbnailPNGOnDesktop } from '@src/lib/screenshot'
4033
import type { SettingsViaQueryString } from '@src/lib/settings/settingsTypes'
34+
import { resetCameraPosition } from '@src/lib/resetCameraPosition'
4135

4236
export const EngineStream = (props: {
4337
pool: string | null
@@ -104,31 +98,7 @@ export const EngineStream = (props: {
10498

10599
kmp
106100
.then(async () => {
107-
// Gotcha: Playwright E2E tests will be zoom_to_fit, when you try to recreate the e2e test manually
108-
// your localhost will do view_isometric. Turn this boolean on to have the same experience when manually
109-
// debugging e2e tests
110-
111-
// We need a padding of 0.1 for zoom_to_fit for all E2E tests since they were originally
112-
// written with zoom_to_fit with padding 0.1
113-
const padding = 0.1
114-
if (isPlaywright()) {
115-
await engineStreamZoomToFit({ engineCommandManager, padding })
116-
} else {
117-
// If the scene is empty you cannot use view_isometric, it will not move the camera
118-
if (kclManager.isAstBodyEmpty(kclManager.ast)) {
119-
await engineViewIsometricWithoutGeometryPresent({
120-
engineCommandManager,
121-
unit:
122-
kclManager.fileSettings.defaultLengthUnit ||
123-
DEFAULT_DEFAULT_LENGTH_UNIT,
124-
})
125-
} else {
126-
await engineViewIsometricWithGeometryPresent({
127-
engineCommandManager,
128-
padding,
129-
})
130-
}
131-
}
101+
await resetCameraPosition()
132102

133103
if (project && project.path) {
134104
createThumbnailPNGOnDesktop({

src/components/ViewControlMenu.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { VIEW_NAMES_SEMANTIC } from '@src/lib/constants'
1313
import { sceneInfra } from '@src/lib/singletons'
1414
import { reportRejection } from '@src/lib/trap'
1515
import { useSettings } from '@src/lib/singletons'
16+
import { resetCameraPosition } from '@src/lib/resetCameraPosition'
1617

1718
export function useViewControlMenuItems() {
1819
const { state: modelingState, send: modelingSend } = useModelingContext()
@@ -38,7 +39,7 @@ export function useViewControlMenuItems() {
3839
<ContextMenuDivider />,
3940
<ContextMenuItem
4041
onClick={() => {
41-
sceneInfra.camControls.resetCameraPosition().catch(reportRejection)
42+
resetCameraPosition().catch(reportRejection)
4243
}}
4344
disabled={shouldLockView}
4445
>

src/lib/resetCameraPosition.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { DEFAULT_DEFAULT_LENGTH_UNIT } from '@src/lib/constants'
2+
import { isPlaywright } from '@src/lib/isPlaywright'
3+
import { engineCommandManager, kclManager } from '@src/lib/singletons'
4+
import {
5+
engineStreamZoomToFit,
6+
engineViewIsometricWithoutGeometryPresent,
7+
engineViewIsometricWithGeometryPresent,
8+
} from '@src/lib/utils'
9+
10+
/**
11+
* Reset the camera position to a baseline, which is isometric for
12+
* normal users and a deprecated "front-down" view for playwright tests.
13+
*
14+
* Gotcha: Playwright E2E tests will be zoom_to_fit, when you try to recreate the e2e test manually
15+
* your localhost will do view_isometric. Turn this boolean on to have the same experience when manually
16+
* debugging e2e tests
17+
*/
18+
export async function resetCameraPosition() {
19+
// We need a padding of 0.1 for zoom_to_fit for all E2E tests since they were originally
20+
// written with zoom_to_fit with padding 0.1
21+
const padding = 0.1
22+
if (isPlaywright()) {
23+
await engineStreamZoomToFit({ engineCommandManager, padding })
24+
} else {
25+
// If the scene is empty you cannot use view_isometric, it will not move the camera
26+
if (kclManager.isAstBodyEmpty(kclManager.ast)) {
27+
await engineViewIsometricWithoutGeometryPresent({
28+
engineCommandManager,
29+
unit:
30+
kclManager.fileSettings.defaultLengthUnit ||
31+
DEFAULT_DEFAULT_LENGTH_UNIT,
32+
})
33+
} else {
34+
await engineViewIsometricWithGeometryPresent({
35+
engineCommandManager,
36+
padding,
37+
})
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)