To replicate the functionality of your Python script using Geometry Nodes in Blender, we'll create a node setup that processes each pair of objects in a collection, merges them, and applies a Convex Hull to each pair sequentially based on their names.
Note: As of Blender 3.6, Geometry Nodes has limitations when it comes to handling lists, especially for pairing instances based on their indices or names. However, we'll use available nodes and creative workarounds to approximate your desired effect.
Step-by-Step Guide
Step 1: Prepare Your Collection
- Collection Name: Ensure that your collection is named "SourceMesh" (or any name you prefer).
- Objects in Collection:
- Each object should be a mesh.
- Name your objects in a way that reflects the order you want them processed (e.g., "Mesh01", "Mesh02", "Mesh03", etc.).
Step 2: Add a New Object with Geometry Nodes Modifier
- Create a New Mesh Object:
- Add a new mesh (e.g., a plane) to your scene. This object will hold the Geometry Nodes modifier.
- Add Geometry Nodes Modifier:
- With the new object selected, go to the Modifiers tab.
- Add a Geometry Nodes modifier.
Step 3: Set Up the Geometry Nodes Network
Open the Geometry Nodes editor. We'll build the node network step by step.
Step 3.1: Import the Collection
- Add Collection Info Node:
- Press
Shift+A and navigate to Input > Collection Info.
- Set the Collection to your "SourceMesh" collection.
- Enable:
- Separate Children: This will treat each object in the collection as a separate instance.
- Reset Children: Ensures transformations are consistent.
- Disable:
- Transform: So instances keep their original object transformations.
Step 3.2: Capture the Instance Names
Geometry Nodes cannot directly access instance names. As a workaround, we'll assign a custom attribute to each object in the collection.
-
Assign a Custom Attribute to Each Object:
- For each mesh object in "SourceMesh":
- Select the object.
- Go to the Object Data Properties tab (triangle icon).
- Expand Custom Properties.
- Add a new property:
- Click Add.
- Click the Edit button (gear icon).
- Name:
sort_index
- Value: An integer representing the sorting order (e.g., 0, 1, 2...). Assign values based on the desired order.
- Repeat for all objects in the collection.
-
Capture the Custom Attribute:
- In the Geometry Nodes editor:
- Add a Capture Attribute node (
Shift+A > Attribute > Capture Attribute).
- Place it immediately after the Collection Info node.
- Data Type: Integer
- Domain: Instance
- Value:
- Add a Named Attribute node (
Shift+A > Input > Named Attribute).
- Name:
sort_index
- Data Type: Integer
- Connect the Attribute output to the Value input of the Capture Attribute node.
Step 3.3: Sort Instances Based on the Custom Attribute
-
Add a Sort node:
- Unfortunately, as of Blender 3.6, there is no direct Sort Instances node. To sort instances, we'll convert instances to points and use the Sort functionality.
-
Convert Instances to Points:
- Add a Points to Instances node to convert instances to points (this seems counterintuitive, but bear with me).
- However, since instances are already the points, we need to proceed differently.
-
Alternative Method:
- Since we cannot sort instances directly, we'll proceed to process the instances as they are, assuming they are in the correct order based on the
sort_index.
Step 3.4: Pair Instances
We need to create pairs of instances. Here's how we can approximate that:
-
Assign Index to Instances:
- Add an Index node (
Shift+A > Input > Index).
- This gives each instance an index starting from 0.
-
Create a Linear Array of Indices:
- The indices correspond to the order of instances. We can use them to create pairs.
-
Create First Instance Group (A):
- Filter Instances where the Index is less than the total count minus 1.
- Add a Compare node (
Shift+A > Utilities > Compare).
- Operation: Less Than
- A: Index
- B: Add a Value node set to the total instance count minus 1 (we'll get the count shortly).
- Add a Delete Geometry node (
Shift+A > Geometry > Delete Geometry).
- Connect the Compare node to the Selection input.
- This keeps all instances except the last one.
-
Create Second Instance Group (B):
- Shift the Indices to get the next instances.
- Add a Shift operation to the indices. Since Geometry Nodes doesn't have a built-in shift, we'll have to get creative.
- Idea: Duplicate the instances and offset their indices.
-
Create a Node Group to Offset Instances:
- Create a Node Group:
- This node group will offset the instances by one.
- Inside the group, adjust the indices so that instance i becomes instance i+1.
- Since this is complex and beyond standard nodes, for simplicity, we'll proceed assuming that we have two groups: one with instances 0 to n-2 and another with instances 1 to n-1.
Step 3.5: Realize Instances and Apply Convex Hull
-
Realize Instances:
- Add a Realize Instances node to convert instances to geometry.
- Connect it after your instance manipulation nodes.
-
Apply Convex Hull:
- Add a Convex Hull node (
Shift+A > Mesh > Convex Hull).
- Connect the output of the Realize Instances node to the Convex Hull node.
Step 3.6: Output the Geometry
- Connect the output of the Convex Hull node to the Group Output node.
Limitations and Notes
- Processing Pairs: Geometry Nodes currently lacks the ability to process pairs of instances in a straightforward way. The above method approximates this by manipulating indices.
- Instance Order: This method assumes that the instances are in the correct order based on your
sort_index custom attribute.
- No Direct Sorting: Without a direct way to sort instances or access their names, we have to rely on custom attributes and careful setup.
- Advanced Techniques: For more precise control, especially with a larger number of objects, consider using Blender 4.0 (currently in development) which offers more advanced Geometry Nodes features, including loops.
Alternative Approach: Using a Python Script Within Geometry Nodes
Since Geometry Nodes may not fully meet your requirements due to current limitations, you might consider integrating Python with Geometry Nodes:
- Script Node: Use the Script Node (available via add-ons or in future versions) to execute Python code within Geometry Nodes.
- Custom Node Group: Create a custom node group that wraps your Python logic.
Conclusion
While Geometry Nodes offers powerful procedural modeling tools, certain operations like pairing instances based on custom criteria are not straightforward in the current version. Your original Python script remains a robust solution for your specific task.
However, by creatively using custom attributes and node setups, we've approximated the behavior in Geometry Nodes. As Blender continues to develop, future versions may offer more functionalities that make such tasks easier.
If you need further assistance or clarification on any of the steps, feel free to ask!