场景轴上的旋转,而不是对象

时间:2018-04-30 01:52:52

标签: javascript three.js

如何围绕世界轴旋转物体而不是物体本身? 我找到了答案,但没有任何对我有用。

如果旋转我想要旋转,那么我制作了一个层次结构,使它看起来有点像波浪。不幸的是,尽管我已经检查并测试了我的所有角度,但它的摇摆不同,我不能让它保持正常。

以下是我正在使用的功能:

function spinThePortal(portal, axis, speed, rotation) {
  if (axis === 0) {
    portal.rotation.y += speed;
  } else {
    portal.rotation.x += speed;
  }

  setTimeout(function () {spinThePortal(portal, axis, speed, rotation);}, 50);
}
function createPortals(firstDoubleCoor, secondDoubleCoor, number) {
  var direction = 1, notDirection = 0;
  if (firstDoubleCoor[0][0] === firstDoubleCoor[1][0]) {
    direction = 0; //vertical lines
    notDirection = 1;
  }
  var amount = difference(firstDoubleCoor[0][notDirection], firstDoubleCoor[1][notDirection]);
  var material = new THREE.MeshBasicMaterial({color: portalColorList[number]});
  var block = new THREE.CubeGeometry(baseSize / 20, baseSize / 20, baseSize / 20);
  function squiggle(coor) {
    var root = new THREE.Mesh(block, material);
    root.position.set(coor[0][0] * baseSize, coor[0][1] * baseSize, baseSize);
    var parent = root;
    for (var i = 0; i < amount * 43; i++) {
      object = new THREE.Mesh(block, material);
      object.position.x = baseSize / 30;
      parent.add(object);
      parent = object;
    }
    scene.add(root);
    root.traverse(function(object) {
      object.rotation.set(Math.PI / 10, Math.PI / 10, 0);
    });
    if (direction === 1) root.rotation.set(0, 0, -Math.PI / 4);
    else root.rotation.set(0, 0, Math.PI / 4);
    if (spinPortals) spinThePortal(root, direction, portalSpinSpeed, 0);
  }
  squiggle(firstDoubleCoor);
  squiggle(secondDoubleCoor);
}

我不知道问题是什么,但如果你需要查看我的完整创作,这里有一个链接:Click

0 个答案:

没有答案