Libgdx ModelBuilder.createRect从一个侧面才能看到 [英] Libgdx ModelBuilder.createRect only visible from one side

查看:327
本文介绍了Libgdx ModelBuilder.createRect从一个侧面才能看到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的第一个libgdx 3D游戏现在我从 createBox 切换到 createRect ,只创建可见的脸(如果一个壁是上的另一个壁的左侧,其右侧面是不可见的...)。我创建4个型号:

In my first libgdx 3D game i now switched from createBox to createRect, to create only the visible faces (if a wall is on the left side of another wall, its right face is not visible...). I am creating 4 models:

  1. frontFace
  2. 背面
  3. rightFace
  4. leftFace
  1. frontFace
  2. backFace
  3. rightFace
  4. leftFace

他们几乎绘制他们实际上应该如何。 但有一个大问题:侧面只有当我看向正 Z方向可见。 如果我把对方(负 Z方向),他们不画。正面和背面只画,如果我期待他们在负 X方向。 有这个事做的法线?我已经将它们设置为:

They are almost drawn how they actually should. But there is one big issue: The side faces are only visible if i look in the positive z-Direction. If i look the other side (negative z-Direction), they don't draw. The front and back faces only draw, if i look to them in negative x-Direction. Has this something to do with the normals? I have set them to:

normal.x = 0;
normal.y = 1;
normal.z = 0;

时的错误?我应该怎么设置法线?它们代表什么呢?我对照明法线贴图的一些基本思想,是一样的吗?

Is that the error? How should i set the normals? What do they stand for? I have some basic idea about normal mapping for lighting, is that the same?

重要提示:我已禁用背面剔除,但它并没有任何区别。视域剔除已打开。如果需要更多的信息,请发表评论,我会尽快将其添加为可能的。谢谢

Important note: I have disabled backface culling, but it did not make any difference. View frustum culling is turned on. If any more informations are needed please post a comment and i will add them as soon as possible. Thanks

推荐答案

也许没有直接关系,但仍需要注意:不要用createRect或createBox以外的任何调试/测试等。相反,将多个形状合并到一个单一的模型/节点/一部分。甚至更好,使用建模应用程序,其中可能的。

Perhaps not directly related, but still important to note: don't use createRect or createBox for anything other than debugging/testing. Instead combine multiple shapes into a single model/node/part. Or even better, use a modeling application where possible.

您没有具体说明如何禁用背面剔除。但请记住,你不应该改变着色器/ RenderContext中之外OpenGL的状态(这样做将会导致联合国predicted行为)。要禁用背面消隐您可以利用材料的属性 IntAttribute.CullFace (见指定它:的https://github.com/libgdx/libgdx/wiki/Material-and-environment#wiki-intattribute),在DefaultShader(或默认ModelBatch)配置 defaultCullFace 成员(见<一href="http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/shaders/DefaultShader.Config.html#defaultCullFace" rel="nofollow">http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/shaders/DefaultShader.Config.html#defaultCullFace)或(DE precated)静态 DefaultShader#defaultCullFace 成员(见<一href="http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/shaders/DefaultShader.html#defaultCullFace" rel="nofollow">http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/shaders/DefaultShader.html#defaultCullFace).

You didn't specify how you disabled backface culling. But keep in mind that you should not change the opengl state outside the shader/rendercontext (doing so will result in unpredicted behavior). To disable backface culling you can either specify it using the material attribute IntAttribute.CullFace (see: https://github.com/libgdx/libgdx/wiki/Material-and-environment#wiki-intattribute), the DefaultShader (or default ModelBatch) Config defaultCullFace member (see http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/shaders/DefaultShader.Config.html#defaultCullFace) or the (deprecated) static DefaultShader#defaultCullFace member (see http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/shaders/DefaultShader.html#defaultCullFace).

无论一个面是正面或背面是基于顶点绕组。或者换句话说:在其中提供矩形的角的顺序来决定哪一面是正面和哪一侧是背面。如果您使用的RECT方法之一,你会发现自变量要么在 00 01 10 11 后缀。在此,当着眼于面,00是左下,01左上角,11是右上和10是右下

Whether a face is front or back is based on the vertex winding. Or in other words: the order in which you provide the corners of the rectangle is used to decide which side is front and which side is back. If you use one of the rect methods, you'll notice the arguments have either the 00, 01, 10 or 11 suffix. Here, when looking at the face, 00 is lower-left, 01 upper-left, 11 is upper-right and 10 is lower-right.

对于一个矩形,这是正常的是垂直向外矩形面对的问题。例如,如果你有前表面上XZ平面的矩形与它的顶部,则其正常为X = 0,Y = 1,Z = 0。如果它的前表面朝向它的底部,那么它的正常为X = 0,Y = -1,Z = 0。同样,如果你有XY平面上的矩形,其正常或者是X = 0,Y = 0,Z = 1或X = 0,Y = 0,Z = -1。需要注意的是在正常不用于面部剔除,它最常用于照明等指定一个不正确的/相反的正常的意愿的的使面被剔除(它可能导致不正确的/黑照明虽然)

For a rectangle, it's normal is the perpendicular facing outwards the rectangle. For example if you have a rectangle on XZ plane with it front face on the top, then its normal is X=0,Y=1,Z=0. If its front face it facing the bottom, then its normal is X=0,Y=-1,Z=0. Likewise if you have a rectangle on XY plane, its normal is either X=0,Y=0,Z=1 or X=0,Y=0,Z=-1. Note that the normal is not used for face culling, it's most commonly used for lighting etc. Specifying an incorrect/opposite normal will not cause the face to be culled (it might cause incorrect/black lighting though).

这篇关于Libgdx ModelBuilder.createRect从一个侧面才能看到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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