Sunday, August 11, 2019

Animation Control Orient Tool

USES
When the rotation axes you need to rotate around are not aligned with the world axes,  an "orient group" is needed (also called "offset group"or "reset group") in order to keep the animation control with zero values. Simply aligning the animation control and freezing transforms won't work because freezing transforms will reset the rotation axes to world. This script finds the rotation values necessary to properly align an animation control to the correct rotation axes, creates a group above the control and assigns the rotation values to it, so that the control can have zero transforms, but still be aligned as needed. 




HOW TO USE

First create your animation control and place it so that its pivot point is where you need it. Then, open the GUI and assign one or two planes, by selecting either a face or 3 vertices and clicking assign, and the animation control. If one of your rotation axes is aligned with one of the world axes, like in the figure A below, you will only need to assign one plane, else you'll need two. You can use the radio buttons next to each plane assignment to select which axis will aligned with that plane. Finally, click "Orient control". 
The script will create a new group named "your_control_name"_orientGrp, and will parent the animation control to it. You can now parent this orient group to your hierarchy and lock all channels, since this group should not be animated.
If the control is not visually facing the way you want, you can rotate it and then freeze transforms, that won't affect the rotation axes since those are coming from the values in the parent group. 


Fig A - Y axis is aligned with the world
Fig B - No axis are aligned with the world
















Choosing the 3 vertices to select can be confusing depending on the shape of your mesh,  the vertices don't need to be defining a face. You might be selecting vertices on the flat side of a hinge, or on the edge loop of the elbow. Watch the video below to see a practical example.





INSTALLATION

To get the Animation Control Orient Tool, download the script file and save it in your "maya/version/scripts" folder:
Download lr_ctrlOrientTool_UI.py

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

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)


Saturday, August 10, 2019

Vray Z-depth Tool

USES
This script connects the Depth White and Depth Black attributes of the Vray Z-depth render element to two locators that follow along with the animation of your camera and object of interest. It gives visual feedback so it's easy to set up and see what area is being covered. The object of interest will always render the same value of gray and the white and black values will remain at a constant distant (set by the user) at all times.

HOW TO USE

First, make sure you have a Vray Z-depth render element in your scene and that it's named exactly "Z_depth". Then select the camera, shift select the object that needs to stay in focus and run the script. The script will create a new group called zDepth_grp which will have two attributes that you can use to control where the whitest and blackest planes will be in the render. When you adjust the value of these attributes you will see in the viewport two locators that slide on the line that connects the camera to the object of interest.






INSTALLATION

To get the Vray Z-depth Tool, download the script file and save it in your "maya/version/scripts" folder:
Download lr_zDepth_tool.py

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

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, August 4, 2019

Multiple Reference Tool


USES:
Unlike Maya's default file reference window, this tool allows you to select more than one file at a time. Also by adding more file rows in the tool UI you can make references for files located in different folders all at once. It enables you to reference one file multiple times in one go and assign a namespace of your choice.

INTERFACE:
Use the "browse" button on the right of each row to select the files you want to reference (you can shift/ctrl select multiple files). Type the desired number of copies  in the "Qty" field and the desired namespace in the "Namespace" field.
Use the "Add file row" button towards the bottom of the UI to add as many rows as you need. You'll need different rows to browse for files that live in different folders, or if you want to assign different quantities or namespaces for different files.
When all your preferences are set click on "Create references" to reference all the files.



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 lr_referenceTool
reload(lr_referenceTool)

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, 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)