gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 04:44:16 27 4
gpt4 key购买 nike

我很难弄清楚什么是检查 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);
});

视锥体剔除未按照此处堆栈溢出问题中的概述工作:post1

还有这个post2还有这个post3正在很好地解释这个主题,但对于这种情况来说还不够。

谢谢你的帮助!

最佳答案

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

关于javascript - Three.js - 如何检查对象是否对相机可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22320124/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com