Skip to content

Commit

Permalink
Nadro/2833/zoom level increase when swapping sketch modes (#3854)
Browse files Browse the repository at this point in the history
* fix: fixing logic around setting the perspective and position of perspective camera when leaving sketch mode

* fix: typo

* A snapshot a day keeps the bugs away! πŸ“·πŸ› (OS: ubuntu-latest)

* A snapshot a day keeps the bugs away! πŸ“·πŸ› (OS: windows-latest)

* Revert "A snapshot a day keeps the bugs away! πŸ“·πŸ› (OS: windows-latest)"

This reverts commit 60b12ff.

* Revert "A snapshot a day keeps the bugs away! πŸ“·πŸ› (OS: ubuntu-latest)"

This reverts commit 9ab973c.

* A snapshot a day keeps the bugs away! πŸ“·πŸ› (OS: ubuntu-latest)

* A snapshot a day keeps the bugs away! πŸ“·πŸ› (OS: windows-latest)

* A snapshot a day keeps the bugs away! πŸ“·πŸ› (OS: windows-latest)

* A snapshot a day keeps the bugs away! πŸ“·πŸ› (OS: windows-latest)

* remove unused vars

* fix: fixed the positions of the mouse clicks since the zoom level has changed?

* fix: updating test to make it work with my new zoom level

* A snapshot a day keeps the bugs away! πŸ“·πŸ› (OS: ubuntu-latest)

* A snapshot a day keeps the bugs away! πŸ“·πŸ› (OS: windows-latest)

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Kurt Hutten Irev-Dev <[email protected]>
  • Loading branch information
3 people committed Sep 19, 2024
1 parent 370375c commit 4285e81
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 23 deletions.
8 changes: 4 additions & 4 deletions e2e/playwright/sketch-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,19 +618,19 @@ test.describe('Sketch tests', () => {
await u.closeDebugPanel()

await click00r(30, 0)
codeStr += ` |> startProfileAt([1.53, 0], %)`
codeStr += ` |> startProfileAt([2.03, 0], %)`
await expect(u.codeLocator).toHaveText(codeStr)

await click00r(30, 0)
codeStr += ` |> line([1.53, 0], %)`
codeStr += ` |> line([2.04, 0], %)`
await expect(u.codeLocator).toHaveText(codeStr)

await click00r(0, 30)
codeStr += ` |> line([0, -1.53], %)`
codeStr += ` |> line([0, -2.03], %)`
await expect(u.codeLocator).toHaveText(codeStr)

await click00r(-30, 0)
codeStr += ` |> line([-1.53, 0], %)`
codeStr += ` |> line([-2.04, 0], %)`
await expect(u.codeLocator).toHaveText(codeStr)

await click00r(undefined, undefined)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 13 additions & 5 deletions e2e/playwright/testing-selections.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ test.describe('Testing selections', () => {

const xAxisClick = () =>
page.mouse.click(700, 253).then(() => page.waitForTimeout(100))
const xAxisClickAfterExitingSketch = () =>
page.mouse.click(639, 278).then(() => page.waitForTimeout(100))
const emptySpaceHover = () =>
test.step('Hover over empty space', async () => {
await page.mouse.move(700, 143, { steps: 5 })
Expand All @@ -44,9 +46,13 @@ test.describe('Testing selections', () => {
)
})
const topHorzSegmentClick = () =>
page.mouse.click(709, 290).then(() => page.waitForTimeout(100))
page.mouse
.click(startXPx, 500 - PUR * 20)
.then(() => page.waitForTimeout(100))
const bottomHorzSegmentClick = () =>
page.mouse.click(767, 396).then(() => page.waitForTimeout(100))
page.mouse
.click(startXPx + PUR * 10, 500 - PUR * 10)
.then(() => page.waitForTimeout(100))

await u.clearCommandLogs()
await expect(
Expand Down Expand Up @@ -196,6 +202,8 @@ test.describe('Testing selections', () => {

// select a line, this verifies that sketches in the scene can be selected outside of sketch mode
await topHorzSegmentClick()
await xAxisClickAfterExitingSketch()
await page.waitForTimeout(100)
await emptySpaceHover()

// enter sketch again
Expand Down Expand Up @@ -425,7 +433,7 @@ const sketch002 = startSketchOn(launderExtrudeThroughVar, seg02)
|> line([0, 20.03], %)
|> line([62.61, 0], %, $seg03)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
|> close(%)
`
)
}, KCL_DEFAULT_LENGTH)
Expand Down Expand Up @@ -1014,7 +1022,7 @@ const extrude001 = extrude(50, sketch001)
|> line([4.95, -8], %)
|> line([-20.38, -10.12], %)
|> line([-15.79, 17.08], %)
fn yohey = (pos) => {
const sketch004 = startSketchOn('XZ')
${extrudeAndEditBlockedInFunction}
Expand All @@ -1024,7 +1032,7 @@ const extrude001 = extrude(50, sketch001)
|> line([-15.79, 17.08], %)
return ''
}
yohey([15.79, -34.6])
`
)
Expand Down
24 changes: 10 additions & 14 deletions src/clientSideScene/CameraControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { reportRejection } from 'lib/trap'

const ORTHOGRAPHIC_CAMERA_SIZE = 20
const FRAMES_TO_ANIMATE_IN = 30
const ORTHOGRAPHIC_MAGIC_FOV = 4

const tempQuaternion = new Quaternion() // just used for maths

Expand Down Expand Up @@ -84,7 +85,7 @@ export class CameraControls {
pendingPan: Vector2 | null = null
interactionGuards: MouseGuard = cameraMouseDragGuards.KittyCAD
isFovAnimationInProgress = false
fovBeforeOrtho = 45
perspectiveFovBeforeOrtho = 45
get isPerspective() {
return this.camera instanceof PerspectiveCamera
}
Expand Down Expand Up @@ -398,7 +399,7 @@ export class CameraControls {
const zoomFudgeFactor = 2280
distance = zoomFudgeFactor / (this.camera.zoom * 45)
}
const panSpeed = (distance / 1000 / 45) * this.fovBeforeOrtho
const panSpeed = (distance / 1000 / 45) * this.perspectiveFovBeforeOrtho
this.pendingPan.x += -deltaMove.x * panSpeed
this.pendingPan.y += deltaMove.y * panSpeed
}
Expand Down Expand Up @@ -516,19 +517,15 @@ export class CameraControls {
_usePerspectiveCamera = () => {
const { x: px, y: py, z: pz } = this.camera.position
const { x: qx, y: qy, z: qz, w: qw } = this.camera.quaternion
const zoom = this.camera.zoom
this.camera = this.createPerspectiveCamera()

this.camera.position.set(px, py, pz)
this.camera.quaternion.set(qx, qy, qz, qw)
const zoomFudgeFactor = 2280
const distance = zoomFudgeFactor / (zoom * this.lastPerspectiveFov)
const direction = new Vector3().subVectors(
this.camera.position,
this.target
)
direction.normalize()
this.camera.position.copy(this.target).addScaledVector(direction, distance)
}
usePerspectiveCamera = async (forceSend = false) => {
this._usePerspectiveCamera()
Expand Down Expand Up @@ -980,9 +977,9 @@ export class CameraControls {
)
this.isFovAnimationInProgress = true
let currentFov = this.lastPerspectiveFov
this.fovBeforeOrtho = currentFov
this.perspectiveFovBeforeOrtho = currentFov

const targetFov = 4
const targetFov = ORTHOGRAPHIC_MAGIC_FOV
const fovAnimationStep = (currentFov - targetFov) / FRAMES_TO_ANIMATE_IN
let frameWaitOnFinish = 10

Expand Down Expand Up @@ -1018,9 +1015,9 @@ export class CameraControls {
)
}
this.isFovAnimationInProgress = true
const targetFov = this.fovBeforeOrtho // Target FOV for perspective
this.lastPerspectiveFov = 4
let currentFov = 4
const targetFov = this.perspectiveFovBeforeOrtho // Target FOV for perspective
this.lastPerspectiveFov = ORTHOGRAPHIC_MAGIC_FOV
let currentFov = ORTHOGRAPHIC_MAGIC_FOV
const initialCameraUp = this.camera.up.clone()
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.usePerspectiveCamera()
Expand Down Expand Up @@ -1056,9 +1053,8 @@ export class CameraControls {
)
}
this.isFovAnimationInProgress = true
const targetFov = this.fovBeforeOrtho // Target FOV for perspective
this.lastPerspectiveFov = 4
let currentFov = 4
const targetFov = this.perspectiveFovBeforeOrtho // Target FOV for perspective
let currentFov = ORTHOGRAPHIC_MAGIC_FOV
const initialCameraUp = this.camera.up.clone()
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.usePerspectiveCamera()
Expand Down

0 comments on commit 4285e81

Please sign in to comment.