结合动画而不是混合?

时间:2018-03-26 17:53:10

标签: three.js gltf

我将蒙皮网格上的动画从在Blender中创建的glTF导入到THREE.js 我有两个同时影响骨骼平移的动画。在Blender中,这些翻译是相加的,但在THREE.js中它们按重量平均。

例如,动画是翻译(2,0,0)和翻译(4,0,0) 如何让AnimationMixer得到(6,0,0)而不是(3,0,0)?

1 个答案:

答案 0 :(得分:0)

对于我的特定需求,我实际上只需要第一帧和最后一帧的值(它们是所有3帧动画,第二帧是默认值)。所以我从关键帧轨道中提取值,并且根本不使用动画系统。       //将动画转换为值       功能convertAnim(clip){

    var anims = [];

      for ( i = 0; i < clips.length; i ++ ){

      anims[i] = {name: "name", bone: []};
      anims[i].name = clips[i].name;

        for ( j = 0; j < clips[i].tracks.length; j++ ){

            var val = clips[i].tracks[j].values

            if ( clips[i].tracks[j].name.indexOf( 'position' ) > -1 ) {
                anims[i].bone[j] = { name: "name", minTranslate: "min", maxTranslate: "max"};
                anims[i].bone[j].name = clips[i].tracks[j].name;

                anims[i].bone[j].minTranslate = new THREE.Vector3( val[0], val[1], val[3] );
                anims[i].bone[j].maxTranslate = new THREE.Vector3( val[val.length - 3], val[val.length - 2], val[val.length - 1] );
            }

            else if ( clips[i].tracks[j].name.indexOf( 'scale' ) > -1 ) {
                anims[i].bone[j] = { name: "name", minSize: "min", maxSize: "max"};
                anims[i].bone[j].name = clips[i].tracks[j].name;

                anims[i].bone[j].minSize = new THREE.Vector3( val[0], val[1], val[2] );
                anims[i].bone[j].maxSize = new THREE.Vector3( val[val.length - 3], val[val.length - 2], val[val.length - 1] );
            }

            else if ( clips[i].tracks[j].name.indexOf( 'scale' ) > -1 ) {
                anims[i].bone[j] = { name: "name", minRotation: "min", maxRotation: "max"};
                anims[i].bone[j].name = clips[i].tracks[j].name;

                anims[i].bone[j].minRotation = new THREE.Quaternion( val[0], val[1], val[2], val[3] );
                anims[i].bone[j].maxRotation = new THREE.Quaternion( val[val.length -4], val[val.length - 3], val[val.length - 2], val[val.length - 1] );
            }           
        }
      }

    return anims;

  }