在模型重复纹理 [英] Repeating Textures on a Model

查看:282
本文介绍了在模型重复纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是pretty的新3D内容Libgdx。我创建一个小游戏,你是在一个迷宫。迷宫组织在一个二维数组,描述了 X轴和Z possition 块键入。因此,它是瓷砖为主。可以说,每块 1立方米。现在,我的性格是2米的高大迷宫应该是4米高。所以我过海誓山盟加4块,如果有一个墙的瓷砖。当然,这是在 100 * 100 米/瓦迷宫巨大的性能影响,甚至与 Viewfrustum-和背面剔除。由于这是我的第一个3D游戏,我想保持它的简单,我不希望使用andvanced剔除技术(八叉树或其他:P)。所以我trye​​d创建 1 * 4 * 1 块而不是 1 * 1 * 1 并将其添加为我的世界。它的伟大工程,表现堪称完美试(60 FPS),但纹理(64 * 64像素)被拉长了,它看起来真的很丑。

I am pretty new to 3D with Libgdx. I am creating a little game, where you are in a maze. The maze is organized in a 2D Array, describing the x and z possition and the block type. So it is Tile-based. Lets say every block is 1 m³. Now my character is 2m tall and the maze should be 4m tall. Therefore i add 4 blocks over eachother if there is a wall on that tile. Of course this is a huge performance impact in a 100 * 100 meter/tile maze, even with Viewfrustum- and backface culling. As this is my first 3D game i want to keep it simple and i don't want to use andvanced culling techniques (octree or whatever :P). So i tryed to create 1*4*1 blocks instead of 1*1*1 and add them as Walls to my world. It works great, performance is perfect again (60 FPS), but the Texture (64*64px) is stretched up and it really looks ugly.

所以,我的问题是:

  1. 是否有可能重复纹理每米,而不是 伸展呢?
  2. 或者我需要修改的质感,有它的4倍 高?
  3. 或者是有一个更好的解决方案?
  1. Is it possible to repeat the texture every meter, instead of stretching it?
  2. Or do i need to modify the texture to have it 4 times as high?
  3. Or is there a even better solution?

编辑:我发现,那纹理活动的 TextureWrap 模式。我设置为 TextureWrap.Repeat ,但我不能设置 UV S上一个纹理。如果要创建一个雪碧出的纹理您可以轻松地将它们设置为4,重复纹理 4倍。但我不能添加雪碧我的型号,只有纹理是可能的。有没有办法重复那些纹理 S'

I found out, that Textures have the TextureWrap modes. I set that to TextureWrap.Repeat, but i can't set the UVs on a Texture. If you are creating a Sprite out of a Texture you can easily set them to 4 to repeat the Texture 4 times. But i can't add a Sprite to my Model, only Textures are possible. Is there a way to repeat those Textures?

推荐答案

你的纹理应用到你的模型的方法取决于模型中的每个顶点的UV值。

The way your texture is applied to your model depends on UV values of each vertex in the model.

如果你认为你的立方体的一个平面 - 它是由4个顶点的矩形。如果顶点具有UV值,如:(0,0),(1,0),(1,1),(0,1)那么你的整个纹理会在您的整个面呈现一次(因为你现在所拥有的)。

If you consider one plane of your cube - it is a rectangle made of 4 vertices. If you vertices have UV values like: (0,0), (1,0), (1,1), (0,1) then your entire texture will be rendered once on your entire plane (as you have right now).

您需要的是改变一些你的UV值4,而不是1 - 你应该使用类似(0,0),(1,0),(1,4),( 0,4) - 这样一来你的纹理将被重复4次。

What you need is to change some of your UVs value to 4 instead of 1 - you should use something like (0,0), (1,0), (1,4), (0,4) - this way your texture will be repeated 4 times.

不幸的是,我不知道如何改变的UV在Libgdx,也许别人会有所帮助。

Unfortunately I don't know how to change UVs in Libgdx, maybe somebody else will help here.

编辑在评论的问题:

您知道,每个顶点渲染都有自己的三维位置向量,由 X,Y,Z 组件。这种再presents在三维空间中的位置。

You know that each vertex you render has its own 3D position vector, made of x,y,z components. This represents the position in a 3D space.

如果您要添加的质感,你需要告诉你的顶点处的纹理的点是。你定义一些2D向量重新presents点的纹理(你也可以使用3D纹理,但我们坚持以2D比如现在)。

If you want to add texture, you need to tell to your vertex at which point of texture it is. You define some 2D vector that represents a point in your texture (you can also use 3D textures but let's stick to 2D example for now).

您的纹理向量分量可以被命名为 X,Y 还可以,但要避免与位置数据,有人可能混淆决定给他们打电话 U,V (这是经常在数学做这样的事情,即使你存储相同类型的数据,这使得一些公式更易于阅读和理解)。这些载体被称为总之纹理坐标的UV

Your texture vector components could be named x,y also, but to avoid possible confusions with position data somebody decided to call them u,v (it's quite often in mathematics to do such things, even if you store the same type of data it makes some equations easier to read and understand). Those vectors are called texture coordinates or UVs in short.

现在想象一下,你有你的纹理在你的面前,它的一个角是(0,0)键,相反的是,在( 1,1)。你采取一些三角形的和为贵利用其覆盖人数每个顶点3个顶点,你记住这一点上你的纹理。然后,当您连接所有3点,你会得到相同的三角形,你会得到渲染。

Now imagine you have your texture in front of you, one of its corners is at (0,0) and the opposite is at (1,1). You take 3 vertices of some triangle and for each vertex you take its UVs and you mark this point on your texture. Then, when you connect all 3 points you'll get the same triangle as you would get from the rendering.

但是,如果你的UV成分之一比 1 大或小于 0 ?为简单起见,我们可以说,GPU将采取相同的纹理,并复制它只是之后原来的(这是行不通的正是这种方式,但结果是一样的)。这回答你关于 4 若干问题 - 如果我们使用一个纹理坐标如(1,4)这意味着我们再动4 * textureHeight从原产地,所以你有你的纹理重复4次。

But what if one of your UVs component is bigger than 1 or smaller than 0? For simplicity we could say that GPU will take the same texture and copy it just after the original one (it doesn't work exactly this way but the result is the same). This answers your question about the 4 number - if we used a texture coordinate like (1,4) it means we're moving 4* textureHeight from origin, so you'll have your texture repeated 4 times.

我想,现在你应该找到一种方法,乌布苏添加到您的顶点,并尝试这个有点。尝试设置0,0.1,1,10,等...因为你的纹理坐标,并期待它给你。这样,您就应该有一些基本的了解如何做的UV工作。

I think that for now you should find a way to add UVs to your vertices and experiment with this a bit. Try to set 0, 0.1, 1, 10, etc... as your texture coordinates and look what it gives you. This way you should get some basic understanding how does UVs work.

这篇关于在模型重复纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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