I have a script to mirror automatically with the correct settings for our project etc.
the thing is, what to do with keyframes for various poses. Shall I kill them or is there a decent way to mirror the keyframes over as well. I started tinkering but the maths and so on was a bit gnarlier than I am used to, so I thought I’d ask here in case anyone has done a similar thing in the past and can give me a tip or two,
cheers,
cw
Hey folks, I have the mirroring and stripping away of keyframes working now, but still having problems with the keyframe mirroring end of things.
found some stuff on the web which helped a lot, though cannot for the life of me find the link now.
t = oppbone.transform
--mirror on x axis
mt=t*(scaleMatrix [-1,1,1])
--mirror on local y axis to get correct xform for bone
mtm=(scaleMatrix [1,1,-1])*mt
For keyframes it all gets a bit hairy. I’m quite happy to work it out with sweat and blood, but if anybody out there knows I am flogging a dead horse, it would be good to know.
Thanks
Can you explain ‘mirroring’ keyframes?
I think he means mirroring transforms about a matrix/transform.
It isn’t too bad once you get the hang of it. I’ll post a proper example tomorrow if you don’t find any other good ones (the CGTalk MXS forums have some pretty good ones IIRC).
Thats what I thought, just wanted to clarify.
Mirroring is really going to depend on what axis’s you want to be flipped. This is the mirror code I wrote and use, to mirror across the y plane on an arbitrary point.
for obj in selection do (
newobj = copy obj
newobj.parent = undefined
mirroredTm = matrix3 1
mirrorTm=scaleMatrix [1,-1,1]
flipTm=scaleMatrix [-1,-1,-1]
--the Matrix to mirror on. Default is origin.
pivotTm = matrix3 1
finalTm = matrix3 1
mirroredTm=(obj.transform*inverse pivotTm*mirrorTm)*pivotTm
finalTm=flipTm*mirroredTm
newobj.transform=finalTm
)
Hey thanks for the replies,
Mirroring the transform is working fine, I can reconstruct my skeleton on the flipside of the mirror plane as I need it, but when it comes to the keyframes for some reason I have a huge mental block!
I think maybe I just need to do some more work on matrix maths and it will quite probably become clear to me.
to clarify my perhaps unclear original enquiry:
Using 3dsmax, and maxscript:
I wish to mirror a set of bones across a plane (at the origin) - I can do this.
I also wish, for each of these bones, for each keyframe on the bone, to recreate that transformation for the mirrored object so that the pose at that keyframe on both sides matches.
I am currently not skills-equipped enough to solve this in a timely manner, and it is not a super urgent issue, but I hope to solve it in the coming weeks with some thought.
I’ve attempted a few techniques, and can come close, but I always fluff something. My gut feeling is that it is something to do with the heirarchy and I’m not sure exactly what.
hope that is clearer, I will post my fumbling progress as I go. Thanks for the links, I will have another search over at cgtalk in case I missed a lead there.
Cheers guys!
If you can mirror the transforms, and thus mirror the transforms of the keys- isn’t that what you need? myBone.transform = myMirroredTransform? Or am I misunderstanding something?
Well, that’s exactly what I thought! It just doesn’t seem to work that way when I actually do it. I am probably missing something obvious.
I will post up a code example tonight after work so you can try it and see what I mean, I don’t think my explanations are sufficiently clear. :D:
Hey guys,
Gonne pick away at this over the weekend.
http://dl.dropbox.com/u/5440025/mirrorbone.mp4
I created point helper per joint and set the transforms, and as they are not in heirarchy it works as I expect.
If I apply those same transforms to the heirarcy of bones it goes haywire, as the transforms are in world space (I am guessing this is the reason anyway)
So hopefully this is clearer, in the clip yuo can see the points doing what I would expect, I just have to work out the correct way to do the same thing for the heirarchy.
If I get the bone’s transform in parent space, mirror that, and apply to the new bone, maybe it will work, I will go check this now.
The reason for the difficulty I was having turns out to be the bones’ setup in the skeletons being inconsistent - some mirrored pairs or bones have different relationships from others - so my first stab was of course never going to work for all of them!
This has prompted lots of discussion in the dept. and tightening up of procedures to ensure we have much better visibility of these kind of issues and can easily handle them, ideally working to a cleaner spec from the off!
Thanks for the help though, as ever, appreciated!
And it only took one year to figure it out!