Unity功能可立即从3D管道访问2D框? [英] Unity function to access the 2D box immediately from the 3D pipeline?

查看:120
本文介绍了Unity功能可立即从3D管道访问2D框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Unity中,假设您有3D对象,

In Unity, say you have a 3D object,

当然,获取AABB很简单,Unity具有直接功能,

Of course, it's trivial to get the AABB, Unity has direct functions for that,

(您可能必须以通常的方式将渲染器的所有边界框加起来,没有问题。)

(You might have to "add up all the bounding boxes of the renderers" in the usual way, no issue.)

现在,所定位的摄像机,AABB确实覆盖了某个2D边界框...

Now, for the Camera in question, as positioned, that AABB indeed covers a certain 2D bounding box ...

实际上...是否有某种内置的直接在Unity中找到橙色2D框的方法?

In fact ... is there some sort of built-in direct way to find that orange 2D box in Unity??

(请注意,要手动完成此操作,您只需要为AABB的8个点发出光线(或使用世界来筛选空间,就像Draco提到的一样);

(Note that to do it manually you just make rays (or use world to screen space as Draco mentions, same) for the 8 points of the AABB; encapsulate those in 2D to make the orange box.)

我不需要手动解决方案,我想问引擎是否每隔一帧就从管道中以某种方式提供此功能?

I don't need a manual solution, I'm asking if the engine gives this somehow from the pipeline every frame?

有电话吗?

(确实,拥有此功能会更好... )

(Indeed, it would be even better to have this ...)

我的感觉是一个或全部


  • 遮挡系统的特别之处

  • 着色器

  • 渲染器

肯定会知道图形卡旁边的橙色框,甚至是管道中的蓝色框,

would surely know the orange box, and perhaps even the blue box inside the pipeline, right off the graphics card, just as it knows the AABB for a given mesh.

我们知道Unity可以让您立即为给定网格的每一帧点击AABB 3D框:实际上,Unity可以

We know that Unity lets you tap the AABB 3D box instantly every frame for a given mesh: In fact does Unity give the "2D frustrum bound" as shown here?

推荐答案

据我所知,没有内置的



但是,找到自己的极限真的很容易。获取网格物体的边界框(如屏幕截图中所示的长方体)就是这样做的方式,您只是在变换后的空间中完成它。

As far as I am aware, there is no built in for this.

However, finding the extremes yourself is really pretty easy. Getting the mesh's bounding box (the cuboid shown in the screenshot) is just how this is done, you're just doing it in a transformed space.


  1. 遍历网格的所有顶点,执行以下操作:

  2. 点从本地空间转换为世界空间(可处理缩放和旋转)

  3. 将点从世界空间转换为屏幕空间

  4. 确定新点是否为X和Y高于/低于存储的最小/最大值,如果是,则用新值更新存储的最小/最大值

  5. 遍历所有顶点后,您将拥有4个值:min -X,min-Y,max-X和max-Y。现在您可以构造边界矩形

  1. Loop through all the verticies of the mesh, doing the following:
  2. Transform the point from local to world space (this handles dealing with scale and rotation)
  3. Transform the point from world space to screen space
  4. Determine if the new point's X and Y are above/below the stored min/max values, if so, update the stored min/max with the new value
  5. After looping over all vertices, you'll have 4 values: min-X, min-Y, max-X, and max-Y. Now you can construct your bounding rectangle

您可能还希望先执行模型的礼品包装,并且仅处理最终的凸包(因为没有点凸包的一部分将永远不在凸包的边界之内)。如果您打算在模型在屏幕上移动,缩放或旋转时绘制此屏幕空间矩形,并且必须重新计算边界框,则需要这样做并缓存结果。

You may also wish to first perform a Gift Wrapping of the model first, and only deal with the resulting convex hull (as no points not part of the convex hull will ever be outside the bounds of the convex hull). If you intend to draw this screen space rectangle while the model moves, scales, or rotates on screen, and have to recompute the bounding box, then you'll want to do this and cache the result.

请注意,如果模型动画(例如,如果您的人形生物站起来并跳跃了千斤顶),这无效。解决动画情况要困难得多,因为要解决凸包问题,必须将每个动画的每一帧都视为原始网格的一部分(以确保所有动画都不会移动网格的一部分)在凸包的外部),通过幂增加了复杂性。

Note that this does not work if the model animates (e.g. if your humanoid stands up and does jumping jacks). Solving for the animated case is much more difficult, as you would have to treat every frame of every animation as part of the original mesh for the purposes of the convex hull solving (to insure that none of your animations ever move a part of the mesh outside the convex hull), increasing the complexity by a power.

这篇关于Unity功能可立即从3D管道访问2D框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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