PDA

View Full Version : MEL script for mirroring animation??


FloydBishop
12-16-2003, 05:13 PM
Hello all,

I'm wondering if there is a MEL script floating around somewhere that will mirror an animation.

For example, a character stands on his left foot and raises his right arm...

You hit the MEL button in your shelf...

BAM!!

The character now stands on his right foot and raises his left arm.

If you can point me to a script I can alter as needed, that would be helpful. Any help would be greatly appreciated.

Thanks!

spinlock
12-17-2003, 08:30 AM
i don't think you're going to find a generic solution to the problem you've posed...

it would be a lot easier to write if you had certain naming conventions in effect. if you named things "right_arm" and "right_leg" and had a corresponding "left_arm" and "left_leg" it would be fairly easy to begin to automate something like you asked for.

otherwise, i think you'd have to select both arms and run your animation switch script... then select both legs and run your script... etc.

if you have a naming scheme going for you, then the script can attempt to match left/right for you, otherwise you'll have to explicitly tell it what (and how) to mirror.

Sporksalot
12-17-2003, 07:53 PM
I wrote one of these a few years back when I worked for a game company. Something like this has to be heavily customized for the character it's to work on.

First you have the problem Spinlock mention, that of the naming of the joints/controls. The script has to know which node is the right hand and which is the left, etc.

The really problem however is that there are hundreds of ways to set up a skeleton/rig, and you'll have to do math of some sort on the attributes to do the mirroring. For example, on the root joint, if Y rotation is to turn left or right, then you'll need -1 scale the values, so a Yrot value of 40 becomes -40, so instead of being turned to the left the char is now turn to the right. But for this to work, I have to assume that you built your control a certain way. If Y rotation on you char is instead leaning forward or backward then it won't work. Or if, Y rot is left to right but facing forward is not zero, but instead is 90, then -1 scaling the values won't work, you'd need to add or substract 90 to get the mirrored rotation value. Of course you'll have to deal with this problem for every attribute of every control, and the possitional attributes can be even more complicated.

So it's possible to write a mirroring script for a specific character, and i've seen it on some autorig solutions. Mine that I wrote would be almost useless on any other charcter than the one i wrote it for. To write a generic one would be very diffecult. Half the script would be just figuring out how the adjust the attributes so that it correctly mirrors. Which is not say that it can't be done.

eric

FloydBishop
12-17-2003, 11:48 PM
Originally posted by spinlock
i don't think you're going to find a generic solution to the problem you've posed...

it would be a lot easier to write if you had certain naming conventions in effect. if you named things "right_arm" and "right_leg" and had a corresponding "left_arm" and "left_leg" it would be fairly easy to begin to automate something like you asked for.


I do have a similar naming convention going on. RH, RK, LH, LK for the right and left hips, knees, etc.

otherwise, i think you'd have to select both arms and run your animation switch script... then select both legs and run your script... etc.

if you have a naming scheme going for you, then the script can attempt to match left/right for you, otherwise you'll have to explicitly tell it what (and how) to mirror.

I'm very new to MEL scripting. Is there a tutorial you can point me to, or perhaps give me some direction to go in as to how to write such a script?

Thanks

JasonOsipa
12-18-2003, 12:46 AM
For something like that to work, you need at VERY least to have a naming convention that is rock-solid. Something like what you're talking about can't really happen without it, and even then, the scripts, unless SHOCKINGLY robust, still will need to basically pair with a specific skeleton/rig.

I've set stuff like this up before, but like I said, they only work with the models for which they were written.
-J.

Sorry, got caught posting at the same time u answered the questions.

K, you just go through, attr by attr on each thing for one side (ls "R*") for example and copy the curves out, and drop them into an array of arrays (eep), then take and delete those curves. Now per (ls "L*") take that, copy the curve and paste it onto it's "R" opposite. ("R"+`substring($obj,2,size($obj))`) -at least I THINK that won't crap out. Then troll through your variable arrays and drop the R stuff onto the left side.

Have you thought about central bones, too? how ONE of the axes will stay the same, whilst the other two will actually become "negatives"? Yuck, I DO remember doing this. Ik handles/foot controls are bad too, cuz they're not just opposite, they match up in certain axes.

and now I explode.

FloydBishop
12-18-2003, 04:41 PM
Originally posted by JasonOsipa
K, you just go through, attr by attr on each thing for one side (ls "R*") for example and copy the curves out, and drop them into an array of arrays (eep), then take and delete those curves. Now per (ls "L*") take that, copy the curve and paste it onto it's "R" opposite. ("R"+`substring($obj,2,size($obj))`) -at least I THINK that won't crap out. Then troll through your variable arrays and drop the R stuff onto the left side.

Have you thought about central bones, too? how ONE of the axes will stay the same, whilst the other two will actually become "negatives"? Yuck, I DO remember doing this. Ik handles/foot controls are bad too, cuz they're not just opposite, they match up in certain axes.

and now I explode.

So is there a script that exists somewhere that I can alter/adjust to work with my rig specifically, or do I start one off from scratch?

I'm rather new to MEL, so much of what you have written above has gone over my head. I just started to read the MEL books I purchased a few months ago, and then I moved cross country... all my books are in storage. :( I may be able to stumble my way through this if I had something to use as a guideline infront of me.

I'll try and read up some more and take another look at what you've suggested, Jason.

macaroniKazoo
12-18-2003, 10:56 PM
it is actually possible to write a generalised mirror script. i looked into it not too long ago, but chickened out because the maths involved was over my head (as most is i might add :) ). but i managed to find a "mirror" matrix that you can just apply to an object, and it will mirror that object around a certain plane, no matter what. it was really quite cool actually.

but i couldn't quite get it to work for centralised controls (ie root, spine, head). if anyone wants the mirror "matrix" or the mirror procedure i was playing with, just gimme a shout.

the naming convention problem can be overcome reasonably easily tho. here our characters are auto-rigged, and the script that builds the rig "tags" each control with a name. by this i mean that it creates a string attribute with info in it.

the left arm for example, has attribs called:

controller_type arm
controller_info L

and if you don't have an auto rig script, this is easy to either setup manually, or write a simple script to add these attribs for you. so the mirror script just checks through the scene for objects with these attributes.

BadMange
12-22-2003, 01:31 PM
Forgive my newb-ness, but couldn't you just copy/paste from one node to the other in the graph editor and adjust the curves? There's a script called animCopy that does this automatically, and you shouldn't need to adjust the curves in the GE afterwards, as they're offset for the correct side (right to left, vice versa). It's at Cybotic.net (http://cybotic.net/scriptsMel.html). Hope this helps!

-Bad Mange

macaroniKazoo
12-22-2003, 01:47 PM
BadMange: yeah you can do that, but its a bit tedious having to do that with all your controls for a character. and tedious usually lends itself to having a mel solution. :)

after all, as long as you can break a task down into reasonably simple, well defined steps, you can script it...

andy_maxman
10-19-2004, 11:31 AM
sorry to wake this thread up again...
but i've been looking up the forums all over to get a solution to what Floyd Bishop asked for and as this thread is almost a year old now....would there be a solution to it now?

and the biggest reason i need this is for walkcycles. any suggestions would improve my workflow.
cheers!
andy

CGTalk Moderation
01-16-2006, 11:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.