Hi,
I’m trying to export all static mesh components in a level to a custom format, and to include light-map information as part of the exported data.
Right now I’m having a hard time figuring out how to calculate the unique (non-overlapping) uvs of each component, so that they properly map against the exported light-map texture.
As far as I can understand by looking at various places in the engine source, the transformation from mesh-uv to light-map-uv using scale & bias seems to be correct.
This is what I have so far:
const FMeshMapBuildData* MeshMapBuildData = StaticMeshComponent->GetMeshMapBuildData(ComponentLODInfo);
const FLightMap2D* LightMap2D = MeshMapBuildData->LightMap->GetLightMap2D();
const int32 LightMapCoordinateIndex = StaticMesh->LightMapCoordinateIndex;
const FVector2D& CoordinateScale = LightMap2D->GetCoordinateScale();
const FVector2D& CoordinateBias = LightMap2D->GetCoordinateBias();
const uint32 VertexCount = VertexBuffer->GetNumVertices();
for (uint32 VertexIndex = 0; VertexIndex < VertexCount; VertexIndex++)
{
const FVector2D& VertexUV = VertexBuffer->GetVertexUV(VertexIndex, LightMapCoordinateIndex);
const FVector2D LightMapUV = (VertexUV * CoordinateScale + CoordinateBias) * FVector2D(1.0f, 0.5f);
LightMapVertexBuffer->SetVertexUV(VertexIndex, LightMapCoordinateIndex, LightMapUV);
}
The problem I’m having is that all components that use the same mesh (for example the standard sphere) get exactly the same scale & bias regardless of where the (scene-)components are placed in the level.
The resulting uvs are therefore overlapping and incorrect for sampling the light-map.
Is there some crucial step that I’m missing to get the actual unique uvs?
Best regards,