Jump to content

In Place Animations


MackeyK24
 Share

Recommended Posts

My Man... @Deltakosh got another one for your review :)

In Unity for animations that move around (like walk that actual move the skinned mesh forward) they have switch 'Apply Root Motion'

when apply root motion is off and they ar using an animation that IS NOT INPLACE they do something to make that skin the bones are on stay

'IN PLACE' ... Does anybody know how I can do something to make my animations stay in place... Maybe at the transform matrix level that I encode into the animation. This is where I 'Sample' the transform compute the matrix to get key for each bone and stack all those on the bone.animation... Maybe I could do something here that 'Keeps' the X,Y AND Z at the original position (like an in place animation)... 

Or is there some other trick to using NON IN PLACE animations as character movement in BabylonJS ???

Otherwise you will have to go replace ALL the individual animations on a Unity character controller with in place animations for each blend tree node walk, strafe, crouch etc... If you can find IN-PLACE animations to fit your existing Avatar Controller setup.

If I can somehow do what unity does (Preferable at the export level when build that bone matrix so I would not have to compensate at runtime or anything like that) and 'DISABLE ROOT MOTION' which keeps a NON-IN-PLACE animation in-place ...

Here is how I build the bone.animation for your reference:


 

AnimationMode.BeginSampling();
for (var i = 0; i < clipFrameCount; i++)
{
    clip.SampleAnimation(source, i * frameTime);
    var local = (transform.parent.localToWorldMatrix.inverse * transform.localToWorldMatrix);
    float[] matrix = new[] {
        local[0, 0], local[1, 0], local[2, 0], local[3, 0],
        local[0, 1], local[1, 1], local[2, 1], local[3, 1],
        local[0, 2], local[1, 2], local[2, 2], local[3, 2],
        local[0, 3], local[1, 3], local[2, 3], local[3, 3]
    };
    var key = new BabylonAnimationKey
    {
        frame = (i + frameOffest),
        values = matrix
    };
    keys.Add(key);
}
AnimationMode.EndSampling();
frameOffest += clipFrameCount;
totalFrameCount += clipFrameCount;

 

then dump on the bone:

 

var babylonAnimation = new BabylonAnimation
{
    name = bone.name + "Animation",
    property = "_matrix",
    dataType = (int)BabylonAnimation.DataType.Matrix,
    loopBehavior = (int)BabylonAnimation.LoopBehavior.Cycle,
    framePerSecond = frameRate,
    keys = keys.ToArray()
};
if (animationState != null)
{
    babylonAnimation.loopBehavior = (int)animationState.loopBehavior;
    babylonAnimation.enableBlending = animationState.enableBlending;
    babylonAnimation.blendingSpeed = animationState.blendingSpeed;
}
bone.animation = babylonAnimation;

 

As always .. any info will help :)

 

Link to comment
Share on other sites

Holly Shit... I think I got it... I can't believe that worked... So simple but I can now 'NOT' apply root motions on root bones:

... If the transform (the bone) == the skinnedMesh.rootBone and (Apply Root Motion is Turn OFF) I simple make the matrix using 0 x and z for JUST THE ROOT bone transform... AND IS FUCKING WORKING... I can't believe it:

 

AnimationMode.BeginSampling();
for (var i = 0; i < clipFrameCount; i++)
{

    clip.SampleAnimation(source, i * frameTime);
    Matrix4x4 local = (transform.parent.localToWorldMatrix.inverse * transform.localToWorldMatrix);
    if (applyRootMotion == false && transform == skinnedMesh.rootBone) {
        local = Matrix4x4.TRS(new Vector3(0,transform.localPosition.y,0), transform.localRotation, transform.localScale);
    }
    float[] matrix = new[] {
        local[0, 0], local[1, 0], local[2, 0], local[3, 0],
        local[0, 1], local[1, 1], local[2, 1], local[3, 1],
        local[0, 2], local[1, 2], local[2, 2], local[3, 2],
        local[0, 3], local[1, 3], local[2, 3], local[3, 3]
    };
    var key = new BabylonAnimationKey
    {
        frame = (i + frameOffest),
        values = matrix
    };
    keys.Add(key);
}
AnimationMode.EndSampling();

 So for the ROOT BONE ONLY ... I don't want the local to world matrix calculation... I just want the local with 0 X and Z ... It looks JUST LIKE unity runtime when they are actually NOT applying root motion to the Skinned Mesh Root Bone Transform... FUCKING AWESOME :)

 

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...