与Libgdx高效的3D块渲染 [英] Efficient 3D block rendering with Libgdx

查看:642
本文介绍了与Libgdx高效的3D块渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是pretty的新的3D节目和libgdx。 我看了一些教程,我已经使我想要的场景。我有一些1X1X1块,用 ModelBuilder.createRect()创建的每一个可见的脸,因此,如果另一个块覆盖面这一块,有没有对这个块创建矩形。另外,顶部和底部的矩形是不需要的,因为我永远无法看到它们(除楼)。所以我想,这是pretty的效率。我也有背面剔除启用,我 Viewfrustum扑杀。不过,如果我看的方向,那里有很多块是我viewfrustum的FPS下降到15-20。这仍然是好适合我,因为我的笔记本电脑是超过5岁,它的性能是不是最好的,但这个答案让我想想。

To start with,I am pretty new to 3D programming and libgdx. I looked at a few tutorials and I already render the scene I want. I have some 1x1x1 blocks, created with ModelBuilder.createRect() for every visible face, so if another block covers a face of this block, there is no rect created for this block. Also the top and bottom rect is not needed, as I can never see them (except for the floor). So I thought, that this is pretty efficient. I also have Backface culling enabled and I do Viewfrustum culling. However, if I look in a direction, where many blocks are in my viewfrustum the FPS go down to 15-20. This is still okay for me, as my laptop is over 5 years old and its performance is not the best, but this answer made me think.

模型构建器仅用于调试。好吧,但是我应该如何再建立我的盒子?为什么要创建一个型号在建模的应用程序(如搅拌机),简单的方块?通过这样做,我甚至不能宰杀的脸,这是由其他模块占用。 所以我的问题是: 如何创建和渲染这些箱子的最有效方法是什么?

"ModelBuilder is used for debug only". Okay, but how should i then create my boxes? Why should i create a Model in a Modeling app (like Blender), for simple squares? By doing this i couldn't even cull the faces, which are occupied by other blocks. So my question is: How can i create and render those boxes the most efficient way?

推荐答案

模型构建器#createRect将为每个矩形的新模式。当渲染模型实例(的一部分),它意味着一个绘制调用。为此模型构建器#createRect是非常低效的。最好是多个矩形组合成模型的单一(一部分)。这可以使用来完成:

ModelBuilder#createRect will create a new model for each rectangle. When rendering a (part of a) model instance, it implies a draw call. Therefor ModelBuilder#createRect is extremely inefficient. It is better to combine multiple rectangle into a single (part of a) Model. This can be done using:

modelBuilder.begin();
MeshPartBuilder mpb = modelBuilder.part(....);
mpb.rect(...); // first rect.
mpb.rect(...); // second rect.
// etc.
Model model = modelBuilder.end();

请注意,这还没有足够有效的对如体素引擎。如果你的目标是优化体素,你可能会想建立网格的自定义RenderableProvider(域剔除和深度排序后)。这里有一个例子:<一href="https://github.com/libgdx/libgdx/tree/master/tests/gdx-tests/src/com/badlogic/gdx/tests/g3d/voxel" rel="nofollow">https://github.com/libgdx/libgdx/tree/master/tests/gdx-tests/src/com/badlogic/gdx/tests/g3d/voxel

Note that this is still not efficient enough for e.g. a voxel engine. If you are aiming to optimize for voxels, you'll probably want to build the mesh (after frustum culling and depth sorting) in a custom RenderableProvider. Here's an example: https://github.com/libgdx/libgdx/tree/master/tests/gdx-tests/src/com/badlogic/gdx/tests/g3d/voxel

这篇关于与Libgdx高效的3D块渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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