Closed Zi1mann closed 1 year ago
void UAIScene::EmptySceneTestExport()
{
// Creating a test scene
std::unique_ptr<aiScene> scene(new aiScene());
// TODO: Fill the scene with data (meshes, materials, etc.)
aiMesh *mesh = new aiMesh();
mesh->mNumVertices = 3;
mesh->mVertices = new aiVector3D [] {{0,0,0}, {0,1,0}, {1,0,0}};
mesh->mNumFaces = 1;
mesh->mFaces = new aiFace[1];
mesh->mFaces[0].mNumIndices = 3;
mesh->mFaces[0].mIndices = new unsigned[] { 0, 1, 2 };
mesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE; // workaround, issue #3778
scene->mNumMeshes = 1;
scene->mMeshes = new aiMesh * [] { mesh };
scene->mNumMaterials = 1;
scene->mMaterials = new aiMaterial * [] { new aiMaterial() };
scene->mRootNode = new aiNode();
scene->mRootNode->mNumMeshes = 1;
scene->mRootNode->mMeshes = new unsigned [] { 0 };
scene->mMetaData = new aiMetadata(); // workaround, issue #3781
// Creating an exporter
// Constructing the export path
FString ExportPath = FPaths::ProjectDir();
ExportPath=FPaths::Combine(ExportPath,"Export");
ExportPath=FPaths::ConvertRelativePathToFull(ExportPath);
if (!FPlatformFileManager::Get().GetPlatformFile().DirectoryExists(*ExportPath))
{
FPlatformFileManager::Get().GetPlatformFile().CreateDirectory(*ExportPath);
}
ExportPath =FPaths::Combine(ExportPath,"Test.obj");
Assimp::Exporter exporter;
// Exporting the scene
if (exporter.Export(scene.get(), "obj", TCHAR_TO_ANSI(*ExportPath)) != AI_SUCCESS)
{
UE_LOG(LogAssimp, Fatal, TEXT("Exporting scene to fbx failed: %s"), ANSI_TO_TCHAR(exporter.GetErrorString()));
}
}
The bug is actually within the assimp library and only happens for fbx format at CreationTimeStamp.Dump(outstream, binary, indent);
I tried the code above to export a triangle for obj format and the output is
Update : I changed assimp version on my pc ( in folder Plugins\UE4_Assimp\Source\ThirdParty\UE_AssimpLibrary\assimp) to latest version (using git ) and rebuilt . now fbx export also works !
This looks promising, I will look into it next week. Thanks for your efforts so far.
I pulled the latest master branch release and rebuild, exporting works, the obj file is written into the created directory. However, the game client still crashes - now without any crash message or entry in the log file at Saved/Logs/
.
Hence I tried walking through your example code trying to find the line introducing this behavior. It already appears when populating aiScene's mMeshes
container even before the exporter is called.
scene->mMeshes = new aiMesh * [] { mesh };
.
Commenting out that line reveals the same also happens on
scene->mMaterials = new aiMaterial * [] { new aiMaterial() };
,
scene->mRootNode = new aiNode();
It seems to be related to the way you initialize your scene, initializing it as
aiScene* scene = new aiScene();
and calling the exporter accordingly
exporter.Export(scene, "obj", TCHAR_TO_ANSI(*ExportPath))
seems to fix the problem. Exporting works, game does not crash anymore. I will close this issue.
Describe the bug Calling Exporter object to export AIScene to file crashes Unreal Engine
To Reproduce Exposing the function below to Blueprints and calling the function at runtime results in an access violation.