Compare commits

...

2 Commits

View File

@ -1,4 +1,17 @@
import { CameraDragInteractionType_type } from '@kittycad/lib/dist/types/src/models'
import { CameraProjectionType } from '@rust/kcl-lib/bindings/CameraProjectionType'
import * as TWEEN from '@tweenjs/tween.js'
import { EngineCommand } from 'lang/std/artifactGraph'
import {
EngineCommandManager,
Subscription,
UnreliableSubscription,
} from 'lang/std/engineConnection'
import { cameraMouseDragGuards, MouseGuard } from 'lib/cameraControls' import { cameraMouseDragGuards, MouseGuard } from 'lib/cameraControls'
import { AxisNames } from 'lib/constants'
import { reportRejection } from 'lib/trap'
import { isReducedMotion, roundOff, throttle, toSync, uuidv4 } from 'lib/utils'
import { deg2Rad } from 'lib/utils2d'
import { import {
Euler, Euler,
MathUtils, MathUtils,
@ -10,26 +23,13 @@ import {
Vector2, Vector2,
Vector3, Vector3,
} from 'three' } from 'three'
import { isQuaternionVertical } from './helpers'
import { import {
DEBUG_SHOW_INTERSECTION_PLANE, DEBUG_SHOW_INTERSECTION_PLANE,
INTERSECTION_PLANE_LAYER, INTERSECTION_PLANE_LAYER,
SKETCH_LAYER, SKETCH_LAYER,
ZOOM_MAGIC_NUMBER, ZOOM_MAGIC_NUMBER,
} from './sceneInfra' } from './sceneInfra'
import {
Subscription,
EngineCommandManager,
UnreliableSubscription,
} from 'lang/std/engineConnection'
import { EngineCommand } from 'lang/std/artifactGraph'
import { toSync, uuidv4 } from 'lib/utils'
import { deg2Rad } from 'lib/utils2d'
import { isReducedMotion, roundOff, throttle } from 'lib/utils'
import * as TWEEN from '@tweenjs/tween.js'
import { isQuaternionVertical } from './helpers'
import { reportRejection } from 'lib/trap'
import { CameraProjectionType } from '@rust/kcl-lib/bindings/CameraProjectionType'
import { CameraDragInteractionType_type } from '@kittycad/lib/dist/types/src/models'
const ORTHOGRAPHIC_CAMERA_SIZE = 20 const ORTHOGRAPHIC_CAMERA_SIZE = 20
const FRAMES_TO_ANIMATE_IN = 30 const FRAMES_TO_ANIMATE_IN = 30
@ -865,28 +865,38 @@ export class CameraControls {
}) })
} }
async updateCameraToAxis( async updateCameraToAxis(axis: AxisNames): Promise<void> {
axis: 'x' | 'y' | 'z' | '-x' | '-y' | '-z'
): Promise<void> {
const distance = this.camera.position.distanceTo(this.target) const distance = this.camera.position.distanceTo(this.target)
const vantage = this.target.clone() const vantage = this.target.clone()
let up = { x: 0, y: 0, z: 1 }
if (axis === 'x') { // Default to Z-up.
vantage.x += distance const unitZ = { x: 0, y: 0, z: 1 }
} else if (axis === 'y') { const unitY = { x: 0, y: 1, z: 0 }
vantage.y += distance let up = unitZ
} else if (axis === 'z') {
vantage.z += distance switch (axis) {
up = { x: -1, y: 0, z: 0 } case AxisNames.X:
} else if (axis === '-x') { vantage.x += distance
vantage.x -= distance break
} else if (axis === '-y') { case AxisNames.NEG_X:
vantage.y -= distance vantage.x -= distance
} else if (axis === '-z') { break
vantage.z -= distance case AxisNames.Y:
up = { x: -1, y: 0, z: 0 } vantage.y += distance
break
case AxisNames.NEG_Y:
vantage.y -= distance
break
case AxisNames.Z:
// Looking from top-down, so X positive to the right, Y positive up.
vantage.z += distance
up = unitY
break
case AxisNames.NEG_Z:
// Looking from bottom-up, so X positive to the left, Y positive up.
vantage.z -= distance
up = unitY
break
} }
await this.engineCommandManager.sendSceneCommand({ await this.engineCommandManager.sendSceneCommand({