Houdini 22.0 Character KineFX

Working with graphs

APEX Script examples of defining graph inputs and outputs, accessing graph elements, and converting graphs to APEX Script code.

On this page

APEX Script allows you to define the inputs and outputs of a graph, access graph elements like nodes and ports, and perform graph operations. See APEX Script for graph building for an introduction to APEX Script.

Specifying graph inputs and outputs

BindInput() and BindOutput() are special functions that define the inputs and outputs of a graph. See this example for how to use BindInput() and BindOutput().

The examples below show how to specify different types of graph inputs:

# Initialize float value
f = BindInput(3.1)

# Uninitialized string type
s: String = BindInput()

# Initialize to empty array
a = BindInput(DictArray())

# Default dictionary key-value pair: {'<key>': <value>}
d = BindInput({'abc': 1.5})

# Create multiple graph inputs
x, y, z = BindInput(2.6, 'test', Dict())

# Type conversion when initializing
i = BindInput(Int(Float(1.5)))

Note

If you don’t specify a type for the graph input, a warning will be raised. Only do the following if you know exactly how you will be using the variable:

a = BindInput()

The input port a that is defined in this way is not displayed in the APEX network view because its type is ambiguous.

You can rename the input and output ports on a graph using keyword arguments (arguments with the syntax <key>=<value>):

i: Int = BindInput(int_test=3)

x,y = BindInput(2, my_str='hello')

BindOutput(y, int_test=i)

Note

Keyword arguments must be placed after positional (non-keyword) arguments.

Rename graph inputs and outputs

Keyword arguments that contain __dot__ are replaced with '.'. This allows APEX Script to handle rigs with geometry names like Base.skel and Base.shp:

x = BindInput(Base__dot__shp=Geometry())

Base__dot__skel: Geometry = BindInput()

BindOutput(Base__dot__skel, Base__dot__shp=x)
Rig geometry names in graph inputs and outputs

Specifying dictionary inputs

In this example, we use values from two dictionaries as inputs to an APEX Script SOP:

Dictionary inputs to APEX Script SOP

Attribute Adjust Dictionary SOP

The Attribute Adjust Dictionary SOP defines a dictionary of input values. We set the following values for the two SOPs:

input_dictionary1

  • Attribute Name = parms1. By default, Attribute Class is set to Detail, so we have a detail attribute called parms1.

  • In the Set Values section, we set two dictionary entries:

    • Key = int1, Type = Integer, Value = 2

    • Key = abc, Type = String, Value = hi

input_dictionary2

  • Attribute Name = parms2

  • In the Set Values section:

    • Key = int2, Type = Integer, Value = 4

    • Key = abc, Type = String, Value = hi again

To view the new parms1 and parms2 dictionaries in the geometry spreadsheet:

  • Select one of the Attribute Adjust Dictionary SOPs.

  • At the top of a pane, click the New Tab icon and select New Pane Tab Type ▸ Inspectors ▸ Geometry Spreadsheet.

  • Select Detail on the top toolbar:

    parms1: {"abc": "hi", "int1": 2 }
    
    parms2: {"abc": "hi again", "int2": 4 }
    

