Could somebody please show me how to calculate UV coords and how to use TextureAtlas helper?
For learning purpose I’ve made loop which generates triangles one by one on X axis, in single mesh.
Of course when I applied that same texture coords (0,0 1,0 0,1) for every triangle, only frist one has proper texture and others are flipped in some pattern.
Is it possible to calculate these abstract flipped texture coordinates for n-th triangle basing on it’s position and rotation relative to first triangle?
And is it possible to do with TextureAtlas, or is it only for working with separate geometries?
Actually I’m not sure what I’m talking about.
Following tutorials, I see only example with 2 dimensional buffer for texture coordinates, also I know it’s more optimized.
Currently I’m able to generate my terrain and objects using single Geometry object which is triangle with desired texture and then I glue them all together with GeometryBatchFactory.optimize(). But I don’t think it’s well optimized approach from CPU perspective. So I already made algorithm which builds terrain up using vertices and then makes one geometry which is let’s say a chunk, but I don’t know how to apply textures there.
Could you advise me which technique is better, UV or triplanar in my case, assuming that I use custom shapes, not just cubes.
Edit: Maybe I’ll change my question. Could you give me link to some tutorials from which I can learn how both techniques work, what are differences, and how can I apply different textures in single mesh.
If you are sharing vertices from one triangle to the next, you will have to accommodate this with the texture coordinates. e.g. the last two vertices of one triangle are indexed as the first two vertices of the next triangle in succession. (like a Quad or a Mesh using TriangleStrip mode)
For example, to make a quad from two triangles using only 4 distinct vertices, the first three vertices will describe a triangle covering one half of the quad up to the diagonal, and the two vertices making up the diagonal line could be used as the first two vertices of the second triangle,… but to finish the third vertex of the second triangle, the fourth quad vertex will need it’s own separate texture coordinate not currently in use by the other three . Otherwise, if you use the first vertex’s texture coordinate for the fourth vertex, the texture will appear flipped (and maybe upside down due to the winding order of the second and third vertices).
@pspeed is right, without seeing the code, any suggestions will be a shot in the dark at best.