|
1 | 1 | # Attributes |
2 | 2 |
|
3 | | -An important concept in Geometry Nodes is attributes. Many trees transfer attributes between geometry, using a combination of *Capture Attribute* and *Transfer Attribute*. |
| 3 | +An important concept in Geometry Nodes is attributes. Many trees capture attributes or transfer them from one geometry to another. |
4 | 4 |
|
5 | | -Unfortunately, it takes quite a bit of code to use this common pattern. |
| 5 | +When using these methods, the `data_type` argument must be correctly specified for the transfer to work as intended. |
6 | 6 |
|
7 | 7 | ```python |
8 | 8 | @tree("Skin") |
9 | 9 | def skin(): |
10 | 10 | # Create a cube |
11 | 11 | c = cube() |
12 | | - # Capture the position |
13 | | - cube_position_attribute = c.capture_attribute( |
14 | | - data_type=CaptureAttribute.DataType.FLOAT_VECTOR, |
15 | | - value=position() |
16 | | - ) |
17 | 12 | # Create a sphere |
18 | 13 | sphere = uv_sphere() |
19 | 14 | # Transfer the position to the sphere |
20 | | - transferred_position = cube_position_attribute.geometry.transfer_attribute( |
| 15 | + transferred_position = c.transfer_attribute( |
21 | 16 | data_type=TransferAttribute.DataType.FLOAT_VECTOR, |
22 | | - attribute=cube_position_attribute.attribute |
| 17 | + attribute=position() |
23 | 18 | ) |
24 | 19 | # Make the sphere conform to the shape of the cube |
25 | 20 | return sphere.set_position(position=transferred_position) |
26 | 21 | ``` |
27 | 22 |
|
28 | | -Thankfully, a convenient `capture(...)` method is available on `Geometry`, which simplifies this function quite a bit. |
| 23 | +To improve the usability of these nodes, `capture(...)` and `transfer(...)` methods are provided on `Geometry` that simply take the attribute and any other optional arguments. |
29 | 24 |
|
30 | 25 | ```python |
31 | 26 | @tree("Skin") |
32 | 27 | def skin(): |
33 | 28 | # Create a cube |
34 | 29 | c = cube() |
35 | | - # Capture the position |
36 | | - cube_position = c.capture(position()) |
37 | 30 | # Create a sphere |
38 | 31 | sphere = uv_sphere() |
39 | 32 | # Make the sphere conform to the shape of the cube |
40 | | - return sphere.set_position(position=cube_position()) |
| 33 | + return sphere.set_position(position=c.transfer(position())) |
41 | 34 | ``` |
42 | 35 |
|
43 | | -## How it Works |
44 | | - |
45 | | -Internally, `capture(...)` works just like the more manual approach. |
46 | | - |
47 | | -1. Capture the attribute from the source |
48 | | - |
49 | | -In the example above, we capture the `position()` from the cube. |
50 | | -The data type is automatically inferred from the input. If you want to customize other options, simply pass them as keyword arguments to `capture(...)`. |
| 36 | +The same is available for `capture(...)`. |
51 | 37 |
|
52 | 38 | ```python |
53 | | -cube_position = c.capture(position()) |
54 | | -cube_position = c.capture(position(), domain=CaptureAttribute.Domain.FACE) # Optionally pass other arguments available on `capture_attribute`. |
| 39 | +geometry_with_attribute, attribute = c.capture(position()) |
55 | 40 | ``` |
56 | 41 |
|
57 | | -2. Transfer the attribute to the target |
| 42 | +> You must use the `Geometry` returned from `capture(...)` for the anonymous attribute it creates to be usable. |
58 | 43 |
|
59 | | -`capture(...)` returns another function that calls `transfer_attribute` with the correct arguments passed automatically. |
60 | | -Call this returned function (which we store in the variable `cube_position`) to transfer the attribute. |
61 | | -In this example we also set the transferred cube position back onto the sphere. |
| 44 | +Any additional keyword arguments can be passed as normal. |
62 | 45 |
|
63 | 46 | ```python |
64 | | -sphere.set_position(position=cube_position()) |
65 | | -sphere.set_position(position=cube_position(mapping=TransferAttribute.Mapping.NEAREST)) # Optionally pass other arguments available on `transfer_attribute`. |
| 47 | +c.transfer(position(), mapping=TransferAttribute.Mapping.INDEX) |
66 | 48 | ``` |
0 commit comments