Trying to understand texture coordinates - UV mapping

Anything libgdx related goes here!

Trying to understand texture coordinates - UV mapping

Postby gadw » Sun Aug 12, 2018 6:48 pm

Hi,
I'm developing 3D and I came across the UV mapping for texturing. I have a triangle I'm drawing and applying texture to it:
Code: Select all
MeshPartBuilder.VertexInfo test1 = new MeshPartBuilder.VertexInfo();
        MeshPartBuilder.VertexInfo test2 = new MeshPartBuilder.VertexInfo();
        MeshPartBuilder.VertexInfo test3 = new MeshPartBuilder.VertexInfo();
        Vector2 uv1 = new Vector2(1, 1);
        Vector2 uv2 = new Vector2(1, 0);
        Vector2 uv3 = new Vector2(0, 1);
        meshBuilder.triangle(
                test1.set(corner00.set(12, 30, 0), new Vector3(1, 0, 0), null, uv1),
                test2.set(corner01.set(12, 30, 8), new Vector3(1, 0, 0), null, uv2),
                test3.set(corner10.set(8, 30, 0), new Vector3(1, 0, 0), null, uv3));

And this shows that:
Image
Everything's ok on that.

But now I'm taking the left vertex a little down:
Code: Select all
meshBuilder.triangle(
                test1.set(corner00.set(12, 30, 0), new Vector3(1, 0, 0), null, uv1),
                test2.set(corner01.set(12, 30, 8), new Vector3(1, 0, 0), null, uv2),
                test3.set(corner10.set(8, 30, -2), new Vector3(1, 0, 0), null, uv3));

And this shows:
Image

I can't understand why the texture is stretched that why? Why the texture is not staying in the same way? Is there are a way to keep the vertices move, but the texture stays in the same pose?

Thanks
gadw
 
Posts: 5
Joined: Mon Jun 26, 2017 9:25 am

Re: Trying to understand texture coordinates - UV mapping

Postby evilentity » Sun Aug 12, 2018 7:30 pm

UV specifies texture coordinates for given vertex, it doesnt matter where the vertex is. If you modify a vertex and want it to look the same you need to modify uvs as well.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4383
Joined: Wed Aug 24, 2011 11:37 am

Re: Trying to understand texture coordinates - UV mapping

Postby gadw » Sun Aug 12, 2018 7:39 pm

Alright. The problem is I can't seem to understand how to update the UVs according to the vertices?
gadw
 
Posts: 5
Joined: Mon Jun 26, 2017 9:25 am


Return to Libgdx

Who is online

Users browsing this forum: shatterblast and 1 guest