我很难确定什么是检查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);
});

Frustum Culling无法按此堆栈溢出问题中的概述进行操作:post1

同样,此post2和此post3解释的主题确实很好,但对于这种情况并不完全。

谢谢你的帮助!

最佳答案

您想看一下遮挡剔除技术。视锥剔除效果很好,不是您要描述的。视锥剔除仅检查对象(或其边界框)是否在相机金字塔内。当您要消除视锥内部的其他对象所遮挡的对象时,除了执行“视锥体剔除”外,还可以执行“遮挡剔除”。但这不是一件容易的事。

09-10 00:56
查看更多