procedural mesh component UV mapping issue

I created a tube by a procedural mesh component. The tube consists of 40 rings with 12 ring segments. Guess I am wrong here but I assumed that I just have to add the number of vertices for each ring and segment in the order the had been added to the vertices array for createing the procedural mesh. This is the current code:

 float HorizontalStep = 1.0f / RingSegments;
 float VerticalStep = 1.0f / LengthSegments;
 TArray<FVector2D> UVs;

for (int32 SegmentIndex = 0; SegmentIndex <= LengthSegments; ++SegmentIndex) {

     for (int32 RingSegmentIndex = 0; RingSegmentIndex < RingSegments; ++RingSegmentIndex) {
    
         // Calculate UVs
         FVector2D UV;
         UV.X = HorizontalStep * RingSegmentIndex;
         UV.Y = VerticalStep * SegmentIndex;
         UVs.Add(UV);



     }
 }

And this is what my UV map looks like. It seem that the last vertex of each ring segment is somehow connected to the first vertex of the previous line. What I’m doing wrong?

Finally, I have fixed it. The line you see in the screenshot is basically a seam that could be removed by explicitly setting the U-position of the last vertex in each ring segment to 1. Below are the changes:

TArray<FVector2D> UVs;

for (int32 SegmentIndex = 0; SegmentIndex <= LengthSegments; ++SegmentIndex) {

     float V = static_cast<float>(SegmentIndex) / LengthSegments;

     for (int32 RingSegmentIndex = 0; RingSegmentIndex < RingSegments; ++RingSegmentIndex) {
    
         // Calculate UVs
         FVector2D UV;

            float U = static_cast<float>(RingSegmentIndex) / RingSegments;
           
           // if last ring segment vertex reached, set its horizontal position to 1.0f
            if (RingSegmentIndex == RingSegments) {
                U = 1.0f;
            }

         UV.X = U;
         UV.Y = V;
         UVs.Add(UV);



     }
 }

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.