【发布时间】:2014-04-14 17:37:20
【问题描述】:
我很难找出检查 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);
});
Frustum Culling 没有按照这里堆栈溢出问题中的描述工作:post1
这个post2 和这个post3 也很好地解释了这个话题,但不完全适合这种情况。
感谢您的帮助!
【问题讨论】:
-
运气好吗?我们现在正在尝试,并且使用 raycaster.intersectObjects(复数)无济于事,尽管当我们的相机物理撞到阻挡物体时它确实给了我们一个打击。 Raycaster.intersectObject(单数)总是给我们什么。
-
在另一种情况下对我有用的是使用 intersectObjects(toTest, true) 的递归参数。我完全忽略了这个参数。
标签: javascript three.js