我很难弄清楚什么是检查相机眼睛是否可以看到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 …Run Code Online (Sandbox Code Playgroud) 如何尽可能快地检测到相机的眼睛是否可以看到 Threejs 对象?该obj.visible属性是二传,所以没有用的。此外frustumCullum还不够,因为它仅指示对象是否在相机视口之外。我需要知道一个物体是否隐藏在另一个更大的物体后面。
有人有想法吗?
干杯
马库斯