Menu

Tween Machine Tool

Tools / Maya Command Plugin

Tween Machine Tool

This tool (Github) is a recreation of a basic version of the Tween Machine tool as a Maya Command Plugin. The plugin is written in Python using the Maya's OpenMaya API for Python and comes with an associated PyQt user-interface.
The tool creates a new key at the current time, between two existing keys and adjusts the value of the new key to be closer to either the previous key or the next key based on the tween value. The UI provides a slider to visualize results of different tween values.
The tools allows working either on animated DAG objects (in this case, key is added to all animation curves of the selected object) or on selected animation curves.
The video below demonstrates the plugin tool and how it works in Maya.
Note: The red tick mark representing a new key in the time slider did not show up on screencapture. But you can see that a new key is added in the animation curve example.

Details:

1. The Command Plugin

To create a command plugin, the plugin extends the MPxCommand class available in the OpenMaya API : Maya Python API 2.0 Reference
This command is undoable, so it allows undo on the add key operation.
The command plugin follows the follownd steps:

  1. First checks if any animation curves are selected and creates a list of them.
    If no animation curve is selected, it loops through selected animated DAG objects and extracts all animation curves to create the list.
    It throws errors if nothing is selected or no animated object is selected.
  2. It loops through the list of animation curves and checks if a key exists at the current time and changes its value based on the tween value from the UI slider.
    If key does not exist, it ensures the current time is between two existing keys and adds a new key at the current time.
    The key value is a simple interpolation of the previous and next key values with the weight (tween value) from the UI.
  3. It adds the addKey operation to animation cache to ensure it's undoable.

2. The User Interface

The UI is developed with PyQt.
The UI script ensures that the tween machine plugin is loaded before displaying the UI. It loads the plugin if it's not already loaded or throws an error if it is unable to load the plugin.
The UI elements are simple: a slider for selecting the tween value, a text label for the slider and another label to display the current slider value.
The tween machine command is called when the slider value is changed and only when the slider was pressed but not released.