diff --git a/src/clientSideScene/sceneEntities.ts b/src/clientSideScene/sceneEntities.ts index 378ca1e67..e73fe8c5b 100644 --- a/src/clientSideScene/sceneEntities.ts +++ b/src/clientSideScene/sceneEntities.ts @@ -129,6 +129,15 @@ export const CIRCLE_CENTER_HANDLE = 'circle-center-handle' export const SEGMENT_WIDTH_PX = 1.6 export const HIDE_SEGMENT_LENGTH = 75 // in pixels export const HIDE_HOVER_SEGMENT_LENGTH = 60 // in pixels +export const SEGMENT_BODIES = [ + STRAIGHT_SEGMENT, + TANGENTIAL_ARC_TO_SEGMENT, + CIRCLE_SEGMENT, +] +export const SEGMENT_BODIES_PLUS_PROFILE_START = [ + ...SEGMENT_BODIES, + PROFILE_START, +] type Vec3Array = [number, number, number] @@ -1264,12 +1273,7 @@ export class SceneEntities { ? new Vector2(profileStart.position.x, profileStart.position.y) : _intersection2d - const group = getParentGroup(object, [ - STRAIGHT_SEGMENT, - TANGENTIAL_ARC_TO_SEGMENT, - PROFILE_START, - CIRCLE_SEGMENT, - ]) + const group = getParentGroup(object, SEGMENT_BODIES_PLUS_PROFILE_START) const subGroup = getParentGroup(object, [ARROWHEAD, CIRCLE_CENTER_HANDLE]) if (!group) return const pathToNode: PathToNode = structuredClone(group.userData.pathToNode) @@ -1917,12 +1921,10 @@ export class SceneEntities { mat.color.set(obj.userData.baseColor) mat.color.offsetHSL(0, 0, 0.5) } - const parent = getParentGroup(selected, [ - STRAIGHT_SEGMENT, - TANGENTIAL_ARC_TO_SEGMENT, - CIRCLE_SEGMENT, - PROFILE_START, - ]) + const parent = getParentGroup( + selected, + SEGMENT_BODIES_PLUS_PROFILE_START + ) if (parent?.userData?.pathToNode) { const updatedAst = parse(recast(kclManager.ast)) if (trap(updatedAst)) return @@ -1983,12 +1985,10 @@ export class SceneEntities { }, onMouseLeave: ({ selected, ...rest }: OnMouseEnterLeaveArgs) => { editorManager.setHighlightRange([[0, 0]]) - const parent = getParentGroup(selected, [ - STRAIGHT_SEGMENT, - TANGENTIAL_ARC_TO_SEGMENT, - CIRCLE_SEGMENT, - PROFILE_START, - ]) + const parent = getParentGroup( + selected, + SEGMENT_BODIES_PLUS_PROFILE_START + ) if (parent) { const orthoFactor = orthoScale(sceneInfra.camControls.camera) @@ -2184,11 +2184,7 @@ function prepareTruncatedMemoryAndAst( export function getParentGroup( object: any, - stopAt: string[] = [ - STRAIGHT_SEGMENT, - TANGENTIAL_ARC_TO_SEGMENT, - CIRCLE_SEGMENT, - ] + stopAt: string[] = SEGMENT_BODIES ): Group | null { if (stopAt.includes(object?.userData?.type)) { return object @@ -2235,11 +2231,7 @@ function colorSegment(object: any, color: number) { }) return } - const straightSegmentBody = getParentGroup(object, [ - STRAIGHT_SEGMENT, - TANGENTIAL_ARC_TO_SEGMENT, - CIRCLE_SEGMENT, - ]) + const straightSegmentBody = getParentGroup(object, SEGMENT_BODIES) if (straightSegmentBody) { straightSegmentBody.traverse((child) => { if (child instanceof Mesh && !child.userData.ignoreColorChange) { diff --git a/src/components/ModelingMachineProvider.tsx b/src/components/ModelingMachineProvider.tsx index 71c3dbd43..d2ebadfa4 100644 --- a/src/components/ModelingMachineProvider.tsx +++ b/src/components/ModelingMachineProvider.tsx @@ -50,9 +50,7 @@ import { applyConstraintAbsDistance } from './Toolbar/SetAbsDistance' import useStateMachineCommands from 'hooks/useStateMachineCommands' import { modelingMachineCommandConfig } from 'lib/commandBarConfigs/modelingCommandConfig' import { - CIRCLE_SEGMENT, - STRAIGHT_SEGMENT, - TANGENTIAL_ARC_TO_SEGMENT, + SEGMENT_BODIES, getParentGroup, getSketchOrientationDetails, } from 'clientSideScene/sceneEntities' @@ -169,11 +167,7 @@ export const ModelingMachineProvider = ({ if (event.type !== 'Set mouse state') return {} const nextSegmentHoverMap = () => { if (event.data.type === 'isHovering') { - const parent = getParentGroup(event.data.on, [ - STRAIGHT_SEGMENT, - TANGENTIAL_ARC_TO_SEGMENT, - CIRCLE_SEGMENT, - ]) + const parent = getParentGroup(event.data.on, SEGMENT_BODIES) const pathToNode = parent?.userData?.pathToNode const pathToNodeString = JSON.stringify(pathToNode) if (!parent || !pathToNode) return context.segmentHoverMap @@ -189,11 +183,10 @@ export const ModelingMachineProvider = ({ event.data.type === 'idle' && context.mouseState.type === 'isHovering' ) { - const mouseOnParent = getParentGroup(context.mouseState.on, [ - STRAIGHT_SEGMENT, - TANGENTIAL_ARC_TO_SEGMENT, - CIRCLE_SEGMENT, - ]) + const mouseOnParent = getParentGroup( + context.mouseState.on, + SEGMENT_BODIES + ) if (!mouseOnParent || !mouseOnParent?.userData?.pathToNode) return context.segmentHoverMap const pathToNodeString = JSON.stringify( diff --git a/src/lib/selections.ts b/src/lib/selections.ts index a984d3625..d15a8a3ec 100644 --- a/src/lib/selections.ts +++ b/src/lib/selections.ts @@ -20,11 +20,8 @@ import { } from 'lang/queryAst' import { CommandArgument } from './commandTypes' import { - STRAIGHT_SEGMENT, - TANGENTIAL_ARC_TO_SEGMENT, getParentGroup, - PROFILE_START, - CIRCLE_SEGMENT, + SEGMENT_BODIES_PLUS_PROFILE_START, } from 'clientSideScene/sceneEntities' import { Mesh, Object3D, Object3DEventMap } from 'three' import { AXIS_GROUP, X_AXIS } from 'clientSideScene/sceneInfra' @@ -163,12 +160,7 @@ export async function getEventForSelectWithPoint({ export function getEventForSegmentSelection( obj: Object3D ): ModelingMachineEvent | null { - const group = getParentGroup(obj, [ - STRAIGHT_SEGMENT, - TANGENTIAL_ARC_TO_SEGMENT, - CIRCLE_SEGMENT, - PROFILE_START, - ]) + const group = getParentGroup(obj, SEGMENT_BODIES_PLUS_PROFILE_START) const axisGroup = getParentGroup(obj, [AXIS_GROUP]) if (!group && !axisGroup) return null if (axisGroup?.userData.type === AXIS_GROUP) { @@ -305,15 +297,7 @@ function updateSceneObjectColors(codeBasedSelections: Selection[]) { const updated = kclManager.ast Object.values(sceneEntitiesManager.activeSegments).forEach((segmentGroup) => { - if ( - ![ - STRAIGHT_SEGMENT, - TANGENTIAL_ARC_TO_SEGMENT, - PROFILE_START, - CIRCLE_SEGMENT, - ].includes(segmentGroup?.name) - ) - return + if (!SEGMENT_BODIES_PLUS_PROFILE_START.includes(segmentGroup?.name)) return const nodeMeta = getNodeFromPath( updated, segmentGroup.userData.pathToNode,