GLTF Hierarchical Skeletal Mesh Exporter
A custom node that is now obsolete since Houdini 21. Actually, this one is the result of one of many RFIs I sent to SideFX related to the GLTF file format.
3D file formats can be interesting to deal with. And each DCC seem to implement their own solution to writing to each format and there almost seems to never be complete consistency - even if there is a public document outlining what the specifications are and what to follow. So many times, we are a the mercy of whatever solution a particular DCC implemented.
This custom node is the result of struggling to make SideFX’s GLTF export work the way I needed for Skeletal Meshes (and to a certain extent, static meshes too).
As we know, in it’s basic form, this file format is a json-formatted file containing a full scene description. Including node hierarchy. SideFX’s GLTF Rop nodes (both in Sop level and Rop level) had some capabilities to maintain node hierarchy but break in more complex scenarios. The first attempt to address these, involved separating all the primitives of a mesh based on its path attribute and creating a separate OBJ network, with all these primitives separated in separate SOP nodes, hooking them up based on their hierarchy and exporting the OBJ network from ROP level.
Luckily, when exporting as as an FBX within Houdini’s ecosystem, the hierarchies are mantained. So instead of writing a custom GLTF exporter from scratch, I could leverage existing tools to sort this out.
There’s this command-line tool from Pär Winzell, J.M.P. van Waveren, and Amanda Watson that was the result of a Facebook Incubator project. Which essentially converts FBX to GLTF and follows all the correct specifications as needed.
So all I needed to do is include this application in our common network drive, and add the path to it’s location to the script. Which is exposed in case anyone wanted to run a separate (or local) version of the script.
And from here it was a simple process of exporting an fbx into a temp folder, running command with the correct flags and print the output to the screen.
This was quite successful and for years, was the best way we had to export in this format which was essential for the work we were doing.
But now, as of Houdini 21, SideFX has upgraded their GLTF nodes, including addressing some other issues I had with existing ones. Happy days!
import subprocess
def export_gltf(node): rop_fbx_node = hou.node('%s/%s' %(node.path(), 'rop_fbx')) rop_fbx_node.parm('execute').pressButton()
directory = node.parm('export_directory').evalAsString()
fbx_file_path = node.parm('fbx_export_path').evalAsString()
app = node.parm('fbx2gltf').evalAsString()
filename = node.parm('file_name').evalAsString().rsplit('.', 1)[0]
file_format = node.parm('file_name').evalAsString().rsplit('.', 1)[1]
command = []
if file_format == 'gltf':
command = ['"%s"' %(app), '-i', '"%s"'%(fbx_file_path), '-o', '"%s%s.gltf"' %(directory, filename)]
elif file_format == 'glb':
command = ['"%s"' %(app), '-b', '-i', '"%s"' %(fbx_file_path), '-o', '"%s%s.glb"' %(directory, filename)]
print(' '.join(command))
#shell_process = subprocess.run(command, capture_output=True, text=True)
shell_process = subprocess.run(' '.join(command), shell=True, capture_output=True, text=True)
print(shell_process.stdout)