Custom mesh visualization with Houdini

Houdini is not the typical software used for scientific visualizations but the possibilities that Houdini offers are truly amazing.

However the first step to use Houdini is to instruct it how to read data. In this guide I’ll describe the steps to read an element mesh. I assume that the mesh data file is in some custom format.

One option is  to convert the custom file into a typical file format like wavefront .obj and then read via a file node.

The option I’ll describe here is to use a python node that reads a custom mesh file. The format of the file is as follows

np nel
X_1 Y_1 Z_1
X_2 Y_2 Z_2
X_np Y_np Z_np
ID1_1 ID2_1 ID3_1 ID4_1
ID1_2 ID2_2 ID3_2 0
ID1_3 ID2_3 ID3_3 ID4_3
ID1_nel ID2_nel ID3_nel ID4_nel

where np is the number of mesh nodes and nel the number of mesh elements. The next np lines are the coordinates of the nodes followed by the node ids that the elements are made of. Note that the file reads either triangular or quadrilateral elements. The triangular elements are indicated by setting 0 as the fourth id of the node element.

By default Houdini interface is split into 3 main windows. Place the cursor anywhere inside the network view window(bottom right), press tab, start typing the word geometry, press enter to confirm and left click to place a geometry node.

Hou_001 Hou_002

Double click to enter inside the geo1 node. Select the default file node and press delete to… delete it!

Inside the geo1 node, with the cursor still located anywhere inside the network view, press tab, type python and press enter to confirm and left click to place the python node. The window above the network view is where the properties of the selected node are shown. For the python node there is just an almost empty area where one can write python code. I’ll add one more property which is a gui element to select the mesh file.

Find the gear button at the top right corner of the property window. Click once and choose Edit Parameter Interface…


At the left panel select the type file and click the arrow between the 2 panels (the one that points to the right) to add a new parameter.


Highlight the newly created property and rename the Name and label as shown in the figure below


Make sure you spell the Name exactly the same way

Next Apply and Accept to close the window and a new property will appear!


You can now click on the icon after the dropdown menu symbol to chose the mesh file.

Finally paste the following code inside the python Code area and you should be able to read a 2D mesh.

node = hou.pwd()
geo = node.geometry()

import csv
import os

# Add code to modify contents of geo.
# Use drop down menu to select examples.

def main():
    mesh_filename = node.parm('mesh_file_parm').eval()
    fmesh = open(mesh_filename,'r')
    temp = fmesh.readline()
    temp1 = temp.split(' ')
    Np = int(temp1[0])
    Nel = int(temp1[1])
    pnts = {}
    for ii in range(0, Np):
        temp = fmesh.readline()
        temp1 = temp.split(' ')
        point = geo.createPoint()
        point.setPosition(hou.Vector3(float(temp1[0])/10000.0, 0.0, float(temp1[1])/10000.0))
        pnts[int(ii)] = point
    for ii in range(0, Nel):
        temp = fmesh.readline()
        temp1 = temp.split(' ')
        poly = geo.createPolygon()
        if int(temp1[3]) != 0:


My example is a 2D mesh for the Central Valley groundwater basin


While this doesn’t seem to be something particularly interesting, it’s basic step for using the Houdini Beast!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.