Three.js - 视图的宽度 [英] Three.js - Width of view
问题描述
有没有办法找出场景渲染部分的宽度?
Is there a way to find out the width of a rendered portion of the scene?
例如,如果我们有一个宽度为 100 的网格,但是以一定的缩放级别渲染...我如何计算正在屏幕中渲染的网格部分的宽度?
For example, if we have a mesh of width 100, but rendered with a certain level of zoom...how can I calculate the width of the portion of the mesh that is being rendered in the screen?
推荐答案
此处必须准确.
您可以计算给定相机视野 camera.fov
和给定距离 dist
与相机的可见矩形区域.
You can calculate the visible rectangular region given the camera's field-of-view, camera.fov
, and a given distance, dist
, from the camera.
由于对象可能具有深度,因此您必须通过网格选择一个平面,并在该距离处进行计算.
Since the object presumably has depth, you have to pick one plane through the mesh, and do the calculation at that distance.
这里是如何计算距相机给定距离 dist
的可见 height
和 width
.
Here is how to calculate the visible height
and width
for a given distance dist
from the camera.
var vFOV = THREE.MathUtils.degToRad( camera.fov ); // convert vertical fov to radians
var height = 2 * Math.tan( vFOV / 2 ) * dist; // visible height
var width = height * camera.aspect; // visible width
three.js r.117
three.js r.117
这篇关于Three.js - 视图的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!