Deborah R. Fowler
Houdini Looping - Copy Options
Posted Sept 1 2022
Updated Aug 2 2024
This page focuses on a step by step description of the copyOptions19.5.hiplc file. There are many ways to create loops in Houdini besides the copy behavior, that is with for-each and wrangles (see links below).
This page is intended to go over the copy nodes, however it is useful to understand the for-each and wrangles next.
I have created a hip file in 19.5 that is designed to introduce a variety of the options for copying/looping. (Note instancing is covered as a separate topic).
Suppose you want to create a grid of tiles 6 x 5 (these can be generalize easily - that is another topic - Houdini Parameter Interface.
Download the file to see the finished results, or try to create and use only as a reference.
CONTEXT NOTE: The copy stamp node has been a very versatile node (which I refer to as the copy node) and was originally a superset of the copy transform and copy to points nodes. Functionality was added to the copy to points node that allows variants (explained below) and the copy to curves node was introduced. In addition, for-each, wrangles (vex) and python appear. Further distinctions are made between implicit and explicit loops with regard to vex and vops but that is a topic for more advanced users. For beginning users, focus on the container with postfix Beginner.
As of Houdini 19.5, the copy stamp node is no longer available from the tab menu. The documentation recommends using for-each instead.
Yes, you should use the for-each instead, yes copy stamp is not as efficient for variants ... but should you ever need it for a reason it is still around until it is fully deprecated via textport (via Technical Desktop) or Windows/Hscript Texport
type in textport:
opunhide Sop copy
Below we will start with the copy transform node and work our way left to right in the container for Beginners.
Note that all the examples produce precisely the same result - many ways to accomplish a task in Houdini.
copy transform - if you recall from your introductory programming class, if you were to do this in code the easiest way would be to have a nested loop, copy 5 boxes (columns) and then repeat each of those 6 time (rows). Copy transform copies based on the "running total". That is, for a row the first is copied 0 units, the next 2 units, the next 4 units and so on. We then used a -2 in the second copy to copy up (note the red origin in the bottom left corner). So we have a copy of a copy (first one creates a row of 5 tiles, next creates 6 of those.
Really, a copy node is performing a looping behavior. I call that an implicit loop since you don't see any explicit code, just a number that determines the copies.
Note that the copy node next to this on the left, does precisely the same thing, except we have turned off transform cummulative and added $CY to specify the copy number.
foreach loop - this node is a bit more obvious - it loops like a loop (although a bit weird with the counter in the foreach_end1 node, however the concept is familar in that when we use a "meta" node we can access the counter (iterator) and use it to place the object.
The expression in the transform node that is performed is detail("../meta","iteration",0) * 2
The is like saying the copy number or iterator times the distance, so again we have for a row, the first copied 0 units, 1 x 2, 2 x 3, and so on
Then the second for each copies the rows 6 times. You can see this by stepping down the network (clicking the blue display flag down the network to trace your steps (history is all there).
pointwrangle - wrangle nodes, also called attribute wrangles, can create the point positions in much the same way, and then we use a copy to points. This looks similar to your coding class, particularly if you are coming from processing/java/C#/C++ or any C-like programming language. This language is called vex. To be exact, it is a vex snippet. (I can talk more about the history of both these languages another time). This is what I can an explicit loop. It is obvious from the syntax that there is a loop structure, indeed a nested loop. Note: To create points, the point wrangle must be set to Detail(only once) which means it executes the code once.
Interestingly enough, we could also feed the pointwrangle a set of points to begin with and then we don't need to have the loop construct. I have taken advantage of the fact that a wrangle node is really processing all the points we feed it if it is in Run Over Points mode. This is what I refer to as an implicit loop - it is not obvious at first glance (and something that sometimes surprises Houdini beginners).
That example is in the Advanced container and is not required for beginner users.
python - similar to what you did in your programming class, you can use python and it looks very similar to the pointwrangle node - same idea, same algorithm, different syntax.
copy to points - in our case, copy to points could also be used by creating a grid of appropriate size and spacing (rows/cols) and using that as the source of the points to be copied to.
There are multiple examples of using the copy to points node on the for-each page toward the bottom
-
Below is a video that covers copy to points variation -
very quick overview of N, orient and point overrides
also on https://www.youtube.com/watch?v=1c4p5I4t7IM
copy to curves - this node was introduced to more easily deal with copying geometry to curves and using the curve tangent information to orient that geometry. In this case, we simply set the Tangent Type to Z Axis (Ignore Curve) and we get the same result as copy to points with our grid.
If you are interested, you can also look at the vops version of the same situation, and the implicit version of the pointwrangle as well as a explicit (details only) version of vops. This is in the Advanced container.
One Final note about copy-with-stamp, textport and hidden nodes - just for fun!
As of Houdini 19.5, the copy stamp node is no longer available from the tab menu. The documentation recommends using for-each instead.
Yes, you should use the for-each instead, yes copy stamp is not as efficient for variants ... but should you ever need it for a reason it is still around until it is fully deprecated via textport (Technical Desktop or go to menu Window/hscript textport ) - create a geo node and then type in textport:
opcf /obj/geo1; opadd copy
opcf will Change Folder - you can also use opcd instead (coming from a linux background this is easier to remember). These can be type on separate lines as well.
opcd /obj/geo1
opadd copy
In fact you could create the geo, copy and sphere node setup by typing
opcd /obj; opadd geo; opcd /obj/geo1; opadd copy; opadd sphere; opwire /obj/geo1/sphere1 -0 /obj/geo1/copy1
There are many commands you can use in textport (opset -d on /obj/geo1/copy1 would turn on the display flag), but you have an excellent gui so this would more likely be used for scripting, and you are more likely to use python - if you are interested there is more information on python in Houdini click here.
You can also use a textport command to make the copy with stamp node available in the tab menu in your geo container
opunhide Sop copy
You can also copy it from the example files with ctrl-C ctrl-V
Many ways to do things in Houdini!