Tyler Britton

Tyler Britton2

About Me

Connect

LOCATION
Not Specified
ウェブサイト

Houdini Engine

Availability

Not Specified

Recent Forum Posts

Modfy Agent Skeleton 2025年4月1日15:49

The overall transform I did was just for simplicity, unfortunately, in production it would be more complicated the just a 'pscale' change.

Is there a procedural way I could do this all with Python? I tried with the code mentioned above which I used in the demo file, but it wasn't quite working. Maybe I was using it incorrectly.

Modfy Agent Skeleton 2025年4月1日13:54

Thanks.

Yeah, I might be misusing some of the terms or explaining them incorrectly.

Here is an example scene showing what I am trying to do. I am modifying the main "body" layer, and then trying to update the skeleton while keeping all my motion clips and everything. Please let me know if there is a better way.

Image Not Found

Modfy Agent Skeleton 2025年3月13日15:04

Thank you for the help.

The joints are all the same, so luckily, I don't need to do any retargeting.
I made a python script that will go through the input agents, and hopefully swaps the skeleton out for the one from the second input. It successfully swaps the rigs, however the skeleton doesn't seem to be swapped, it is still the one from the first input.

Any help is appreciated.

node = hou.pwd()
input_geo = node.geometry()  # This is the writable geometry in a Python SOP
reference_geo = node.inputs()[1].geometry()  # Second input (read-only)

# Get reference agent from second input
if len(reference_geo.prims()) > 0:
    reference_agent = reference_geo.prims()[0]
    reference_def = reference_agent.definition()
    reference_rig = reference_def.rig()
    reference_shape_lib = reference_def.shapeLibrary()
    print(f"Reference rig found: {reference_rig}")
    print(f"Reference definition: {reference_def}")
    print(f"Reference shape library: {reference_shape_lib}")
else:
    print("Error: No agent in reference input (second input)")
    raise hou.NodeError("No agent in reference input")

# Process each agent in the input geometry
for i, agent in enumerate(input_geo.prims()):
    print(f"\n--- Agent #{i} ---")
    
    # Get original definition and info
    original_def = agent.definition()
    print(f"Original definition: {original_def}")
    print(f"Original rig: {original_def.rig()}")
    print(f"Original clips: {len(original_def.clips())}")
    print(f"Original layers: {len(original_def.layers())}")
    print(f"Original transform groups: {len(original_def.transformGroups())}")
    
    # Create a new frozen definition with the reference rig
    new_def = original_def.freeze(new_rig=reference_rig)
    print(f"New definition created: {new_def}")
    print(f"New rig: {new_def.rig()}")
    print(f"Clips preserved: {len(new_def.clips())}")
    print(f"Layers preserved: {len(new_def.layers())}")
    print(f"Transform groups preserved: {len(new_def.transformGroups())}")
    
    # Update the agent's definition in place
    # In a Python SOP, node.geometry() is directly modifiable
    agent.setDefinition(new_def)
    
    # Verify the change
    print(f"Updated agent: {agent}")
    print(f"New agent definition: {agent.definition()}")
    print(f"New agent rig: {agent.definition().rig()}")

Reference rig found: <hou.AgentRig rig:new_agent>
Reference definition: <hou.AgentDefinition 0x0000773c34602100>
Reference shape library: None

--- Agent #0 ---
Original definition: <hou.AgentDefinition 0x000077400e9f9780>
Original rig: <hou.AgentRig rig:agent1>
Original clips: 18
Original layers: 65
Original transform groups: 7
New definition created: <hou.AgentDefinition 0x0000773c3f3aeb00>
New rig: <hou.AgentRig rig:new_agent>
Clips preserved: 18
Layers preserved: 65
Transform groups preserved: 7
Updated agent: <hou.Agent prim #0 of geometry frozen at 0x773ff5d23c00>
New agent definition: <hou.AgentDefinition 0x0000773c3f3aeb00>
New agent rig: <hou.AgentRig rig:new_agent>