Wednesday, January 13, 2016

Crowd randomizer

This is a quick little script I wrote for a project I worked on.

We had a few cached variations of characters of different sizes and colors with different animations. We instanced these caches the number of times we needed to fill out our bleachers(in the script I called this group 'objects'). Then, we had cubes that had been instanced and placed on the bleachers to represent the characters positions (in the script I call this group 'placeholders'). This script places each character in the position of one of the cubes in a random order.

To run the script, copy the code below to the script editor and change the value of the variable 'num' on line 4, to the number of objects you want to randomize (the number of objects to reposition should match the number of placeholders). Then, highlight all the text and hit ctrl+ENTER to execute the code.


Tuesday, August 25, 2015

Some useful shelf tools...

SNAP TO PLACE

How to use:

Copy the code below to the script editor and drag it onto your custom shelves so you can access it at any time (remember to save your shelves before quitting Maya)

Select object with correct location first and then the object you want to move to match the first. Then run the script found below. It snaps the second object(s) selected to the location and rotation of the first object's pivot.
If the second object(s) has any keyframes on any translation or rotation channels, it sets a keyframe at the current frame on those channels.
The rotations may not match if either one of the objects has freeze transforms.



CREATE CONTROL

How to use:

Copy the code below to the script editor and drag it onto your custom shelves so you can access it at any time (remember to save your shelves before quitting Maya)

This is a tool to create nurb curves as controls for a rig. When rigging I found myself going through the same steps a bunch of times to create all the controls I needed, so I created this shelf button that does about 90% of the job for me. Here's how it works:

Select the object and then run the script. It will create a nurbs circle and snap it to the object. It will  rotate the circle so that it's perpendicular to the longest dimension of the object and will resize it to make it slightly bigger than the second longest dimension of the object. It will also delete history on the circle and freeze transforms. This usually gets me pretty close to where I want to get and all that's left is moving or tweaking the shape in component mode to get it to look the way I want.


CREATE CAMERA

How to use:

Copy the code below to the script editor and drag it onto your custom shelves so you can access it at any time (remember to save your shelves before quitting Maya)

