如何获得两个不同的非索引缓冲区几何的两个不同面之间的交集?

时间:2019-06-09 08:54:04

标签: javascript three.js intersection raycasting face

如何与非索引缓冲区几何图形相交?我想检测两个不同的非索引缓冲区几何的两个不同面之间的交集。我从每个面的中间设置光线,但是raycaster不适用于非索引几何。

我想看到这样的结果: enter image description here

非常感谢您!

我的代码


var box = new THREE.Mesh(geometry.toNonIndexed(), material);

var raycaster = new THREE.Raycaster();
var intersects = [];

var pos = box.geometry.attributes.position;
var ori = new THREE.Vector3();
var dir = new THREE.Vector3();

var a = new THREE.Vector3(),
  b = new THREE.Vector3(),
  c = new THREE.Vector3(),
  tri = new THREE.Triangle();



var faces = pos.count / 3;
for (let i = 0; i < faces; i++) {
  a.fromBufferAttribute(pos, i * 3 + 0);
  b.fromBufferAttribute(pos, i * 3 + 1);
  c.fromBufferAttribute(pos, i * 3 + 2);
  tri.set(a, b, c);
  tri.getMidpoint(ori);
  tri.getNormal(dir)
  // scene.add(new THREE.ArrowHelper(raycaster.ray.direction, raycaster.ray.origin, 30, 0xff0000));
  raycaster.set(ori, dir);
  intersects = raycaster.intersectObject(box, true);

  if (intersects.length > 0) {

    console.log(intersects[0]);

  }
}

0 个答案:

没有答案