Corweee
(Corweee)
December 7, 2019, 6:05pm
158
anonymous_user_2681644d:
@ElephantFury @YuuJin OK I think I found the problem. UE4 fbx import has code to automatically flip the V-coordinate to account for different UV origin. But this is breaking UDIM coordinates which contain UVs outside the 0-1 range.
In Engine\Source\Editor\UnrealEd\Private\Fbx\FbxStaticMeshImport.cpp, search for the comment “//UVs attributes”, around line 716. Replace the following block of code with this:
for (int32 UVLayerIndex = 0; UVLayerIndex < FBXUVs.UniqueUVCount; UVLayerIndex++)
{
FVector2D FinalUVVector(0.0f, 0.0f);
if (FBXUVs.LayerElementUV[UVLayerIndex] != NULL)
{
int UVMapIndex = (FBXUVs.UVMappingMode[UVLayerIndex] == FbxLayerElement::eByControlPoint) ? ControlPointIndex : RealFbxVertexIndex;
int32 UVIndex = (FBXUVs.UVReferenceMode[UVLayerIndex] == FbxLayerElement::eDirect) ?
UVMapIndex : FBXUVs.LayerElementUV[UVLayerIndex]->GetIndexArray().GetAt(UVMapIndex);
FbxVector2 UVVector = FBXUVs.LayerElementUV[UVLayerIndex]->GetDirectArray().GetAt(UVIndex);
const float U = static_cast<float>(UVVector[0]);
const float V = static_cast<float>(UVVector[1]);
const float VTile = FMath::FloorToFloat(V);
const float VOffset = V - VTile;
FinalUVVector.X = U;
FinalUVVector.Y = VTile + (1.f - VOffset); //flip the Y of UVs for DirectX
}
VertexInstanceUVs.Set(AddedVertexInstanceId, UVLayerIndex, FinalUVVector);
}
This will flip the V-coordinate within each UDIM page, but will preserve the layout of each page. A similar change needs to be made in FbxSkeletalMeshImport.cpp as well.
I’ll get this fix into the engine, but it probably won’t make it for 4.24. So you’ll need to apply fix locally for now.
Currently having issues with the UDIMs stacking in the wrong direction and just need to know if this only works with the source version of the engine and if I need to re-import my mesh for this to take effect or if this will just automatically fix the UV orientation on meshes already imported into my project.
Thanks!