tsStickyLips tool

This tool will let you easily create a sticky lips setup for your character. The setup created is based on a wire deformer.


1. Download the script from this link: tsStickyLips.rar;

2. Copy file tsStickyLips.pyc into your maya scripts/ folder;

3. From the script editor, in a python tab type:

import tsStickyLips



As the sticky lips deformation lies on top of other deformations, this should be your very last step in facial rigging.

1. Select top edges for the uplip and press ‘<<<’;

2.  Select top edges for the bottomlip and press ‘<<<’;

3. Press ‘Create stickyLips’ button.

The script will create a copy of the geometry with sticky lips setup. You can hide the previous geo and go rendering with this copy.


Optional parameters:

The tool provides automatically on weighting the wire deformer influence areas. Two optional parameters can be tweaked to change how the weighting is done:

- Selection growth: Grows vertex selection before setting weight influence to 1;

- Smoothness: How many times the weighting should be smoothed.


Here’s the source code of the main procedure for the tech guys:

def createStyckyLips(top_edges, bottom_edges, selection_growth = 2, smoothing=8):
 base_mesh = top_edges[0].split(".")[0]

 # Create curve on top edge sel on duplicated mesh
 top_curve = cmds.polyToCurve(form=2, degree=1)[0]
 top_curve_shape = cmds.listRelatives(top_curve, c=1)[0]

 # Create curve on bottom edge sel on duplicated mesh
 bottom_curve = cmds.polyToCurve(form=2, degree=1)[0]
 bottom_curve_shape = cmds.listRelatives(bottom_curve, c=1)[0]

 # Create wire average curve
 avg_node = cmds.createNode("avgCurves")
 cmds.setAttr(avg_node + ".automaticWeight", 0)
 cmds.setAttr(avg_node + ".automaticWeight", 0)
 avg_curve = cmds.duplicate(top_curve)[0]
 avg_curve_shape = cmds.listRelatives(avg_curve, c=1)[0]
 cmds.connectAttr(top_curve_shape + ".worldSpace[0]", avg_node + ".inputCurve1", force=1)
 cmds.connectAttr(bottom_curve_shape + ".worldSpace[0]", avg_node + ".inputCurve2", force=1)
 cmds.connectAttr(avg_node + ".outputCurve", avg_curve_shape + ".create", force=1)

 #Create duplicate mesh with inputs
 dup_mesh = mel.eval("polyDuplicateAndConnect;")[0]
 dup_top_edges = [x.replace(base_mesh, dup_mesh) for x in top_edges]
 dup_bottom_edges = [x.replace(base_mesh, dup_mesh) for x in bottom_edges]

 # Create wire deformer on duplicate mesh
 wire_deformer = mel.eval("wire -gw false -en 1.000000 -ce 0.000000 -li 0.000000 -w " + avg_curve + " " + dup_mesh +";")[0]
 base_wire = avg_curve + "BaseWire"
 base_wire_shape = cmds.listRelatives(base_wire, c=1)[0]
 cmds.connectAttr(avg_node + ".outputCurve", base_wire_shape + ".create", force=1)

 # Set wire deformer params
 cmds.setAttr( wire_deformer + ".scale[0]", 0)
 cmds.setAttr( wire_deformer + ".envelope", 1.2)
 editAttrs(wire_deformer, ["ce","te","li","ro","sc[0]"], l=1, k=0, cb=0)

 #Set weights

 #Zero all weights
 mel.eval("artAttrToolScript 4 \"" + wire_deformer +"\";")
 mel.eval("artAttrPaintOperation artAttrCtx Replace;")
 mel.eval("artAttrCtx -e -value 0 `currentCtx`;")
 mel.eval("artAttrCtx -e -clear `currentCtx`;")

 #Select vertices
 mel.eval("changeSelectMode -component;")
 mel.eval("hilite -r " + dup_mesh + " ;")
 mel.eval("setComponentPickMask \"Line\" true;")
 cmds.select(dup_top_edges, dup_bottom_edges)

 for i in range(selection_growth):

 #Set weights for region to 1
 mel.eval("artAttrValues artAttrContext;")

 mel.eval("artAttrToolScript 4 \"" + wire_deformer +"\";")
 mel.eval("artAttrPaintOperation artAttrCtx Replace;")
 mel.eval("artAttrCtx -e -value 1 `currentCtx`;")
 mel.eval("artAttrCtx -e -clear `currentCtx`;")

 #Smooth n times
 mel.eval("artAttrValues artAttrContext;")
 mel.eval("artAttrPaintOperation artAttrCtx Smooth;")

 for i in range(smoothing):
 mel.eval("artAttrCtx -e -clear `currentCtx`;")

 mel.eval("changeSelectMode -object;")

 # Group,rename all objects
 main_grp = cmds.group(em=1, w=1, n=resolveName("GRP_sticky"))
 cmds.setAttr(main_grp + ".visibility", 0)
 editAttrs(main_grp, ["tx","ty","tz","rx","ry","rz","sx","sy","sz"], l=1, k=0, cb=0)

 top_curve = cmds.rename(top_curve, resolveName("CRV_sticky_top"))
 bottom_curve = cmds.rename(bottom_curve, resolveName("CRV_sticky_bottom"))
 avg_curve = cmds.rename(avg_curve, resolveName("CRV_wire"))
 base_wire = cmds.rename(base_wire, resolveName(avg_curve + "BaseWire"))

 cmds.parent(top_curve, bottom_curve, avg_curve, base_wire, main_grp)
 if cmds.listRelatives(dup_mesh, p=1):
 cmds.parent(dup_mesh, w=1)

 wire_deformer = cmds.rename(wire_deformer, resolveName("stickyWire"))

