* implement dual camer sync direction The existance of the client side scene requires two cameras to stay in sync, really these need to be a master-slave relationship, intitial this was implemented with the client side scene taking the lead and sending updates to the server using the endpoint (as it didn't require an new endpoints), but even though we added a sequence property to this endpoint and sent it over udp, it was still an abuse of this endpoint as the engine didn't have this endpoint setup with a fload of messages and low-latency in mind. Now we have migrated back to sending mouse events to the engine instead, but with the engine replying with camera details on drag_end etc so that we can keep the client camera in sync. The client side camera still does take the master role in sketch mode as it makes sense to keep the low latency benfits of the local camera for the locallay rendered assets in sketch mode, moving the camera in this mode already did hide the engine camera while the camera is moving so as to avoid ghoasting so this works well. The camera controls now work by syncing in either direction depending on what's appropiate * fmt * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * update default plane extrude numbers * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * trigger-ci --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
163 lines
4.4 KiB
TypeScript
163 lines
4.4 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) || e.button === 1,
|
|
right: !!(e.buttons & 2) || e.button === 2,
|
|
left: !!(e.buttons & 1) || e.button === 0,
|
|
})
|
|
|
|
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,
|
|
},
|
|
},
|
|
}
|