Animations on Models

Good day fellow PlayCanvas users!

I am currently working on a little game and as normal in a game, I used characters and want to apply animations to them. Until now I was using Mixamo characters and when I selected the correct character and downloaded the animation for that specific character it worked fine. Now I don’t know if this is a mixamo issue, but I’d like to apply an animation to characters in general. I understand that the characters should be rigged in the same way and therefore this should not pose a problem right ?

My problem is, that I downloaded a character “SWAT” from mixamo and then selected an animation on the Y-Bot character, downloaded the fbx, imported that into the PlayCanvas project (got a .json Files as expected) and tried applying that animation to the SWAT model in PlayCanvas. When I start the application I get the error:

Uncaught TypeError: Cannot read property '_pos' of undefined
    at Skeleton.addTime (playcanvas-stable.dbg.js:18328)
    at Skeleton.set (playcanvas-stable.dbg.js:18383)
    at Skeleton.set (playcanvas-stable.dbg.js:18368)
    at AnimationComponent.play (playcanvas-stable.dbg.js:23167)
    at AnimationComponent.setModel (playcanvas-stable.dbg.js:23185)
    at ModelComponent.set (playcanvas-stable.dbg.js:23869)
    at ModelComponent._onModelAssetLoad (playcanvas-stable.dbg.js:23712)
    at ModelComponent._bindModelAsset (playcanvas-stable.dbg.js:23694)
    at ModelComponent.set (playcanvas-stable.dbg.js:23832)
    at ModelComponentSystem.initializeComponentData (playcanvas-stable.dbg.js:24154)

Does anyone know how to fix this? When use the same Character and download the animation it works fine. I am curious to know this, because I like to make my own animations and need to know if I can use a standard rigged character and then just use these animations.

Thank you in advance!

https://developer.playcanvas.com/en/tutorials/animation-blending/

See if this helps

I did find the problem, but I have no clue how to fix it…

The problem occurs in these Code-Lines of the playcanvas-stable.dbg.js:

for (i = 0;i < nodes.length;i++) {
        node = nodes[i];
        nodeName = node._name;
        keys = node._keys;
        interpKey = this._interpolatedKeyDict[nodeName];
        foundKey = false;
        if (keys.length !== 1) {
          for (var currKeyIndex = this._currKeyIndices[nodeName];currKeyIndex < keys.length - 1 && currKeyIndex >= 0;currKeyIndex += offset) {
            k1 = keys[currKeyIndex];
            k2 = keys[currKeyIndex + 1];
            if (k1.time <= this._time && k2.time >= this._time) {
              alpha = (this._time - k1.time) / (k2.time - k1.time);
              interpKey._pos.lerp(k1.position, k2.position, alpha);
              interpKey._quat.slerp(k1.rotation, k2.rotation, alpha);
              interpKey._scale.lerp(k1.scale, k2.scale, alpha);
              interpKey._written = true;
              this._currKeyIndices[nodeName] = currKeyIndex;
              foundKey = true;
              break;
            }
          }
        }
        if (keys.length === 1 || !foundKey && this._time === 0.0 && this.looping) {
          interpKey._pos.copy(keys[0].position);
          interpKey._quat.copy(keys[0].rotation);
          interpKey._scale.copy(keys[0].scale);
          interpKey._written = true;
        }
      }

My understanding of it, is that it tries to match the entires of the Rigged Model with the entries of the animation. Now the problem happens, because of the names persisted in:

nodes[i];

are different than the dictionary indexes of:

 this._interpolatedKeyDict[nodeName];

I imported the same model and animation in unity and with some adjustments I was able to get the animation working on my character.

Does anyone have a clue how I could fix this ? I can’t really rename the indexes in unity, and the FBX Exporter does a bad job with the hirarchy where the export only shows: “CharacterX-Root” and not the entire hirarchy with hips, arms etc.

I’ll try some animation software such as Maya or something and see if I can get it to work.

Sure, try with Maya, it will probably fix the issue. Can you also check the debugger and tell me which line of code exactly the problem is in and also send me your entire code so that I can follow all the variables?

P. S - can you please see if you can help me with this - Scene change not functioning properly