The Algorithm of the Mirror Blendshape Scripts

In this post we will discuss about the different types of scripts available on the internet, and discuss about one script that I wrote to do the blendshapes.

First of all, there are many scripts online that claim to do a mirror blendshape. But in the past many have not worked for me. Until recently I was a fan of ntMBS script. I was working with that script on a current character and it worked fine till 2am. I closed the system, and next day, the same script was not creating the shapes anymore. It kept duplicating my base geometry and the pivot point was way off and all the geometry I had selected before running the script had their transforms frozen. BAD BAD thing to happen.

So, after scouring the internet for long, I realized it was better to write a script myself.

What the script does:
1) creates a duplicate of the blendshape to be mirrored.
2) creates a duplicate of the baseGeo.
3) scales the duplicated blendshape in X axis by -1. This will make the blendshape appear on the opposite side.
We are not done yet. If you do a createDeofrmer->Blendshape now, and move the slider to 1, you will notice the geometry flips round. You might freeze transforms on the flipped blendshape and try it again. You will still see that it flips. this is beacuse your geometry has many vertices and each of them is assigned a number. when you flip, the vertex12 which was on left cheek is now on right side of the face. It still has the same number as vertex12.
remember how I said blendshapes are vertex based deformations? so, when you move the blendshape slider to 1, you will see the vertex12 flipping over to go and match its new location. (to see this in action… in component mode, select the vertex on the left cheek bone and note its number from script editor, or by looking at the top line of the maya application window. After sliding the blendshapecontrol to 1, select the left cheek vert again. You will see its a different number. select the right cheek vertex and you will see that the vertex that was on the left side has moved to the right side.)

so when we scale the expression on X axis with -1, we get the desired shape, but not the desired vertex orientations. But we are half way there.

solution? – we could drive a duplicate of the baseGeo with correct vertex orientation to match the expression of the flipped blendshape.

We will do this using the wrap deformer. for wrap deformer to work correctly,
1) the two mesh need to be exactly on top of each other.
2) when the deforemer is applied, the mesh needs to match each other as closely as possible on a vertex level.
3) when the top geo/vert is moved, the vert closest to it also moves as though attracted by a magnet. It does not necessarily look for corresponding vertex number. (which is very good for us)

so by sliding the blendshape slider back to Zero, we get to the original baseGeo. The baseGeo and flippedBlendshape are at same place in worldspace and exactly similar. now, when the slider is moved to 1, the base geo follows along with the flipped expression and produces a flipped expression.

now its just a matter of deleting unwanted nodes, deleting history.

That’s it.

the ntMBS script and many other scripts also work in the same way.
for some reason thought none of these scripts worked for me until I wrote the script myself.

you know the logic. Try and script it yourself. I could always email you the script if you wanted.
In my script, you just need to select all the blendshapes you want flipped at once, then select the base geo, run the script. Now take a walk / grab some coffee, cos it will take some time to apply the wrap deformer.
when you come back, all the mirrored shapes should be sitting right next to your blendshapes you selected and also named accordingly.

Is my script perfect?
No… I have seen that at times the wrap deformer doesn’t exactly do a great job. I have no idea why it doesn’t work on some particular shapes, while it works on others perfectly. Well!!! I know the cause.. not so much the reasoning. I am doing some research into this and when I have something more solid, I will post it as another discussion.

oh! btw, of the 30 shapes I tried to mirror at once, only 2 did not work as well as I wanted to. I would still call it a success for a betaRelease.


4 Comments to “The Algorithm of the Mirror Blendshape Scripts”

  1. I would love it if you emailed me the script. I’m studying animation at BYU and we have an assignment to do blendshapes, this would make things a lot easier. thanks

  2. please Sent me a Script. i would like to mirror blend with script…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: