Bake Alembic Cameras

It's quite common to receive animated cameras as alembics. In houdini those cameras are stuck in the alembic node. To convert them to a regular Houdini camera I've wrote this litte helper script. Select the camera you want to free from it's alembic and run this script as a shelf too. Et voila. Now you can easily parent object to it and do some other fun stuff.


# Free Cam Script created by Johannes Heintz johannes {at} riotpixels.de
def freeCam():
    selected = hou.selectedNodes()[0]
    newCam = hou.node('/obj').createNode('cam', selected.name() + '_baked')
    hou.setFrame(int(hou.playbar.playbackRange()[0]))
    newCam.parmTuple("res").set(selected.parmTuple("res").eval())
    scale = float(hou.ui.readInput("scale", initial_contents="1")[1])
    
    for f in range(int(hou.playbar.playbackRange()[0]), int(hou.playbar.playbackRange()[1]) + 1):
        hou.setFrame(f)
        transform = selected.worldTransform()
        explode = transform.explode()
        translate = explode["translate"] * scale
        rotate = explode["rotate"]
        newCam.parm("tx").setKeyframe(hou.Keyframe(translate[0]))
        newCam.parm("ty").setKeyframe(hou.Keyframe(translate[1]))
        newCam.parm("tz").setKeyframe(hou.Keyframe(translate[2]))   
        newCam.parm("rx").setKeyframe(hou.Keyframe(rotate[0]))
        newCam.parm("ry").setKeyframe(hou.Keyframe(rotate[1]))
        newCam.parm("rz").setKeyframe(hou.Keyframe(rotate[2]))
        newCam.parm("focal").setKeyframe(hou.Keyframe(selected.parm("focal").eval()))
        newCam.parm("focus").setKeyframe(hou.Keyframe(selected.parm("focus").eval() * scale))
freeCam()