Running Custom Code in Houdini.

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

 

Let us assume that we posses some kind of VEX code definitions for complex functions objects and operators. You can copy and paste the code into a text file that you then name Complex.h.

Planar representation of complex numbers as 2 dimensional vectors. Courtesy upload.wikimedia.org/wikipedia/commons/thumb/6/69/Complex_conjugate_picture.svg/1200px-Complex_conjugate_picture.svg.png

In the simple curves tutorial we had such a situation where we included code from outside. See the code below to see how it was done in the point wrangle node.

$HIP was used to address the location where the .hip file (or .hipnc) is stored. /include goes into a sub-directory of the current location and /Complex.h located the file with the code. You can think of the #include “filename” command as a copy and paste operator of outside text.

96.gif
The directory structure for this example.

Note: you might have to restart Houdini for it to find the new /include/Complex.h” file if you created it recently.

Try to keep reusable methods neatly organized in directories for usage in other projects.

 

Using “Export” in Your Custom Code

Normal function definitions normally only allow you to output 1 object of a specific type. Inside function definitions you cannot even have access to attributes that are addressed with @. However, the following trick will make things a lot nicer for us. We will explain how to create multiple outputs of multiple types in a single custom function.

The following two nodes do the exact same job but one of them calls the function form the file while the other one defines it locally inside the node. Defining functions into files is of course the better choice if you reuse a function and if you are done debugging it.

two nodes.PNG
The two nodes that do the same thing but have their function written in different places.

Notice that our function takes two types of inputs, the regular ones and export inputs. The latter one has the special ability to modify whatever is put into it. This means that you can insert any type of input (int, float, array etc.) and expect the code to write into it. In our example we took the input, scaled it by two and passed it on directly into attributes or another variable through the export slots. Checking the geometry spreadsheet reveals that the output has been successfully passed into the attributes.

geo spreadsheet check.PNG
This is the “detail” view in the geometry spreadsheet. Notice that these values only make sense if the export slots where successfully modified in the function.

 

Gradient Example

The gradient of a function is a typical example of an operation that you will probably need again and again in the future. This makes it an ideal candidate to go into your beloved “Util.h” file that you can then use in multiple projects in Houdini. The Util.h code can be read at the bottom of this tutorial.

This example can be studied using the supplement material.

The following example involves the coloring of a sphere (modify @Cd), the creation of an attribute specifically bound to the red part of the color, the computation of the gradient on the triangles for this change in the red color and the averaging of the triangle gradients to the points.

sphere col.PNG
The above mentioned functions. We also prepare for a copy stamp node to display arrows on the points.

 

show arrows.PNG
Here we display arrows on each point on the sphere to see the gradient field.

The final results shows the sphere and how the gradient direction of each point on the sphere. Due to our color choice, this gradient field runs from one pole to the opposite.

grad field.gif
Resulting gradient field on the sphere.

Here comes the code involved in the making of this gradient:

As promised, here comes the final “Util.h” file as used in this tutorial.

Print Friendly, PDF & Email