Three.js中导入的FBX模型的另一个网格周围的网格旋转问题

问题描述 投票:0回答:1

出于学习目的,我从一个网站上下载了一个免费的FBX模型,该网站恰好是一架直升机。我想在Three.js中以编程方式模拟直升机叶片的旋转。我通过FBXLoader成功导入了模式,没有任何问题。我在Blender中检查了它的网格,它有五十多个网格。我查明了刀片的网格,并将其写在load()函数中:

      pivotPoint = new THREE.Object3D();
      const loader = new THREE.FBXLoader();
      group = new THREE.Object3D();

  loader.load(
    'Apache.fbx',
     object => {
          scene.add(object);

         const twentyFive = scene.getObjectByName('Mesh25'); //This is the shaft which the blades should rotate around
         console.log(twentyFive); //x: 685.594482421875, y: 136.4067840576172, z: -501.9534606933594
         twentyFive.add(pivotPoint);

         const twentyEight = scene.getObjectByName('Mesh28');//These four are the blades
         const twentyNine = scene.getObjectByName('Mesh29');
         const twentySeven = scene.getObjectByName('Mesh27');
         const twentySix = scene.getObjectByName('Mesh26');

         group.add(twentyEight);
         group.add(twentyNine);
         group.add(twentySeven);
         group.add(twentySix);

         pivotPoint.add(group);
         scene.add(pivotPoint);
         scene.add(twentyFive);

      },
        progress => ...,
        error => ...
       );

以及循环渲染功能中的以下内容:

pivotPoint.rotation.y += 0.01;

但是,一旦我添加了嵌套的Object3D,四个刀片就消失了,或者在将代码更改为具有多种变化的上述版本后,四个刀片将奇怪地绕着天空中的其他点旋转,除了机身,而灾区的飞行员看着这场灾难,被上述守则惊呆了,好像直升机即将坠毁!我尝试对代码进行许多更改。基本上,我曾经在另一个场景中的某些光源上使用过Object3D育儿,但现在不知道出了什么问题。此外,叶片绕Mesh25(我希望的枢轴)旋转的是一个大圆,没有与机身接触,尽管这四个叶片都围绕其质心旋转。我非常感谢您的帮助,因为我确实需要学习与类似的进口型号搏斗。

three.js rotation pivot axis mesh
1个回答
0
投票

在适当的地方使用attach代替attach

add

这首先假设正确创建了模型,并且轴的位置 const twentyFive = scene.getObjectByName('Mesh25'); // add the pivot and group first so they are in the scene pivotPoint.add(group); twentyFive.add(pivotPoint); const twentyEight = scene.getObjectByName('Mesh28'); const twentyNine = scene.getObjectByName('Mesh29'); const twentySeven = scene.getObjectByName('Mesh27'); const twentySix = scene.getObjectByName('Mesh26'); // use attach to move something in the scene hierarchy without // changing its position group.attach(twentyEight); group.attach(twentyNine); group.attach(twentySeven); group.attach(twentySix); 位于轴的中心。

注意:如果轴的原点位于正确的位置,并且刀片已经是轴的子代,则只需旋转轴即可。

© www.soinside.com 2019 - 2024. All rights reserved.