Exporting .OBJ sequence from Houdini

While working with Houdini, I came across a project where I needed to export an animation as a serie of .obj files. Each .obj representing a frame of the animation.

In order to achieve that, I used a mix of node and python code to automate the process.

To showcase the process, this is the animation we are going to export:

Houdini Animation

Nothing fancy, this is not the purpose of this article ;D

Creating the Exporter HDA

The Exporter HDA will only consist of a python script responsible for moving the Houdini Timeline and export an .obj file at each frame. Creating an HDA for that gives us the opportunity to reuse that same behaviour for any kind of animation.

At the Objects level, we'll create a Null node and create an HDA from it. Right-Click on the Null, "Create A Digital Asset". I called it "AnimObjExporter".

Houdini HDA Creation

Houdini Export HDA

We'll now go in the node 'Types Properties' and hide the default parameters:

Houdini Parameters

Parameter Interface

Let's expose our parameters interface. We'll need 4 parameters for our litle tool:

Export Node - The geometry node that we want to export.
Export Location - The directory in which the files will be written.
Frame Range - Animation range we want to export.
Export Button - Trigger the export.

Script implementation

All we need to do now is to fetch parameters value and export the geometry node at each frame.
This is what this script is doing:

def export(node):
    export_path = node.parm('export_path').evalAsString()
    export_frame_count = node.parm('frame_count').evalAsInt()
    output_node = node.renderNode()
    # reset current timeline...
    # iterate over all frames and export it as static geometry.
    for cur_frame in range(export_frame_count):
        path = export_path + 'frame' + '_' + str(cur_frame) + '.obj'
        geo = output_node.geometry()
        fbx_rop = node.node('rop_fbx1')
        execute = fbx_rop.parm('execute')
        output_path = fbx_rop.parm('sopoutput')

The scene .hip file used to make this quick tutorial can be found here and the export HDA here.