Skip to content

Part 2: using custom attributes in Geometry Nodes

In this second part of our three-part series, we will continue using scientific data to make a 3D visualization in Blender. In the first part of this series, we loaded data into Blender attributes using the Python API. This second part will show you how to use your custom attributes within Geometry Nodes to create, delete and alter geometry.

Figure 1: The animation we're working towards

Recap of what we did in the first part

In the previous part we used particle collision data from the CERN accelerator, and we ended up with many vertices in a cube-like arrangement. Furthermore, every vertex has a float value associated with it through the attribute myAttributeFloat. This value represents the energy recorded by the detector belonging to the vertex. See Figure 2 below:

Figure 2: our starting point for this part. On the left you see the very useful Spreadsheet editor included in the Geometry Nodes workspace.

If you are totally new to Geometry Nodes

This series is not meant as an introduction to Geometry Nodes, but is to show an example of how you can use Geometry Nodes to manipulate geometry and your own custom data. If you are new to Geometry Nodes you can read the relevant chapter in the advanced part of the course. Or have a look at the first free video of a course from Blender Studio. That will give you enough background for now.

Three-step plan towards the animation

In three steps we will create the basis for the animation in Fig. 1:

  1. We remove detectors/vertices that did not detect anything.
  2. We replace the remaining detectors/vertices with cube geometry. We do this so that we can shade them in the next part.
  3. We want to be able to make detectors (dis)appear so that we can make the animation as in Fig. 1.

Step 1: removing non-detections.

Many vertices seen in Fig. 2 represent detectors that detected no energy from a particle. We want to remove those vertices that have a myAttributeFloat value lower than a certain threshold. We can remove geometry using the Delete Geometry node. In this case we want to remove vertices, so we set it to the Points domain. We now need to feed in a list of booleans into the Selection socket, which determines what gets deleted. See Figure 4 below.

Figure 4: first version of the Geometry Node setup we are building. Here we use the attribute myAttributeFloat to remove detectors that did not measure any energy from particles.

To get access to the attribute myAttributeFloat we use a Named Attribute node and fill in the attribute name. Next we want to compare the myAttributeFloat value to a threshold and for this we use a Compare node and set its mode to Less Than and feed the attribute into socket A, and set socket B to a threshold value of 0.1. If we now connect the Delete Geometry node to the Group Output node we see the result as in Fig:

Figure 5: the result from the Geometry Node network seen in Fig. 4, showing only the vertices that had a detection value over the treshold

Step 2: replace vertices with cubes.

To be able to shade every detector, we generate a piece of geometry, in this case a cube, at the location of every vertex/detector. We do this by creating an instance of a cube at every vertex using the Instance on Points node. But because this node requires a point cloud as input we first convert our vertices coming out of the Delete Geometry node into points using the Mesh to Points node.

Figure 6: second version of the Geometry node we are building. We now make instances of cubes from the vertices we had.

We add a Cube node which we connect to the Instance socket, which results in this output:

Figure 7: here is the result from the Geometry Node in Fig. 6, the vertices are now turned into cubes

Step 3: make detectors appear and disappear

To make the animation seen in Fig. 1, we also need to make the cubes appear and disappear. We will make them appear from the center outwards (in the radial direction). Thus, we need to be able to cut away detectors located at a radius larger than a certain threshold. And instead of hard-coding this threshold, we will make a new Geometry Node input for the threshold, which will make it possible to animate the threshold.

We can access the position of the detectors by adding a Position node (see Fig. 8). We retrieve the length of the points (i.e. distance from the origin) using the Vector Math node and set its mode to Length. We will feed it into a Compare node, set to Greater Than or Equal, which will be fed into a new Delete Geometry node together with the threshold value:

Figure 8: version three of the Geometry Node we are making. We can now also remove detectors at locations on the x axis larger and smaller than a certain threshold.

We now need to implement the threshold that determines which detectors are removed. We will not hard-code this threshold like we did for the other Compare and Delete Geometry nodes. We will make a new Group Input node instead and we will use the socket that has no name. If we connect the unnamed socket to the B socket of the Compare node, we will see the unnamed socket is given a default name (for example B).

The new input also shows up in the Modifier Properties tab in the Properties editor, at the right side of the window (see Fig. 8). You can also press the N key in the Geometry Node Editor window to open the Sidebar (or go to the View tab and tick the Sidebar option) and then navigate to the Group tab in the Sidebar to see the list of inputs and outputs of this Geometry Node modifier (also see Fig. 8). Here you will see, and have the possibility to rename, the new input we just created. I named it Cutoff for animation. You can see an example result in Fig. 9.

Figure 9: result from the Geometry Node in Fig. 8, with cubes further away from the origin than the threshold removed

In the next part we will use the fact that you can animate the inputs of modifiers. We can click the small dot next to the value of Cutoff for animation in the Modifier Properties tab to start animating the threshold. For now, you can play with the value of Cutoff for animation to see what it looks like.

A last addition

In the next part we want to give all the detectors/cubes we just made a different color depending on the value of the myAttributeFloat attribute. But now all the cubes are an instance of one and the same cube. We need to make every instance a real geometry and we do this using the Realize Instances node. Now this does not change how the scene looks just yet, but it is essential for the shading we do in the next blog of this series.

Figure 10: we use Realize Instances to turn all the cube instances into real geometry data.


Last update: 28 August 2024 16:29:56