Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Allow orbit in sketch mode via setting #4990

Merged
merged 10 commits into from
Jan 16, 2025
2 changes: 2 additions & 0 deletions src/clientSideScene/CameraControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export class CameraControls {
interactionGuards: MouseGuard = cameraMouseDragGuards.Zoo
isFovAnimationInProgress = false
perspectiveFovBeforeOrtho = 45
// NOTE: Duplicated state across Provider and singleton. Mapped from settingsMachine
_setting_allowOrbitInSketchMode = false
get isPerspective() {
return this.camera instanceof PerspectiveCamera
}
Expand Down
32 changes: 30 additions & 2 deletions src/components/ModelingMachineProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const ModelingMachineProvider = ({
auth,
settings: {
context: {
app: { theme, enableSSAO },
app: { theme, enableSSAO, allowOrbitInSketchMode },
modeling: {
defaultUnit,
cameraProjection,
Expand Down Expand Up @@ -634,7 +634,8 @@ export const ModelingMachineProvider = ({
input.plane
)
await kclManager.updateAst(modifiedAst, false)
sceneInfra.camControls.enableRotate = false
sceneInfra.camControls.enableRotate =
sceneInfra.camControls._setting_allowOrbitInSketchMode
sceneInfra.camControls.syncDirection = 'clientToEngine'

await letEngineAnimateAndSyncCamAfter(
Expand All @@ -647,6 +648,7 @@ export const ModelingMachineProvider = ({
zAxis: input.zAxis,
yAxis: input.yAxis,
origin: [0, 0, 0],
animateTargetId: input.planeId,
}
}),
'animate-to-sketch': fromPromise(
Expand All @@ -671,6 +673,7 @@ export const ModelingMachineProvider = ({
origin: info.sketchDetails.origin.map(
(a) => a / sceneInfra._baseUnitMultiplier
) as [number, number, number],
animateTargetId: info?.sketchDetails?.faceId || '',
}
}
),
Expand Down Expand Up @@ -1188,6 +1191,31 @@ export const ModelingMachineProvider = ({
}
}, [engineCommandManager.engineConnection, modelingSend])

useEffect(() => {
const inSketchMode = modelingState.matches('Sketch')

// If you are in sketch mode and you disable the orbit, return back to the normal view to the target
if (!allowOrbitInSketchMode.current) {
const targetId = modelingState.context.sketchDetails?.animateTargetId
if (inSketchMode && targetId) {
letEngineAnimateAndSyncCamAfter(engineCommandManager, targetId)
.then(() => {})
.catch((e) => {
console.error(
'failed to sync engine and client scene after disabling allow orbit in sketch mode'
)
console.error(e)
})
}
}

// While you are in sketch mode you should be able to control the enable rotate
// Once you exit it goes back to normal
if (inSketchMode) {
sceneInfra.camControls.enableRotate = allowOrbitInSketchMode.current
}
}, [allowOrbitInSketchMode])

// Allow using the delete key to delete solids
useHotkeys(['backspace', 'delete', 'del'], () => {
modelingSend({ type: 'Delete selection' })
Expand Down
5 changes: 5 additions & 0 deletions src/components/SettingsAuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ export const SettingsAuthProviderBase = ({
sceneInfra.theme = opposingTheme
sceneEntitiesManager.updateSegmentBaseColor(opposingTheme)
},
setAllowOrbitInSketchMode: ({ context }) => {
sceneInfra.camControls._setting_allowOrbitInSketchMode =
context.app.allowOrbitInSketchMode.current
// ModelingMachineProvider will do a use effect to trigger the camera engine sync
},
toastSuccess: ({ event }) => {
if (!('data' in event)) return
const eventParts = event.type.replace(/^set./, '').split('.') as [
Expand Down
8 changes: 8 additions & 0 deletions src/lib/settings/initialSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ export function createSettings() {
inputType: 'boolean',
},
}),
allowOrbitInSketchMode: new Setting<boolean>({
defaultValue: false,
description: 'Toggle free camera while in sketch mode',
validate: (v) => typeof v === 'boolean',
commandConfig: {
inputType: 'boolean',
},
}),
onboardingStatus: new Setting<OnboardingStatus>({
defaultValue: '',
// TODO: this could be better but we don't have a TS side real enum
Expand Down
4 changes: 4 additions & 0 deletions src/lib/settings/settingsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export function configurationToSettingsPayload(
onboardingStatus: configuration?.settings?.app?.onboarding_status,
dismissWebBanner: configuration?.settings?.app?.dismiss_web_banner,
streamIdleMode: configuration?.settings?.app?.stream_idle_mode,
allowOrbitInSketchMode:
configuration?.settings?.app?.allow_orbit_in_sketch_mode,
projectDirectory: configuration?.settings?.project?.directory,
enableSSAO: configuration?.settings?.modeling?.enable_ssao,
},
Expand Down Expand Up @@ -80,6 +82,8 @@ export function projectConfigurationToSettingsPayload(
onboardingStatus: configuration?.settings?.app?.onboarding_status,
dismissWebBanner: configuration?.settings?.app?.dismiss_web_banner,
streamIdleMode: configuration?.settings?.app?.stream_idle_mode,
allowOrbitInSketchMode:
configuration?.settings?.app?.allow_orbit_in_sketch_mode,
enableSSAO: configuration?.settings?.modeling?.enable_ssao,
},
modeling: {
Expand Down
2 changes: 2 additions & 0 deletions src/machines/modelingMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export interface SketchDetails {
zAxis: [number, number, number]
yAxis: [number, number, number]
origin: [number, number, number]
// face id or plane id, both are strings
animateTargetId?: string
}

export interface SegmentOverlay {
Expand Down
12 changes: 12 additions & 0 deletions src/machines/settingsMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const settingsMachine = setup({
'Execute AST': () => {},
toastSuccess: () => {},
setClientSideSceneUnits: () => {},
setAllowOrbitInSketchMode: () => {},
persistSettings: () => {},
resetSettings: assign(({ context, event }) => {
if (!('level' in event)) return {}
Expand Down Expand Up @@ -157,6 +158,15 @@ export const settingsMachine = setup({
actions: ['setSettingAtLevel', 'toastSuccess'],
},

'set.app.allowOrbitInSketchMode': {
target: 'persisting settings',
actions: [
'setSettingAtLevel',
'toastSuccess',
'setAllowOrbitInSketchMode',
],
},

'set.modeling.cameraProjection': {
target: 'persisting settings',

Expand All @@ -183,6 +193,7 @@ export const settingsMachine = setup({
'setClientSideSceneUnits',
'Execute AST',
'setClientTheme',
'setAllowOrbitInSketchMode',
],
},

Expand All @@ -194,6 +205,7 @@ export const settingsMachine = setup({
'setClientSideSceneUnits',
'Execute AST',
'setClientTheme',
'setAllowOrbitInSketchMode',
],
},

Expand Down
7 changes: 7 additions & 0 deletions src/wasm-lib/kcl/src/settings/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ pub struct AppSettings {
/// When the user is idle, and this is true, the stream will be torn down.
#[serde(default, alias = "streamIdleMode", skip_serializing_if = "is_default")]
stream_idle_mode: bool,
/// When the user is idle, and this is true, the stream will be torn down.
#[serde(default, alias = "allowOrbitInSketchMode", skip_serializing_if = "is_default")]
allow_orbit_in_sketch_mode: bool,
}

// TODO: When we remove backwards compatibility with the old settings file, we can remove this.
Expand Down Expand Up @@ -586,6 +589,7 @@ textWrapping = true
dismiss_web_banner: false,
enable_ssao: None,
stream_idle_mode: false,
allow_orbit_in_sketch_mode: false,
},
modeling: ModelingSettings {
base_unit: UnitLength::In,
Expand Down Expand Up @@ -647,6 +651,7 @@ includeSettings = false
dismiss_web_banner: false,
enable_ssao: None,
stream_idle_mode: false,
allow_orbit_in_sketch_mode: false,
},
modeling: ModelingSettings {
base_unit: UnitLength::Yd,
Expand Down Expand Up @@ -713,6 +718,7 @@ defaultProjectName = "projects-$nnn"
dismiss_web_banner: false,
enable_ssao: None,
stream_idle_mode: false,
allow_orbit_in_sketch_mode: false,
},
modeling: ModelingSettings {
base_unit: UnitLength::Yd,
Expand Down Expand Up @@ -791,6 +797,7 @@ projectDirectory = "/Users/macinatormax/Documents/kittycad-modeling-projects""#;
dismiss_web_banner: false,
enable_ssao: None,
stream_idle_mode: false,
allow_orbit_in_sketch_mode: false,
},
modeling: ModelingSettings {
base_unit: UnitLength::Mm,
Expand Down
1 change: 1 addition & 0 deletions src/wasm-lib/kcl/src/settings/types/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ includeSettings = false
dismiss_web_banner: false,
enable_ssao: None,
stream_idle_mode: false,
allow_orbit_in_sketch_mode: false,
},
modeling: ModelingSettings {
base_unit: UnitLength::Yd,
Expand Down
Loading