Texture Pattern bunching up at UV Seam; How to mitigate? [Javascript]

I am trying to wrap a sphere with a patterned texture, while using code to handle the object being stretched/resized without stretching the pattern. Unfortunately, some of my triangles are displaying severely bunched up renditions of the pattern, as seen below.

I am pretty confident that this is due to the fact that the UV seam is going through these triangles, so when reassigning a UV to each triangle based on the normal of each vertice, it crosses values across the seam and puts in a much larger than needed selection of the pattern.

For the sake of fixing this with the tools I have available, I want to fix this via scripting. I believe one way to do it would be with the following pseudocode made into real code:

If the triangle has verticies with very different normals:
Split the triangle into 4 identical right triangles (using edge midpoints)
Add those 4 triangles into the mesh while removing the previous one
Ensure the new vertice normals are properly calculated
Return to the If statement for each of the 4 new triangles

Here’s where I need help: How do I build this functionality in my script? I’m having trouble making this flow a reality with proper structure/syntax. I am using Unityscript, so it would need to be formatted as such.

Any help would be incredibly appreciated. Thank you.

That line happens because theres no UV seam, the last batch of triangles loops back from a high uv value to zero.
Duplicate the verts along the seam so you have 2 vertices in the same spot, with different uv values

1 Like

Thanks for the explanation, that’s a very helpful diagram too!

That does get back to my question though, how can I use a script to put the additional verts where they are needed on my mesh to fix this? Sadly this isn’t just a lack of understanding of the situation, but me having trouble actually implementing the fix.