Animation: Motion Inside VEX or Python code

file Banner.png
Click here to get to find a link to the Guided Houdini Files.

 

This Tutorial will show you how to implement time motion into VEX code but also teach you how to pass parameters such as $F into VEX and mention how to access frame number and the current time in python.

About the trouble with $F

In the previous example we saw how $F can be used to manipulate node parameters. However, we can not simply use $F inside a VEX code of a wrangler. That would be too nice. The reason: $objects are part of Houdini’s Hscript language that is different from the VEX language. After dealing with $F we will see how there are easier solutions.

Now we need to pass $F over to the point wrangle code through channels. Lets show this with an example where we let a spiral curve spin. First we need the basic node chain to create the spiral.

nodes2.PNG
The set of nodes we use now.
archStill.PNG
A an archimedean spiral. We also add variations in the z-axis.

The grid was given 100 points and the scale_x node does the same as in the simple curve example:

The spiral transform ist done with the following code depending on the attribute value of f@phi at every point. We will explain how f@phi is defined below.

Transfering $F to VEX

In order to include the output of $F we need to create another node parameter just like in the previous tutorial on creating geometry from scratch. Open the Parameter interface of the point wrangle node (the one that handles the animation)  and drag and drop a floating parameter into to right side. Rename the parameter in order to access it by name inside the VEX code.

add parameter.gif
Node Parameter Creation reminder gif.

Now modify the parameter by inserting $F into it. Then edit the  VEX code to look like this.

add parameter field.gif
Place $F inside the node parameter.

 

Now hit play to see the frames in action. Adjust the global animation options or scale the parameters for speed and max-number-of-frames adjustment.

arch spiral animation.gif
This curve is not rotated. It is reparameterised every time.

 

About the non-trouble with @Time and @Frame

We already covered in the simple curve tutorial the usage of the @Time global parameter. Simply write @Time or @Frame inside the VEX code to archive the animation after pressing play. We can modify the code above to do just that:

You can optionally also use @Frame to get the floating point number of the frame number.

In Python Code

Inside a python node you will be in need of different commands to access the frame number and time. Here are two ways from the python reference page of houdini.

To access the $F inside the channel use hou.ch( … )

here is an example of python code with acces to the frame number:

Note that the above code only works if you use this node before the python node. This is because here the communication between python and existing attributes is done using floats, not vectors:

 

Print Friendly, PDF & Email