Have fun!



tsFrameBlendshapes tool

This tool is part of my personal toolset.
It let’s you easily create, connect and animate animation based corrective blendshapes,.
Just go to the frame you want to correct/deform, hit “Sculpt” and edit the shape of your mesh. The cool thing is that the script works on pose: you can sculpt the corrective shape in any pose, then the script will bring back your deformed mesh in base pose automatically to create your corrective shape.
Coded in python.

keyBaker tool

Download it here: Key Baker

This plugin bakes the animation on the selected objects and save the bake on a file.
You can then import and apply the baked animation just by browsing the bake file in the Import tab.

The export interface

The import interface

How it works:

For each selected object, the script saves the values of each published and keyable attribute for each frame in the selected interval.
When you apply the cache, the script simply looks for each object in the bake and keys the relative attributes to the values saved in the bake.

Be careful that applying the animation bake will destroy any keyframed animation currently set to your objects. Thus, the right way to go would be caching the animation and then applying the cache to a clean copy of the scene, with no keys, expressions or constraints that might control the published attributes.

Copy the file keyBaker.pyc into your script folder, source the file and call the main() function, as shown here:

import keyBaker

For any suggestion, bug report or question, you are free to contact me.

OBJ flow exporter

This tool allows to export and import a mesh as a flow of OBJ files, driven by an expression, written in python.
It is based on the standard Maya exporter plugin.

Watch the preview here:

It is a bit raw, but it does its work pretty well. We used it in production for managing a metaball lava flow and it worked very fast.


Copy the .py file into your Maya scripts folder;

Import the script;

Call these functions:

displayExportUI(): for the exporting tool;

displayImportUI(): for the importing tool.

After the job is done, you can tweak the animation of your OBJ flow just by editing the expression created by the script.

You can download it here: bakeToObj.py.zip

Feel free to edit and improve the code and I’d like to keep updated for any improvement.

Please note that once you import an obj flow, you have effectively separate meshes, that means you can’t for example use motion blur, since at each frame the visible mesh changes.

Have fun!

Merging vertices at corner


Today a Modeler at work asked to me if there is a tool in Maya to merge two vertices from 2 different meshes in the corner, (not just by averaging their positions) like depicted in figure:

I was unsure about the toolset for modeling provided by Maya, but I thought it was a good chance to write out some code and have fresh material for the blog.

My idea was to create a script that, by selecting some vertices or edges from different (or the same) meshes would move the external points right to the corner.

