javascript - 在特定时间播放混音器动画( 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 秒处开始...或者特定的关键帧编号?
解决方案
当你调用 时.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
属性的更多信息。
推荐阅读
- nginx - 如何在通过 Helm 安装的 Nginx DaemonSet 中禁用 HTTPS?
- c++ - c++中字符串插值的最简单语法
- flutter - 在 Flutter 中对齐 GridView 内的项目
- python - 破折号表:当 dbc.Card 太小时换行
- openrefine - OpenRefine - 在列中拆分多个值并填充 1 或相应的名称
- python - 使用 Python 制作 R2 图
- python - Python 在 sulbist 中搜索项目列表 A 并返回列表 A 中未找到项目的索引
- javascript - TypeError:无法读取 JQuery cdn 未定义的属性“requestContent”
- spring-boot - Spring Boot 2.3.1:缺少托管 bean
- java - 更新到 Java JDK 11 后,Maven Surefire 测试失败