Model loading in c++?

Is there a way to import a .fbx file into the editor using c++, without writing a custom importer using the fbx sdk?
NOT at runtime, as in a few other questions, just into the editor…

It seems like this should be a simple task, but I can’t find any info on it…

Using the sdk files in /thirdParty/FBX/etc

I am trying:

#include <fbxsdk/fileio/fbx/fbxio.h>
#include <fbxsdk/fileio/fbximporter.h>
#include <fbxsdk/fileio/fbxiobase.h>
#include <fbxsdk/fileio/fbxiosettings.h>
#include <fbxsdk/core/fbxmanager.h>
#include <fbxsdk/scene/fbxscene.h>

bool AcreateMesh::testMesh(FString filename, FString type)
{    	
	    //create a SdkManager	
		FbxManager *lSdkManager = FbxManager::Create();

	 // create an IOSettings object
		 FbxIOSettings * ios = FbxIOSettings::Create(lSdkManager, IOSROOT);
	
		 // set some IOSettings options 
		 ios->SetBoolProp(IMP_FBX_MATERIAL, true);
	     ios->SetBoolProp(IMP_FBX_TEXTURE, true);

				
		 // create an empty scene
		 FbxScene* lScene = FbxScene::Create(lSdkManager, "");
	
		 // Create an importer.
		 FbxImporter* lImporter = FbxImporter::Create(lSdkManager, "");
	
		 // Initialize the importer by providing a filename and the IOSettings to use
		 lImporter->Initialize("C:\\myfile.fbx", -1, ios);
	
		 // Import the scene.
		 lImporter->Import(lScene);
	
		 // Destroy the importer.
		 lImporter->Destroy();

		 return true;
	
}

But all of the FBX functions are undefined. What am I missing here?

Thanks!

FBX support is built into the editor. Are you trying to use that or extend it?

Heya, thanks for your reply. I am trying to extend it. I need to batch import fbx models and read custom user properties from them upon import.

First thing to check is that your module has the right dependencies and include paths in your *.cs file. Then you need to look at how the import factories work, so that you are following a pattern that will work in the editor.

ok thanks. Would you be able to point me to an example please?

Take a look at UnrealEd.Build.cs

Ok cool, so i have copied what I think are the right dependencies into my .cs.
Is my code above valid? Or should I replace it with a UFactory? Is there any docs on UFactory creation? I can’t find much info around.
Thanks again!

If you want to be able to import with the custom properties manually in the editor, then it needs to be a UFactory based implementation like the existing FBX support. If that doesn’t matter, then do it the way that makes the most sense for you.

Ok. Forgive my idiocy… What would be the absolute simplest way that I can get an fbx file into the editor? All I really need is to do exactly what the editor does, but in code. Thanks for your help!

Ah. You can write a commandlet and run that to batch import a whole directory or such. You can use the editor code as an example of how to call the code directly and then just call it once for each asset you need to import

A commandlet? I will google and discover what this is. :slight_smile: Where is the editor function that I need? And can i call it from the existing engine code? or do i need to copy the code to a new class?

I don’t suppose you are aware of an example anywhere that I could borrow from?

Again, sorry, I thought I had a handle on ue4 c++, but this has totally lost me.

Were you ever able to solve this? I’ve tried including “FBX” using AddThirdPartyPrivateStaticDependencies(), but no success. This is definitely the right module, so I’m not sure what’s up.

Hey, did you ever find the solution to this ? I’m stuck there as well, I added FBX to the AddThirdPartyPrivateStaticDependencies, but it tells me it can’t find FbxImporter.h when I try to include it.

I did! The solution is only available in the editor. Check this conversation out: Generate Procedural Mesh - C++ - Unreal Engine Forums

You can populate a FRawMesh similar to how you make a procedural mesh, but then you can use it to build a static mesh and save that. If you already have your geometry data loaded then this is the best way to save it.

So there’s no way to “simply” use the same method the “import” button uses in UE4 ? A bit like the second part of the suggested answer there : fbx - Unreal Engine 4, import with c++? - Stack Overflow ? Something with FFbxImporter ? That’s weird since the “import” button should be calling some UE4 code that we should be able to reuse ourselves, right ?