在特定时间播放混音器动画( playAt() 或 skipTo() ) [英] Play mixer animation at a specific time ( playAt() or skipTo() )

查看:26
本文介绍了在特定时间播放混音器动画( playAt() 或 skipTo() )的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a basic mesh animation in a .gltf that I want to play at a specific time in seconds.

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

Here's the loader and mixer setup:

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) 这不起作用.mixer.time 确实返回播放后经过的实际时间(以秒为单位),但不能设置为任何值.

So far I tried with .startAt(10) which is just a delay before playing. It should really be renamed to .delay(). startAt() should be what I'm looking for. I've also tried with .play(10) which doesn't work. mixer.time does return the actual time ellapsed since play in seconds but it cannot be set to anything.

我不明白整个 clock.getDelta() 的事情,它是如何知道要播放什么的,因为这些数字似乎是重复的.如何让动画从动画中的 10 秒开始......或者特定的关键帧编号?

I don't understand the whole clock.getDelta() thing and how does it know what to play since the numbers seem to repeat. How do I make the animation start at say 10 second in the animation... or specific keyframe number maybe?

推荐答案

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

When you call .clipAction(), you get an object of AnimationAction type, which you can use to chain commands (as you did in your example above). Instead of chaining, you can store this in a variable, and then use the .time property of AnimationAction to tell it where to start.

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

您可以阅读有关 .time 属性的更多信息 在文档的这个页面.

You can read more about the .time property in this page of the docs.

这篇关于在特定时间播放混音器动画( playAt() 或 skipTo() )的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