TriAxis-Games / RealtimeMeshComponent

Unreal Engine 5 plugin component for rendering runtime generated content.

Home Page:https://rmc.triaxis.games/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scale is not correct during mesh creation

ivl opened this issue · comments

Let say we are create simple quad landscape 500x500 quads

const float QuadSize = 10.0f; // Size of each quad in Unreal units (cm)
for (int32 y = 0; y < 500; ++y)
{
for (int32 x = 0; x < 500; ++x)
{
// Determine the world positions and heights for each corner of the quad

    float OriginX = x * QuadSize;
    float OriginY = y * QuadSize;

    // Define vertices with position, normal, tangent, color, and UV

    int32 V1 = Builder.AddVertex(FVector3f(OriginX, OriginY, 0.0f))
        .SetNormalAndTangent(FVector3f(0.0f, 0.0f, 1.0f), FVector3f(1.0f, 0.0f, 0.0f))
        .SetColor(FColor::White)
        .SetTexCoord(FVector2f(0.0f, 0.0f));

    int32 V2 = Builder.AddVertex(FVector3f(OriginX + QuadSize, OriginY, 0.0f))
        .SetNormalAndTangent(FVector3f(0.0f, 0.0f, 1.0f), FVector3f(1.0f, 0.0f, 0.0f))
        .SetColor(FColor::White)
        .SetTexCoord(FVector2f(1.0f, 0.0f));

    int32 V3 = Builder.AddVertex(FVector3f(OriginX, OriginY + QuadSize, 0.0f))
        .SetNormalAndTangent(FVector3f(0.0f, 0.0f, 1.0f), FVector3f(1.0f, 0.0f, 0.0f))
        .SetColor(FColor::White)
        .SetTexCoord(FVector2f(0.0f, 1.0f));

    int32 V4 = Builder.AddVertex(FVector3f(OriginX + QuadSize, OriginY + QuadSize, 0.0f))
        .SetNormalAndTangent(FVector3f(0.0f, 0.0f, 1.0f), FVector3f(1.0f, 0.0f, 0.0f))
        .SetColor(FColor::White)
        .SetTexCoord(FVector2f(1.0f, 1.0f));

    // Add triangles (ensure counter-clockwise winding order)
    Builder.AddTriangle(V1, V3, V2);
    Builder.AddTriangle(V2, V3, V4);
}

}

Output result is not correct - ist longer over x axis than y. Should be square. if change count of quads from 500 to 100 its works well as expected. output correct suare plane.

How is the builder configured? If you're using uint16 as the index type it'll cap out and wrap around at 2^16=65536 vertices which you'd be well over with 500x500x4=1M vertices, whereas 100x100x4=40k so that will fit. You should be able to just change the index type to uint32 and it should work from there.

Side note, you don't appear to be re-using vertices across adjacent quads. You don't strictly have to, but it's definitely more efficient if you can.

-Chris

got you. thanks for quick response. please close issue.

You're welcome! Glad it helped!

-Chris