Add repeat zone support
This commit is contained in:
parent
e3befbefc9
commit
da99654edb
6 changed files with 117 additions and 4 deletions
|
|
@ -23,7 +23,8 @@
|
|||
- [Boolean Math](./api/advanced-scripting/boolean-math.md)
|
||||
- [Curves](./api/advanced-scripting/curves.md)
|
||||
- [Drivers](./api/advanced-scripting/drivers.md)
|
||||
- [Simulation](./api/advanced-scripting/simulation.md)
|
||||
- [Simulation Zones](./api/advanced-scripting/simulation-zones.md)
|
||||
- [Repeat Zones](./api/advanced-scripting/repeat-zones.md)
|
||||
|
||||
# Tutorials
|
||||
|
||||
|
|
|
|||
42
book/src/api/advanced-scripting/repeat-zones.md
Normal file
42
book/src/api/advanced-scripting/repeat-zones.md
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# Repeat Zones
|
||||
|
||||
Blender 4.0 introduced repeat zones.
|
||||
|
||||
Using a *Repeat Input* and *Repeat Output* node, you can loop a block of nodes for a specific number of iterations.
|
||||
|
||||
You must use the `@repeat_zone` decorator to create these special linked nodes.
|
||||
|
||||
```python
|
||||
from geometry_script import *
|
||||
|
||||
@tree
|
||||
def test_loop(geometry: Geometry):
|
||||
@repeat_zone
|
||||
def doubler(value: Float):
|
||||
return value * 2
|
||||
return points(count=doubler(5, 1)) # double the input value 5 times.
|
||||
```
|
||||
|
||||
The function should modify the input values and return them in the same order.
|
||||
|
||||
When calling the repeat zone, pass the *Iterations* argument first, then any other arguments the function accepts.
|
||||
|
||||
For example:
|
||||
|
||||
```python
|
||||
def doubler(value: Float) -> Float
|
||||
```
|
||||
|
||||
would be called as:
|
||||
|
||||
```python
|
||||
doubler(iteration_count, value)
|
||||
```
|
||||
|
||||
When a repeat zone has multiple arguments, return a tuple from the zone.
|
||||
|
||||
```python
|
||||
@repeat_zone
|
||||
def multi_doubler(value1: Float, value2: Float):
|
||||
return (value1 * 2, value2 * 2)
|
||||
```
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# Simulation
|
||||
# Simulation Zones
|
||||
|
||||
Blender 3.6 includes simulation nodes.
|
||||
|
||||
|
|
@ -19,4 +19,20 @@ def test_sim(geometry: Geometry):
|
|||
|
||||
The first argument should always be `delta_time`. Any other arguments must also be returned as a tuple with their modified values.
|
||||
Each frame, the result from the previous frame is passed into the zone's inputs.
|
||||
The initial call to `my_sim` in `test_sim` provides the initial values for the simulation.
|
||||
The initial call to `my_sim` in `test_sim` provides the initial values for the simulation.
|
||||
|
||||
## Blender 4.0+
|
||||
|
||||
A "Skip" argument was added to the *Simulation Output* node in Blender 4.0.
|
||||
|
||||
Return a boolean value first from any simulation zone to determine whether the step should be skipped.
|
||||
|
||||
The simplest way to migrate existing node trees is by adding `False` to the return tuple.
|
||||
|
||||
```python
|
||||
@simulation_zone
|
||||
def my_sim(delta_time, geometry: Geometry, value: Float):
|
||||
return (False, geometry, value)
|
||||
```
|
||||
|
||||
You can pass any boolean value as the skip output.
|
||||
Reference in a new issue