我正在努力找到最佳方法来检查Object3d是否对相机可见。
屏幕中央有一个球体。一些立方体随机添加在其表面上。我需要一种方法来检查哪些立方体对相机可见(在球体前半部分),哪些不可见(在球体后半部分)。
到目前为止,我发现的似乎是正确的方向,但我可能遗漏了与THREE.Raytracer类有关的内容。
这是我使用的代码的fiddle链接:jsfiddle。我已尽可能地使它清晰明了。
这个fiddle的这一部分可能包含有错误的代码:
var raycaster = new THREE.Raycaster();
var origin = camera.position, direction, intersects, rayGeometry = new THREE.Geometry(), g;
pointGroup.children.forEach(function(pointMesh) {
direction = pointMesh.position.clone();
// I THINK THIS CALCULATION MIGHT BE WRONG - BUT DON'T KNOW HOW TO CORRECT IT
raycaster.set(origin, direction.sub(origin).normalize());
// if the pointMesh's position is on the back half of the globe, the ray should intersect with globe first and the hit the point as second target - because the cube is hidden behind the bigger sphere object
intersects = raycaster.intersectObject(pointMesh);
// this is always empty - should contain objects that are located on the back of the sphere ...
console.log(intersects);
});
锥台剔除在这个Stack Overflow问题中没有按照预期工作: post1
此外,post2和post3解释得非常好,但并不完全适用于这种情况。
谢谢您的帮助!