Part 2
Starting at about 36 mins in
1. Adding Sliders
So now that you can get variation using stamping and random variables, how do you add sliders to allow the artist to control your tool?
In the end, it is the same principle, but it requires some creativity with referencing (you already know how to do that).
In the picture below, we are in the context of the castle building node "Castle_Wall". The parameters (or sliders) we added are the top four. Remember that the sliders we are adding are being added to the node that builds the whole castle. So these will change the whole look of the "village" rather than modifiying each individual building alone.
Go to the node you want to modify and select "Edit Parameter Interface"
Add a parameter by selecting the type of data type you want it to be. Float is a great one because it is a number that isn't limited to whole numbers (that would be integer)
Set the name and label (label is what you see, name is what you will type when referencing) in the parameter tab. You can also add default values as shown in the picture below.
Now that these parameters exist, go back to your copy node where you were working on stamping, and reference the parameters (our new sliders) in the stamping function.
Here Seth has the following code:rand($PT) * ch("../maxwidth")
rand($PT) * ch("../maxheight")
Think about what this does, (or watch it at 35:38) as Seth moves the slider maxheight that he just created, all the buildings will go up or down.
cool, so with that function we can now adjust the height and width of all buildings, or rather, we can adjust the width and height of the whole village.
What about variation? What if we want a "new" random height and width of all the buildings in the village?
Look at the very fist picture in this post. You will notice height varation and width variation variables. Go ahead and make those. Remember, the naming is arbitrary, the referencing is the thing that really matters.
Now back to our rand function. Before it might have looked like this: rand($PT) * ch("../maxwidth")
If you were to add 1 to $PT all the buildings random values would change. rand($PT +1 ) * ch("../maxwidth"). Instead of adding 1, why not reference a value which the artist can easily change like the slider variable we just created?
now our function looks like this ^
Now as you change the "variation" slider, the buildings widths randomly change every time you move the slider. You can keep moving until you get a variation you like. Pretty sick. (watch @ 38:40)
2. Putting limits on the variable
I probably don't want my buildings to be height 0 and I probably don't want them to be 500 either. I can edit my parameter and add a range.
3. Using python with Houdini
Everything we learned about Python in Maya applies to Houdini. We can even use Houdini's library of functions they have already written. Learn about them here:
For example, what if you wanted to control you random expression a wee bit more. You want a couple buildings to be even higher than the others like the picture below.
To do this, open up the expression editor by right clicking the value box, then selecting "Edit Expression." Or pressing "Alt e" If you don't open up the editor, you can only type in one liners. Gross.
Also, remember to change the language to Python as shown below
You know the language has been changed when the box changes colors to red. Yuck, that makes me think it's an error.
import hou <- Needed to access houdini's built in functions
import random <- Needed to use Python's built in random functions
heightvariation = hou.ch("../heightvar" ) <- We make a variable that get's the reference value
pointNum = hou.expandString( "$PT" ) <- To make every fourth point different, we need it's value
pointNum = int ( pointNum) <- Oops, houdini returned it to us as a String, not an int. So we convert it.
finalValue = 0 <- We declare finalValue because we need it to exist beyond our "if, else" block of code
if pointNum % 4 == 0: <- If pointNum is a multiple of 4, enter our if statement.
finalValue = (random.random() * heightvariation) + 6 <- make it bigger! Use a random value
else:
finalValue = 3 <- make other buildings size three. I would personally do finalValue = heightvariation
return finalValue
4. What the %?
% is called modulus. "Mod" for short. All it does is return the remainder.
4%4 = 0
5%4 = 1
6%4 = 2
7%4 = 3
8%4 = 0
9%4 = 1
10%4 =2
and so on... Notice how it repeats
So you can use it to get multiples of a number. If you do X%4 == 0, every time X is a multiple of 4 it will equal 0 and thus enter that block of code.
5. The End!
UGH, that was painful. But now I know this stuff pretty well. Just ask me in person. haha











No comments:
Post a Comment