PDA

View Full Version : keys on x y z


donvlatko
09-04-2004, 09:09 AM
I need help on a not so big problem but more pain in ass.

I have a skeletal with animation and on some bones I have keys on all 3 channel(example frame 10 x,y,z,) and on frame 15 only on x and y. What I need is to have keys on 3 channels on every frame where I have put keys, how can I do that quickly.

I think there is a mel for that somewhere but I can remember the name:((

can someone help me on this, I really don't want to spent all night on this.....please

dwalden74
09-04-2004, 08:10 PM
This should be easy enough. Just query where your joints already have keyframes, then add new keyframes at those same frames. For example:

//Select the joints you need to key and run this:
{
string $joints[] = `ls -sl -type joint`;
for ($j in $joints)
{
float $keys[] = `keyframe -q ($j + ".rx")`;
for ($k in $keys)
{
setKeyframe -t $k ($j + ".rz");
}
}
}

This will set keyframes on the joints` rotateZ attributes, wherever you already have keyframes on the joints` rotateX attrs.

hope this helps-
david

donvlatko
09-05-2004, 08:48 AM
wow thanks man I will try it!!

donvlatko
09-06-2004, 09:17 AM
thanks it help but my problem is that some time I miss key on some other rotation this is also same for transition:(

misterdi
09-07-2004, 10:15 AM
If it is only involve rotation, you could simply change your curve interpolation from independent Euler to synchronized Euler.

donvlatko
09-07-2004, 10:50 AM
but I need keys, somehow to short the process with mel

misterdi
09-07-2004, 12:18 PM
Isn't it what synchronized Euler will do?.

Let say you have rx at frame 5, ry at frame 5,10,20 and rz at frame 15, 25, won't synchronized Euler will add extra key for all three rotation at frame 5, 10, 15, 20 and 25

Usually this is the workflow that I do to get all three axis to get keyframes at same frames, you can switch it back to independent Euler after the keys are created and work as usual.

donvlatko
09-07-2004, 06:04 PM
ok I will try, what about translation...same?

misterdi
09-08-2004, 07:05 AM
Sorry, it won't work for other animcurve, it's only for rotation.

So for other animcurve you need to script it

This is some idea of the script
proc synchronizeAnim(string $object, string $attr, string $timeList[])
{
for ($i = 0; $i < size($timeList); $i++)
{
float $time = $timeList[$i];
//
// check if curve does have keyframe
// and insert one if it doesn't
//
if (size(`keyframe -t $time -at $attr -q $object`) == 0)
{
setKeyframe -insert -at $attr -t $time $object;
}
}
}

proc string[] convertFloat2StringArray(float $floatArray[])
{
string $stringArray[];
for ($i = 0; $i < size($floatArray); $i++)
{
$stringArray[$i] = $floatArray[$i];
}
return($stringArray);
}

proc synchXYZ(string $object, string $attribute)
{
if ($attribute == "r" || $attribute == "t" || $attribute == "s")
{
switch ($attribute) {
case "t":
$attr = "translate";
break;
case "r":
$attr = "rotate";
break;
case "s":
$attr = "scale";
break;
}
//
// list all keyframes
// Convert to string array
// And remove duplicate entries
//
float $timeList[] = `keyframe -at $attr -t ":" -q -tc $object`;
string $timeListString[] = `convertFloat2StringArray($timeList)`;
string $newList[] = `stringArrayRemoveDuplicates($timeListString)`;
string $axis[3] = {"x", "y", "z"};
for ($i = 0; $i < 3; $i++)
{
$attr = $attribute + $axis[$i];
synchronizeAnim($object, $attr, $newList);
}
}
else
{
print ("Usage:\nsynchXYZ(objectName,attribute\nuse only \n\"t\" for translation\n\"r\" for rotation\n\"s\" for scale");
}
}


To use the script let say you have joint20 to synchronize the rotation you should type

synchXYZ("joint20", "r");

either in command line or script editor after you run the script.

But tell you frankly, I'm hopeless in MEL scripting, so you may find error in the script. Hopefully somebody can come up with better script. This script doesn't check full path DAGnode so if you have duplicate name in the structure it might run into problems.

Hope this help

donvlatko
09-08-2004, 08:37 AM
wow man thanks a lot!I will try it....I am also bad in mel but I know a little so I check



The synchronized Euler helps a lot I must say!It's same that wan't work on translations:(

misterdi
09-08-2004, 08:46 AM
My script will work for translation, rotation and scale only.

You can specify the attribute to look for as a second argument.

"t" -> translation
"r" -> rotation
"s" -> scale

so if you want to synchronize the translate attribute you can called it as

synchXYZ("joint20", "t");

donvlatko
09-12-2004, 09:16 AM
thnaks all for a help!!!

CGTalk Moderation
01-19-2006, 04:00 AM
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.