* solve a couple of scene scale bugs * Some cam fixes (#1520) * rotate and zoom basics working * intergrate mouse guards, and add pan * implement orthographic camera again * implement switch to perspective camera again * migrate dollyzoom * make pan robust for differnt FOV and orthographic cam * tween to quaternion and default plane selection working with quirks * fix pan It the up and right was derived from the camera's up, which is a static [0,0,1] not the camera's current cameras real up, which aligns itself as best to [0,0,1] but is not that especially when looking straight up or down, and the pan felt very awkward in these vertical look sintuations * fix raycastRing to use new camera * fix tween to quaternion for camera lock situations And get all playwright tests passing * fix up CamToggle, even thought this component is not setup properly to use react properties from our scene class * add animation to cameras back in * first big clean up of sceneInfra * move more cam stuff out of sceneInfra * clean up mouse guard logic * clean up camera change callbacks * fix some sitations where animation to xy doesn't work great * needs to take the target into consideration * last bits of clean up * more clean up * make vitest happ * fix up remaining interaction guards * make scrolling less sensative for trackpads * remove debug cube * fix snapshot tests
163 lines
4.3 KiB
TypeScript
163 lines
4.3 KiB
TypeScript
const noModifiersPressed = (e: React.MouseEvent) =>
|
|
!e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey
|
|
|
|
export type CameraSystem =
|
|
| 'KittyCAD'
|
|
| 'OnShape'
|
|
| 'Trackpad Friendly'
|
|
| 'Solidworks'
|
|
| 'NX'
|
|
| 'Creo'
|
|
| 'AutoCAD'
|
|
|
|
export const cameraSystems: CameraSystem[] = [
|
|
'KittyCAD',
|
|
'OnShape',
|
|
'Trackpad Friendly',
|
|
'Solidworks',
|
|
'NX',
|
|
'Creo',
|
|
'AutoCAD',
|
|
]
|
|
|
|
interface MouseGuardHandler {
|
|
description: string
|
|
callback: (e: React.MouseEvent) => boolean
|
|
lenientDragStartButton?: number
|
|
}
|
|
|
|
interface MouseGuardZoomHandler {
|
|
description: string
|
|
dragCallback: (e: React.MouseEvent) => boolean
|
|
scrollCallback: (e: React.MouseEvent) => boolean
|
|
lenientDragStartButton?: number
|
|
}
|
|
|
|
export interface MouseGuard {
|
|
pan: MouseGuardHandler
|
|
zoom: MouseGuardZoomHandler
|
|
rotate: MouseGuardHandler
|
|
}
|
|
|
|
const butName = (e: React.MouseEvent) => ({
|
|
middle: !!(e.buttons & 4),
|
|
right: !!(e.buttons & 2),
|
|
left: !!(e.buttons & 1),
|
|
})
|
|
|
|
export const cameraMouseDragGuards: Record<CameraSystem, MouseGuard> = {
|
|
KittyCAD: {
|
|
pan: {
|
|
description: 'Right click + Shift + drag or middle click + drag',
|
|
callback: (e) =>
|
|
(butName(e).middle && noModifiersPressed(e)) ||
|
|
(butName(e).right && e.shiftKey),
|
|
},
|
|
zoom: {
|
|
description: 'Scroll wheel or Right click + Ctrl + drag',
|
|
dragCallback: (e) => !!(e.buttons & 2) && e.ctrlKey,
|
|
scrollCallback: () => true,
|
|
},
|
|
rotate: {
|
|
description: 'Right click + drag',
|
|
callback: (e) => butName(e).right && noModifiersPressed(e),
|
|
},
|
|
},
|
|
OnShape: {
|
|
pan: {
|
|
description: 'Right click + Ctrl + drag or middle click + drag',
|
|
callback: (e) =>
|
|
(butName(e).right && e.ctrlKey) ||
|
|
(butName(e).middle && noModifiersPressed(e)),
|
|
},
|
|
zoom: {
|
|
description: 'Scroll wheel',
|
|
dragCallback: () => false,
|
|
scrollCallback: () => true,
|
|
},
|
|
rotate: {
|
|
description: 'Right click + drag',
|
|
callback: (e) => butName(e).right && noModifiersPressed(e),
|
|
},
|
|
},
|
|
'Trackpad Friendly': {
|
|
pan: {
|
|
description: 'Left click + Alt + Shift + drag or middle click + drag',
|
|
callback: (e) =>
|
|
(butName(e).left && e.altKey && e.shiftKey && !e.metaKey) ||
|
|
(butName(e).middle && noModifiersPressed(e)),
|
|
},
|
|
zoom: {
|
|
description: 'Scroll wheel or Left click + Alt + OS + drag',
|
|
dragCallback: (e) => butName(e).left && e.altKey && e.metaKey,
|
|
scrollCallback: () => true,
|
|
},
|
|
rotate: {
|
|
description: 'Left click + Alt + drag',
|
|
callback: (e) => butName(e).left && e.altKey && !e.shiftKey && !e.metaKey,
|
|
lenientDragStartButton: 0,
|
|
},
|
|
},
|
|
Solidworks: {
|
|
pan: {
|
|
description: 'Right click + Ctrl + drag',
|
|
callback: (e) => butName(e).right && e.ctrlKey,
|
|
lenientDragStartButton: 2,
|
|
},
|
|
zoom: {
|
|
description: 'Scroll wheel or Middle click + Shift + drag',
|
|
dragCallback: (e) => butName(e).middle && e.shiftKey,
|
|
scrollCallback: () => true,
|
|
},
|
|
rotate: {
|
|
description: 'Middle click + drag',
|
|
callback: (e) => butName(e).middle && noModifiersPressed(e),
|
|
},
|
|
},
|
|
NX: {
|
|
pan: {
|
|
description: 'Middle click + Shift + drag',
|
|
callback: (e) => butName(e).middle && e.shiftKey,
|
|
},
|
|
zoom: {
|
|
description: 'Scroll wheel or Middle click + Ctrl + drag',
|
|
dragCallback: (e) => butName(e).middle && e.ctrlKey,
|
|
scrollCallback: () => true,
|
|
},
|
|
rotate: {
|
|
description: 'Middle click + drag',
|
|
callback: (e) => butName(e).middle && noModifiersPressed(e),
|
|
},
|
|
},
|
|
Creo: {
|
|
pan: {
|
|
description: 'Middle click + Shift + drag',
|
|
callback: (e) => butName(e).middle && e.shiftKey,
|
|
},
|
|
zoom: {
|
|
description: 'Scroll wheel or Middle click + Ctrl + drag',
|
|
dragCallback: (e) => butName(e).middle && e.ctrlKey,
|
|
scrollCallback: () => true,
|
|
},
|
|
rotate: {
|
|
description: 'Middle click + drag',
|
|
callback: (e) => butName(e).middle && noModifiersPressed(e),
|
|
},
|
|
},
|
|
AutoCAD: {
|
|
pan: {
|
|
description: 'Middle click + drag',
|
|
callback: (e) => butName(e).middle && noModifiersPressed(e),
|
|
},
|
|
zoom: {
|
|
description: 'Scroll wheel',
|
|
dragCallback: () => false,
|
|
scrollCallback: () => true,
|
|
},
|
|
rotate: {
|
|
description: 'Middle click + Shift + drag',
|
|
callback: (e) => butName(e).middle && e.shiftKey,
|
|
},
|
|
},
|
|
}
|