使用 Three.js 手动截锥 [英] Manual frustum culling with three.js

查看:32
本文介绍了使用 Three.js 手动截锥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用three.js 开发体素游戏.为此,我需要根据需要生成尽可能多的块来填充屏幕.目前,我正在围绕播放器加载一个半径为 20 的圆.

I'm working on a voxel game with three.js. For this, I need to generate as many chunk as required to fill the screen. Currently, I'm loading a circle of radius 20 around the player.

计算填充相机视锥所需的块的确切范围并避免计算不可见块的最简单方法是什么?

What is the simplest way to compute the exact range of chunks required to fill the camera frustrum and avoid computing invisible chunks ?

每个块都具有完全相同的大小(假设我们有一个具有正确值的矢量 size),并且处于 Y=0(X 和 Z 变化).

Every chunk has the exact same size (let's say we have a vector size with the correct value), and are at Y=0 (X and Z varying).

推荐答案

var frustum = new THREE.Frustum();
frustum.setFromMatrix( new THREE.Matrix4().multiply( camera.projectionMatrix, camera.matrixWorldInverse ) );

for (var i=0; i<objects.length; i++) {
  objects[i].visible = frustum.intersectsObject( objects[i] );
}

只有在相机视锥内的物体才会被渲染

only objects that are within camera frustum will be rendered

记录在此处

希望这对您有帮助吗?

这篇关于使用 Three.js 手动截锥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