使用CreateFromMorphTargetSequence Three.js使用动画加载3D模型

时间:2020-11-07 19:59:09

标签: javascript three.js gltf

我正在尝试加载此GBL文件并播放动画。此代码返回以下错误:

TypeError:无法读取Function.CreateFromMorphTargetSequence上未定义的属性“ length”

    Combinations
0   (a, f, e)
1   (a, d, f)
2   (b, c, d)
3   (a, a, d)
4   (f, b, c)
5   (e, b, b)
6   (e, e, d)
7   (c, f, f)
8   (f, e, b)
9   (d, c, e)

如何解决此错误并在播放动画时加载模型?

1 个答案:

答案 0 :(得分:2)

const morphClip = THREE.AnimationClip.CreateFromMorphTargetSequence('RingsRising',model.morphTargets);

Object3D的实例没有morphTargets属性。

从glTF资产播放动画应如下所示:

const animations = gltf.animations;
const mixer = new THREE.AnimationMixer( model );
mixer.clipAction( animations[ 0 ] ).setDuration( 1 ).play();

实时示例:https://threejs.org/examples/webgl_morphtargets_horse