程序图渲染优化:只绘制可见部分?

发布于 2024-12-11 12:50:57 字数 618 浏览 0 评论 0原文

背景

假设我有数百万 个互连的 Node 实例,它们一起形成一个图。每个节点都有一个2D位置。用户必须能够平移该图的程序渲染。每个Node都有一个draw方法,但是如果我每帧都draw所有Node,速度会非常慢。

由于用户通常不想看到整个图形而是放大图形,因此优化在于不绘制屏幕外的节点

我的方法

将 2D 世界空间划分为矩形。将每个 Node 分配给它们所在的任何 Segment。绘图时,首先找出用户视图与哪一组 Segment 相交,然后 < code>仅绘制这些Segment中的Node

现在我的实际问题是:

如何确定的最佳大小?(让它太大,这与绘图是一样的)让它太小,就会有太多的东西需要迭代。)

Background

Let's say I have millions of interconnected Node instances which together form a graph. Each Node has a 2D position. A user has to be able to pan through a procedural render of this graph. Each Node has a draw method, but if I draw all Nodes every frame, it's very slow.

As the user does not usually want to see the whole graph but instead is zoomed in, the optimisation is in not drawing the Nodes that are off screen.

My approach

Divide the 2D world space into rectangular Segments. Assign each Node to whatever Segment they're in. When drawing, find out first which set of Segments the user's view intersects with and draw only the Nodes in those Segments.

Now for my actual question:

How do I determine the optimal size of a Segment? (Make it too big and it's the same thing as drawing everything. Make it too small and there are again too many to iterate through.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清浅ˋ旧时光 2024-12-18 12:50:57

我认为四叉树在这里可能比划分为固定大小的矩形更有帮助。

I think Quad trees may be more helpful here than the division into fixed-size rectangles.

尽揽少女心 2024-12-18 12:50:57

嗯,你总是可以通过反复试验来确定它。
顺便说一句,片段的大小可能取决于缩放级别。

另一种可能的解决方案是拥有两个排序的节点数组。一个数组 Node[] axx 位置排序,另一个 Node[] ayy 位置排序。
如果要显示 (x1, y1) - (x2, y2) 中的节点,您将构建一组位于用边界过滤的排序数组的交集处的节点。

Well, you can always determine it by trials-and-errors.
By the way, the size of the segment may depend on the zoom level.

Another possible solution is to have two sorted arrays of nodes. One array Node[] ax sorted by the x position and the other Node[] ay by the y position.
If you want to display nodes in (x1, y1) - (x2, y2), you will build a set of nodes which are at the intersection of the sorted arrays filtered with the bounds.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文