You can follow along with this example file:
copy_loop_example.hip
The method is broken down into 4 main steps:
- Create an ordered list of groups for each "piece".
- Create a single point at the center of each piece.
- Transform each piece to the global origin.
- Copy each piece back onto its corresponding point.
Creating Groups
The first step is key. Say you have created a fractured model using the Voronoi node. You end up with an ordered list of primitive groups, going from 0 to n. When you hold MMB onto the node you can see your group list. (If needed, you can right-click and choose "Extended Information" to see all primitive groups). Before you continue, the list of groups must be in order and no skipping; meaning that they need a common prefix, such as "piece", be in order from top to bottom, and have no missing or empty groups.
You can also use the old Connectivity to Partition combo.
NOTE: In Houdini 12, the list doesn't have to be in order from top to bottom, but should still have a common prefix and not have missing groups.
Creating Center Points
The next step is simple. Just use a ForEach SOP and for each "piece", create a center point using an Add SOP and the centroid() expression.
The Add SOP can just hang on the side as long as it is displayed. You don't need to connect it to anything.
Points created at center of each piece |
Centering All Pieces
The third step will go into a different branch from your primitive groups. You need to move each group to global origin. You can use another ForEach and inside, use a Transform SOP.
The Transform SOP has -$GCX, -$GCY, -$GCZ in its xyz translate parameters.
Inside the center ForEach |
The Transform SOP has -$GCX, -$GCY, -$GCZ in its xyz translate parameters.
Centered pieces |
The Copy Loop
The last step is a little hard to grasp the first time you see it. What will happen is this:
- You take your centered pieces.
- Isolate all but one piece.
- Copy that piece to its corresponding point.
- Repeat those steps for each piece.
The key that makes this work is copy stamping using the Copy SOP. You will need 2 Copy SOPs, one to place the piece onto the point, and one to stamp, or loop, the action for every piece.
As a simple example, say you have a Sphere, a Mountain, then a Copy and create 5 copies. Normally each copy will look the same. But if you want each copy to have an offset in the noise, you can use stamping. Check "Stamp Inputs" and create a custom variable, anything you want. Then set that value to $CY, which represents the copy number. Now go back up to the Mountain and use the stamp() expression one of the offset parameters.
So what you are doing is sending information back up the network and it reflects back to the copy step.
So back to the main event, we will use the same Copy node with $CY, along with another Copy node before it that places the pieces onto the points. We will use the stamp() expression in the Source Group and Template Group parameters.
piece0 gets copied to point 0, piece1 gets copied to point 1, etc.
For convenience, we can set the number of copies, or loops, to ensure we are including all of the pieces or not over-copying by using a combination of the argc() and primgroupmask() expressions.
So now that we have this set up, we can now manipulate the center points to affect the pieces. Convert them to particles, add some animated noise expression, change normal direction, add color or pscale, whatever...
Sometimes you may need to set your normals and upvectors to the points depending on the situation.