diff --git a/AssetStudioFBXNative/api.cpp b/AssetStudioFBXNative/api.cpp index 3fe775e..cf4a856 100644 --- a/AssetStudioFBXNative/api.cpp +++ b/AssetStudioFBXNative/api.cpp @@ -462,7 +462,7 @@ AS_API(void) AsFbxMeshCreateElementNormal(FbxMesh* pMesh) pNormal->SetReferenceMode(FbxGeometryElement::eDirect); } -AS_API(void) AsFbxMeshCreateElementUV(FbxMesh* pMesh, int32_t uv) +AS_API(void) AsFbxMeshCreateDiffuseUV(FbxMesh* pMesh, int32_t uv) { if (pMesh == nullptr) { @@ -474,6 +474,18 @@ AS_API(void) AsFbxMeshCreateElementUV(FbxMesh* pMesh, int32_t uv) pUV->SetReferenceMode(FbxGeometryElement::eDirect); } +AS_API(void) AsFbxMeshCreateNormalMapUV(FbxMesh* pMesh, int32_t uv) +{ + if (pMesh == nullptr) + { + return; + } + + auto pUV = pMesh->CreateElementUV(FbxString("UV") + FbxString(uv), FbxLayerElement::eTextureNormalMap); + pUV->SetMappingMode(FbxGeometryElement::eByControlPoint); + pUV->SetReferenceMode(FbxGeometryElement::eDirect); +} + AS_API(void) AsFbxMeshCreateElementTangent(FbxMesh* pMesh) { if (pMesh == nullptr) @@ -613,7 +625,7 @@ AS_API(void) AsFbxMeshElementUVAdd(FbxMesh* pMesh, int32_t elementIndex, float u return; } - auto pElem = pMesh->GetElementUV(elementIndex); + auto pElem = pMesh->GetElementUV(FbxString("UV") + FbxString(elementIndex)); auto& array = pElem->GetDirectArray(); array.Add(FbxVector2(u, v)); diff --git a/AssetStudioFBXNative/api.h b/AssetStudioFBXNative/api.h index 1422136..fb21034 100644 --- a/AssetStudioFBXNative/api.h +++ b/AssetStudioFBXNative/api.h @@ -66,7 +66,9 @@ AS_API(void) AsFbxMeshInitControlPoints(fbxsdk::FbxMesh* pMesh, int32_t vertexCo AS_API(void) AsFbxMeshCreateElementNormal(fbxsdk::FbxMesh* pMesh); -AS_API(void) AsFbxMeshCreateElementUV(fbxsdk::FbxMesh* pMesh, int32_t uv); +AS_API(void) AsFbxMeshCreateDiffuseUV(fbxsdk::FbxMesh* pMesh, int32_t uv); + +AS_API(void) AsFbxMeshCreateNormalMapUV(fbxsdk::FbxMesh* pMesh, int32_t uv); AS_API(void) AsFbxMeshCreateElementTangent(fbxsdk::FbxMesh* pMesh); diff --git a/AssetStudioFBXWrapper/FbxExporterContext.PInvoke.cs b/AssetStudioFBXWrapper/FbxExporterContext.PInvoke.cs index e97271a..57334db 100644 --- a/AssetStudioFBXWrapper/FbxExporterContext.PInvoke.cs +++ b/AssetStudioFBXWrapper/FbxExporterContext.PInvoke.cs @@ -142,7 +142,10 @@ namespace AssetStudio.FbxInterop private static extern void AsFbxMeshCreateElementNormal(IntPtr mesh); [DllImport(FbxDll.DllName, CallingConvention = CallingConvention.Winapi)] - private static extern void AsFbxMeshCreateElementUV(IntPtr mesh, int uv); + private static extern void AsFbxMeshCreateDiffuseUV(IntPtr mesh, int uv); + + [DllImport(FbxDll.DllName, CallingConvention = CallingConvention.Winapi)] + private static extern void AsFbxMeshCreateNormalMapUV(IntPtr mesh, int uv); [DllImport(FbxDll.DllName, CallingConvention = CallingConvention.Winapi)] private static extern void AsFbxMeshCreateElementTangent(IntPtr mesh); diff --git a/AssetStudioFBXWrapper/FbxExporterContext.cs b/AssetStudioFBXWrapper/FbxExporterContext.cs index b5762f6..375569e 100644 --- a/AssetStudioFBXWrapper/FbxExporterContext.cs +++ b/AssetStudioFBXWrapper/FbxExporterContext.cs @@ -255,12 +255,14 @@ namespace AssetStudio.FbxInterop AsFbxMeshCreateElementNormal(mesh); } - for (var i = 0; i < 2; i += 1) + if (importedMesh.hasUV[0]) { - if (importedMesh.hasUV[i]) - { - AsFbxMeshCreateElementUV(mesh, i); - } + AsFbxMeshCreateDiffuseUV(mesh, 0); + } + + if (importedMesh.hasUV[1]) + { + AsFbxMeshCreateNormalMapUV(mesh, 1); } if (importedMesh.hasTangent)