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
This commit is contained in:
@ -29,15 +29,9 @@ import { useSelector } from '@xstate/react'
|
|||||||
import type { MouseEventHandler } from 'react'
|
import type { MouseEventHandler } from 'react'
|
||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { useRouteLoaderData } from 'react-router-dom'
|
import { useRouteLoaderData } from 'react-router-dom'
|
||||||
import { isPlaywright } from '@src/lib/isPlaywright'
|
|
||||||
import {
|
|
||||||
engineStreamZoomToFit,
|
|
||||||
engineViewIsometricWithGeometryPresent,
|
|
||||||
engineViewIsometricWithoutGeometryPresent,
|
|
||||||
} from '@src/lib/utils'
|
|
||||||
import { DEFAULT_DEFAULT_LENGTH_UNIT } from '@src/lib/constants'
|
|
||||||
import { createThumbnailPNGOnDesktop } from '@src/lib/screenshot'
|
import { createThumbnailPNGOnDesktop } from '@src/lib/screenshot'
|
||||||
import type { SettingsViaQueryString } from '@src/lib/settings/settingsTypes'
|
import type { SettingsViaQueryString } from '@src/lib/settings/settingsTypes'
|
||||||
|
import { resetCameraPosition } from '@src/lib/resetCameraPosition'
|
||||||
|
|
||||||
export const EngineStream = (props: {
|
export const EngineStream = (props: {
|
||||||
pool: string | null
|
pool: string | null
|
||||||
@ -104,31 +98,7 @@ export const EngineStream = (props: {
|
|||||||
|
|
||||||
kmp
|
kmp
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
// Gotcha: Playwright E2E tests will be zoom_to_fit, when you try to recreate the e2e test manually
|
await resetCameraPosition()
|
||||||
// your localhost will do view_isometric. Turn this boolean on to have the same experience when manually
|
|
||||||
// debugging e2e tests
|
|
||||||
|
|
||||||
// We need a padding of 0.1 for zoom_to_fit for all E2E tests since they were originally
|
|
||||||
// written with zoom_to_fit with padding 0.1
|
|
||||||
const padding = 0.1
|
|
||||||
if (isPlaywright()) {
|
|
||||||
await engineStreamZoomToFit({ engineCommandManager, padding })
|
|
||||||
} else {
|
|
||||||
// If the scene is empty you cannot use view_isometric, it will not move the camera
|
|
||||||
if (kclManager.isAstBodyEmpty(kclManager.ast)) {
|
|
||||||
await engineViewIsometricWithoutGeometryPresent({
|
|
||||||
engineCommandManager,
|
|
||||||
unit:
|
|
||||||
kclManager.fileSettings.defaultLengthUnit ||
|
|
||||||
DEFAULT_DEFAULT_LENGTH_UNIT,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
await engineViewIsometricWithGeometryPresent({
|
|
||||||
engineCommandManager,
|
|
||||||
padding,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (project && project.path) {
|
if (project && project.path) {
|
||||||
createThumbnailPNGOnDesktop({
|
createThumbnailPNGOnDesktop({
|
||||||
|
@ -13,6 +13,7 @@ import { VIEW_NAMES_SEMANTIC } from '@src/lib/constants'
|
|||||||
import { sceneInfra } from '@src/lib/singletons'
|
import { sceneInfra } from '@src/lib/singletons'
|
||||||
import { reportRejection } from '@src/lib/trap'
|
import { reportRejection } from '@src/lib/trap'
|
||||||
import { useSettings } from '@src/lib/singletons'
|
import { useSettings } from '@src/lib/singletons'
|
||||||
|
import { resetCameraPosition } from '@src/lib/resetCameraPosition'
|
||||||
|
|
||||||
export function useViewControlMenuItems() {
|
export function useViewControlMenuItems() {
|
||||||
const { state: modelingState, send: modelingSend } = useModelingContext()
|
const { state: modelingState, send: modelingSend } = useModelingContext()
|
||||||
@ -38,7 +39,7 @@ export function useViewControlMenuItems() {
|
|||||||
<ContextMenuDivider />,
|
<ContextMenuDivider />,
|
||||||
<ContextMenuItem
|
<ContextMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
sceneInfra.camControls.resetCameraPosition().catch(reportRejection)
|
resetCameraPosition().catch(reportRejection)
|
||||||
}}
|
}}
|
||||||
disabled={shouldLockView}
|
disabled={shouldLockView}
|
||||||
>
|
>
|
||||||
|
40
src/lib/resetCameraPosition.ts
Normal file
40
src/lib/resetCameraPosition.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { DEFAULT_DEFAULT_LENGTH_UNIT } from '@src/lib/constants'
|
||||||
|
import { isPlaywright } from '@src/lib/isPlaywright'
|
||||||
|
import { engineCommandManager, kclManager } from '@src/lib/singletons'
|
||||||
|
import {
|
||||||
|
engineStreamZoomToFit,
|
||||||
|
engineViewIsometricWithoutGeometryPresent,
|
||||||
|
engineViewIsometricWithGeometryPresent,
|
||||||
|
} from '@src/lib/utils'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the camera position to a baseline, which is isometric for
|
||||||
|
* normal users and a deprecated "front-down" view for playwright tests.
|
||||||
|
*
|
||||||
|
* Gotcha: Playwright E2E tests will be zoom_to_fit, when you try to recreate the e2e test manually
|
||||||
|
* your localhost will do view_isometric. Turn this boolean on to have the same experience when manually
|
||||||
|
* debugging e2e tests
|
||||||
|
*/
|
||||||
|
export async function resetCameraPosition() {
|
||||||
|
// We need a padding of 0.1 for zoom_to_fit for all E2E tests since they were originally
|
||||||
|
// written with zoom_to_fit with padding 0.1
|
||||||
|
const padding = 0.1
|
||||||
|
if (isPlaywright()) {
|
||||||
|
await engineStreamZoomToFit({ engineCommandManager, padding })
|
||||||
|
} else {
|
||||||
|
// If the scene is empty you cannot use view_isometric, it will not move the camera
|
||||||
|
if (kclManager.isAstBodyEmpty(kclManager.ast)) {
|
||||||
|
await engineViewIsometricWithoutGeometryPresent({
|
||||||
|
engineCommandManager,
|
||||||
|
unit:
|
||||||
|
kclManager.fileSettings.defaultLengthUnit ||
|
||||||
|
DEFAULT_DEFAULT_LENGTH_UNIT,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
await engineViewIsometricWithGeometryPresent({
|
||||||
|
engineCommandManager,
|
||||||
|
padding,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user