Import fbx model in runtime c++

Hello everyone! I’m making code to import a model into static mesh (c++) but the asset itself if emptyand UE4 does not see him. I see this asset in Windows and weighs only 332 bytes.


 

  1. UnFbx::FFbxImporter* importFBX = UnFbx::FFbxImporter::GetInstance();
  1. FString FbxPath = TEXT("C:\\Users\\Vick\\Documents\\Unreal Projects\\vrprj\\Source\\vrprj\\RosesOrange.fbx");
  1. //FString FbxPath2 = TEXT("C:\Users\Vick\Documents\Unreal Projects\vrprj\Source\vrprj\RosesOrange.fbx");
  1. if (importFBX->ImportFromFile(TEXT("C:\\Users\\Vick\\Documents\\Unreal Projects\\vrprj\\Source\\vrprj\\RosesOrange.fbx"), TEXT("fbx"))) {
  1. TArray<FbxNode*> FbxMeshArray;
  1. FbxGeometryConverter *pFbxGeometryConverter = importFBX->GetGeometryConverter();
  1. importFBX->FillFbxMeshArray(importFBX->Scene->GetRootNode(), FbxMeshArray, importFBX);
  1. UFbxStaticMeshImportData* importData = NewObject<UFbxStaticMeshImportData>(GetTransientPackage(), NAME_None, RF_NoFlags, NULL);
  1. importData->bImportMeshLODs = true;
  1. importData->StaticMeshLODGroup = FName(TEXT("HighDetailLOD"));
  1. FBXImportOptions *pFBXImportOptions =importFBX->GetImportOptions();
  1. pFBXImportOptions->bAutoComputeLodDistances=true;
  1. pFBXImportOptions->bPreserveSmoothingGroups = true;
  1. for (int i = 0; i < FbxMeshArray.Num(); i++) {
  1. pFbxGeometryConverter->ConvertNurbsSurfaceToNurbsInPlace(FbxMeshArray*);
  1. TArray<FbxNode*> array;
  1. array.Add(FbxMeshArray*);
  1. UStaticMesh* mesh = NewObject<UStaticMesh>();
  1. mesh = (UStaticMesh*)importFBX->ImportStaticMesh(GetTransientPackage(), FbxMeshArray*, FbxMeshArray*->GetName(), RF_NoFlags, importData, mesh, 1);
  1. //UFbxAnimSequenceImportData* animData = NewObject<UFbxAnimSequenceImportData>();
  1. if (mesh->GetFullName() != "None")
  1. {
  1. UE_LOG(LogTemp, Warning, TEXT("ImportStaticMeshAsSingle success mesh"));
  1. UE_LOG(LogTemp, Warning, TEXT("%s"), importFBX->GetErrorMessage());
  1. UPackage* Package = CreatePackage(NULL, TEXT("/Game/MyMeshFolderTest2/Mesh")); //Create package if not exist
  1. Package->FullyLoad(); //Load full package for import
  1. Package->MarkPackageDirty(); // Mark package dirty to be able to save
  1. FAssetRegistryModule::AssetCreated(mesh); //Notifies registry of new asset in-memory
  1. FString PackageFileName = FPackageName::LongPackageNameToFilename(TEXT("/Game/MyMeshFolderTest2/Mesh"), FPackageName::GetAssetPackageExtension());
  1. bool bSaved = UPackage::SavePackage(Package, mesh, EObjectFlags::RF_Public, *PackageFileName, GError, nullptr, true, true);
  1. if (bSaved == true)
  1. {
  1. UE_LOG(LogTemp, Warning, TEXT("Saved package"));
  1. }
  1. UE_LOG(LogTemp, Warning, TEXT("Start02"));
  1. UFbxFactory* factory = NewObject<UFbxFactory>(UFbxFactory::StaticClass(), FName("Factory"), RF_NoFlags);
  1. factory->ImportUI->StaticMeshImportData->bCombineMeshes = true;
  1. bool canceled = false;
  1. //UPackage* Package = CreatePackage(NULL, TEXT("/Game/MyMeshFolder/Mesh")); //Create package if not exist
  1. factory->ImportObject(factory->ResolveSupportedClass(), Package, FName("MyMesh_%s", i), RF_Public | RF_Standalone, FbxPath, nullptr, canceled);
  1. if (canceled == true)
  1. {
  1. UE_LOG(LogTemp, Warning, TEXT("Import canceled."));
  1. }
  1. }
  1. }
  1. }

 

This code compiling, and then a click start-buttom, i have this warning : “LogFbx: Warning: No smoothing group information was found in this FBX scene. Please make sure to enable the ‘Export Smoothing Groups’ option in the FBX Exporter plug-in before exporting the file. Even for tools that don’t support smoothing groups, the FBX Exporter will generate appropriate smoothing data at export-time so that correct vertex normals can be inferred while importing.” and "FBXImport: Warning: Can’t detect import type. No mesh is found or animation track. " I experimented witch FBXImportOptions and UFbxStaticMeshImportData, but its does not help. How i can fix this problem?

@Llama_Llama Did the import work for you? I am also thinking trying to import gltf, ifc models throught datasmith & C++.