![](https://files.koenig.kodeco.com/uploads/2023/05/geometry_nodes_blender_featured_banner@1.5x.png)
Procedural Game Asset creation with Geometry Nodes in Blender
In this article, you’ll learn about procedural asset creation in Blender using geometry nodes. In the process, you’ll create a treasure chest with a guardian protecting its treasure. By Ayush.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Procedural Game Asset creation with Geometry Nodes in Blender
25 mins
- Getting Started
- Using Geometry Nodes
- Utilizing the Spreadsheet
- Using the Node Editor
- Modeling with Geometry Nodes
- Data Flow in Geometry Nodes
- Extruding the Chest Panels
- Combining branches
- Data Processing
- Understanding Socket Shapes
- Debugging Nodes
- Manipulating Vectors
- Pivoting
- Instancing
- Distributing Collection Elements
- Selective Instancing
- Using Curve Nodes
- Mesh to Curve Conversion
- Spline Manipulation and Profiles
- Exploring Basic Materials
- Where to Go From Here?
Combining branches
Now it’s time to make a cover for your treasure chest. A halved and hollow cylinder is the perfect shape for this. The 3D scene already contains a cylinder mesh. So, you need to reference the cylinder in the node tree to change its shape to resemble a cover. The Object Info node can be used to get mesh data such as geometry from external objects.
In the cover_nodes
group, connect the geometry socket from Object Info to the same socket in Group Output.
This time however, the cylinder will not render because Group Output in the root geometry nodes system already has a noodle connected with it. The geometry input in Group Output doesn’t have an elongated shape, so it can’t accept multiple noodles. So, in order to render multiple meshes, you’ll use the Join Geometry node. Its geometry input has an elongated socket that it uses to render multiple geometry at once.
In the root node system, drop the Join Geometry before Group Output and connect the geometry output from the cover_nodes
to the same input in Join Geometry.
Data Processing
Next, cut the cylinder in half to resemble a cover. The Delete Geometry node takes an input geometry and deletes portions based on a selection criteria. For this particular use case, Delete Geometry has to delete all the faces below the z-axis. Adding the Delete Geometry node between the cylinder’s Object Info will delete the entire cylinder by default because Blender doesn’t know what to delete. So, you need to select faces below the z-axis for deletion.
Understanding Socket Shapes
The selection input in Delete Geometry, though, is shaped differently. Socket shapes are a visual representation for the data they accept or transmit.
- A circle shape for an input means the node uses the same input for all the elements. Transform has circular sockets for its transformation — meaning that they only accept a single vector.
- A diamond with a dot shape means that the socket can accept different values for each element but is currently accepting just a single value. The selection socket in Delete Geometry currently has no noodle so is selecting all points for the delete operation.
Use the Position node, which returns the position attribute of a mesh, and then isolate the z-coordinate using the Separate XYZ node. Using all these isolated z-coordinates as a selection gives the final socket shape: a diamond. This shape indicates that all the elements receive different values.
The selection socket takes elements with positive values. Since you require points below the z-axis, you need to map the positive z-coordinates to a 0 and the negative z-coordinates to a 1, which is the function of the Not node performing the boolean not operation.
In the cover_nodes
group, drop Delete Geometry before Group Output and connect the Boolean output socket of the Not to the selection input of Delete Geometry.
The cylinder is now shaped to resemble a chest cover.
The data in a geometry nodes system flows left to right, so you might be wondering how Position functions since it has no inputs — and what data the nodes after it process. The data flow rule actually has an exception. Nodes such as Position actually depend on the context of the geometry nodes they are connected to. In this case, Delete Geometry holds geometry data that flows through Not and Separate XYZ into Position (Right to Left). This combination of nodes is often referred to as a Field. Fields yield different results for each element of the geometry in a node, hence they are represented with diamond sockets and the dotted noodle as opposed to the default noodle.
Debugging Nodes
You can use the spreadsheet to examine all the data that passes through and all the nodes that manipulate it in a typical geometry nodes system. It has all the information needed to debug or optimize the node tree, from vertex information to normals and much more. Use the Viewer node to check any value at any point in the node tree. It takes a geometry feed as an input as well as the attribute that requires inspection. In this case, you’ll need to monitor the Z socket from Separate XYZ and the Boolean socket from Not.
First, add a Viewer node in the cover_nodes
group. Connect the Object Info node’s Geometry output to the Viewer node’s Geometry input. For the value input in the Viewer node, connect the Z socket from Separate XYZ. Now, check rows 12 and 20. Note that the Viewer’s value (the first column in the spreadsheet) is the same value as the Z position (the fourth column in the spreadsheet).
Next, reconnect the value input in Viewer to the Boolean output socket from Not. Note that on rows 12 and 20, a positive Z position shows as 0 in the viewer and a negative Z position shows a 1 in the viewer. Your Not node is doing its job.
From both screenshots, Viewer logs relevant information in the spreadsheet — making it easier to monitor the node system. The position attributes at index 12 and 20 have a positive and negative value when Separate XYZ is being monitored, and value of 0 and 1 when Not is being monitored. Hence, Delete Geometry selects similar indexes to 20 for the delete operation.
Manipulating Vectors
Now the chest has a body and a cover. You need to flip it in order to get to the treasure inside, and you need to clamp the flip angle so the cover can’t clip through the body. An obvious solution is to connect the geometry socket from Delete Geometry to a Transform node. A typical cover of a treasure chest rotates from the side. But, incrementing any of the rotations here (x-, y- and z-) makes the cover rotate along its center. This happens because the cover’s pivot point is in its center. So, you need to relocate the pivot to the edge. The Vector Rotate node is a specialization of the Transform node — and as its name states, it rotates an input vector along an axis and center point by the given angle.