Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/hooks/useEngineConnectionSubscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
ExtrudeFacePlane,
} from '@src/machines/modelingMachine'
import toast from 'react-hot-toast'
import { findAllChildrenAndOrderByPlaceInCode } from '@src/lang/modifyAst/boolean'

export function useEngineConnectionSubscriptions() {
const { send, context, state } = useModelingContext()
Expand Down Expand Up @@ -146,7 +147,7 @@ export function useEngineConnectionSubscriptions() {
}

sceneInfra.modelingSend({
type: 'Select default plane',
type: 'Select sketch plane',
Comment on lines -151 to +152

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been a bad name for a while, thought I should fix it up while I was in here.

data: {
type: 'defaultPlane',
planeId: planeId,
Expand All @@ -163,7 +164,7 @@ export function useEngineConnectionSubscriptions() {
const planeInfo =
await sceneEntitiesManager.getFaceDetails(planeOrFaceId)
sceneInfra.modelingSend({
type: 'Select default plane',
type: 'Select sketch plane',
data: {
type: 'offsetPlane',
zAxis: [
Expand Down Expand Up @@ -192,7 +193,7 @@ export function useEngineConnectionSubscriptions() {
return
}

// Artifact is likely an extrusion face
// Artifact is likely an sweep face

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little bit of clean up, using the more generic term.

const faceId = planeOrFaceId
const extrusion = getSweepFromSuspectedSweepSurface(
faceId,
Expand Down Expand Up @@ -316,15 +317,30 @@ export function useEngineConnectionSubscriptions() {
}
: { type: 'wall' }

if (err(extrusion)) {
return Promise.reject(
new Error(`Extrusion is not a valid artifact: ${extrusion}`)
)
}

const lastChild = findAllChildrenAndOrderByPlaceInCode(
{ type: 'sweep', ...extrusion },
kclManager.artifactGraph
)[0]
const lastChildCodeRef =
lastChild.type === 'compositeSolid'
? lastChild.codeRef.range
: null
Comment thread
Irev-Dev marked this conversation as resolved.
Outdated

const extrudePathToNode = !err(extrusion)
? getNodePathFromSourceRange(
kclManager.ast,
extrusion.codeRef.range
lastChildCodeRef || extrusion.codeRef.range
)
: []

sceneInfra.modelingSend({
type: 'Select default plane',
type: 'Select sketch plane',
data: {
type: 'extrudeFace',
zAxis: [z_axis.x, z_axis.y, z_axis.z],
Expand Down
3 changes: 2 additions & 1 deletion src/lang/modifyAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,8 @@ export function sketchOnExtrudedFace(

const expressionIndex = Math.max(
sketchPathToNode[1][0] as number,
extrudePathToNode[1][0] as number
extrudePathToNode[1][0] as number,
node.body.length - 1
)
_node.body.splice(expressionIndex + 1, 0, newSketch)
const newpathToNode: PathToNode = [
Expand Down
27 changes: 27 additions & 0 deletions src/lang/modifyAst/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,26 @@ export function findAllChildrenAndOrderByPlaceInCode(
artifact: Artifact,
artifactGraph: ArtifactGraph
): Artifact[] {
const pathToCompositeSolidMap: { [key: string]: string[] } = {}
for (const [id, artifact] of artifactGraph) {
if (artifact.type === 'compositeSolid') {
for (const pathId of artifact.solidIds) {
if (pathToCompositeSolidMap[pathId]) {
pathToCompositeSolidMap[pathId].push(id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for a path to get used in multiple CSG ops? If so, composite_solid_id: Option<ArtifactId>, would need to get converted to composite_solid_ids: Vec<ArtifactId>,.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but not yet I don't think, it would be the keepTool situation.

} else {
pathToCompositeSolidMap[pathId] = [id]
}
}
for (const pathId of artifact.toolIds) {
if (pathToCompositeSolidMap[pathId]) {
pathToCompositeSolidMap[pathId].push(id)
} else {
pathToCompositeSolidMap[pathId] = [id]
}
}
}
}

@Irev-Dev Irev-Dev May 6, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtran I wanted to ask you about this

I'm building up a little map to go from a pathId to compositeSolids if they exist, because the composite solids in the artifactGraph done have edges going both ways, so there's no way to go from a path to its compositeSolid

I did try adding the edge going the other way in https://github.com/KittyCAD/modeling-app/compare/kurt-composite-attempt?expand=1
But I danno it just didn't work and I couldn't figure out why, I thought maybe I screwed up the merge logic, but it looks okay to me?

But what do you think, solve this in rust, or just keep what I've got?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll wait for @jtran's input before merging

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you say "it just didn't work", what symptoms are you actually seeing? The Mermaid chart generation wasn't updated, but when I did that, the charts show that the edges are bidirectional for the sim tests we have. But for some reason, edges in the graph are lost. Here's the diff of the intersect_cubes sim test. The path (3) correctly gains the edge to the composite (17), but it loses the edge to the solid2d (13). Same thing with the other path (4).

Screenshot 2025-05-06 at 11 31 01 AM

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I think I fixed it. The above diff made it obvious. I'll push to your branch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a few commits. This one is the fix: e23e6d2.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Looking now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, what a silly mistake :/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I've removed my little mapping, just waiting for CI to be green.


const result: string[] = []
const stack: string[] = [artifact.id]

Expand Down Expand Up @@ -211,6 +231,13 @@ export function findAllChildrenAndOrderByPlaceInCode(
pushToSomething(currentId, current?.segIds)
} else if (current?.type === 'sweep') {
pushToSomething(currentId, current?.surfaceIds)
const path = artifactGraph.get(current.pathId)
if (path && path.type === 'path') {
const compositeSolidIds = pathToCompositeSolidMap[current.pathId]
if (compositeSolidIds) {
result.push(...compositeSolidIds)
}
}
} else if (current?.type === 'wall' || current?.type === 'cap') {
pushToSomething(currentId, current?.pathIds)
} else if (current?.type === 'segment') {
Expand Down
6 changes: 3 additions & 3 deletions src/machines/modelingMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export type ModelingMachineEvent =
}
| { type: 'Sketch On Face' }
| {
type: 'Select default plane'
type: 'Select sketch plane'
data: DefaultPlane | ExtrudeFacePlane | OffsetPlane
}
| {
Expand Down Expand Up @@ -4421,7 +4421,7 @@ export const modelingMachine = setup({

exit: ['hide default planes', 'set selection filter to defaults'],
on: {
'Select default plane': {
'Select sketch plane': {
target: 'animating to plane',
actions: ['reset sketch metadata'],
},
Expand All @@ -4434,7 +4434,7 @@ export const modelingMachine = setup({
id: 'animate-to-face',

input: ({ event }) => {
if (event.type !== 'Select default plane') return undefined
if (event.type !== 'Select sketch plane') return undefined
return event.data
},

Expand Down