APEX Script SOP

  1. We have the following code in the Snippet parameter:

    int1: Int = BindInput()
    int2: Int = BindInput()
    abc: String = BindInput()
    
    BindOutput(int1,int2,abc)
    

    Note

    If you don’t bind the output or do anything with the input values, the graph will not displayed any logic because nothing is being done with the inputs.

  2. Specify the input dictionaries. In the Invocation section:

    • Under Input1 Bindings, turn on Dictionary To Bind and specify the dictionary connected to the 1st input of the APEX Script SOP, in our case, parms1 (from the Attribute Adjust Dictionary SOP’s Attribute Name parameter).

    • Under Input2 Bindings, turn on Dictionary To Bind and specify the dictionary connected to the 2nd input of the APEX Script SOP, in our case, parms2.

    The APEX Script SOP looks in the input dictionaries, parms1 and parms2, and tries to find entries with keys int1, int2, and abc. For keys that exist in multiple dictionaries, the latter dictionary entry is used. In our case, both dictionaries have an entry with key abc, so the abc entry from the 2nd dictionary is used. In addition, a warning is raised on the APEX Script SOP.

  3. By default, the first entry of Output Dictionary Bindings is populated with the following:

    • Apex Outputs Group is the set to output. This is the name of the output node in the graph.

    • Output Attrib is set to parms. We can set this to any name for the output dictionary.

    To view the graph outputs in the geometry spreadsheet:

    • In the geometry spreadsheet, beside the node name, select Invoked from the drop-down menu.

    • Click Detail on the top toolbar. The graph outputs are stored in the dictionary specified in Output Attrib, in our case, parms:

      parms: {"abc": "hi again", "int1": 2, "int2": 4 }
      

Binding multiple outputs

We can set the graph to have multiple input and output nodes by using BindInput and BindOutput functions with the special function argument __name to name nodes:

  1. In an APEX Script SOP, we have the following code in the Snippet parameter:

    # Default 'parms' name used
    f = BindInput(3.1)
    
    # 2nd input node is named 'input2'
    s: String = BindInput('abc', __name='input2')
    
    # Default 'output' name used
    BindOutput(f)
    
    # 2nd output node is named 'output2'
    BindOutput(s, __name='output2')
    
    Graph with multiple input and output nodes
  2. By default, the first entry of Output Dictionary Bindings is filled out with the following:

    • Apex Outputs Group is the set to output. This is the name of the output node in the graph.

    • Output Attrib is set to parms. We can set this to any name for the output dictionary.

    To view the graph outputs in the geometry spreadsheet:

    • In the geometry spreadsheet, beside the node name, select Invoked from the drop-down menu.

    • Click Detail on the top toolbar. Only the parms dictionary is displayed because we have only told the APEX Script SOP to output the values of the output node.

  3. To also output the output2 node values:

    • Click beside Output Dictionary Bindings.

    • For the new entry, set Apex Outputs Group to output2 and Output Attrib to, say, parms2.

    On the geometry spreadsheet, there are now two output dictionaries displayed, parms and parms2:

    parms:  {"f": 3.1 }
    
    parms2: {"s": "abc" }
    

Graph nodes and ports

APEX Script provides functions that allow you to perform various graph operations and access graph elements like nodes and ports. These functions are primarily used in rigging for building up the rig logic of a character. See the graph::* nodes for the graph operations that are available in APEX Script.

The syntax to find a graph node with a specific node name:

graph.<node_name>

The syntax to find a specific input or output port on a node:

graph.<node_name>.<port_name>_[in|out]

Connect two ports:

# Create graph
graph = ApexGraphHandle()

# Add two TransformObject nodes to graph
a = graph.addNode('test_a', 'TransformObject')
b = graph.addNode('test_b', 'TransformObject')

# Set port variables
p_a = graph.test_a.xform_out
p_b = graph.test_b.xform_in

# Connect ports
graph.addWire(p_a, p_b)

Find all nodes based on a pattern:

# Create graph
graph = ApexGraphHandle()

# Add two TransformObject nodes to graph
a = graph.addNode('test_a', 'TransformObject')
b = graph.addNode('test_b', 'TransformObject')

# Find all nodes that begin with 'test'
n = graph.findNodes('test*')

Find a port on a node:

# Create graph
graph = ApexGraphHandle()

# Add TransformObject node to graph
a = graph.addNode('test_a', 'TransformObject')

# Find input port 'xform' on node
p = graph.findPort(a, 'xform[in]')

Get data on nodes and ports (see function mappings for how to use the data() function):

# Create graph
graph = ApexGraphHandle()

# Add TransformObject node to graph
a = graph.addNode('test_a', 'TransformObject')

# Get node data
(a_name, a_callback, a_pos, a_color, a_parms) = a.data()

