Three.js - 如何检查对象是否对相机可见

het*_*sch 7 javascript three.js

我很难弄清楚什么是检查相机眼睛是否可以看到Object3d的最佳方法.

我在屏幕中间有一个球体.一些立方体随机添加在其表面上.我需要的是一种方法来检查哪些立方体是可见的(在球体的前半部分),哪一个是不可见的(在球体的后半部分)用于相机的眼睛.

到目前为止我发现的似乎是正确的方向 - 但我必须错过THREE.Raytracer类的东西.

这是我正在使用的代码的小提琴:jsfiddle.我试图让它尽可能清楚.

这部分小提琴可能包含错误的代码:

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);
}); 
Run Code Online (Sandbox Code Playgroud)

Frustum Culling没有像这个堆栈溢出问题中所概述的那样工作:post1

post2和这篇文章3正在解释这个话题非常好,但对于这种情况并不完全.

谢谢你的帮助!

gai*_*tat 4

您想了解遮挡剔除技术。视锥体剔除工作正常,但不是您所描述的那样。视锥体剔除仅检查对象(或其边界框)是否位于相机金字塔内部。特别是当您想要消除被视锥体内其他对象遮挡的对象时,除了视锥体剔除之外,还可以执行遮挡剔除。但这并不是一件容易的事。