Jump to content

How To Mirror Matrix Pose


MackeyK24
 Share

Recommended Posts

Hi Guys...

Yo @Deltakosh or anybody else :)

Gotta a quick question. Is there a way to "MIRROR"  an skeletal animation pose (bone._martix)...

If is was playing animation of walk left... and I have access to and want to FLIP/MIRROR that matrix pose to make it walk right...

is the some kind of BABYLON.Matrix.Mirror type function ???

Link to comment
Share on other sites

Nope, neither matrix.invert or matrix.scaling (1,-1,1) actually flips or mirrors the pose left to right.

I am trying to save space in encoding animation keys, if i have a walk left, i would like to NOT have to encode a walk right animation. So i was

think i could MIRROR or FLIP the pose at actual runtime animation when i interpolate the animation frame to get the POSE for that frame update.

But i am afraid i DONT know the math involded in FLIPPING or MIRRORING the animation pose matrix...

Does anyone know how or if maybe i have decompose the matrix and then flip or mirror the individual TRS (Translation, Rotation and Scale) then put back together...Kinda like a DecomposedLerp maybe ????

Anyone got any thoughts :)

 

 

Link to comment
Share on other sites

Well, Blender has a copy / paste to the other side functionality.  I just posed a bone many different ways, copied to clipboard, & "cross-pasted" it.  The UI show that the signs on the Y & Z of the quaternion part are flipped.  In BJS coordinate is switched where Z is up, but it is still Y & Z.

Maybe Matrix.Scaling(1, -1, -1)  or just update the quarternion

Link to comment
Share on other sites

Well I tried to multiply by scaling(1,-1,-1)... Does not work... makes my model SQIUSH down to little blob or disappears complete from view.

Take a look at my HOW i am trying to MIRROR a pose if the blender.mirror flag is set...But the sampleMatrix multiply by scaling does not work:

if (blender.track != null) {
  this._sampleMatrix.reset();
  BABYLON.Utilities.SampleAnimationMatrix(this._boneAnim, blender.frame, BABYLON.Scalar.Clamp(blender.track.behavior, 0, 1), this._sampleMatrix);
  if (blender.mirror === true) {
    this._sampleMatrix.multiplyToRef(BABYLON.Matrix.Scaling(1,-1,-1), this._sampleMatrix);
  }
  this.blendAnimationMatrix(layer, this._sampleMatrix, blender.weight);
}

 

Link to comment
Share on other sites

I would suggest a test apart from your code, where say leftFoot bone is rotated.  Grab matrix & do stuff to it, then assign it to rightFoot bone & mark bone dirty.  If this is not working, try decomposing, changing rotation recombine.

You are doing too much.  Part of this code not great production quality yet, but should work.  if (blender.track !== null) & if (blender.mirror === true) probably better.

Link to comment
Share on other sites

9 hours ago, JCPalmer said:

I would suggest a test apart from your code, where say leftFoot bone is rotated.  Grab matrix & do stuff to it, then assign it to rightFoot bone & mark bone dirty.  If this is not working, try decomposing, changing rotation recombine.

 You are doing too much.  Part of this code not great production quality yet, but should work.  if (blender.track !== null) & if (blender.mirror === true) probably better.

I dont know about toooo much... Each line is doing something specific in the animation process...

What make you say DOING too much ???

the first line blender.track != null .... Need that !

the second line reset a matrix buffer so i dont instantiate new matrix each frame... Need that !

the third line actually SAMPLES the animation matrix pose... Need that !

the forth and fifth lines TRY to mirror if the blender.mirror flag is set... Need that !

the six and final line ADDS the animation matrix to the current BLEND BUFFER that later gets assigned bone and the matrix is updated.

I have all the animation frame code as OPTIMIZED i can get it... I can blend multiple animation from multiple layers with a MINIMUM amount of overhead

Note: I always get issues when test for null using !== as apposed to != (for null only).... And i am just OLD school i know blender.mirror and blender.mirror === true are the same thing...

I just like SEEING blender.mirror === true or blender.value === false.... More easy to tell when i am glancing thru code the blender.mirror or !blender.mirror

So again i dont know what mean... Doing too much... How could i be doing ANY less ???

For a larger picture of the actual Animation State Machine:

babylon.scenestates.ts

Note: Still a work in progress... But so far i am doing all this with like 1 to 1.5 millisecs overhead (THUS FAR) :)

 

Link to comment
Share on other sites

I mean get the pose cross copy working, before trying to put everything through that Blender thing.  I made a PG, which shows switching the sign on the Y & Z of the quaternion does the trick. Playing with the scale DOES NOT WORK.  Without simplifying your test, running it through an interpolater is just going to make matters much harder to figure out.  You do not need anything, if the pose is not right.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...