From 3a06ae6e34fd86b5dd117d0eadd97eee13fe0bbc Mon Sep 17 00:00:00 2001 From: Kurt Hutten Date: Mon, 12 May 2025 21:28:09 +1000 Subject: [PATCH] fix sketch on offset plane animations (#6858) * fix sketch on offset plane animations * trigger CI --- src/clientSideScene/sceneEntities.ts | 83 +++++++++------------------- src/lang/queryAst.ts | 14 +++++ 2 files changed, 39 insertions(+), 58 deletions(-) diff --git a/src/clientSideScene/sceneEntities.ts b/src/clientSideScene/sceneEntities.ts index dcf4dfd84..189c4c35c 100644 --- a/src/clientSideScene/sceneEntities.ts +++ b/src/clientSideScene/sceneEntities.ts @@ -122,7 +122,10 @@ import { updateSketchNodePathsWithInsertIndex, } from '@src/lang/modifyAst' import { mutateAstWithTagForSketchSegment } from '@src/lang/modifyAst/addEdgeTreatment' -import { getNodeFromPath } from '@src/lang/queryAst' +import { + getNodeFromPath, + getPathNormalisedForTruncatedAst, +} from '@src/lang/queryAst' import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils' import { codeRefFromRange, @@ -1295,11 +1298,10 @@ export class SceneEntities { // Update the width and height of the draft rectangle const nodePathWithCorrectedIndexForTruncatedAst = - structuredClone(updatedEntryNodePath) - nodePathWithCorrectedIndexForTruncatedAst[1][0] = - Number(nodePathWithCorrectedIndexForTruncatedAst[1][0]) - - Number(planeNodePath[1][0]) - - 1 + getPathNormalisedForTruncatedAst( + updatedEntryNodePath, + updatedSketchNodePaths + ) const _node = getNodeFromPath( truncatedAst, @@ -1502,11 +1504,10 @@ export class SceneEntities { // Update the width and height of the draft rectangle const nodePathWithCorrectedIndexForTruncatedAst = - structuredClone(updatedEntryNodePath) - nodePathWithCorrectedIndexForTruncatedAst[1][0] = - Number(nodePathWithCorrectedIndexForTruncatedAst[1][0]) - - Number(planeNodePath[1][0]) - - 1 + getPathNormalisedForTruncatedAst( + updatedEntryNodePath, + updatedSketchNodePaths + ) const _node = getNodeFromPath( truncatedAst, @@ -1678,13 +1679,11 @@ export class SceneEntities { this.sceneInfra.setCallbacks({ onMove: async (args) => { - const firstProfileIndex = Number(updatedSketchNodePaths[0][1][0]) const nodePathWithCorrectedIndexForTruncatedAst = - structuredClone(updatedEntryNodePath) - - nodePathWithCorrectedIndexForTruncatedAst[1][0] = - Number(nodePathWithCorrectedIndexForTruncatedAst[1][0]) - - firstProfileIndex + getPathNormalisedForTruncatedAst( + updatedEntryNodePath, + updatedSketchNodePaths + ) const _node = getNodeFromPath( truncatedAst, nodePathWithCorrectedIndexForTruncatedAst, @@ -1878,14 +1877,8 @@ export class SceneEntities { this.sceneInfra.setCallbacks({ onMove: async (args) => { - const firstProfileIndex = Number(sketchNodePaths[0][1][0]) - const nodePathWithCorrectedIndexForTruncatedAst = structuredClone( - mod.pathToNode - ) - - nodePathWithCorrectedIndexForTruncatedAst[1][0] = - Number(nodePathWithCorrectedIndexForTruncatedAst[1][0]) - - firstProfileIndex + const nodePathWithCorrectedIndexForTruncatedAst = + getPathNormalisedForTruncatedAst(mod.pathToNode, sketchNodePaths) const _node = getNodeFromPath( truncatedAst, nodePathWithCorrectedIndexForTruncatedAst, @@ -1954,14 +1947,6 @@ export class SceneEntities { ) }, onClick: async (args) => { - const firstProfileIndex = Number(sketchNodePaths[0][1][0]) - const nodePathWithCorrectedIndexForTruncatedAst = structuredClone( - mod.pathToNode - ) - - nodePathWithCorrectedIndexForTruncatedAst[1][0] = - Number(nodePathWithCorrectedIndexForTruncatedAst[1][0]) - - firstProfileIndex // If there is a valid camera interaction that matches, do that instead const interaction = this.sceneInfra.camControls.getInteractionType( args.mouseEvent @@ -2109,14 +2094,8 @@ export class SceneEntities { this.sceneInfra.setCallbacks({ onMove: async (args) => { - const firstProfileIndex = Number(sketchNodePaths[0][1][0]) - const nodePathWithCorrectedIndexForTruncatedAst = structuredClone( - mod.pathToNode - ) - - nodePathWithCorrectedIndexForTruncatedAst[1][0] = - Number(nodePathWithCorrectedIndexForTruncatedAst[1][0]) - - firstProfileIndex + const nodePathWithCorrectedIndexForTruncatedAst = + getPathNormalisedForTruncatedAst(mod.pathToNode, sketchNodePaths) const _node = getNodeFromPath( truncatedAst, nodePathWithCorrectedIndexForTruncatedAst, @@ -2185,14 +2164,6 @@ export class SceneEntities { ) }, onClick: async (args) => { - const firstProfileIndex = Number(sketchNodePaths[0][1][0]) - const nodePathWithCorrectedIndexForTruncatedAst = structuredClone( - mod.pathToNode - ) - - nodePathWithCorrectedIndexForTruncatedAst[1][0] = - Number(nodePathWithCorrectedIndexForTruncatedAst[1][0]) - - firstProfileIndex // If there is a valid camera interaction that matches, do that instead const interaction = this.sceneInfra.camControls.getInteractionType( args.mouseEvent @@ -2365,11 +2336,10 @@ export class SceneEntities { this.sceneInfra.setCallbacks({ onMove: async (args) => { const nodePathWithCorrectedIndexForTruncatedAst = - structuredClone(updatedEntryNodePath) - nodePathWithCorrectedIndexForTruncatedAst[1][0] = - Number(nodePathWithCorrectedIndexForTruncatedAst[1][0]) - - Number(planeNodePath[1][0]) - - 1 + getPathNormalisedForTruncatedAst( + updatedEntryNodePath, + updatedSketchNodePaths + ) const _node = getNodeFromPath( truncatedAst, nodePathWithCorrectedIndexForTruncatedAst, @@ -2901,10 +2871,7 @@ export class SceneEntities { : { ...this.kclManager.ast } const nodePathWithCorrectedIndexForTruncatedAst = - structuredClone(pathToNode) - nodePathWithCorrectedIndexForTruncatedAst[1][0] = - Number(nodePathWithCorrectedIndexForTruncatedAst[1][0]) - - Number(sketchNodePaths[0][1][0]) + getPathNormalisedForTruncatedAst(pathToNode, sketchNodePaths) const _node = getNodeFromPath>( modifiedAst, diff --git a/src/lang/queryAst.ts b/src/lang/queryAst.ts index 03b838575..64b057a09 100644 --- a/src/lang/queryAst.ts +++ b/src/lang/queryAst.ts @@ -1306,3 +1306,17 @@ export function findPipesWithImportAlias( return pipes } + +export const getPathNormalisedForTruncatedAst = ( + entryNodePath: PathToNode, + sketchNodePaths: PathToNode[] +): PathToNode => { + const nodePathWithCorrectedIndexForTruncatedAst = + structuredClone(entryNodePath) + const minIndex = Math.min( + ...sketchNodePaths.map((path) => Number(path[1][0])) + ) + nodePathWithCorrectedIndexForTruncatedAst[1][0] = + Number(nodePathWithCorrectedIndexForTruncatedAst[1][0]) - minIndex + return nodePathWithCorrectedIndexForTruncatedAst +}