gradientspace/UE5RuntimeToolsFrameworkDemo

Saving of DynamicMesh runtime as an archive/file and load it back later

Opened this issue · 2 comments

I am looking for a way to save the meshes generated to the drive and load it back

I am able to export and import the meshes into .obj files with the functions RTGUtils::WriteOBJMesh and URuntimeToolsFrameworkSubsystem::ImportMeshSceneObject respectively. But When I have done a boolean operation with 2 objects namely A and B, the WriteOBJMesh function is only giving me the original mesh A. I want to write the final mesh to an OBJ file.

This is my code for writing the obj files:

void AToolsFrameworkPlayerController::WriteMeshesToDrive() const
{
	TArray<TObjectPtr<AActor>> OutActors;
	UGameplayStatics::GetAllActorsOfClass(this, ADynamicSDMCActor::StaticClass(), OutActors);
	for (TObjectPtr<AActor> Actor : OutActors)
	{
		if (TObjectPtr<ADynamicSDMCActor> DynamicSdmcActor = Cast<ADynamicSDMCActor>(Actor))
		{
			FString Path = FPaths::ProjectContentDir() + FGuid::NewGuid().ToString(EGuidFormats::DigitsWithHyphens) + TEXT(".obj");
			UE_LOG(LogTemp, Warning, TEXT("Exporting Mesh to path %s with status %d"), *Path,
			       RTGUtils::WriteOBJMesh(Path, DynamicSdmcActor->GetMeshRef(), true));
		}
	}
}

[SOLVED]
The code below can write the mesh into an OBJ file. But when loading back. The polygroups are lost.

void AToolsFrameworkPlayerController::WriteMeshesToDrive() const
{
	for(const TObjectPtr<URuntimeMeshSceneObject> RuntimeMeshSceneObject : URuntimeMeshSceneSubsystem::Get()->GetSceneObjects())
	{
		FString Path = FPaths::ProjectContentDir() + FGuid::NewGuid().ToString(EGuidFormats::DigitsWithHyphens) + TEXT(".obj");
		UE_LOG(LogTemp, Warning, TEXT("Exporting Mesh to path %s with status %d"), *Path,
			   RTGUtils::WriteOBJMesh(Path, *RuntimeMeshSceneObject->GetSourceMesh().Get(), true));
	}
}