This tool speeds up the process of creating a camera and opening it in a new window. First find the camera angle you want using your perspective camera (or any other camera you don't mind moving around). With that viewport selected, run the script. It will create a new camera with the same properties and open a new panel to display the new camera view, with a resolution gate on, no grid and objects displayed in smooth shaded mode. It will also name the cameras incrementally as cam01, cam02, and so on.


LOCATOR AT SELECTION

How to use:

Copy the code below to the script editor and drag it onto your custom shelves so you can access it at any time (remember to save your shelves before quitting Maya)

Select an object and run the script. It will create a locator named 'objectName_loc' at the position of the pivot point of the selected object.

Dynamic parenting & space matching

USES:

This tool is useful when an object needs to have multiple parents and needs to switch which parent to follow within a scene. The space matching section prevents the object from popping to a different location when the parent is changed and makes sure that the object stays in place.
The top part of the window is used to parent the object to up to 3 drivers. It adds a "Follow" channel to the object, where the user can select the desired driver from a drop down list.
When assigning an object in the Space Matching section, it will load the list of parents from the "follow" channel. Switching parents with the buttons that load in this section will match the world space position of the object so that it remains in place, while switching parents by selecting from the list in the "Follow" channel of the object won't match the space and the object will pop to a different position.
The Space Matching section will work as well with dynamic parents that weren't created with the top part of this tool. For that case, there's a text input field to input the name of the channel that controls the parents.

INTERFACE:

Dynamic Parenting:

First select the object or objects to be parented and click on the "Object(s)" button. Then select what will be the world space (I usually assign the Master Control of the rig as World) and click on "World". Then select what will be the parent and click "Driver1". Driver2 is optional, you can assign a 2nd driver or leave it empty. Finally, click on "PARENT OBJECTS"
The script will parent the object under a locator (named objectName_loc) so that the translation and rotation channels of the object don't get locked by the parent constraint.

Space Matching:

If you created the dynamic parent using this tool, you can leave the default value ("follow") as the channel name. Else, type in the name of the channel that your object uses to select the parent (long name, not nice name*) and click on the "assign" button next to the text input field. Then, select the object with the dynamic parent and click on the top "assign" button. This will load one button for each parent. Clicking on the desired parent button will change the value on the object channel while keeping the object in the exact same place.

*The nice name is what Maya displays in the channel box, you will need to find out the long name of the attribute, which may or may not be the same. To find the long name, select the object and go to Modify/Edit attribute... Select the attribute from the list and look at the line that says New name, that will be the name you need to type in (case sensitive)

INSTALLATION:

To get the this tool download the script file and save it in your maya/version/scripts folder:

Then run the following code in the script editor (make sure to be in a python tab):
import spaceMatch
reload(spaceMatch)

You can save these lines in a shelf button for easy access.


If you don't want to download the file you can just copy the code below to the script editor and drag it onto your custom shelves so you can access it at any time (remember to save your shelves before quitting Maya)


Sunday, October 12, 2014

Snap Keys Tool UI


USES
The Maya SnapKey command can't resolve cases where there is more than one keyframe in between two consecutive whole number frames and you'll get a warning message like this: "// Warning: line 0: Had to skip snapping on some keys since multiple keys existed between the snap multiple. Command result indicates number of skipped keys. // " 
The Snap Tools UI provides tools to handle this situation,

INTERFACE

One button fix:
The Snap and Fix button will call the Maya snapKey command on the selected time range and then handle the leftover non-integer keyframes following these rules:
- if the previous whole number frame doesn't have keyframes, it moves the non-integer key to the previous whole number frame.
- if the previous whole number frame already has a keyframe, it moves the non-integer key to the next whole number frame, unless the next whole number already has a keyframe
- if both the previous whole frame and the next whole frame already have keyframes, it deletes the non-integer keyframe.

Manual fix:
If you want a different solution than the automatic "Snap and Fix" you can handle it manually using the following tools that work on the selected time range.
Update list: It populates and refreshes the "Select key:" drop down menu with all the non-integer keys found in the time range for the selected object. You will need to use this button to refresh the list if you alter the keys without using the Snap Tools UI (for example using Ctrl+Z or deleting or moving a key directly from the timeline or the graph editor)
Snap: It calls the Maya snapKey command and populates the  "Select key:" drop down menu with all the non-integer keys found in the time range for the selected object.
The rest of the tools are pretty self explanatory:
Delete selected key
Move key to previous whole number
Move key to next whole number
Go to selected key

INSTALLATION

To get the Snap Tools UI, download the script file and save it in your maya/version/scripts folder:
Download snapTools.py

Then run the following code in the script editor (make sure to be in a python tab):
import snapTools
reload(snapTools)

You can save these lines in a shelf button for easy access.


If you don't want to download the file you can just copy the code below to the script editor and drag it onto your custom shelves so you can access it at any time (remember to save your shelves before quitting Maya)



Wednesday, September 10, 2014

Marker Keys UI



The Marker Keys tool looks up on what frames in the timeline (or a selected time range) the original object has keyframes and sets "marker" keyframes (just for reference) on the recipient object.

USES
Sometimes after my blocking animation pass is done, a new ctrl is added to the rig (e.g. clothes ctrls, accessory ctrl) or a new prop is added to the scene. The new ctrl doesn't have any keys on the timeline, so I use marker keys as a reference to know where my blocking poses are, and that way my new ctrl will have keyframes on the same times as the rest of my ctrls. I also use marker keys when part of my blocking is not working (like an arm for example) and I want to delete all keyframes on those ctrls and start from scratch.

INTERFACE
Selection section
This section is used to determine the objects and time range that will be used by the "SET MARKER KEYS" function. First you need to select an original object (the one that already has keyframes) and press "assign original" and then select the recipient object (the one that will get the marker keys) and press "assign recipient". If you select multiple objects, only the first one will be assigned.
Then you can select a time range, or by default the UI will load  the values you have your timeline set to.

Keyable channels section
You can select which attributes get keyed. By default, only Tx is selected, since you only need to have one channel keyed to get a red "tick" on your timeline and be able to use the "," and "." buttons to navigate between keyframes. Selecting no channels at all will result in all attributes being keyed, including scale, visibility and any other attributes your object may have.

Finally, press "SET MARKER KEYS" and the keyframes will be assigned to your recipient.

Additional tools section
The lower section consists of additional tools that can be useful when working with this method. These tools work on the current selection, no matter what's assigned as Original or Recipient at the top.

Copy to next key:
Copies the key at the current time and pastes it where the next marker key is.
Once the marker keys are set, I'll go to each one and position the ctrl where I want it at that point in time. When I go to the next marker key, the ctrl will go back to the initial position (where it was when I set the marker keys), in most cases, this is not what I want, I want to keep animating from the position in the previous pose. For that purpose, before moving to the next marker key, I use the "copy to next key" tool.

Delete all keys:
Deletes all keyframes in the time range determined in the Selection section.

Set keyframes per channel:
Sets a keyframe only on the channel clicked. This is the same as right clicking on a channel in the channel box and selecting "Key Selected", but you only need to click one button.


INSTALLATION
To get the Marker keys UI, download the script file and save it in your maya/version/scripts folder:
Download markerKeys.py

Then run the following code in the script editor (make sure to be in a python tab):

import markerKeys
reload(markerKeys)

You can save these lines in a shelf button for easy access.

If you don't want to download the file you can just copy the code below to the script editor and drag it onto your custom shelves so you can access it at any time (remember to save your shelves before quitting Maya)