Website powered by

Houdini Blog #38: Viewer States

General / 03 March 2020
This post I will be talking about Viewer states in Houdini, this is done with Python. So if you have used python before it will come in handy.

An example here that I build with viewer states is this decal tool. This decal tool was very useful when building my models for the current building tool. For this workflow I use a similar approach like Star Citizen, where you use tiling materials and detail a model by placing decals.

How it will look in game. (notice also that I use a fancy decal with Parallax to get depth in the decal)

What is a Viewer state

A viewer state controls how to interpret mouse movements, clicks, keys, and so on in the viewport. To make a Viewer State you will need an understanding of python with Houdini.

With Houdini 18 there is more integration of the viewer states then before. I have had my eye on viewer states for a while and once I noticed the better integration I jumped on it.

So where are these viewer states made? You can find/make viewer states in the HDA property menu. Under Interactive there is a viewer state tab and here is a menu to write the code.

If you are looking for examples, there are a couple of them in Houdini. Here is how you can see them.

Example Viewer state

Let's make a simple example to test out the viewer states. This example will show how to use the scroll of your mouse to control a parameter of a HDA.

To start make a HDA with a tube and expose the Columns. Like in the image below here.

Then go to the Interactive tab where you have the viewer state and click on New.

A menu will pop up with presets. For this example just use the blank one. I highly recommend looking at all of them if you want to learn more about Viewer States.

Once you clicked on Accept, some code will appear in the menu. This code will help us integrate the next part easier.

Now you need to get access to the scroll of the mouse wheel. You can find this on the website and documentations about viewer states. 

On the website copy paste the part with the border around in the image.

So in Houdini it looks like this.

Test this out to see if the print works. Go click on your HDA and make sure you are using this handle.

Scrolling with your mouse should now print 1 or -1 based on the direction.

Final step is to link the Columns parameter in the code. Here is how you can do this.

In general to set a parameter it will look like this 


When setting the parameter value also ask what is the current value and then add 1 or -1 from the scroll.

This results then in controlling the columns with the mouse scroll.

If you are looking for more info take a look at the documentations 

That was it for this post, I hope you enjoyed it :)

Special thanks my Houdini Wizard patreons.