Using drivers, we can pass values to the Blender Geometry Nodes tree that cannot be obtained from nodes, for example, the total number of frames in a project animation. However, there are cases when a value needs to be passed from Geometry Nodes to some property of an object not related to GN. In this case, drivers can also help us.
As an example, let’s consider a situation where we need to control the camera focusing from Geometry Nodes.
First, we need an object on which we will build a Geometry Nodes node tree. Add an Ico Sphere to the scene (shift + a – Mesh – Ico Sphere).
Append a Geometry Nodes modifier to it and create a new node tree by clicking the “New” button.
Add a camera to the scene (shift + a – Camera) and enable the Depth of Field checkbox in the camera properties.
Switch back to the sphere and add the Set Position node to its node tree (shift + a – Geometry – Write – Set Position).
To transfer the value from Geometry Nodes to the camera, we use the Set Position node, which changes the position of the object in the scene, since we need the state of the scene to be updated when the value in the node changes. Otherwise, the driver will not work.
Now let’s pass the offset value from the Set Position node, along the Y axis, to the value of the Focus Distance field of the camera.
Switch to the camera, right-click once on this field and select Add Driver.
In the driver settings, specify:
- Single Property
- Select the object type – Geometry Nodes, and in the field itself, specify the node tree from our sphere
- Here we need to write the full path to the value of the source node (Set Position), starting from the node tree that we specified in point 2.
1 |
nodes["Set Position"].inputs[3].default_value[1] |
We specified the Set Position node, its fourth input (3 because all lists are numbered starting from zero), the “default_value” property, which transmits the current value of this input, and the Y axis (1 because, again, the components are numbered starting from zero, X – 0, Y – 1, …).
- Correct the expression to make visualisation more clear.
Now, switch back to the Geometry Nodes node tree and try to change the value of the Y coordinate in the “Offset” field of the Set Position node.
As we can see, focusing and defocusing of the camera occurs simultaneously with the offsetting of the sphere.
The value from Geometry Nodes is passed directly to the field that controls the camera focus!
Now we can hide the sphere from displaying and still have the ability to control the camera focus by changing the value in the Geometry Nodes node tree.