I am trying to write a new class that uses the import function from FBXMainImport.cpp.
The function is:
namespace UnFbx
{
bool FFbxImporter::ImportFile(FString Filename)
{
bool Result = true;
bool bStatus;
FileBasePath = FPaths::GetPath(Filename);
// Create the Scene
Scene = FbxScene::Create(SdkManager,"");
UE_LOG(LogFbx, Log, TEXT("Loading FBX Scene from %s"), *Filename);
int32 FileMajor, FileMinor, FileRevision;
IOS_REF.SetBoolProp(IMP_FBX_MATERIAL, true);
IOS_REF.SetBoolProp(IMP_FBX_TEXTURE, true);
IOS_REF.SetBoolProp(IMP_FBX_LINK, true);
IOS_REF.SetBoolProp(IMP_FBX_SHAPE, true);
IOS_REF.SetBoolProp(IMP_FBX_GOBO, true);
IOS_REF.SetBoolProp(IMP_FBX_ANIMATION, true);
IOS_REF.SetBoolProp(IMP_SKINS, true);
IOS_REF.SetBoolProp(IMP_DEFORMATION, true);
IOS_REF.SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true);
IOS_REF.SetBoolProp(IMP_TAKE, true);
// Import the scene.
bStatus = Importer->Import(Scene);
// Get the version number of the FBX file format.
Importer->GetFileVersion(FileMajor, FileMinor, FileRevision);
// output result
if(bStatus)
{
UE_LOG(LogFbx, Log, TEXT("FBX Scene Loaded Succesfully"));
CurPhase = IMPORTED;
// Release importer now as it is unneeded and in the failure case is part of CleanUp()
Importer->Destroy();
Importer = NULL;
}
else
{
ErrorMessage = ANSI_TO_TCHAR(Importer->GetStatus().GetErrorString());
AddTokenizedErrorMessage(FTokenizedMessage::Create(EMessageSeverity::Warning, FText::Format(LOCTEXT("FbxSkeletaLMeshimport_FileLoadingFailed", "FBX Scene Loading Failed : '{0}'"), FText::FromString(ErrorMessage))), FFbxErrors::Generic_LoadingSceneFailed);
CleanUp();
Result = false;
CurPhase = NOTSTARTED;
}
return Result;
}
}
I think you may still have problems though. Only methods prefixed with UNREALED_API are exported from the module for external use. So try ImportFromFile instead of ImportFile. I guess this might work, though I’m kind of confused as to why the header file is in the private source subdirectory if it is exporting symbols. I had assumed being in private meant nothing was exported for use by other modules.
Where have you put your code? This class is defined in the UnrealEd module, so if it even is possible to import it, you could only do so from inside an Editor module in your project (as opposed to the main game module), which referenced “UnrealEd” in its dependencies within its .build.cs file.
Even then you’re going to have issues, since you won’t be able to access the Scene member as you’ve tried, as it’s not exported. Looking through the list of methods that are exported, there is ImportStaticMesh, but it requires an FbxNode as input, and I don’t see any way to get one from the accessible methods. It looks to me like if this class was intended to be exposed to other modules, that functionality wasn’t completed. So your only options may be to either modify the engine code, or just copy and paste what you need into your project.
Well, if you are willing to modify the engine source, you can move it to the public folder and also add export tags (UNREALED_API) to the FFbxImporter class itself and/or specific methods you need to access. You’d still have to move your code that uses it to an editor module, but unless you need to import meshes at runtime in your packaged game, it would make sense to do that anyway. Regardless it’s a bit of work…
The copy and paste alternative means copying the FFbxImporter class implementation and anything it relies on into your own module, yes. This may also be problematic as I suspect it may be using a third party library.
Although I’ve heard the term before, I’m afraid I have no idea what a commandlet is.
It’s probably worth posting in the feedback forum as a request. I get the feeling there’s a bunch of stuff in the engine source that would be useful to have exported for use in external modules, but just hasn’t been because internally to Epic it hasn’t been needed and noone else has asked. I’ve had to copy and paste engine code on a couple of occasions myself for the same reasons.
For anyone who still has issues with this, I had a “cannot resolve externals” error when using FFbxImporter and it was because of what is mentioned above but if you look at the FbxImporter.h file any function that has UNREALED_API in the declaration can be used externally. Below are two examples. The first works and the second does not however, both are functions defined in the FFbxImporter class.
//Working import function
using namespace UnFbx;
FString FbxPath = absoluteFilePath;
FFbxImporter* = FFbxImporter::GetInstance();
if (FBXImporter->ImportFromFile(FbxPath, "Mesh"))
{
UE_LOG(LogTemp, Warning, TEXT("FBX Importer Imported from file"));
}
// Nonworking import function
FString FbxPath = absoluteFilePath;
FFbxImporter* = FFbxImporter::GetInstance();
if (FBXImporter->ImportFile(FbxPath, "Mesh"))
{
UE_LOG(LogTemp, Warning, TEXT("FBX Importer Imported from file"));
}