Skip to content

Commit 81f9fdc

Browse files
committed
Add 3MF docs
1 parent 89652eb commit 81f9fdc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+8938
-9
lines changed

docs/1.8.6

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/1.8.6/ios/blocks.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Blocks
2+
---
3+
4+
A block is a nested list of instructions, contained inside `{ ... }` braces. Some commands, such as [builders](builders.md) or [CSG operations](csg.md), accept a block parameter instead of a simple value like a number or [vector](literals.md#vectors-and-tuples).
5+
6+
Instructions inside a block are executed within the [scope](scope.md) of the command that invoked them. Typically that means that any transforms or material changes made inside the block will only apply to geometry created inside the same block. This also applies to any symbols that you define inside the block.
7+
8+
You can define your own blocks using the `define` command. Here is a block that creates a five-pointed star:
9+
10+
```swift
11+
define star {
12+
path {
13+
for 1 to 5 {
14+
point 0 -0.5
15+
rotate 1 / 5
16+
point 0 -1
17+
rotate 1 / 5
18+
}
19+
point 0 -0.5
20+
}
21+
}
22+
```
23+
24+
You can call it by simply referencing its name, like this:
25+
26+
```swift
27+
star
28+
```
29+
30+
![Star](../../images/star.png)
31+
32+
**Note:** there is a subtle distinction between the code above and the code below:
33+
34+
```swift
35+
define star path {
36+
for 1 to 5 {
37+
point 0 -0.5
38+
rotate 1 / 5
39+
point 0 -1
40+
rotate 1 / 5
41+
}
42+
point 0 -0.5
43+
}
44+
```
45+
46+
In the original code, we defined a new block symbol that creates a star-shaped path. In the code above we've defined a symbol whose value is a star-shaped path. The former code is evaluated at the point when it is *called*, whereas the latter code is evaluated at the point when it is *defined*.
47+
48+
The end-result is the same in this case, so it may seem like the distinction doesn't matter, but the advantage of the former approach is that we can add *options* to vary the behavior of the code when it is called.
49+
50+
## Options
51+
52+
To add an option to a block, you use the `option` command. This works in a similar way to the [define](symbols.md) command, but it allows the specified value to be overridden by the caller.
53+
54+
The code below extends the `star` definition with options for the radius and number of points:
55+
56+
```swift
57+
define star {
58+
option radius 1
59+
option points 5
60+
path {
61+
for 1 to points {
62+
point 0 -0.5
63+
rotate 1 / points
64+
point 0 -radius
65+
rotate 1 / points
66+
}
67+
point 0 -0.5
68+
}
69+
}
70+
```
71+
72+
Now we can use those options to create a star with 6 points if we choose:
73+
74+
```swift
75+
star {
76+
points 6
77+
radius 2
78+
}
79+
```
80+
81+
![Star](../../images/six-pointed-star.png)
82+
83+
---
84+
[Index](index.md) | Next: [Scope](scope.md)

docs/1.8.6/ios/bounds.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
Bounds
2+
---
3+
4+
ShapeScript's [size](transforms.md#size) ands [scale](transforms.md#relative-transforms) commands let you control the relative size of a shape, but sometimes it's useful to know the exact dimensions.
5+
6+
A cube of size 1 has an easily-predicted size of one world unit square, but what about a more complex shape, such as a 5-pointed star (see the [procedural paths](paths.md#procedural-paths) and [blocks](blocks.md) sections for details):
7+
8+
```swift
9+
define star path {
10+
for 1 to 5 {
11+
point 0 -0.5
12+
rotate 1 / 5
13+
point 0 -1
14+
rotate 1 / 5
15+
}
16+
point 0 -0.5
17+
}
18+
19+
// draw star
20+
extrude {
21+
color red
22+
star
23+
}
24+
25+
// draw cube
26+
cube {
27+
color green 0.5
28+
}
29+
```
30+
31+
![Star with unit cube](../../images/star-with-unit-cube.png)
32+
33+
We can see that the star is larger than the unit cube, but other than trial-and-error or complex math, how can we get the exact size? This is where the `bounds` [member property](expressions.md#members) comes in.
34+
35+
## Mesh Bounds
36+
37+
Paths and meshes both expose a `bounds` property that represents a bounding box around the shape. From this you can get the exact size and position needed to place a box around the star:
38+
39+
```swift
40+
define star {
41+
...
42+
}
43+
44+
// define star shape
45+
define shape extrude {
46+
color red
47+
star
48+
}
49+
50+
// draw star
51+
shape
52+
53+
// draw box around star
54+
cube {
55+
color green 0.5
56+
position shape.bounds.center
57+
size shape.bounds.size
58+
}
59+
```
60+
61+
![Star with fitted cube](../../images/star-with-fitted-cube.png)
62+
63+
## Path Bounds
64+
65+
In the example above we computed the bounds of a solid `mesh` (an extruded star-shaped `path`) but you can also get the bounds of a `path` directly. The following code draws the star path inside its bounding rectangle:
66+
67+
```swift
68+
define star {
69+
...
70+
}
71+
72+
// draw star
73+
star
74+
75+
// draw rectangle around star
76+
square {
77+
position shape.bounds.center
78+
size shape.bounds.size
79+
}
80+
```
81+
82+
![Star with fitted rectangle](../../images/star-with-fitted-rect.png)
83+
84+
## Bounds Members
85+
86+
The `bounds` member property has the following sub-properties that you can use:
87+
88+
* `min` - The position of the corner of the box with the smallest X, Y and Z values relative to the origin.
89+
* `max` - The position of the corner of the box with the largest X, Y and Z values relative to the origin.
90+
* `center` - The position of the center of the box relative to the origin.
91+
* `size` - The size (width, height and depth) of the box in world units.
92+
* `width` - The width of the box along the X axis (equivalent to `size.width`)
93+
* `height` - The height of the box along the Y axis (equivalent to `size.height`)
94+
* `depth` - The depth of the box along the Z axis (equivalent to `size.depth`)
95+
96+
So, for example, to get the height of a shape, you could use:
97+
98+
```swift
99+
print someShape.bounds.size.height
100+
```
101+
102+
or just:
103+
104+
```swift
105+
print someShape.bounds.height
106+
```
107+
108+
And to get the X coordinate of its rightmost edge you could use:
109+
110+
```swift
111+
print someShape.bounds.max.x
112+
```
113+
114+
---
115+
[Index](index.md) | Next: [Meshes](meshes.md)

0 commit comments

Comments
 (0)