首页 文章

验证clipAction动画何时在three.js中播放完毕

提问于
浏览
1

我在Blender中制作了一个动画网格,其中包含两个动画片段,我将其命名为intro和idle . 我用JSON中的Blender导出器导出它 . 一切都很好 . 我可以切换我想要播放的动画 . 我的问题是我想播放第一个动画 entirely ,然后切换到我将设置为循环的第二个动画 .

以下是我用于JSON和动画部分的代码部分:

var jsonLoader = new THREE.JSONLoader();
    jsonLoader.load('models/feuille(19fevrier).json',
    function (geometry, materials) {

        mesh = new THREE.SkinnedMesh(geometry,
            new THREE.MeshLambertMaterial({
            skinning: true
        }));

        mixer = new THREE.AnimationMixer(mesh);

        action.intro = mixer.clipAction(geometry.animations[ 0 ]);
        action.idle = mixer.clipAction(geometry.animations[ 1 ]);

        action.intro.setEffectiveWeight(1);
        action.idle.setEffectiveWeight(1);
        action.intro.enabled = true;
        action.idle.enabled = true;

        action.intro.setLoop(THREE.LoopOnce, 0);


        scene.add(mesh);

        scene.traverse(function(children){
            objects.push(children);
        });

        action.intro.play();

    });

我正在寻找的是 a function that tells me that the action is complete ,像clipAction完成播放时的onComplete事件 . 我在three.js GitHub上找到了这个回复:

mesh.mixer.addEventListener('finished',function(e){

   // some code

 });

它似乎有效,但我并不真正理解 addEventListener 在这种情况下,也不是 function(e) 的意思 .

the code I found on GitHub的链接

1 回答

  • 1

    addEventListener 是用于处理事件的标准JavaScript dispatchEvent/addEventListener concept的一部分 . 每当动画结束时,three.js动画子系统都会调度一个事件 . 来自 AnimationAction.js

    this._mixer.dispatchEvent( {
        type: 'finished', action: this,
        direction: deltaTime < 0 ? -1 : 1
    } );
    

    如您所见, e event参数为您提供完整的 AnimationAction 对象(e.action),以及表示动画方向的整数(e.direction) .

    不要因为这是无证件的行为而感到沮丧(three.js的增长速度远远超过Doob先生所能正确记录的速度) . 利用可用的功能,但要注意功能发布中可能发生的变化 .

相关问题