Convert to inplace animation code snippet

Hi

This is a simple function to convert AnimClip to In-Place animation. Works with cyclic animation (walk, run,…).

public void convertToInPlace(AnimClip clip) {
    for (AnimTrack track : clip.getTracks()) {
        if (track instanceof TransformTrack transformTrack) {
            Vector3f[] translations = transformTrack.getTranslations();
            if (translations != null) {
                Vector3f start = translations[0];
                Vector3f end = translations[translations.length - 1];

                Vector3f delta = end.subtract(start);
                Vector3f factor = delta.divide(translations.length - 1);
                Vector3f vTemp = new Vector3f();
                for (int index = 0; index < translations.length; index++) {
                    Vector3f translation = translations[index];
                    vTemp.set(factor).multLocal(index);
                    translation.subtractLocal(vTemp);
                }

                transformTrack.setKeyframesTranslation(translations);
            }
        }
    }
}

@sgold it might be nice to add a similar function in Wes library.

Edit:
Here is an example video:

7 Likes

Good idea!

My first reaction was that the method should only modify tracks whose target is a Spatial or a root joint. Those are the only tracks likely to include non-zero translations, so perhaps it’s a moot point. What do you think?

1 Like

Yes, agree with you, I also use it only for the root joint in my case.

1 Like

I’ve added some code to Wes, but I’m stuck on creating a test/demo app, because all the walk/run animations in jme3-testdata seem to be in-place animations.

@Ali_RS, can you point me to a good test model with Creative Commons licensing, preferably a CC-0?

1 Like

What about using Mixamo characters and animations?

They are royalty free for personal, commercial, and non-profit projects.

I already have an account in Mixamo, if you want I can download it (with animations) and convert it to j3o for you.

1 Like

May be good to document that it will work best with cyclic animation (walk, run,…).

If animation root motion speed is not linear during the animation then in-place animation may not look good.

See this example:

1 Like

Okay, I did that.

1 Like

I can download it (with animations) and convert it to j3o for you

What would be the license of the converted model?

1 Like

From what I understand it would be a typical stock model type license with adding credit to Mixamo.

1 Like

I don’t see how I could comply with such a license. Ah well…

Today I released Wes v0.7.0, which includes in-place animation routines and improves support for morph animations.

3 Likes

Thanks

1 Like

There’s now an example app that converts a traveling animation to an in-place animation.

It uses the “ninja-fighter” model from @adi.barda’s 3-D models repo.

1 Like