clean up by grouping segment labels

This commit is contained in:
Kurt Hutten Irev-Dev
2024-09-10 17:30:21 +10:00
parent 93d3df4877
commit fa580d4035
3 changed files with 29 additions and 60 deletions

View File

@ -129,6 +129,15 @@ export const CIRCLE_CENTER_HANDLE = 'circle-center-handle'
export const SEGMENT_WIDTH_PX = 1.6 export const SEGMENT_WIDTH_PX = 1.6
export const HIDE_SEGMENT_LENGTH = 75 // in pixels export const HIDE_SEGMENT_LENGTH = 75 // in pixels
export const HIDE_HOVER_SEGMENT_LENGTH = 60 // 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] type Vec3Array = [number, number, number]
@ -1264,12 +1273,7 @@ export class SceneEntities {
? new Vector2(profileStart.position.x, profileStart.position.y) ? new Vector2(profileStart.position.x, profileStart.position.y)
: _intersection2d : _intersection2d
const group = getParentGroup(object, [ const group = getParentGroup(object, SEGMENT_BODIES_PLUS_PROFILE_START)
STRAIGHT_SEGMENT,
TANGENTIAL_ARC_TO_SEGMENT,
PROFILE_START,
CIRCLE_SEGMENT,
])
const subGroup = getParentGroup(object, [ARROWHEAD, CIRCLE_CENTER_HANDLE]) const subGroup = getParentGroup(object, [ARROWHEAD, CIRCLE_CENTER_HANDLE])
if (!group) return if (!group) return
const pathToNode: PathToNode = structuredClone(group.userData.pathToNode) const pathToNode: PathToNode = structuredClone(group.userData.pathToNode)
@ -1917,12 +1921,10 @@ export class SceneEntities {
mat.color.set(obj.userData.baseColor) mat.color.set(obj.userData.baseColor)
mat.color.offsetHSL(0, 0, 0.5) mat.color.offsetHSL(0, 0, 0.5)
} }
const parent = getParentGroup(selected, [ const parent = getParentGroup(
STRAIGHT_SEGMENT, selected,
TANGENTIAL_ARC_TO_SEGMENT, SEGMENT_BODIES_PLUS_PROFILE_START
CIRCLE_SEGMENT, )
PROFILE_START,
])
if (parent?.userData?.pathToNode) { if (parent?.userData?.pathToNode) {
const updatedAst = parse(recast(kclManager.ast)) const updatedAst = parse(recast(kclManager.ast))
if (trap(updatedAst)) return if (trap(updatedAst)) return
@ -1983,12 +1985,10 @@ export class SceneEntities {
}, },
onMouseLeave: ({ selected, ...rest }: OnMouseEnterLeaveArgs) => { onMouseLeave: ({ selected, ...rest }: OnMouseEnterLeaveArgs) => {
editorManager.setHighlightRange([[0, 0]]) editorManager.setHighlightRange([[0, 0]])
const parent = getParentGroup(selected, [ const parent = getParentGroup(
STRAIGHT_SEGMENT, selected,
TANGENTIAL_ARC_TO_SEGMENT, SEGMENT_BODIES_PLUS_PROFILE_START
CIRCLE_SEGMENT, )
PROFILE_START,
])
if (parent) { if (parent) {
const orthoFactor = orthoScale(sceneInfra.camControls.camera) const orthoFactor = orthoScale(sceneInfra.camControls.camera)
@ -2184,11 +2184,7 @@ function prepareTruncatedMemoryAndAst(
export function getParentGroup( export function getParentGroup(
object: any, object: any,
stopAt: string[] = [ stopAt: string[] = SEGMENT_BODIES
STRAIGHT_SEGMENT,
TANGENTIAL_ARC_TO_SEGMENT,
CIRCLE_SEGMENT,
]
): Group | null { ): Group | null {
if (stopAt.includes(object?.userData?.type)) { if (stopAt.includes(object?.userData?.type)) {
return object return object
@ -2235,11 +2231,7 @@ function colorSegment(object: any, color: number) {
}) })
return return
} }
const straightSegmentBody = getParentGroup(object, [ const straightSegmentBody = getParentGroup(object, SEGMENT_BODIES)
STRAIGHT_SEGMENT,
TANGENTIAL_ARC_TO_SEGMENT,
CIRCLE_SEGMENT,
])
if (straightSegmentBody) { if (straightSegmentBody) {
straightSegmentBody.traverse((child) => { straightSegmentBody.traverse((child) => {
if (child instanceof Mesh && !child.userData.ignoreColorChange) { if (child instanceof Mesh && !child.userData.ignoreColorChange) {

View File

@ -50,9 +50,7 @@ import { applyConstraintAbsDistance } from './Toolbar/SetAbsDistance'
import useStateMachineCommands from 'hooks/useStateMachineCommands' import useStateMachineCommands from 'hooks/useStateMachineCommands'
import { modelingMachineCommandConfig } from 'lib/commandBarConfigs/modelingCommandConfig' import { modelingMachineCommandConfig } from 'lib/commandBarConfigs/modelingCommandConfig'
import { import {
CIRCLE_SEGMENT, SEGMENT_BODIES,
STRAIGHT_SEGMENT,
TANGENTIAL_ARC_TO_SEGMENT,
getParentGroup, getParentGroup,
getSketchOrientationDetails, getSketchOrientationDetails,
} from 'clientSideScene/sceneEntities' } from 'clientSideScene/sceneEntities'
@ -169,11 +167,7 @@ export const ModelingMachineProvider = ({
if (event.type !== 'Set mouse state') return {} if (event.type !== 'Set mouse state') return {}
const nextSegmentHoverMap = () => { const nextSegmentHoverMap = () => {
if (event.data.type === 'isHovering') { if (event.data.type === 'isHovering') {
const parent = getParentGroup(event.data.on, [ const parent = getParentGroup(event.data.on, SEGMENT_BODIES)
STRAIGHT_SEGMENT,
TANGENTIAL_ARC_TO_SEGMENT,
CIRCLE_SEGMENT,
])
const pathToNode = parent?.userData?.pathToNode const pathToNode = parent?.userData?.pathToNode
const pathToNodeString = JSON.stringify(pathToNode) const pathToNodeString = JSON.stringify(pathToNode)
if (!parent || !pathToNode) return context.segmentHoverMap if (!parent || !pathToNode) return context.segmentHoverMap
@ -189,11 +183,10 @@ export const ModelingMachineProvider = ({
event.data.type === 'idle' && event.data.type === 'idle' &&
context.mouseState.type === 'isHovering' context.mouseState.type === 'isHovering'
) { ) {
const mouseOnParent = getParentGroup(context.mouseState.on, [ const mouseOnParent = getParentGroup(
STRAIGHT_SEGMENT, context.mouseState.on,
TANGENTIAL_ARC_TO_SEGMENT, SEGMENT_BODIES
CIRCLE_SEGMENT, )
])
if (!mouseOnParent || !mouseOnParent?.userData?.pathToNode) if (!mouseOnParent || !mouseOnParent?.userData?.pathToNode)
return context.segmentHoverMap return context.segmentHoverMap
const pathToNodeString = JSON.stringify( const pathToNodeString = JSON.stringify(

View File

@ -20,11 +20,8 @@ import {
} from 'lang/queryAst' } from 'lang/queryAst'
import { CommandArgument } from './commandTypes' import { CommandArgument } from './commandTypes'
import { import {
STRAIGHT_SEGMENT,
TANGENTIAL_ARC_TO_SEGMENT,
getParentGroup, getParentGroup,
PROFILE_START, SEGMENT_BODIES_PLUS_PROFILE_START,
CIRCLE_SEGMENT,
} from 'clientSideScene/sceneEntities' } from 'clientSideScene/sceneEntities'
import { Mesh, Object3D, Object3DEventMap } from 'three' import { Mesh, Object3D, Object3DEventMap } from 'three'
import { AXIS_GROUP, X_AXIS } from 'clientSideScene/sceneInfra' import { AXIS_GROUP, X_AXIS } from 'clientSideScene/sceneInfra'
@ -163,12 +160,7 @@ export async function getEventForSelectWithPoint({
export function getEventForSegmentSelection( export function getEventForSegmentSelection(
obj: Object3D<Object3DEventMap> obj: Object3D<Object3DEventMap>
): ModelingMachineEvent | null { ): ModelingMachineEvent | null {
const group = getParentGroup(obj, [ const group = getParentGroup(obj, SEGMENT_BODIES_PLUS_PROFILE_START)
STRAIGHT_SEGMENT,
TANGENTIAL_ARC_TO_SEGMENT,
CIRCLE_SEGMENT,
PROFILE_START,
])
const axisGroup = getParentGroup(obj, [AXIS_GROUP]) const axisGroup = getParentGroup(obj, [AXIS_GROUP])
if (!group && !axisGroup) return null if (!group && !axisGroup) return null
if (axisGroup?.userData.type === AXIS_GROUP) { if (axisGroup?.userData.type === AXIS_GROUP) {
@ -305,15 +297,7 @@ function updateSceneObjectColors(codeBasedSelections: Selection[]) {
const updated = kclManager.ast const updated = kclManager.ast
Object.values(sceneEntitiesManager.activeSegments).forEach((segmentGroup) => { Object.values(sceneEntitiesManager.activeSegments).forEach((segmentGroup) => {
if ( if (!SEGMENT_BODIES_PLUS_PROFILE_START.includes(segmentGroup?.name)) return
![
STRAIGHT_SEGMENT,
TANGENTIAL_ARC_TO_SEGMENT,
PROFILE_START,
CIRCLE_SEGMENT,
].includes(segmentGroup?.name)
)
return
const nodeMeta = getNodeFromPath<CallExpression>( const nodeMeta = getNodeFromPath<CallExpression>(
updated, updated,
segmentGroup.userData.pathToNode, segmentGroup.userData.pathToNode,