Unreal/CarlaUE4/Plugins/RoadRunnerImporter/Source/RoadRunnerImporter/Private/RoadRunnerFbxFactory.cpp
////////////////////////////////////////////////////////////////////////////////
// Try to create the object using the RoadRunner scene import factory if the
// metadata file exists, otherwise, fall back to the default FbxFactory.
Try to create the object using the RoadRunner scene import factory if the
metadata file exists, otherwise, fall back to the default FbxFactory.
Try to create the object using the RoadRunner scene import factory if the metadata file exists otherwise fall back to the default FbxFactory .
UObject * URoadRunnerFbxFactory::FactoryCreateFile(UClass * inClass, UObject * inParent, FName inName, EObjectFlags flags, const FString & filename, const TCHAR * parms, FFeedbackContext * warn, bool & outCancelled)
{
	FString rrMetadataFile = FPaths::ChangeExtension(filename, ".rrdata.xml");
	if (!FPaths::FileExists(rrMetadataFile))
	{
		return UFbxFactory::FactoryCreateFile(inClass, inParent, inName, flags, filename, parms, warn, outCancelled);
	}
	FXmlFile* rrXml = new FXmlFile(rrMetadataFile);
	if (!rrXml->IsValid())
	{
		UE_LOG(RoadRunnerImporter, Warning, TEXT("RoadRunner metadata file not valid. Reverting to default fbx factory."));
		return UFbxFactory::FactoryCreateFile(inClass, inParent, inName, flags, filename, parms, warn, outCancelled);
	}
	auto fbxSceneFactory = NewObject<URoadRunnerFbxSceneImportFactory>();
	fbxSceneFactory->AddToRoot();
	UObject* newObj = fbxSceneFactory->FactoryCreateFile(inClass, inParent, inName, flags, filename, parms, warn, outCancelled);
	fbxSceneFactory->RemoveFromRoot();
	return newObj;
}
UObject * URoadRunnerFbxFactory :: FactoryCreateFile ( UClass * inClass , UObject * inParent , FName inName , EObjectFlags flags , const FString & filename , const TCHAR * parms , FFeedbackContext * warn , bool & outCancelled ) { FString rrMetadataFile = FPaths :: ChangeExtension ( filename , " " ) ; if ( ! FPaths :: FileExists ( rrMetadataFile ) ) { return UFbxFactory :: FactoryCreateFile ( inClass , inParent , inName , flags , filename , parms , warn , outCancelled ) ; } FXmlFile * rrXml = new FXmlFile ( rrMetadataFile ) ; if ( ! rrXml -> IsValid ( ) ) { UE_LOG ( RoadRunnerImporter , Warning , TEXT ( " " ) ) ; return UFbxFactory :: FactoryCreateFile ( inClass , inParent , inName , flags , filename , parms , warn , outCancelled ) ; } auto fbxSceneFactory = NewObject < URoadRunnerFbxSceneImportFactory > ( ) ; fbxSceneFactory -> AddToRoot ( ) ; UObject * newObj = fbxSceneFactory -> FactoryCreateFile ( inClass , inParent , inName , flags , filename , parms , warn , outCancelled ) ; fbxSceneFactory -> RemoveFromRoot ( ) ; return newObj ; }
Try to create the object using the RoadRunner scene import factory if the
metadata file exists, otherwise, fall back to the default FbxFactory.
Try to create the object using the RoadRunner scene import factory if the metadata file exists otherwise fall back to the default FbxFactory .
// Only use our scene import if metadata file exists, and is valid, otherwise use the default one // Protect factory from garbage collection