File tree Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ import inspect
2+ import typing
3+
4+ class SimulationInput :
5+ class DeltaTime : pass
6+ class ElapsedTime : pass
7+
8+ def simulation (block : typing .Callable [typing .Any , 'Geometry' ]):
9+ """
10+ Create a simulation input/output block.
11+
12+ > Only available in the `geometry-node-simulation` branch of Blender 3.5.
13+ """
14+ def wrapped (geometry : 'Geometry' , * args , ** kwargs ):
15+ from geometry_script import simulation_input , simulation_output
16+ simulation_in = simulation_input (geometry = geometry )
17+ signature = inspect .signature (block )
18+ for key , value in signature .parameters .items ():
19+ match value .annotation :
20+ case SimulationInput .DeltaTime :
21+ kwargs [key ] = simulation_in .delta_time
22+ case SimulationInput .ElapsedTime :
23+ kwargs [key ] = simulation_in .elapsed_time
24+ return simulation_output (geometry = block (simulation_in .geometry , * args , ** kwargs )).geometry
25+ return wrapped
Original file line number Diff line number Diff line change 1111from .static .expression import *
1212from .static .input_group import *
1313from .static .sample_mode import *
14+ from .static .simulation import *
1415from .arrange import _arrange
1516
1617def _as_iterable (x ):
Original file line number Diff line number Diff line change 2222 - [ Attributes] ( ./api/advanced-scripting/attributes.md )
2323 - [ Boolean Math] ( ./api/advanced-scripting/boolean-math.md )
2424 - [ Drivers] ( ./api/advanced-scripting/drivers.md )
25+ - [ Simulation] ( ./api/advanced-scripting/simulation.md )
2526
2627# Tutorials
2728
Original file line number Diff line number Diff line change 1+ # Simulation
2+
3+ > This API is subject to change as future builds of Blender with simulation nodes are released.
4+
5+ The ` geometry-nodes-simulation ` branch of Blender 3.5 includes support for "simulation nodes".
6+
7+ Using a * Simulation Input* and * Simulation Output* node, you can create effects that change over time.
8+
9+ As a convenience, the ` @simulation ` decorator is provided to make simulation node blocks easier to create.
10+
11+ ``` python
12+ @simulation
13+ def move_over_time (
14+ geometry : Geometry, # the first input must be `Geometry`
15+ speed : Float,
16+ dt : SimulationInput.DeltaTime, # Automatically passes the delta time on any argument annotated with `SimulationInput.DeltaTime`.
17+ elapsed : SimulationInput.ElapsedTime, # Automatically passes the elapsed time
18+ ) -> Geometry:
19+ return geometry.set_position(
20+ offset = combine_xyz(x = speed)
21+ )
22+ ```
23+
24+ Every frame the argument ` geometry ` will be set to the geometry from the previous frame. This allows the offset to accumulate over time.
25+
26+ The ` SimulationInput.DeltaTime ` /` SimulationInput.ElapsedTime ` types mark arguments that should be given the outputs from the * Simulation Input* node.
You can’t perform that action at this time.
0 commit comments