从fbx模型构建骨架

时间:2018-09-20 21:14:42

标签: animation three.js fbx

我试图将搅拌机的电枢导出为FBX文件,然后使用FBXLoader加载后,用其构造骨架。然后,我想将其与带有皮肤的网格角色合并。我的目标是拥有不同的模型和不同的姿势,并能够在它们之间进行混合和匹配。

我试图在此处创建它的代码笔:https://codepen.io/michael-tipton/pen/mGvvQr?editors=0011 1 但是fbxloader并未从Dropbox中提取文件。不确定如何进行。

从FBX文件创建骨骼的主要功能如下:

function createBones( root , array ) {
            if(root === null && root === undefined ) {
              return;
            } else {
              let bone = new THREE.Bone();

              bone.position.set( root.position.x, root.position.y, root.position.z );
              bone.name = root.name;
              bone.setRotationFromQuaternion( root.quaternion );
              bone.scale.set( root.scale.x, root.scale.y, root.scale.z );
              if(root.parent !== null && root.parent !== undefined ) {
                  bone.parent = root.parent;
              }
              array.push(bone);

              for(let i = 0, count = root.children.length; i < count; i++) {
                  createBones(root.children[i], array);
              }
              return;
            }
        }

我很难确定如何进行故障排除。我尝试使用skeletonhelper,但电枢是如此扭曲,并且与模型(也非常小)不同,以至于让我知道发生了什么情况并不是特别有用。

我不确定电枢是否正确加载,我是否没有正确地重新创建骨骼或其他原因。当我尝试对电枢进行某种形式的运动时,蒙皮网完全没有运动。

是否有人在解决此类问题方面有经验,或者对我如何了解正在发生的事情有任何想法?感谢您阅读本文,并获得100万业障积分!

1 个答案:

答案 0 :(得分:0)

首先,我注意到控制台中的消息泛滥,因此我从动画中注释了您的console.log:

var animate = function() {
  const v = Date.now() / 2000
  var hips = scene.getObjectByName("hips");
  if (hips) {
    hips.position.x = Math.sin(v) * 10
    hips.position.z = Math.cos(v) * 10
  }
  //console.log(hips);
}

那是我注意到CORS问题的时候,所以在本地下载了文件。
然后我收到一个有关缺少的库(inflate.min.js)的错误,该错误已下载并添加到项目中。

这是“为我工作”中的代码,不再出现控制台错误:
https://raw.githack.com/heldersepu/hs-scripts/html/HTML/bones/bones.html

相关问题