Add support for camera Pan (#182)

This commit is contained in:
Frank Noirot
2023-07-20 14:08:32 -04:00
committed by GitHub
parent 5d90c0488f
commit 1666e17ca5
2 changed files with 15 additions and 4 deletions

View File

@ -31,17 +31,20 @@ export const Stream = () => {
const handleMouseMove: MouseEventHandler<HTMLVideoElement> = ({ const handleMouseMove: MouseEventHandler<HTMLVideoElement> = ({
clientX, clientX,
clientY, clientY,
ctrlKey,
}) => { }) => {
if (!videoRef.current) return if (!videoRef.current) return
if (!cmdId.current) return if (!cmdId.current) return
const { left, top } = videoRef.current.getBoundingClientRect() const { left, top } = videoRef.current.getBoundingClientRect()
const x = clientX - left const x = clientX - left
const y = clientY - top const y = clientY - top
const interaction = ctrlKey ? 'pan' : 'rotate'
debounceSocketSend({ debounceSocketSend({
type: 'ModelingCmdReq', type: 'ModelingCmdReq',
cmd: { cmd: {
CameraDragMove: { CameraDragMove: {
interaction: 'rotate', interaction,
window: { window: {
x: x, x: x,
y: y, y: y,
@ -56,6 +59,7 @@ export const Stream = () => {
const handleMouseDown: MouseEventHandler<HTMLVideoElement> = ({ const handleMouseDown: MouseEventHandler<HTMLVideoElement> = ({
clientX, clientX,
clientY, clientY,
ctrlKey,
}) => { }) => {
if (!videoRef.current) return if (!videoRef.current) return
const { left, top } = videoRef.current.getBoundingClientRect() const { left, top } = videoRef.current.getBoundingClientRect()
@ -66,11 +70,13 @@ export const Stream = () => {
const newId = uuidv4() const newId = uuidv4()
cmdId.current = newId cmdId.current = newId
const interaction = ctrlKey ? 'pan' : 'rotate'
engineCommandManager?.sendSceneCommand({ engineCommandManager?.sendSceneCommand({
type: 'ModelingCmdReq', type: 'ModelingCmdReq',
cmd: { cmd: {
CameraDragStart: { CameraDragStart: {
interaction: 'rotate', interaction,
window: { window: {
x: x, x: x,
y: y, y: y,
@ -84,6 +90,7 @@ export const Stream = () => {
const handleMouseUp: MouseEventHandler<HTMLVideoElement> = ({ const handleMouseUp: MouseEventHandler<HTMLVideoElement> = ({
clientX, clientX,
clientY, clientY,
ctrlKey,
}) => { }) => {
if (!videoRef.current) return if (!videoRef.current) return
const { left, top } = videoRef.current.getBoundingClientRect() const { left, top } = videoRef.current.getBoundingClientRect()
@ -94,11 +101,13 @@ export const Stream = () => {
return return
} }
const interaction = ctrlKey ? 'pan' : 'rotate'
engineCommandManager?.sendSceneCommand({ engineCommandManager?.sendSceneCommand({
type: 'ModelingCmdReq', type: 'ModelingCmdReq',
cmd: { cmd: {
CameraDragEnd: { CameraDragEnd: {
interaction: 'rotate', interaction,
window: { window: {
x: x, x: x,
y: y, y: y,
@ -123,6 +132,8 @@ export const Stream = () => {
onMouseDown={handleMouseDown} onMouseDown={handleMouseDown}
onMouseUp={handleMouseUp} onMouseUp={handleMouseUp}
onMouseLeave={handleMouseUp} onMouseLeave={handleMouseUp}
onContextMenu={(e) => e.preventDefault()}
onContextMenuCapture={(e) => e.preventDefault()}
/> />
</div> </div>
) )

View File

@ -30,7 +30,7 @@ interface CursorSelectionsArgs {
// TODO these types should be in the openApi spec, and therefore in @kittycad/lib // TODO these types should be in the openApi spec, and therefore in @kittycad/lib
interface MouseStuff { interface MouseStuff {
interaction: 'rotate' interaction: 'rotate' | 'pan' | 'zoom'
window: { window: {
x: number x: number
y: number y: number