Separate geometry with index transfer
Main Concept
If the geometry was originally connected, then there is a way to precalculate the indices needed to transfer attributes including the position from one part to another.
For this we will use the ‘Accumulate Field’ node. What this node does is just addition iteratively through a group of points. We could take advantage of the way Indices (Index plural, so the ‘Index’ node) get recalculated when geometry gets removed, and the order in which the ‘Accumulate Field’ node iterates through elements when doings its addition.
A meshes Indices are always numbers going from 0 and ascending till it reaches the last element (which will be $n-1$), and there can’t be missing numbers in-between; So when geometry is removed, which would now cause gaps in the numbers (meaning skipping numbers), blender will recalculate them (or more condense them). The way the Indices end up is actually the same order, but now all consecutive numbers starting from 0. So:
|
|
|
|
|
|
|
Initial/Potential Indices: |
0 |
1 |
4 |
5 |
7 |
9 |
Final/Actual Indices: |
0 |
1 |
2 |
3 |
4 |
5 |
Now, the 'Accumulate Field' node counts (Iterates) in the order of the Indices.
Index: |
0 |
1 |
2 |
3 |
4 |
5 |
Value: |
5 |
9 |
6 |
8 |
4 |
1 |
Accumulate - leading: |
5 |
14 |
20 |
28 |
32 |
33 |
Here I just shuffling the Indices to show the point:
Index: |
5 |
4 |
1 |
0 |
3 |
2 |
Value: |
1 |
4 |
9 |
5 |
8 |
6 |
Accumulate - Leading: |
33 |
32 |
14 |
5 |
28 |
20 |
The ‘Accumulate Field’ Trailing starts at 0 and then starts counting up - basically everything is pushed off one, which is perfect for counting Indices.
For us to calculate what the new index is going to be once the geometry is separated, all we have to do is set a Group ID (this is just a selection) of what the new geometry is going to be and accumulate over it, and it will condense the Indices to range.
Index: |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
Value: |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
Group ID / Selection: |
0 |
0 |
1 |
1 |
1 |
0 |
0 |
1 |
1 |
1 |
Accumulate - Trailing: |
0 |
1 |
0 |
1 |
2 |
2 |
3 |
3 |
4 |
5 |
Implementation Differences
When could you even use this generated Index? In the case of separating vertices for example only one of the outputs of the separate geometry will have those vertices, do in that case knowing its Index is pointless, because you already know it from the ‘Index’ node, and the other part of the separated geometry doesn’t have that geometry and thus doesn’t have the Index you calculated…
The Only case of shared geometry is when separating faces, because both sides have the vertices and edges that were the same on the original mesh [I’m only going to be discussing vertices is the demonstration, because you set position on vertices, but this could be done for other elements as well].
There is another way of doing this, where you use a ‘Delete Geometry’ do separate some part of the mesh, and then transfer some attribute(s) back to the original mesh. This could be done when separating any type element and on any domain.
[Advantage to this method
- There is you need to rejoin and merge the separated elements, since you are just transferring it back to the original mesh.
- There is no need to capture the selection or idex etc.
]
Node Implementation
In the case of separating faces. The boarder vertices are included in the group of whatever side you are transferring from. You could easily get the boarder vertices with the ‘Face Group Boundaries’ node, and add (or subtract) them to the Group ID.
Here are illustrations of sampling in both directions.
In the above two Figures you could see that I used the boarder selection as the selection, since that is the part of the mesh that the ‘Index’ does and could map to correctly [it is the only shared geometry].
Here are illustrations the ‘Delete Geometry’ method:
(I don't think the 'Capture Attribute' nodes are necessary the illustrations below)
The difference is in the ‘Delete Geometry’ (and ‘Capture Attribute’) domain.
Here is a pretty cool example where you smooth the boarder vertices of a (selection on a) noise texture:
Here I’m altering the ‘Position’ directly and not the geometry itself because I don’t need to [but it is necessary to use the separate geometry trick for it to smooth only between the boarder vertices].
Btw if you wanted to see it on your given example:
(just be be clear; this will work the same way if you just do this
.)