KCL: Rotations in pattern transform (#3979)

Pattern transforms now have a new `rotation` parameter, letting you rotate each instance of the shape. Currently only rotation around the local origin (i.e. rotating the object around the center of its own bounding box) works correctly. Rotating around a global origin (i.e. center of the scene) will be fixed on the server side soon.
This commit is contained in:
Adam Chalmers
2024-09-26 15:02:45 -05:00
committed by GitHub
parent 27c6f75a49
commit ca95427f21
16 changed files with 213 additions and 17 deletions

View File

@ -24,7 +24,9 @@ const sketch001 = startSketchOn('XZ')
|> circle({ center: [0, 0], radius: 2 }, %)
const extrude001 = extrude(5, sketch001)
const pattern01 = patternTransform(int(ceil(5 / 2)), (id) => {
let n = int(ceil(5 / 2))
assertEqual(n, 3, 0.0001, "5/2 = 2.5, rounded up makes 3")
const pattern01 = patternTransform(n, (id) => {
return { translate: [4 * id, 0, 0] }
}, extrude001)
```

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -137746,7 +137746,7 @@
"unpublished": false,
"deprecated": false,
"examples": [
"const sketch001 = startSketchOn('XZ')\n |> circle({ center: [0, 0], radius: 2 }, %)\nconst extrude001 = extrude(5, sketch001)\n\nconst pattern01 = patternTransform(int(ceil(5 / 2)), (id) => {\n return { translate: [4 * id, 0, 0] }\n}, extrude001)"
"const sketch001 = startSketchOn('XZ')\n |> circle({ center: [0, 0], radius: 2 }, %)\nconst extrude001 = extrude(5, sketch001)\n\nlet n = int(ceil(5 / 2))\nassertEqual(n, 3, 0.0001, \"5/2 = 2.5, rounded up makes 3\")\nconst pattern01 = patternTransform(n, (id) => {\n return { translate: [4 * id, 0, 0] }\n}, extrude001)"
]
},
{
@ -203740,7 +203740,7 @@
{
"name": "patternTransform",
"summary": "Repeat a 3-dimensional solid by successively applying a transformation (such",
"description": "as rotation, scale, translation, visibility) on each repetition.",
"description": "as rotation, scale, translation, visibility) on each repetition.\nThe transformation takes a single parameter: an integer representing which number replication the transform is for. E.g. the first replica to be transformed will be passed the argument `1`.",
"tags": [],
"args": [
{
@ -210861,6 +210861,7 @@
"unpublished": false,
"deprecated": false,
"examples": [
"fn cube = (length, center) => {\n let l = length / 2\n let x = center[0]\n let y = center[1]\n let p0 = [-l + x, -l + y]\n let p1 = [-l + x, l + y]\n let p2 = [l + x, l + y]\n let p3 = [l + x, -l + y]\n\n return startSketchAt(p0)\n |> lineTo(p1, %)\n |> lineTo(p2, %)\n |> lineTo(p3, %)\n |> lineTo(p0, %)\n |> close(%)\n |> extrude(length, %)\n}\n\nlet width = 20\nfn transform = (i) => {\n return {\n // Move down each time.\n translate: [0, 0, -i * width],\n // Make the cube longer, wider and flatter each time.\n scale: [pow(1.1, i), pow(1.1, i), pow(0.9, i)],\n // Turn by 15 degrees each time.\n rotation: { angle: 15 * i, origin: \"local\" }\n}\n}\n\nlet myCubes = cube(width, [100, 0])\n |> patternTransform(25, transform, %)",
"// Parameters\nconst r = 50 // base radius\nconst h = 10 // layer height\nconst t = 0.005 // taper factor [0-1)\n// Defines how to modify each layer of the vase.\n// Each replica is shifted up the Z axis, and has a smoothly-varying radius\nfn transform = (replicaId) => {\n let scale = r * abs(1 - (t * replicaId)) * (5 + cos(replicaId / 8))\n return {\n translate: [0, 0, replicaId * 10],\n scale: [scale, scale, 0]\n}\n}\n// Each layer is just a pretty thin cylinder.\nfn layer = () => {\n return startSketchOn(\"XY\")\n // or some other plane idk\n |> circle({ center: [0, 0], radius: 1 }, %, $tag1)\n |> extrude(h, %)\n}\n// The vase is 100 layers tall.\n// The 100 layers are replica of each other, with a slight transformation applied to each.\nlet vase = layer()\n |> patternTransform(100, transform, %)"
]
},