Skip to content

Commit 06a743d

Browse files
authored
Add setting to enable touch controls, defaulting to on (#7732)
* Add a setting to enable touch controls, defaulted to true * Clean up impl, don't need to teardown just need to toggle `enable` option * Re-run CI to enable Vercel deploy * Update settings docs test output
1 parent c314f39 commit 06a743d

File tree

7 files changed

+48
-2
lines changed

7 files changed

+48
-2
lines changed

docs/kcl-lang/settings/user.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ The controls for how to navigate the 3D view.
129129

130130
**Possible values:** `zoo`, `onshape`, `trackpad_friendly`, `solidworks`, `nx`, `creo`, `autocad`
131131

132+
**Default:** None
133+
134+
##### enable_touch_controls
135+
136+
Toggle touch controls for 3D view navigation
137+
138+
132139
**Default:** None
133140

134141
##### highlight_edges

rust/kcl-lib/src/settings/types/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ pub struct ModelingSettings {
286286
/// The controls for how to navigate the 3D view.
287287
#[serde(default, skip_serializing_if = "is_default")]
288288
pub mouse_controls: MouseControlType,
289+
/// Toggle touch controls for 3D view navigation
290+
#[serde(default, skip_serializing_if = "is_default")]
291+
pub enable_touch_controls: DefaultTrue,
289292
/// Highlight edges of 3D objects?
290293
#[serde(default, skip_serializing_if = "is_default")]
291294
pub highlight_edges: DefaultTrue,

src/clientSideScene/CameraControls.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ export class CameraControls {
127127
interactionGuards: MouseGuard = cameraMouseDragGuards.Zoo
128128
isFovAnimationInProgress = false
129129
perspectiveFovBeforeOrtho = 45
130+
touchControlManager: HammerManager | null = null
131+
enableTouchControls = true
130132
// TODO: proper dependency injection
131133
getSettings: (() => SettingsType) | null = null
132134

@@ -268,7 +270,7 @@ export class CameraControls {
268270
this.domElement.addEventListener('pointermove', this.onMouseMove)
269271
this.domElement.addEventListener('pointerup', this.onMouseUp)
270272
this.domElement.addEventListener('wheel', this.onMouseWheel)
271-
this.setUpMultiTouch(this.domElement)
273+
this.initTouchControls(this.enableTouchControls)
272274

273275
window.addEventListener('resize', this.onWindowResize)
274276
this.onWindowResize()
@@ -1369,7 +1371,7 @@ export class CameraControls {
13691371
*
13701372
* TODO: Add support for sketch mode touch camera movements
13711373
*/
1372-
setUpMultiTouch = (domElement: HTMLCanvasElement) => {
1374+
setUpTouchControls = (domElement: HTMLCanvasElement) => {
13731375
/** Amount in px needed to pan before recognizer runs */
13741376
const panDistanceThreshold = 3
13751377
/** Amount in scale delta needed to pinch before recognizer runs */
@@ -1522,6 +1524,16 @@ export class CameraControls {
15221524
hammertime.on('pinchend pinchcancel doublepanend', (event) => {
15231525
this.onMouseUpInner(event.srcEvent as PointerEvent)
15241526
})
1527+
1528+
return hammertime
1529+
}
1530+
1531+
initTouchControls = (shouldEnable?: boolean) => {
1532+
if (this.touchControlManager === null) {
1533+
this.touchControlManager = this.setUpTouchControls(this.domElement)
1534+
}
1535+
1536+
this.touchControlManager.set({ enable: shouldEnable })
15251537
}
15261538
}
15271539

src/clientSideScene/ClientSideSceneComp.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ function useShouldHideScene(): { hideClient: boolean; hideServer: boolean } {
6969

7070
export const ClientSideScene = ({
7171
cameraControls,
72+
enableTouchControls,
7273
}: {
7374
cameraControls: ReturnType<
7475
typeof useSettings
7576
>['modeling']['mouseControls']['current']
77+
enableTouchControls: ReturnType<
78+
typeof useSettings
79+
>['modeling']['enableTouchControls']['current']
7680
}) => {
7781
const canvasRef = useRef<HTMLDivElement>(null)
7882
const { state, send, context } = useModelingContext()
@@ -84,6 +88,9 @@ export const ClientSideScene = ({
8488
sceneInfra.camControls.interactionGuards =
8589
cameraMouseDragGuards[cameraControls]
8690
}, [cameraControls])
91+
useEffect(() => {
92+
sceneInfra.camControls.initTouchControls(enableTouchControls)
93+
}, [enableTouchControls])
8794
useEffect(() => {
8895
sceneInfra.updateOtherSelectionColors(
8996
state?.context?.selectionRanges?.otherSelections || []

src/components/EngineStream.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ export const EngineStream = (props: {
590590
</canvas>
591591
<ClientSideScene
592592
cameraControls={settings.modeling.mouseControls.current}
593+
enableTouchControls={settings.modeling.enableTouchControls.current}
593594
/>
594595
<ViewControlContextMenu
595596
event="mouseup"

src/lib/settings/initialSettings.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,19 @@ export function createSettings() {
431431
</>
432432
),
433433
}),
434+
/** Whether to enable the touch listeners for controlling the camera, which run separate from the mouse control listeners
435+
*
436+
*/
437+
enableTouchControls: new Setting<boolean>({
438+
defaultValue: true,
439+
hideOnLevel: 'project',
440+
description:
441+
'Enable touch events to navigate the 3D scene. When enabled, orbit with one-finger drag, pan with two-finger drag, and zoom with pinch.',
442+
validate: (v) => typeof v === 'boolean',
443+
commandConfig: {
444+
inputType: 'boolean',
445+
},
446+
}),
434447
/**
435448
* Projection method applied to the 3D view, perspective or orthographic
436449
*/

src/lib/settings/settingsUtils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export function configurationToSettingsPayload(
7575
mouseControls: mouseControlsToCameraSystem(
7676
configuration?.settings?.modeling?.mouse_controls
7777
),
78+
enableTouchControls:
79+
configuration?.settings?.modeling?.enable_touch_controls,
7880
highlightEdges: configuration?.settings?.modeling?.highlight_edges,
7981
enableSSAO: configuration?.settings?.modeling?.enable_ssao,
8082
showScaleGrid: configuration?.settings?.modeling?.show_scale_grid,
@@ -119,6 +121,7 @@ export function settingsPayloadToConfiguration(
119121
mouse_controls: configuration?.modeling?.mouseControls
120122
? cameraSystemToMouseControl(configuration?.modeling?.mouseControls)
121123
: undefined,
124+
enable_touch_controls: configuration?.modeling?.enableTouchControls,
122125
highlight_edges: configuration?.modeling?.highlightEdges,
123126
enable_ssao: configuration?.modeling?.enableSSAO,
124127
show_scale_grid: configuration?.modeling?.showScaleGrid,

0 commit comments

Comments
 (0)