This very simple task presents some non-trivial challenges.

First of all, what we ‘see’ programmatically from a mesh is just a cloud of points, their connections (the edges), the faces and so on, so we have to figure what we need as input from the user and how to elaborate it to achieve the result.

When developing tools, one of the crucial aspect I focus more is keeping the tool usable, that means simple and easy to understand for the user.

Here’s my approach:

Imagine if we could extend the longitudinal edges for each mesh: the intersection points between these edges would give us the final positions where to place the vertices at the border for each mesh.

Mathematically speaking, our problem can be reduced into calculating the intersection points between 2 lines representing 2 adjacent edges from the different meshes.

Now we can remodel the problem in this way: given 2 edges, calculate their intersection and move the closer points to the intersection.

Given 2 lines R and S in a 3d space (in our case constructed by extending to infinite 2 mesh edges), we might have the following cases:

- R intersect S in P(x’, y’, z’);

- R || S => they are parallel, thus S never intersect R or R=S always;

- R and S are crooked: never intersect and no parallel.

According the different cases, we might approach different solutions. I opted for averaging the border vertices in case S=R and in the other cases finding the 2 closest points P and R where P in R and Q in S, so we keep the direction of the edge. In case R intersect S, it follows that P=R.

Selected 2 edges, we can find the two extreme vertices using the polyInfo command:

sel = cmds.ls(sl=1)
if len(sel) !=2:
   OpenMaya.MGlobal.displayError("Select exactly 2 edges")

   vtxsA = cmds.polyInfo(sel[0], edgeToVertex=1)[0].split()
   vtxsB = cmds.polyInfo(sel[1], edgeToVertex=1)[0].split()

Now we have a set of four points. We need to know wich 2 of these points to move after we find the intersection. We might match point by point and find the 2 closest. I used a different approach: for each point of an edge, find the closer to the average of the 2 vertices of the other edges (A and B represents the 2 edges):

if distance(posA[1], avgB)< distance(posA[0], avgB):


 if distance(posB[1], avgA)< distance(posB[0], avgA):


We can compute the intersection between 2 lines in the 3d space using  different approaches, according the way we choose to represent them: e.g. intersection between planes, parametric equations and so on.

I went for parametric equations:

For S:

X(t) = x0 + (x1-x0)*t

Y(t) = y0 + (y1-y0)*t

Z(t) = z0 + (z1-z0)*t

For R:

X’(h) = x’0 + (x’1-x’0)*h

Y’(h) = y’0 + (y’1-y’0)*h

Z’(h) = z’0 + (z’1-z’0)*h

with l=x1-x0, l’=x1′-x0′, m=y1-y0, m’= .., n=.., n’=..,  as the director parameter of the lines.

From the parametric equations we can compute the vector difference:

D(t,h) = [Dx(t,h), Dy(t,h), Dz(t,h)]


Dx = X’(h) – X(t), Dy=Y’(h) – Y(t), Dz=Z’(h)-Z(t)

We can study the gradient of D(t,h) to find the minimum value, i.e. :

This give us a system in 2 equations with 2 variables (t and h).

According the solutions given by the system we can see if the lines intersect, are parallel or crooked. The rest of the code is raw math to translate all these concepts.

The final lines assign the corresponding coordinates given by h and t to the closest vertices to the corner:

PA_X = qA + t*lA

PA_Y = uA + t*mA

PA_Z = wA + t*nA

PB_X = qB + h*lB

PB_Y = uB + h*mB

PB_Z = wB + h*nB


cmds.xform(closerA, t=[PA_X, PA_Y, PA_Z], ws=1)
cmds.xform(closerB, t=[PB_X, PB_Y, PB_Z], ws=1)

You can download the sourcecode here:


To test it, source the contained .py file, select 2 edges as shown in picture and call the function mergeAngle()

The code is pretty rough but effective.. just coded in half an hour. It wants to be a start point to work on. A better implementation would include iterate along all the border vertices to get the corresponding edges and fix them at a glance.. any suggestion, request, improvement is very welcome.

Thanks for reading