0

I am parsing an OBJ which has texture coordinates more than 1 and less than 0 as well. I then write it back by making the UV values in the range [0,1]. Based on the understanding from another question on SO, am doing the conversion to the range [0,1] as follows.

                if (oldU > 1.0) or (oldU < 0.0):
                    oldU = math.modf(oldU)[0] # Returns the floating part
                    if oldU < 0.0 :
                        oldU = 1 + oldU

                if (oldV > 1.0) or (oldV < 0.0):
                    oldV = math.modf(oldV)[0] # Returns the floating part
                    if oldV < 0.0:
                        oldV = 1 + oldV

But I see some jagged lines in my output obj file and the original obj file when rendered in some software:

enter image description here Original

enter image description here Restricted to [0,1]

1 Answer 1

2

This may work not as you've expected.

Given some triangle edge that starts at U=0.9 and ends at U=1.1 then after your UV clipping you'll get start at 0.9 but end at 0.1 so the triangle will use different part of your texture. I believe this happens at the bottom of your mesh.

In general there's no problem with using UV outside of 0-1 range so first try to render the mesh as it is and see if you have any problems.

If you really want to move UVs to 0-1 range then scale and move UVs instead of clipping them per vertex. Iterate over all vertices and store min and max values for U and V, then scale UV for every vartex, so min becomes 0 and max becomes 1.

5
  • Thank you. I understood the problem, but I still do not understand how scaling the values will resolve this issue ? If a triangle edge is the way you describe it, I can never represent it by giving it values between 0 and 1. Instead I should probably further break down triangles with such edges in a way that all the new generated triangles have all their vertices on one side of the boundary. Then probably scaling will be of help. Could you please explain a bit more ?
    – Amit Tomar
    Mar 26, 2017 at 19:00
  • Actually I am stitching my textures to form an atlas. So I can't be enabling GL_REPEAT later on. What I want is for all the individual textures to have their UVs restricted to [0,1] and stitch them together so that repetition is not required.
    – Amit Tomar
    Mar 27, 2017 at 4:42
  • Something related : stackoverflow.com/questions/662107/…
    – Amit Tomar
    Mar 27, 2017 at 4:46
  • Breaking down triangles as you've said you'd need to create one of the new vertices at exactly U=1 point, so no edge crosses 1.0 value, then the next edge would start from U=0, but I see no reason for doing that. And the answer for the related question you've posted says to not to clip UVs, just to enable texture wrapping.
    – kolenda
    Mar 28, 2017 at 15:58
  • I understand you want to use atlas for this, you can still do it, but I don't get your mesh UVs. Could you post some screen from UV mapping of this object? Or at least show us the full texture and full rendered object?
    – kolenda
    Mar 28, 2017 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.