首页 > 解决方案 > 在特定时间播放混音器动画( playAt() 或 skipTo() )

问题描述

我在 .gltf 中有一个基本的网格动画,我想在特定时间以秒为单位播放。

这是加载器和混合器设置:

GLTFLoader.load( 'myscene.gltf', function ( gltf ) {

    model = gltf.scene;
    scene.add( model );

    mixer = new THREE.AnimationMixer( model );
    mixer.clipAction(gltf.animations[0])
        .setDuration( 60 ) //total of 1 min
        .play(); 

    render();
});

render()我有:

function render() {

        var delta = clock.getDelta();

        if (mixer != null) {
            mixer.update(delta);
        };

        //console.log(delta); //Doesn't show anything valuable.

        renderer.clear();
        composer.render();
        counter++;
}

到目前为止,我尝试过,.startAt(10)这只是播放前的延迟。它真的应该重命名为.delay(). startAt()应该是我要找的。我也试过.play(10)which 不起作用。mixer.time确实返回自播放以来经过的实际时间(以秒为单位),但它不能设置为任何值。

我不明白整个clock.getDelta()事情,因为数字似乎重复,它怎么知道要玩什么。如何使动画在动画中的 10 秒处开始...或者特定的关键帧编号?

标签: javascriptthree.js

解决方案


当你调用 时.clipAction(),你会得到一个AnimationAction类型的对象,你可以用它来链接命令(就像你在上面的例子中所做的那样)。您可以将其存储在变量中,而不是链接,然后使用.time属性AnimationAction来告诉它从哪里开始。

var mixer = new THREE.AnimationMixer( model );
var action = mixer.clipAction( gltf.animations[ 0 ] );
action.setDuration( 60 )
action.play();
action.time = 5;

您可以在文档的此页面中阅读有关该.time属性的更多信息。


推荐阅读