THREE.js适合正交相机到场景 [英] THREE.js fit Orthographic camera to scene

查看:198
本文介绍了THREE.js适合正交相机到场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了很多关于堆栈溢出的相关问题,但我找不到这个问题的答案。

I've searched through many related questions on stack overflow, but I couldn't quite find the answer to this problem.

我有一个很大的动态组Object3D在我的场景中,用正交相机正面看着它们。

I have a big, dynamic group of Object3D's in my scene, with an orthographic camera looking at them head-on.

我想要一个简单的函数,当被调用时,它将简单地匹配顶部/左/右/右/缩放正交相机的属性以正确适合Object3D组。

I want to have a simple function which, when called, will simply match the top/left/bottom/right/zoom properties of the Orthographic camera to properly fit the Object3D group.

我尝试了各种各样的东西,但我的代码都不值得张贴。我需要从一个全新的角度来看这个(双关语)。我已经找到了各种其他的答案,一旦你知道从组的边界框的面到相机的距离,就会讨论改变相机的fov,但是我不知道如何使用正交相机来实现它,因为(据我所知,fov属性不起作用(也许它确实如此,我只是不知道)。

I've tried all kinds of things, but none of my code is worth posting. I need to look at this from a whole new angle (pun intended). I have found various other answers which discuss changing the fov of the camera, once you know the distance from the face of bounding box of the group to the camera, but I don't know how to implement that with an orthographic camera, since (as far as I've tried) the fov property doesn't work with it (maybe it actually does, I just don't know).

所以我不喜欢特别喜欢要求代码,但是我想要一个能够自动调整正交相机的相应属性以适合作为参数传递给它的对象的函数,例如:

So I don't particularly like asking for code, but nevertheless I would like a function which would automatically adjsut the appropriate properties of the Orthographic camera to fit the object passed to it as a parameter, for example:

function fitOrthographicCameraToObject3DGroup(group) {
    //implement here (my question)
}


推荐答案

设置边界框后,设置正交相机的上/下/下/右应该不是问题。只需占用边界框的一半长度。

Setting the top/left/bottom/right of the orthographic camera once you have the bounding box should not be a problem. Just take the half lengths of the bounding box.

缩放是问题所在,您可以通过按比例放大或缩小场景,将场景限制在单位立方体中。适当的数量取决于您的边界框大小。然后你不必担心变焦,上面的上/左/下/右值变为0.5 / 0.5 / -0.5 / -0.5。

The zoom is the issue and for that you can confine your scene in a unit cube by scaling up or down your scene by the appropriate amount depending on your bounding box size. Then you dont have to worry about the zoom and the above top/left/bottom/right values become 0.5/0.5/-0.5/-0.5.

这篇关于THREE.js适合正交相机到场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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