Three.js,Raycaster,射线阵列?

时间:2017-03-01 08:09:22

标签: three.js raycasting

我有两条光线,一条在相机中心时突出显示网格,另一条在点击时突出显示网格。 JS Bin

// ...
raycasterClick = new THREE.Raycaster();
raycasterCenter = new THREE.Raycaster();
// ...
function animate() {
  requestAnimationFrame(animate);
  // ...
  // clear intersected
  for (var i = 0; i < INTERSECTED.length; i++) {
    INTERSECTED[i].material.emissive.setHex(INTERSECTED[i].currentHex);
    INTERSECTED.splice(i, 1);
  }
  // click
  raycasterClick.setFromCamera(mouse, camera);
  var intersects = raycasterClick.intersectObjects(scene.children);
  for (var i = 0; clickedIn && i < intersects.length; i++) {
    var length = INTERSECTED.push(intersects[0].object) - 1;
    INTERSECTED.currentHex = INTERSECTED[length].material.emissive.getHex();
    INTERSECTED[length].material.emissive.setHex(0xff0000);
  }
  // center
  raycasterCenter.setFromCamera(center, camera);
  var intersects = raycasterCenter.intersectObjects(scene.children);
  for (var i = 0; i < intersects.length; i++) {
    var length = INTERSECTED.push(intersects[0].object) - 1;
    INTERSECTED.currentHex = INTERSECTED[length].material.emissive.getHex();
    INTERSECTED[length].material.emissive.setHex(0xff0000);
    if(intersects[0].distance<=2&&controls.moveZ==-1)controls.moveZ=0;
  }
  // ...
}

我想知道是否必须像上面的示例中那样为每条光线调用new THREE.Raycaster(),或者有一种方法只能通过制作一组光线来调用它。对于数组,我只需要遍历所有scene.children一次。我在考虑资源。

如何在Three.js中创建光线数组?

0 个答案:

没有答案