# Output node data
BindOutput(a_name, a_callback, a_pos, a_color, a_parms)

# 'xform' output port of TransformObject node
p = a.xform_out

# Get port data
(p_name, p_alias, p_datatype, p_porttype, p_isconnected, p_ispromoted) = p.data()

# Output port data
BindOutput(p_name, p_alias, p_datatype, p_porttype, p_isconnected, p_ispromoted)

See the list of ports returned from a function:

# x is an array of APEX port IDs
x = graph.matchPorts('*xform*')

# Initialize an array of strings
arr = StringArray()

# Add the port names to the array
for p in x:
    p_name = p.data()
    arr.append(p_name)

# Output the array of port names
BindOutput(arr)

Variadic ports

Variadic ports are ports that can take in multiple connections. As you make connections to a variadic port, subports are created on the node.

Variadic inputs

In APEX Script, variadic inputs are stored in a dictionary with the following key-value pair:

  • key - subport name

  • value - subport value

The example below adds three values. The first argument is a regular input, and the second argument is a variadic input stored as a dictionary with two entries. The subport names of the variadic input are explicitly set:

x = 3

sum = Add_Int(1, {'bbb': 2, 'ccc': x})
Named variadic input subports

If the variadic input is the last port on the node, there is no need to specify the subport names:

x = 3

sum = Add_Int(1, 2, x)

If no values are specified for the non-variadic ports, the variadic port name must be specified:

<function>(<variadic_port>={<subport1>:<value1>, <subport2>:<value2>, ...})

sum = Add_Int(b={'x': 4, 'y': 5})

Variadic outputs

To name the subports of a variadic output, use the keyword argument <variadic_arg_name>_out=[<subport_names>], where <subport_names> is an array of strings.

The example below gets the variadic outputs from IntBitMaskToBool:

input: Int = BindInput(8)

# Variadic output subports named 'aa', 'bb', 'cc', 'dd'
a,b,c,d = input.IntBitMaskToBool.v2_0(mask__out=['aa', 'bb', 'cc', 'dd'])

# Output subport values
BindOutput(input,a,b,c,d)
Named variadic output subports

If the keyword argument is not provided, the subport names are set to the variable names:

input: Int = BindInput(8)

# Variadic output subports named 'a', 'b', 'c', 'd'
a,b,c,d = input.IntBitMaskToBool.v2_0()

# Output subport values
BindOutput(input,a,b,c,d)
Variadic output subports set to APEX Script variable name

Dictionary entries can be of any type, so to extract the entries of a dictionary using dict::Extract, you must first specify the types of the variables you want to extract the dictionary entries to:

# Specify dictionary entry types
a: Int
b: Float
c: Vector3

dict_test = {
    'aa': 5,
    'bb': 0.2,
    'cc': (5,10,15)
}

a,b,c = dict_test.extract(args__out=['aa', 'bb', 'cc'])

BindOutput(a,b,c)
Get variadic output subports from dict::Extract

Converting graphs to APEX Script code

The APEX Script and APEX AutoRig Component SOPs provide the option to convert graphs to APEX Script code.

For the APEX Script SOP:

  1. Connect an existing graph into the 2nd input of the APEX Script SOP.

  2. In the Decompile section, set the drop-down menu to Second Input.

  3. Click the Convert to Snippet button.

The APEX Script code will appear in the Snippet parameter.

See the special functions that may be added to the decompiled code.

How-to

To...Do this

See the nodes or ports returned from a function

View a single port ID:

# x is an APEX port ID
name = x.data()
BindOutput(name)

View a list of port IDs:

# x is an array of APEX port IDs
x = graph.matchPorts('*xform*')

# Initialize an array of strings
arr = StringArray()

# Add the port names to the array
for p in x:
    p_name = p.data()
    arr.append(p_name)

# Output the array of port names
BindOutput(arr)

