2024-10-31 11:43:14 -05:00
|
|
|
---
|
|
|
|
source: kcl/src/simulation_tests.rs
|
|
|
|
description: Program memory after executing helix_ccw.kcl
|
KCL: Patterns of patterns can use the original sketch/solid as target (#5284)
Right now, if you model something like this box with a button:
<img width="413" alt="Screenshot 2025-02-06 at 3 08 03 PM" src="https://github.com/user-attachments/assets/04818a70-7cf3-4ee3-b8c5-df5959ac10db" />
Let's say you want to pattern the button, and repeat it a second time. If you try, you'll actually pattern the entire model (box + button).
<img width="486" alt="Screenshot 2025-02-06 at 3 08 52 PM" src="https://github.com/user-attachments/assets/09fc28d9-5d80-4ab3-b4dc-b8de2945fcba" />
Why? Because right now, when you sketch on a face (like the button was), both the box and the button share the same ID. All extrusions from a solid will share the same ID, because they all refer to the same composite solid.
This is helpful in some ways -- arguably the solid _is_ just one big complex shape now -- but it's not helpful in other ways. What if I want to only pattern the button? Luckily there's an original ID for the button part, which is still stored. So we just need a way to tell the pattern stdlib functions whether to use the target's main ID or its original ID. This PR adds a new optional bool, `useOriginal`, to patterns. It's false by default, to keep backwards-compatibility (make sure that old KCL code doesn't change).
This PR is based on https://github.com/KittyCAD/modeling-app/pull/3914. It's based on work Serena and I are doing to fix a bug (engine does not allow patterning a 3D solid which was sketched on a face of another solid). @gserena01 our test program is now:
```
w = 400
case = startSketchOn('XY')
|> startProfileAt([-w, -w], %)
|> line(endAbsolute = [-w, w])
|> line(endAbsolute = [w, -w])
|> line(endAbsolute = [-w, -w])
|> close()
|> extrude(length = 200)
bump1 = startSketchOn(case, 'end')
|> circle({ center = [-50, -50], radius = 40 }, %)
|> extrude(length = 20)
// We pass in "bump1" here since we want to pattern just this object on the face.
useOriginal = true
target = bump1
transform = {
axis = [1, 0, 0],
instances = 3,
distance = -100
}
patternLinear3d(transform, target, useOriginal)
```
If you change the `useOriginal = true` to `false` you can see the difference.
2025-02-06 17:46:47 -06:00
|
|
|
snapshot_kind: text
|
2024-10-31 11:43:14 -05:00
|
|
|
---
|
|
|
|
{
|
|
|
|
"environments": [
|
|
|
|
{
|
|
|
|
"bindings": {
|
|
|
|
"HALF_TURN": {
|
2024-11-14 17:27:19 -06:00
|
|
|
"type": "Number",
|
|
|
|
"value": 180.0,
|
2024-10-31 11:43:14 -05:00
|
|
|
"__meta": []
|
|
|
|
},
|
|
|
|
"QUARTER_TURN": {
|
2024-11-14 17:27:19 -06:00
|
|
|
"type": "Number",
|
|
|
|
"value": 90.0,
|
2024-10-31 11:43:14 -05:00
|
|
|
"__meta": []
|
|
|
|
},
|
|
|
|
"THREE_QUARTER_TURN": {
|
2024-11-14 17:27:19 -06:00
|
|
|
"type": "Number",
|
|
|
|
"value": 270.0,
|
2024-10-31 11:43:14 -05:00
|
|
|
"__meta": []
|
|
|
|
},
|
|
|
|
"ZERO": {
|
2024-11-14 17:27:19 -06:00
|
|
|
"type": "Number",
|
|
|
|
"value": 0.0,
|
2024-10-31 11:43:14 -05:00
|
|
|
"__meta": []
|
|
|
|
},
|
|
|
|
"part001": {
|
|
|
|
"type": "Solid",
|
2025-01-22 09:42:09 +13:00
|
|
|
"value": {
|
|
|
|
"type": "Solid",
|
2024-10-31 11:43:14 -05:00
|
|
|
"id": "[uuid]",
|
2025-02-05 23:50:00 -05:00
|
|
|
"artifactId": "[uuid]",
|
2025-01-22 09:42:09 +13:00
|
|
|
"value": [
|
2024-10-31 11:43:14 -05:00
|
|
|
{
|
2025-01-22 09:42:09 +13:00
|
|
|
"faceId": "[uuid]",
|
|
|
|
"id": "[uuid]",
|
|
|
|
"sourceRange": [
|
|
|
|
35,
|
|
|
|
78,
|
|
|
|
0
|
2024-10-31 11:43:14 -05:00
|
|
|
],
|
2025-01-22 09:42:09 +13:00
|
|
|
"tag": null,
|
|
|
|
"type": "extrudeArc"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"sketch": {
|
|
|
|
"type": "Sketch",
|
|
|
|
"id": "[uuid]",
|
|
|
|
"paths": [
|
|
|
|
{
|
|
|
|
"__geoMeta": {
|
|
|
|
"id": "[uuid]",
|
|
|
|
"sourceRange": [
|
|
|
|
35,
|
|
|
|
78,
|
|
|
|
0
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"ccw": true,
|
|
|
|
"center": [
|
|
|
|
5.0,
|
|
|
|
5.0
|
|
|
|
],
|
|
|
|
"from": [
|
|
|
|
15.0,
|
|
|
|
5.0
|
|
|
|
],
|
|
|
|
"radius": 10.0,
|
|
|
|
"tag": null,
|
|
|
|
"to": [
|
|
|
|
15.0,
|
|
|
|
5.0
|
|
|
|
],
|
|
|
|
"type": "Circle"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"on": {
|
|
|
|
"type": "plane",
|
|
|
|
"id": "[uuid]",
|
2025-02-05 23:50:00 -05:00
|
|
|
"artifactId": "[uuid]",
|
2025-01-22 09:42:09 +13:00
|
|
|
"value": "XY",
|
|
|
|
"origin": {
|
|
|
|
"x": 0.0,
|
|
|
|
"y": 0.0,
|
|
|
|
"z": 0.0
|
|
|
|
},
|
|
|
|
"xAxis": {
|
|
|
|
"x": 1.0,
|
|
|
|
"y": 0.0,
|
|
|
|
"z": 0.0
|
|
|
|
},
|
|
|
|
"yAxis": {
|
|
|
|
"x": 0.0,
|
|
|
|
"y": 1.0,
|
|
|
|
"z": 0.0
|
|
|
|
},
|
|
|
|
"zAxis": {
|
|
|
|
"x": 0.0,
|
|
|
|
"y": 0.0,
|
|
|
|
"z": 1.0
|
|
|
|
},
|
|
|
|
"units": {
|
|
|
|
"type": "Mm"
|
|
|
|
},
|
|
|
|
"__meta": []
|
|
|
|
},
|
|
|
|
"start": {
|
2024-10-31 11:43:14 -05:00
|
|
|
"from": [
|
2024-11-25 13:07:03 -05:00
|
|
|
15.0,
|
2024-10-31 11:43:14 -05:00
|
|
|
5.0
|
|
|
|
],
|
|
|
|
"to": [
|
2024-11-25 13:07:03 -05:00
|
|
|
15.0,
|
2024-10-31 11:43:14 -05:00
|
|
|
5.0
|
|
|
|
],
|
2025-01-22 09:42:09 +13:00
|
|
|
"tag": null,
|
|
|
|
"__geoMeta": {
|
|
|
|
"id": "[uuid]",
|
|
|
|
"sourceRange": [
|
|
|
|
35,
|
|
|
|
78,
|
|
|
|
0
|
|
|
|
]
|
|
|
|
}
|
2024-10-31 11:43:14 -05:00
|
|
|
},
|
2025-02-05 23:50:00 -05:00
|
|
|
"artifactId": "[uuid]",
|
KCL: Patterns of patterns can use the original sketch/solid as target (#5284)
Right now, if you model something like this box with a button:
<img width="413" alt="Screenshot 2025-02-06 at 3 08 03 PM" src="https://github.com/user-attachments/assets/04818a70-7cf3-4ee3-b8c5-df5959ac10db" />
Let's say you want to pattern the button, and repeat it a second time. If you try, you'll actually pattern the entire model (box + button).
<img width="486" alt="Screenshot 2025-02-06 at 3 08 52 PM" src="https://github.com/user-attachments/assets/09fc28d9-5d80-4ab3-b4dc-b8de2945fcba" />
Why? Because right now, when you sketch on a face (like the button was), both the box and the button share the same ID. All extrusions from a solid will share the same ID, because they all refer to the same composite solid.
This is helpful in some ways -- arguably the solid _is_ just one big complex shape now -- but it's not helpful in other ways. What if I want to only pattern the button? Luckily there's an original ID for the button part, which is still stored. So we just need a way to tell the pattern stdlib functions whether to use the target's main ID or its original ID. This PR adds a new optional bool, `useOriginal`, to patterns. It's false by default, to keep backwards-compatibility (make sure that old KCL code doesn't change).
This PR is based on https://github.com/KittyCAD/modeling-app/pull/3914. It's based on work Serena and I are doing to fix a bug (engine does not allow patterning a 3D solid which was sketched on a face of another solid). @gserena01 our test program is now:
```
w = 400
case = startSketchOn('XY')
|> startProfileAt([-w, -w], %)
|> line(endAbsolute = [-w, w])
|> line(endAbsolute = [w, -w])
|> line(endAbsolute = [-w, -w])
|> close()
|> extrude(length = 200)
bump1 = startSketchOn(case, 'end')
|> circle({ center = [-50, -50], radius = 40 }, %)
|> extrude(length = 20)
// We pass in "bump1" here since we want to pattern just this object on the face.
useOriginal = true
target = bump1
transform = {
axis = [1, 0, 0],
instances = 3,
distance = -100
}
patternLinear3d(transform, target, useOriginal)
```
If you change the `useOriginal = true` to `false` you can see the difference.
2025-02-06 17:46:47 -06:00
|
|
|
"originalId": "[uuid]",
|
2025-01-22 09:42:09 +13:00
|
|
|
"units": {
|
|
|
|
"type": "Mm"
|
2024-10-31 11:43:14 -05:00
|
|
|
},
|
2025-01-22 09:42:09 +13:00
|
|
|
"__meta": [
|
|
|
|
{
|
|
|
|
"sourceRange": [
|
|
|
|
35,
|
|
|
|
78,
|
|
|
|
0
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2024-10-31 11:43:14 -05:00
|
|
|
},
|
2025-01-22 09:42:09 +13:00
|
|
|
"height": 10.0,
|
|
|
|
"startCapId": "[uuid]",
|
|
|
|
"endCapId": "[uuid]",
|
|
|
|
"units": {
|
|
|
|
"type": "Mm"
|
2024-10-31 11:43:14 -05:00
|
|
|
},
|
|
|
|
"__meta": [
|
|
|
|
{
|
|
|
|
"sourceRange": [
|
|
|
|
35,
|
2024-11-25 09:21:55 +13:00
|
|
|
78,
|
2024-11-07 11:23:41 -05:00
|
|
|
0
|
2024-10-31 11:43:14 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2025-01-22 09:42:09 +13:00
|
|
|
}
|
2024-10-31 11:43:14 -05:00
|
|
|
}
|
|
|
|
},
|
2025-02-12 10:22:56 +13:00
|
|
|
"snapshots": [],
|
2024-10-31 11:43:14 -05:00
|
|
|
"parent": null
|
|
|
|
}
|
|
|
|
],
|
2025-02-12 10:22:56 +13:00
|
|
|
"currentEnv": [
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
],
|
|
|
|
"callStack": []
|
2024-10-31 11:43:14 -05:00
|
|
|
}
|