forma-dsl-mcp 0.3.8 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -18
- package/package.json +2 -2
- package/src/bin.js +1 -1
- package/src/catalogue.js +15 -15
- package/src/document.js +8 -38
- package/src/examples.js +1 -1
- package/src/guide.js +24 -24
- package/src/reference/README.md +15 -5
- package/src/reference/api/describe-parameters.md +4 -4
- package/src/reference/api/evaluation-context.md +13 -13
- package/src/reference/api/export.md +7 -7
- package/src/reference/api/geometry-node.md +9 -9
- package/src/reference/api/kernel.md +8 -8
- package/src/reference/api/low-level.md +9 -9
- package/src/reference/api/render.md +8 -8
- package/src/reference/api/values.md +12 -12
- package/src/reference/cli.md +199 -0
- package/src/reference/errors.md +14 -14
- package/src/reference/language/control-flow.md +3 -3
- package/src/reference/language/expressions.md +10 -10
- package/src/reference/language/overview.md +11 -11
- package/src/reference/language/scope.md +13 -13
- package/src/reference/language/syntax.md +4 -4
- package/src/reference/reference/align.md +9 -9
- package/src/reference/reference/booleans.md +5 -5
- package/src/reference/reference/component.md +12 -12
- package/src/reference/reference/conversions.md +8 -8
- package/src/reference/reference/functions.md +8 -8
- package/src/reference/reference/local.md +4 -4
- package/src/reference/reference/model.md +10 -10
- package/src/reference/reference/param.md +8 -8
- package/src/reference/reference/part.md +12 -12
- package/src/reference/reference/refinement.md +10 -10
- package/src/reference/reference/shapes-2d.md +15 -15
- package/src/reference/reference/shapes-3d.md +13 -13
- package/src/reference/reference/transforms.md +10 -10
- package/src/reference.js +4 -3
- package/src/roots.js +2 -2
- package/src/server.js +2 -2
- package/src/tools.js +15 -15
- package/src/workspace.js +7 -7
|
@@ -46,13 +46,13 @@ the *minimum* face at that coordinate. `z = 5` means "sit this on a surface at h
|
|
|
46
46
|
|
|
47
47
|
#### Returns
|
|
48
48
|
|
|
49
|
-
The children, unioned and translated. Dimensionality passes through
|
|
49
|
+
The children, unioned and translated. Dimensionality passes through - a 2D child accepts
|
|
50
50
|
`x` and `y` only.
|
|
51
51
|
|
|
52
52
|
#### Caveats
|
|
53
53
|
|
|
54
54
|
- **`align` needs a kernel context.** It is the one block that cannot be evaluated without
|
|
55
|
-
one: `align needs a kernel context
|
|
55
|
+
one: `align needs a kernel context - render the model rather than building it`. Building a
|
|
56
56
|
node tree with a bare `Evaluator` and no context will fail on it.
|
|
57
57
|
- **It costs a kernel round-trip.** The child has to be solved before the alignment can be
|
|
58
58
|
computed, so the subtree is evaluated at build time rather than lazily. The digest cache
|
|
@@ -60,7 +60,7 @@ The children, unioned and translated. Dimensionality passes through — a 2D chi
|
|
|
60
60
|
- It measures the **bounding box**, not the geometry. For anything that is not
|
|
61
61
|
axis-aligned, the box is larger than the shape.
|
|
62
62
|
- Children are unioned first, so several blocks inside one `align` move together.
|
|
63
|
-
- A label
|
|
63
|
+
- A label - `align "name" { }` - is accepted and silently ignored.
|
|
64
64
|
|
|
65
65
|
---
|
|
66
66
|
|
|
@@ -81,7 +81,7 @@ align {
|
|
|
81
81
|
}
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
Most shapes take a `center = true` attribute, which is cheaper
|
|
84
|
+
Most shapes take a `center = true` attribute, which is cheaper - it changes how the shape is
|
|
85
85
|
built rather than measuring it afterwards. Reach for `align` when the thing being centred is
|
|
86
86
|
a **composition** rather than a single shape, and there is no one attribute to set.
|
|
87
87
|
|
|
@@ -131,9 +131,9 @@ align {
|
|
|
131
131
|
|
|
132
132
|
| Approach | When |
|
|
133
133
|
| --- | --- |
|
|
134
|
-
| `center = true` on the shape | A single primitive. Free
|
|
134
|
+
| `center = true` on the shape | A single primitive. Free - it changes how the shape is built |
|
|
135
135
|
| `translate` by a known amount | You already know the dimensions, usually because they are params |
|
|
136
|
-
| `align` | The extent is **computed**
|
|
136
|
+
| `align` | The extent is **computed** - a hull, a composition, an offset outline - and writing the arithmetic would mean duplicating it |
|
|
137
137
|
|
|
138
138
|
A model that knows its own dimensions should use them:
|
|
139
139
|
|
|
@@ -154,7 +154,7 @@ kernel round-trip. For anything small, prefer clarity.
|
|
|
154
154
|
|
|
155
155
|
## Troubleshooting
|
|
156
156
|
|
|
157
|
-
### `align needs a kernel context
|
|
157
|
+
### `align needs a kernel context - render the model rather than building it`
|
|
158
158
|
|
|
159
159
|
An `Evaluator` was constructed without a `context`, and the document contains an `align`.
|
|
160
160
|
[`render`](../api/render.md) always supplies one, so this only comes up when driving the
|
|
@@ -170,12 +170,12 @@ unaffected.
|
|
|
170
170
|
|
|
171
171
|
### `align: "x" must be "min", "center", "max" or a number`
|
|
172
172
|
|
|
173
|
-
The value is a string that is not one of the three keywords
|
|
173
|
+
The value is a string that is not one of the three keywords - `"middle"` and `"centre"` are
|
|
174
174
|
the usual culprits. The spelling is `"center"`.
|
|
175
175
|
|
|
176
176
|
### `align needs at least one shape inside it`
|
|
177
177
|
|
|
178
|
-
The body produced nothing
|
|
178
|
+
The body produced nothing - an `if` that took no branch, or a `for` over an empty list.
|
|
179
179
|
|
|
180
180
|
### `align: unknown attribute "z"` on a 2D shape
|
|
181
181
|
|
|
@@ -27,7 +27,7 @@ None.
|
|
|
27
27
|
|
|
28
28
|
- **Usually unnecessary.** Sibling blocks are already implicitly unioned, so
|
|
29
29
|
`part "p" { a b }` and `part "p" { union { a b } }` are the same. Write `union`
|
|
30
|
-
explicitly when it makes the grouping clearer
|
|
30
|
+
explicitly when it makes the grouping clearer - typically as one operand of a
|
|
31
31
|
`difference`.
|
|
32
32
|
- The order of the children does not affect the result, and does not affect the digest
|
|
33
33
|
either: union members are sorted by subtree size before hashing, so two unions written in a
|
|
@@ -86,7 +86,7 @@ None.
|
|
|
86
86
|
|
|
87
87
|
#### Caveats
|
|
88
88
|
|
|
89
|
-
- With one child, it is that child. With none, it is an error
|
|
89
|
+
- With one child, it is that child. With none, it is an error -
|
|
90
90
|
`"intersection" needs at least one shape inside it`.
|
|
91
91
|
- Order does not affect the result.
|
|
92
92
|
|
|
@@ -149,7 +149,7 @@ intersection {
|
|
|
149
149
|
}
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
-
For a single flat cut, [`trim`](refinement.md#trim) is cheaper
|
|
152
|
+
For a single flat cut, [`trim`](refinement.md#trim) is cheaper - it cuts with a half-space
|
|
153
153
|
and needs no second solid.
|
|
154
154
|
|
|
155
155
|
### Grouping so a transform applies to several shapes
|
|
@@ -164,7 +164,7 @@ translate {
|
|
|
164
164
|
}
|
|
165
165
|
```
|
|
166
166
|
|
|
167
|
-
Inside a `difference`, though, each child is separate
|
|
167
|
+
Inside a `difference`, though, each child is separate - so to subtract two shapes *as one
|
|
168
168
|
body*, group them explicitly:
|
|
169
169
|
|
|
170
170
|
```hcl
|
|
@@ -178,7 +178,7 @@ difference {
|
|
|
178
178
|
```
|
|
179
179
|
|
|
180
180
|
Here the `union` is not decorative: without it the two cylinders would be two separate
|
|
181
|
-
cutters, which happens to give the same result for a difference
|
|
181
|
+
cutters, which happens to give the same result for a difference - but not for an
|
|
182
182
|
`intersection`, where it changes the answer entirely.
|
|
183
183
|
|
|
184
184
|
---
|
|
@@ -27,7 +27,7 @@ model "m" {
|
|
|
27
27
|
Declares a block named `NAME`. Its body is ordinary geometry; its `param` declarations are
|
|
28
28
|
the attributes a call site may pass.
|
|
29
29
|
|
|
30
|
-
Once declared, it is called like any other block
|
|
30
|
+
Once declared, it is called like any other block - the call site cannot tell a component
|
|
31
31
|
from a builtin, which is the point.
|
|
32
32
|
|
|
33
33
|
#### Body
|
|
@@ -41,7 +41,7 @@ from a builtin, which is the point.
|
|
|
41
41
|
|
|
42
42
|
#### Returns
|
|
43
43
|
|
|
44
|
-
One geometry node
|
|
44
|
+
One geometry node - everything in the body, unioned. The dimensionality is whatever the body
|
|
45
45
|
produced, so a component may return 2D or 3D geometry and be used wherever that fits.
|
|
46
46
|
|
|
47
47
|
#### Caveats
|
|
@@ -60,8 +60,8 @@ produced, so a component may return 2D or 3D geometry and be used wherever that
|
|
|
60
60
|
branch, fails with `component "c" produced no geometry`.
|
|
61
61
|
- **Recursion is not supported.** A component that calls itself has no base case the
|
|
62
62
|
evaluator can see, and hits the nesting limit:
|
|
63
|
-
`nesting deeper than 64 blocks
|
|
64
|
-
- A label on a call
|
|
63
|
+
`nesting deeper than 64 blocks - is a component using itself?`
|
|
64
|
+
- A label on a call - `my_component "label" { }` - is accepted and silently ignored.
|
|
65
65
|
Do not rely on it.
|
|
66
66
|
|
|
67
67
|
---
|
|
@@ -88,7 +88,7 @@ component "tray" {
|
|
|
88
88
|
}
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
Note the empty braces on `lid`. `param lid` on its own is a **syntax error**
|
|
91
|
+
Note the empty braces on `lid`. `param lid` on its own is a **syntax error** - a param needs
|
|
92
92
|
either `= expression` or a braced body, even an empty one.
|
|
93
93
|
|
|
94
94
|
Inside the body, a param is read by its bare name. There is no `var.` for component params;
|
|
@@ -172,7 +172,7 @@ model "m" {
|
|
|
172
172
|
### Reuse is free
|
|
173
173
|
|
|
174
174
|
Identity in the geometry tree is content identity, so a component called twenty times with
|
|
175
|
-
the same arguments is **evaluated once**
|
|
175
|
+
the same arguments is **evaluated once** - its digest is the same each time, and the kernel
|
|
176
176
|
sees one node. Calling it twenty times with twenty different sizes does cost twenty
|
|
177
177
|
evaluations, because the content genuinely differs.
|
|
178
178
|
|
|
@@ -190,7 +190,7 @@ A `param` with no default and no body:
|
|
|
190
190
|
|
|
191
191
|
```hcl
|
|
192
192
|
component "c" {
|
|
193
|
-
param s // ✗ syntax error
|
|
193
|
+
param s // ✗ syntax error - the parser is looking for `=` or `{`
|
|
194
194
|
box { size = [s, s, s] }
|
|
195
195
|
}
|
|
196
196
|
|
|
@@ -207,19 +207,19 @@ the call site, or give the declaration a default.
|
|
|
207
207
|
|
|
208
208
|
### `c: unknown param "t"`
|
|
209
209
|
|
|
210
|
-
The call passed an attribute the component does not declare
|
|
210
|
+
The call passed an attribute the component does not declare - usually a typo, or an
|
|
211
211
|
attribute meant for a block inside the component. Components have no pass-through: every
|
|
212
212
|
value they need must be declared.
|
|
213
213
|
|
|
214
214
|
### `component "box" shadows a builtin block`
|
|
215
215
|
|
|
216
|
-
The name is already a builtin. Pick another
|
|
216
|
+
The name is already a builtin. Pick another - `rounded_box`, `my_box`, `case_body`. See the
|
|
217
217
|
[full block list](../README.md#shapes) for what is taken.
|
|
218
218
|
|
|
219
219
|
### `a component cannot declare parts`
|
|
220
220
|
|
|
221
221
|
A [`part`](part.md) is a piece of the scene, not geometry an enclosing block can operate on,
|
|
222
|
-
so it cannot come out of a component. Invert it
|
|
222
|
+
so it cannot come out of a component. Invert it - put the part in the model and call the
|
|
223
223
|
component inside it:
|
|
224
224
|
|
|
225
225
|
```hcl
|
|
@@ -231,7 +231,7 @@ component "c" { box { size = [1, 1, 1] } }
|
|
|
231
231
|
model "m" { part "p" { c { } } }
|
|
232
232
|
```
|
|
233
233
|
|
|
234
|
-
### `nesting deeper than 64 blocks
|
|
234
|
+
### `nesting deeper than 64 blocks - is a component using itself?`
|
|
235
235
|
|
|
236
236
|
Almost always direct or mutual recursion. There is no base case the evaluator can detect,
|
|
237
237
|
because a component's body is expanded before any condition inside it is known. Rewrite the
|
|
@@ -239,7 +239,7 @@ recursion as a [`for`](../language/control-flow.md#for) loop.
|
|
|
239
239
|
|
|
240
240
|
### `component "c" produced no geometry`
|
|
241
241
|
|
|
242
|
-
The body evaluated to nothing
|
|
242
|
+
The body evaluated to nothing - an empty body, a loop over an empty list, or an `if` with no
|
|
243
243
|
`else` whose condition was false. A component must return something; guard at the call site
|
|
244
244
|
instead:
|
|
245
245
|
|
|
@@ -49,7 +49,7 @@ extrude {
|
|
|
49
49
|
- A `height` of `0` or less yields empty geometry rather than an error, so a parameter
|
|
50
50
|
sweeping to zero does not break the model.
|
|
51
51
|
- `scale_top = [0, 0]` gives a point, which is one way to build a pyramid from any profile.
|
|
52
|
-
- The profile is swept as drawn
|
|
52
|
+
- The profile is swept as drawn - `extrude` does not centre it. A `rect` that is not centred
|
|
53
53
|
produces a box in the positive quadrant.
|
|
54
54
|
|
|
55
55
|
---
|
|
@@ -76,7 +76,7 @@ revolve { angle = 180 segments = 64 polygon { points = profile } }
|
|
|
76
76
|
radius. A profile drawn from `[0, 0]` upwards produces a solid standing on the XY plane.
|
|
77
77
|
- **Every X must be ≥ 0.** A profile that crosses the axis revolves through itself and the
|
|
78
78
|
result is not what you drew.
|
|
79
|
-
- The profile does not have to touch the axis. One that does not produces a tube
|
|
79
|
+
- The profile does not have to touch the axis. One that does not produces a tube - which is
|
|
80
80
|
how [`torus`](shapes-3d.md#torus) is built internally.
|
|
81
81
|
- An `angle` of `0` or less yields empty geometry rather than an error.
|
|
82
82
|
|
|
@@ -84,7 +84,7 @@ revolve { angle = 180 segments = 64 polygon { points = profile } }
|
|
|
84
84
|
|
|
85
85
|
## `project`
|
|
86
86
|
|
|
87
|
-
The shadow a solid casts on the XY plane
|
|
87
|
+
The shadow a solid casts on the XY plane - its full outline, from any Z.
|
|
88
88
|
|
|
89
89
|
```hcl
|
|
90
90
|
project { bracket { } }
|
|
@@ -120,7 +120,7 @@ slice { z = 12 bracket { } }
|
|
|
120
120
|
|
|
121
121
|
- Takes 3D geometry and produces 2D.
|
|
122
122
|
- A plane that misses the solid gives an empty cross-section, not an error.
|
|
123
|
-
- A plane exactly on a flat face is ambiguous
|
|
123
|
+
- A plane exactly on a flat face is ambiguous - offset it slightly.
|
|
124
124
|
|
|
125
125
|
---
|
|
126
126
|
|
|
@@ -129,7 +129,7 @@ slice { z = 12 bracket { } }
|
|
|
129
129
|
### Profiles are where the modelling happens
|
|
130
130
|
|
|
131
131
|
Most shapes are easier to describe in 2D and then given thickness. A rounded box, for
|
|
132
|
-
instance, has no primitive
|
|
132
|
+
instance, has no primitive - it is a rounded rectangle with a height:
|
|
133
133
|
|
|
134
134
|
```hcl
|
|
135
135
|
extrude {
|
|
@@ -215,7 +215,7 @@ model "m" {
|
|
|
215
215
|
|
|
216
216
|
### Inspecting a cross-section
|
|
217
217
|
|
|
218
|
-
`slice` is a debugging tool as much as a modelling one
|
|
218
|
+
`slice` is a debugging tool as much as a modelling one - extrude the slice thinly to see
|
|
219
219
|
where the walls actually fell:
|
|
220
220
|
|
|
221
221
|
```hcl
|
|
@@ -243,7 +243,7 @@ extrude { height = 10 rect { size = [1, 1] } } // ✓
|
|
|
243
243
|
Two children of different dimensionality. Extrude each profile separately, or union the
|
|
244
244
|
profiles before extruding.
|
|
245
245
|
|
|
246
|
-
### `part "body" is 2D
|
|
246
|
+
### `part "body" is 2D - extrude or revolve it before rendering`
|
|
247
247
|
|
|
248
248
|
A profile reached the renderer. Somewhere the `extrude` or `revolve` is missing, or is
|
|
249
249
|
wrapped around the wrong block.
|
|
@@ -261,7 +261,7 @@ have X ≥ 0.
|
|
|
261
261
|
### My revolved solid is lying down
|
|
262
262
|
|
|
263
263
|
`revolve` maps the profile's **Y** to the result's **Z**. A profile written as (x, z) with
|
|
264
|
-
the height in the first component produces a solid on its side
|
|
264
|
+
the height in the first component produces a solid on its side - swap the components.
|
|
265
265
|
|
|
266
266
|
### `revolve` produced nothing
|
|
267
267
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Functions
|
|
2
2
|
|
|
3
3
|
Thirty builtin functions, callable in any [expression](../language/expressions.md). They take
|
|
4
|
-
**positional arguments only**
|
|
4
|
+
**positional arguments only** - named arguments are an error - and there are no user-defined
|
|
5
5
|
functions: to name a value declare a [`local`](local.md), and to name geometry declare a
|
|
6
6
|
[`component`](component.md).
|
|
7
7
|
|
|
@@ -103,7 +103,7 @@ local bolts = max(3, min(16, var.bolts))
|
|
|
103
103
|
|
|
104
104
|
`len(value)` → number
|
|
105
105
|
|
|
106
|
-
The length of a list or a string. Anything else gives `0`
|
|
106
|
+
The length of a list or a string. Anything else gives `0` - it does not raise.
|
|
107
107
|
|
|
108
108
|
```hcl
|
|
109
109
|
len([1, 2, 3]) // 3
|
|
@@ -168,7 +168,7 @@ range(4) // [0, 1, 2, 3]
|
|
|
168
168
|
range(2, 6) // [2, 3, 4, 5]
|
|
169
169
|
range(0, 10, 2.5) // [0, 2.5, 5, 7.5]
|
|
170
170
|
range(5, 0, -1) // [5, 4, 3, 2, 1]
|
|
171
|
-
range(0, -5) // []
|
|
171
|
+
range(0, -5) // [] - backwards with a positive step is empty, not infinite
|
|
172
172
|
```
|
|
173
173
|
|
|
174
174
|
This is what drives most [`for`](../language/control-flow.md#for) loops.
|
|
@@ -211,14 +211,14 @@ String interpolation already converts, so `str` is mostly useful when building a
|
|
|
211
211
|
| `pi` | 3.141592653589793 |
|
|
212
212
|
| `e` | 2.718281828459045 |
|
|
213
213
|
|
|
214
|
-
They are ordinary names in the root scope, so they can be shadowed by a param or a local
|
|
214
|
+
They are ordinary names in the root scope, so they can be shadowed by a param or a local -
|
|
215
215
|
avoid doing so.
|
|
216
216
|
|
|
217
217
|
```hcl
|
|
218
218
|
local circumference = 2 * pi * var.radius
|
|
219
219
|
```
|
|
220
220
|
|
|
221
|
-
Since every angle in the language is in degrees, `pi` comes up less than it would elsewhere
|
|
221
|
+
Since every angle in the language is in degrees, `pi` comes up less than it would elsewhere -
|
|
222
222
|
mostly in arc lengths and areas rather than in rotations.
|
|
223
223
|
|
|
224
224
|
---
|
|
@@ -281,8 +281,8 @@ model "m" {
|
|
|
281
281
|
|
|
282
282
|
### `len takes 1 argument(s), got 2`
|
|
283
283
|
|
|
284
|
-
A fixed-arity function got the wrong count. The variadic ones
|
|
285
|
-
`concat`, `range`
|
|
284
|
+
A fixed-arity function got the wrong count. The variadic ones - `min`, `max`, `sum`,
|
|
285
|
+
`concat`, `range` - accept any number; the rest do not.
|
|
286
286
|
|
|
287
287
|
### `pow: functions take positional arguments`
|
|
288
288
|
|
|
@@ -305,7 +305,7 @@ allocating until the tab dies.
|
|
|
305
305
|
|
|
306
306
|
### `... must be a finite number`
|
|
307
307
|
|
|
308
|
-
Something upstream produced `NaN` or `Infinity`
|
|
308
|
+
Something upstream produced `NaN` or `Infinity` - `sqrt` of a negative, `min()` of nothing,
|
|
309
309
|
`num("abc")`. The error names the block and attribute that read it, not where it was
|
|
310
310
|
produced, so work backwards from there.
|
|
311
311
|
|
|
@@ -13,7 +13,7 @@ local radius = var.diameter / 2
|
|
|
13
13
|
|
|
14
14
|
### `local NAME = expression`
|
|
15
15
|
|
|
16
|
-
Binds a name to the result of an expression. Locals hold values, never geometry
|
|
16
|
+
Binds a name to the result of an expression. Locals hold values, never geometry - to name a
|
|
17
17
|
piece of geometry, declare a [`component`](component.md).
|
|
18
18
|
|
|
19
19
|
#### Parameters
|
|
@@ -30,7 +30,7 @@ Nothing. A local binds a name; it produces no geometry.
|
|
|
30
30
|
#### Caveats
|
|
31
31
|
|
|
32
32
|
- **Locals are ordered at the top level.** A local may refer to params, to constants and to
|
|
33
|
-
locals declared *above* it
|
|
33
|
+
locals declared *above* it - never below. `local a = b` before `local b = 2` fails with
|
|
34
34
|
`unknown name "b"`.
|
|
35
35
|
- **Locals inside a body are not ordered.** Every local in one block body is resolved before
|
|
36
36
|
any of that body's blocks are built, so a block may use a local declared after it. See
|
|
@@ -130,7 +130,7 @@ model "frame" {
|
|
|
130
130
|
|
|
131
131
|
| Use | When |
|
|
132
132
|
| --- | --- |
|
|
133
|
-
| [`param`](param.md) | The value is an **input**
|
|
133
|
+
| [`param`](param.md) | The value is an **input** - someone outside the document should be able to change it |
|
|
134
134
|
| `local` | The value is **derived** from params or is a fixed table, and should never be a control |
|
|
135
135
|
| [`component`](component.md) | You are naming **geometry**, not a value |
|
|
136
136
|
|
|
@@ -152,7 +152,7 @@ local cavity_top = top + 2 // runs past the opening so the neck is not capp
|
|
|
152
152
|
|
|
153
153
|
### `unknown name "b"`
|
|
154
154
|
|
|
155
|
-
A top-level local referred to something declared below it. Move the declaration up
|
|
155
|
+
A top-level local referred to something declared below it. Move the declaration up - locals
|
|
156
156
|
are resolved strictly in source order:
|
|
157
157
|
|
|
158
158
|
```hcl
|
|
@@ -38,7 +38,7 @@ A scene: a list of parts, each with a name, a colour, an opacity and a geometry
|
|
|
38
38
|
#### Caveats
|
|
39
39
|
|
|
40
40
|
- **Every part must be 3D.** A 2D part is rejected before it is solved:
|
|
41
|
-
`part "body" is 2D
|
|
41
|
+
`part "body" is 2D - extrude or revolve it before rendering`.
|
|
42
42
|
- **A model must produce something.** An empty body, or one whose only loop ran zero times,
|
|
43
43
|
fails with `model "m" produced no geometry`.
|
|
44
44
|
- **Declaring the same model twice is an error**: `model "m" is declared twice`.
|
|
@@ -63,7 +63,7 @@ Naming one that does not exist fails with `no model named "exploded"`. In the ed
|
|
|
63
63
|
first model is the one shown.
|
|
64
64
|
|
|
65
65
|
Several models in one document is the idiomatic way to keep variants of the same object
|
|
66
|
-
together
|
|
66
|
+
together - a printable part and the assembly it belongs to, say:
|
|
67
67
|
|
|
68
68
|
```hcl
|
|
69
69
|
component "bracket" { ... }
|
|
@@ -81,7 +81,7 @@ model "assembly" { // what it looks like assembled
|
|
|
81
81
|
|
|
82
82
|
### Parts, and geometry without them
|
|
83
83
|
|
|
84
|
-
Geometry written straight into a model
|
|
84
|
+
Geometry written straight into a model - outside any `part` - becomes **one default part
|
|
85
85
|
named after the model**, coloured `#b8c4d0`:
|
|
86
86
|
|
|
87
87
|
```hcl
|
|
@@ -101,7 +101,7 @@ model "m" {
|
|
|
101
101
|
// parts: "pin", then "m"
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
Prefer explicit parts once there is more than one piece
|
|
104
|
+
Prefer explicit parts once there is more than one piece - they are what the viewer colours
|
|
105
105
|
and lists, and what an exporter can write out separately.
|
|
106
106
|
|
|
107
107
|
### Model params
|
|
@@ -119,10 +119,10 @@ model "bracket" {
|
|
|
119
119
|
|
|
120
120
|
| | Document `param` | Model `param` |
|
|
121
121
|
| --- | --- | --- |
|
|
122
|
-
| Default required | No
|
|
122
|
+
| Default required | No - may be required instead | **Yes**: `model "m": param "s" needs a default` |
|
|
123
123
|
| Settable by the caller | Yes, via `render(source, { params })` | No |
|
|
124
124
|
| Appears in `describeParameters` | Yes | No |
|
|
125
|
-
| Readable as `var.NAME` | Yes | No
|
|
125
|
+
| Readable as `var.NAME` | Yes | No - bare name only |
|
|
126
126
|
|
|
127
127
|
Use them to give one model's fixed numbers a name without adding a control to the editor.
|
|
128
128
|
For anything the caller should change, declare the param at the top level.
|
|
@@ -142,7 +142,7 @@ model "stacked_trays" {
|
|
|
142
142
|
}
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
-
An optional part goes behind an `if` **around** the part, never inside it
|
|
145
|
+
An optional part goes behind an `if` **around** the part, never inside it - a part with no
|
|
146
146
|
geometry is an error:
|
|
147
147
|
|
|
148
148
|
```hcl
|
|
@@ -174,13 +174,13 @@ model "assembly" {
|
|
|
174
174
|
The body evaluated to nothing. Usual causes:
|
|
175
175
|
|
|
176
176
|
- an empty body;
|
|
177
|
-
- a `for` over an empty list
|
|
177
|
+
- a `for` over an empty list - `range(0, var.n)` where `n` is `0`;
|
|
178
178
|
- an `if` with no `else` whose condition was false.
|
|
179
179
|
|
|
180
180
|
Guard the degenerate case so something is always produced, or make the parameter's minimum
|
|
181
181
|
exclude it.
|
|
182
182
|
|
|
183
|
-
### `part "body" is 2D
|
|
183
|
+
### `part "body" is 2D - extrude or revolve it before rendering`
|
|
184
184
|
|
|
185
185
|
A part ended up holding a cross-section rather than a solid. 2D shapes cannot be rendered
|
|
186
186
|
directly:
|
|
@@ -209,5 +209,5 @@ Two models share a name, so `render(source, { model: 'm' })` would be ambiguous.
|
|
|
209
209
|
### My `render(source, { params })` value is ignored
|
|
210
210
|
|
|
211
211
|
The param is probably declared inside the model rather than at the top level. Only top-level
|
|
212
|
-
params are settable. Check with [`describeParameters`](../api/describe-parameters.md)
|
|
212
|
+
params are settable. Check with [`describeParameters`](../api/describe-parameters.md) - it
|
|
213
213
|
lists exactly the params a caller can set.
|
|
@@ -29,7 +29,7 @@ param bolts {
|
|
|
29
29
|
|
|
30
30
|
#### Attributes
|
|
31
31
|
|
|
32
|
-
Every attribute is optional. **Only `default` affects geometry**
|
|
32
|
+
Every attribute is optional. **Only `default` affects geometry** - the rest describe the
|
|
33
33
|
control the editor should build, and are returned verbatim by
|
|
34
34
|
[`describeParameters`](../api/describe-parameters.md).
|
|
35
35
|
|
|
@@ -43,7 +43,7 @@ control the editor should build, and are returned verbatim by
|
|
|
43
43
|
| `description` | string | Help text |
|
|
44
44
|
| `options` | list | A fixed set of choices, for a dropdown rather than a free field |
|
|
45
45
|
|
|
46
|
-
Unknown attributes are **not** rejected here
|
|
46
|
+
Unknown attributes are **not** rejected here - a param block is metadata, and anything in it
|
|
47
47
|
is passed through to the descriptor. This is the one block in the language that does not
|
|
48
48
|
reject attributes it does not understand.
|
|
49
49
|
|
|
@@ -55,13 +55,13 @@ Nothing. A param binds a name; it produces no geometry.
|
|
|
55
55
|
|
|
56
56
|
- **`min`, `max`, `step` and `options` are not enforced.** They shape the editor's control
|
|
57
57
|
and nothing else. `render(source, { params: { bolts: 9999 } })` succeeds on a param
|
|
58
|
-
declared `max = 16`. Validate in the model if a bound matters
|
|
58
|
+
declared `max = 16`. Validate in the model if a bound matters -
|
|
59
59
|
`local n = min(max(var.bolts, 3), 16)`.
|
|
60
60
|
- A param block may contain **attributes only**. Nested blocks inside it are an error:
|
|
61
61
|
`a param block holds attributes, not nested blocks`.
|
|
62
62
|
- Declaring the same param twice is an error: `param "a" is declared twice`.
|
|
63
63
|
- A param's `default` may refer to params declared **above** it by their bare name, but not
|
|
64
|
-
to `var`
|
|
64
|
+
to `var` - `var` is assembled after every param has resolved. See
|
|
65
65
|
[Scope](../language/scope.md#the-root-scope).
|
|
66
66
|
- A param declared inside a `model` is a different thing: it must have a default and cannot
|
|
67
67
|
be set from outside. See [`model`](model.md#model-params).
|
|
@@ -124,7 +124,7 @@ When `type` is omitted it is inferred from the default: a number gives `number`,
|
|
|
124
124
|
`bool`, a string `string`, a list `vector`. A param with neither a `type` nor a `default`
|
|
125
125
|
falls back to `number`.
|
|
126
126
|
|
|
127
|
-
An `angle` param is an ordinary number as far as the language is concerned
|
|
127
|
+
An `angle` param is an ordinary number as far as the language is concerned - every angle in
|
|
128
128
|
forma is in degrees, and the type only tells the editor to label the control that way.
|
|
129
129
|
|
|
130
130
|
### Declaring a required input
|
|
@@ -155,7 +155,7 @@ param bore = diameter / 2 - wall * 4 // ✓ bare names of earlier params
|
|
|
155
155
|
```
|
|
156
156
|
|
|
157
157
|
For a value that is always derived and should never be a control, use a
|
|
158
|
-
[`local`](local.md) instead
|
|
158
|
+
[`local`](local.md) instead - locals are computed after every param and may use `var.`.
|
|
159
159
|
|
|
160
160
|
### Offering a fixed set of choices
|
|
161
161
|
|
|
@@ -191,7 +191,7 @@ give it a default, or supply one:
|
|
|
191
191
|
await render(source, { params: { height: 20 } });
|
|
192
192
|
```
|
|
193
193
|
|
|
194
|
-
[`describeParameters`](../api/describe-parameters.md) works on such a document
|
|
194
|
+
[`describeParameters`](../api/describe-parameters.md) works on such a document - it is built
|
|
195
195
|
to be callable before any value exists, so a front end can discover what to ask for.
|
|
196
196
|
|
|
197
197
|
### `param "a" is declared twice`
|
|
@@ -201,7 +201,7 @@ overwritten, because a duplicated input would make the editor's control ambiguou
|
|
|
201
201
|
|
|
202
202
|
### `a param block holds attributes, not nested blocks`
|
|
203
203
|
|
|
204
|
-
Something inside the braces was parsed as a block rather than an attribute
|
|
204
|
+
Something inside the braces was parsed as a block rather than an attribute - usually a
|
|
205
205
|
missing `=`:
|
|
206
206
|
|
|
207
207
|
```hcl
|
|
@@ -19,7 +19,7 @@ Groups geometry into one named, coloured piece of the scene. Parts are solved in
|
|
|
19
19
|
and drawn in their own colour.
|
|
20
20
|
|
|
21
21
|
A part is **not an operand**. It does not contribute geometry to the block around it, and an
|
|
22
|
-
enclosing `translate` will not move it
|
|
22
|
+
enclosing `translate` will not move it - which is why a part belongs directly in a
|
|
23
23
|
[`model`](model.md), or inside a `for` or `if` in one.
|
|
24
24
|
|
|
25
25
|
#### Label
|
|
@@ -57,7 +57,7 @@ Nothing, to the enclosing block. The part travels separately and lands in the sc
|
|
|
57
57
|
- **A part cannot come out of a [`component`](component.md)**:
|
|
58
58
|
`a component cannot declare parts`. Call the component inside a part instead.
|
|
59
59
|
- **Every part must be 3D** by the time it renders:
|
|
60
|
-
`part "body" is 2D
|
|
60
|
+
`part "body" is 2D - extrude or revolve it before rendering`.
|
|
61
61
|
- Several blocks inside a part are implicitly unioned, exactly as anywhere else.
|
|
62
62
|
- Nothing rejects two parts with the same name; the viewer will simply list two entries
|
|
63
63
|
called the same thing.
|
|
@@ -121,7 +121,7 @@ if var.show_label {
|
|
|
121
121
|
part "label" { color = "#f4f1e4" label_band { } }
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
// ✗
|
|
124
|
+
// ✗ - when show_label is false this is an empty part, which is an error
|
|
125
125
|
part "label" {
|
|
126
126
|
if var.show_label { label_band { } }
|
|
127
127
|
}
|
|
@@ -159,13 +159,13 @@ for (const part of result.parts) {
|
|
|
159
159
|
part.name; // "bottle"
|
|
160
160
|
part.color; // "#8fd3e8"
|
|
161
161
|
part.opacity; // 1
|
|
162
|
-
part.node; // the GeometryNode
|
|
162
|
+
part.node; // the GeometryNode - what context.collect() wants
|
|
163
163
|
part.concrete; // the solved Manifold solid, owned by the context
|
|
164
164
|
part.mesh; // positions and normals, ready to upload
|
|
165
165
|
}
|
|
166
166
|
```
|
|
167
167
|
|
|
168
|
-
Parts are solved independently, so two parts that share a subtree still solve it once
|
|
168
|
+
Parts are solved independently, so two parts that share a subtree still solve it once - the
|
|
169
169
|
digest cache is keyed on content, not on which part asked.
|
|
170
170
|
|
|
171
171
|
To export one part, pass its `concrete` to [`toBinarySTL`](../api/export.md#tobinarystl).
|
|
@@ -176,7 +176,7 @@ To export one part, pass its `concrete` to [`toBinarySTL`](../api/export.md#tobi
|
|
|
176
176
|
|
|
177
177
|
### `a part needs at least one shape inside it`
|
|
178
178
|
|
|
179
|
-
The part's body produced nothing
|
|
179
|
+
The part's body produced nothing - usually an `if` inside it that took no branch, or a `for`
|
|
180
180
|
over an empty list. Move the condition outside the part.
|
|
181
181
|
|
|
182
182
|
### `a part cannot contain another part`
|
|
@@ -194,9 +194,9 @@ component "shell" { ... } // geometry only
|
|
|
194
194
|
model "m" { part "shell" { shell { } } } // the part lives here
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
-
### `part "body" is 2D
|
|
197
|
+
### `part "body" is 2D - extrude or revolve it before rendering`
|
|
198
198
|
|
|
199
|
-
The part holds a cross-section. Extrude or revolve it first
|
|
199
|
+
The part holds a cross-section. Extrude or revolve it first - see
|
|
200
200
|
[2D ↔ 3D](conversions.md).
|
|
201
201
|
|
|
202
202
|
### A part inside an operation disappears
|
|
@@ -208,7 +208,7 @@ depends on whether the operation had anything else to work with:
|
|
|
208
208
|
// ✗ fails: "translate" needs at least one shape inside it
|
|
209
209
|
translate { offset = [0, 0, 10] part "p" { box { size = [1, 1, 1] } } }
|
|
210
210
|
|
|
211
|
-
// ✗ worse
|
|
211
|
+
// ✗ worse - renders, but part "p" is silently gone from the scene
|
|
212
212
|
translate {
|
|
213
213
|
offset = [0, 0, 10]
|
|
214
214
|
box { size = [1, 1, 1] }
|
|
@@ -220,10 +220,10 @@ part "p" { translate { offset = [0, 0, 10] box { size = [1, 1, 1] } } }
|
|
|
220
220
|
```
|
|
221
221
|
|
|
222
222
|
Nothing warns about the second case. If a part you declared is missing from the render,
|
|
223
|
-
check that it is written directly in the [`model`](model.md)
|
|
224
|
-
one
|
|
223
|
+
check that it is written directly in the [`model`](model.md) - or inside a `for` or `if` in
|
|
224
|
+
one - and not nested inside a transform or a boolean.
|
|
225
225
|
|
|
226
226
|
### Two parts have the same name
|
|
227
227
|
|
|
228
228
|
Nothing rejects it. Part names come from an expression, so a loop that computes the same
|
|
229
|
-
label twice produces duplicates
|
|
229
|
+
label twice produces duplicates - include the loop index: `part "leg_${i}"`.
|