To view the port names:

  1. In the APEX Script SOP, Invocation section, click beside Output Dictionary Bindings.

  2. In the geometry spreadsheet, click Detail on the top toolbar.

KineFX

Overview

Preparing character elements

Rigging with APEX graphs

  • APEX graph basics

    Introduction to the APEX graph evaluation framework.

  • APEX graph debugger

    Inspect the values of an APEX graph’s ports within the APEX network view.

  • APEX Script basics for graph building

    An overview of APEX Script, a code interface for building APEX graphs.

  • Graphs for numerical operations

    Example graphs of numerical operations like adding two values, fetching multiple results, and retrieving information from geometry.

  • Graphs for viewport animation

    Example graphs of animate state functionality like creating controls and constraints, and defining joint hierarchies.

  • Graphs for deforming geometry

    Example of a SOP network and APEX graph for deforming a 3-joint tube geometry.

  • Graph metadata

    Information added to graph nodes and ports.

  • APEX path pattern

    A set of rules that allow you to filter and select elements within graphs, skeletons, geometry, and the character folder structure.

  • APEX graph nodes

    APEX nodes provide operations for building up the functionality of APEX graphs, which are used in KineFX to create character rigs and perform other geometry manipulation.

  • APEX updates for H22

    New and updated APEX graph nodes for Houdini 22.

Building rig graphs with APEX Script

Rigging with rig components

Animating in the viewport

  • Animation workflow

    Example networks of adding characters, props, characters, and animation to a scene.

  • Animating in LOPs

    Rig and animate characters and props in the context of a USD stage.

  • Working in the animate state

    Select and manipulate controls, define transform limits for controls, and add skin controls to a character.

  • Animate state menus and HUDs

    Menus, HUDs, toolbars, and options in the animate state.

  • Animate state hotkeys

    Hotkeys available in the animate state.

  • Posing

    Pose characters in the animation scene by using locators, copying and pasting controls, and mirroring poses.

  • Motion paths

    Visualize the motion of controls as curves in 3D space.

  • Constraints

    Create relationships between controls in the animate state.

  • Dynamic motion

    Add physically-accurate projectile motion to your animation in the animate state.

  • Ragdoll

    Add a ragdoll simulation to your animation in the animate state.

  • Full body IK

    Apply full body inverse kinematics to pose the character using high-level targets rather than manipulating individual joints.

  • Secondary motion

    Add physically-accurate effects like lag/overshoot, jiggle, and spring to your animation in the animate state.

  • Control selection sets

    A tree view of controls, selections, and selection sets for the animate state. Allows management of control selection and visibility.

  • Motion mixer

    Combine and edit the animation clips of multiple characters in a timeline-based view.

  • Character picker

    Create a 2D layout with simple buttons for selecting character controls in an animation scene.

  • Animation catalog

    Save, manage, and apply animations and single-frame poses to an animation scene.

  • Animation layers

    Create multiple layers of animation without affecting the original animation.

  • Animation toolbar

    A customizable toolbar consisting of simple slider tools that quickly apply modifications to animation controls and curves.

  • Animation bookmarks

    Frame markers that help organize and identify the different parts of your animation.

Customizing the animate state

SOP-based animation

  • Physics-based motion

    Add physically-accurate motion to your animation using the Projectile Motion and Pendulum Motion SOPs.

  • Ragdoll simulations

    Add a ragdoll simulation to your animation using the Ragdoll Solver SOP.

Deformation

  • Blend shapes

    Create blend shapes using blend shape SOP nodes.

Animation retargeting

Pre-H20

Panes

  • Motion mixer

    A timeline-based view of the animation clips and motion effects of multiple characters.

  • Character picker

    Create a 2D layout with simple buttons to select character controls in an animation scene.

  • Rig tree view

    A hierarchical view of character components, including packed character folders, KineFX rigs, and Object node rigs.

  • Animation editor

    View and edit animated parameters and their transitions between keyframes.

  • Geometry spreadsheet

    Displays details about the geometry selected in the network editor.

Appendix