Houdini and Unreal
So it seems like these tutorials are helpful to some people so I’m going to keep them going. I’m probably going to start mixing back in the non-Houdini tutorials again soon. As always if there’s a specific topic you’d like to see covered just message me. I’m pretty open to suggestions.
Note: I’d highly recommend reading parts 1 and 2 before jumping into this tutorial.
Up until now all coding has been done using Houdini’s visual scripting tool, but sometimes you need a little more control to accomplish what you are after. If you are coming from a Python heavy background (E.G. Blender, Modo) then I’ve got good news for you. Python scripting is pretty deeply integrated into Houdini. So much so that most inputs will accept python script instead of their normal inputs and work just fine. If you’re a real RTFM type of guy then here’s the link for you http://www.sidefx.com/docs/houdini15.0/hom/_index. For everyone else I’ll try to explain what I’m doing the best I can as go through each step. Lets look at an example.
Lets make a really simple Christmas tree. To do this I’m just going to use two tubes.
One will make up the trunk of the tree and the other will be the body of the tree. Make sure that these are both set to polygon as the primitive type. Notice that on the tube that will make the body I’ve set one radius to zero in order to get the geometry to form a point at the top. So now we have the two parts that will make up the Christmas tree but if I just merge them right now the way they are I’ll get this gross mess.
The problem is that I want the body of the tree to sit on top of the base of the tree. I could just move the body up, but if I did that then if I later changed the height of the base I’d have to fix the height of the body. The whole point to using Houdini is that changing one parameter should automatically update other parameters. I want to body of the tree to always sit right on top of the base of the tree no matter what the base’s height is. To do that I’m going to use inline scripting.
Lets look at the tube that makes the body of the tree. I know that it’s the center Y parameter that I’m going to need to change because that’s the one that dictates the tube’s vertical position. The first thing I want to do is offset the fact that it measures from the center. The body meets the base at its bottom, not its center so I need to add half the height of the body to its vertical position. Luckily height is a parameter on this tube. If we right-click on that parameter it will open a context menu allowing us to copy it.
Now if we go to the Center Y parameter and right-click it should give us the option to paste a relative reference.
This will auto generate the code needed to access that parameter. You could just type that code in and it would work exactly the same. That “ch” function is shorthand for “channel”, and it’s one of the more commonly used functions when working in Houdini. It’s used for accessing parameters on this or other nodes. In this case we are using it to grab the value of the “height” parameter on this node. Now we’ve moved it up the height of this tube but that’s not really where we want it. We want it up half the height of this tube plus the full height of the other tube.
Now I could probably grab the height of the other tube exactly the same way I grabbed the height of this tube, but for the sake of showing you something more useful let’s pretend height wasn’t a freely available parameter on the other tube. We still want to know where the top of it is. Luckily there’s a python function for that! Bbox is shorthand for bounding box, and it will attempt to draw a box around the shape you supply it and then return an attribute of that box, in this case the Y max. For our needs we pass the function “../tube1” which is the path to the other tube and D_YMAX which is the attribute type for Y max.
Note: Pay attention to the auto-complete and pop-up text that displays as you type. It can help you figure out what the functions looking for. For instance for the bbox function it will list the valid types which helps cause it is unlikely you’d just guess that the type for Y max is called D_YMAX.
If you combine all of that together you should get the following equation and your model should look something like this:
So now no matter how you change the height of the base the body will always sit right on top of it. In retrospect this looks nothing like a Christmas tree…Guard tower. That’s it we were building a guard tower the whole time. Congratulations it’s a fine looking guard tower. But should you need it to look like a Christmas tree it’s super easy to change thanks to this non destructive workflow. just alter the height of the base and the width of the body and you get this.
Now that’s a much better Christmas tree.