【发布时间】:2019-02-14 03:25:19
【问题描述】:
我目前正在three.js 中开发一个类似Tamagotchi 的浏览器应用程序。但目前我坚持实现一只手,点击时会抚摸头像。
Hand 是一个装配好的 Blender 模型,有 2 个动画,空闲和戳动画。在 gltf 查看器中,模型可以很好地处理两种动画。 但是在 js 中添加时,手要么完全扭曲,要么渲染正确但位置无法识别(与光标一起移动)。
我查看的大多数示例仅添加了一个一般场景,而不仅仅是一个动画模型。在这些动画的两个版本中,我都会收到动画错误。
扭曲版本的代码:
loader.load('resources/models/gltf/Hand.gltf', function(gltf) {
gltf.scene.traverse(function(node) {
if (node.isMesh) hand = node;
});
//hand.material.morphTargets = true;
scene.add(hand);
mixer = new THREE.AnimationMixer(hand);
clips = hand.animations;
hand = gltf;
scene.add(hand.scene);
});
第二个版本,Hand 被正确渲染,但无法识别事件处理的位置。
loader.load('resources/models/gltf/Hand.gltf', function(gltf) {
var hand = gltf.scene;
var animations = gltf.animations;
mixer = new THREE.AnimationMixer(hand);
for (var i = 0; i < animations.length; i++) {
mixer.clipAction(animations[i]).play();
}
scene.add(hand);
});
空闲动画功能:
function idleAnim() {
var idleClip = THREE.AnimationClip.findByName(clips, "Idle");
var action = mixer.clipAction(idleClip);
action.play();
console.log("idling");
}
链接:https://github.com/JoeJoe49/AnimTest
提前致谢和问候。
【问题讨论】:
标签: javascript three.js blender gltf