1.合并多个StaticMesh
这个比较简单
#include "Public/EditorLevelLibrary.h"
.cs里面加入“EditorScriptingUtilities"
TArray
FEditorScriptingMergeStaticMeshActorOptions MergeOptions;
FEdtiorScriptingCreateProxyMeshActorOptions CreateOptions;
AStaticMeshActor* OutMergeActor;
MergeOptions.MeshMergingSettings.bPivotPointAtZero = true;
將需要合并的StaticMeshActors添加進ActorsToMerge(這裏省略)
方法1.
UEditorLevelLibrary::CreateProxyMeshActor(ActorsToMerge, CreateOptions, OutMergeActor);
方法2.
UEditorLevelLibrary::MergeStaticMeshActors(ActorsToMerge, MergeOptions, OutMergeActor);
方法3:
const IMeshMergeUtilities& MeshUtilities = FModuleManager::Get().LoadModuleChecked
MeshUtilities.MergeComponentsToStaticMesh(AllComponents, world, MergeOptions.MeshMergingSettings, nullptr, nullptr, PackageName, OutAssetsToSync, MergedActorLocation, ScreenAreaSize, true);
2.合并多个Landscape
方法同合并多个StaticMesh类似,只是需要先生成一步
Landscape LOD,得到每一块地形的StaticMesh,再合并
不同的是添加ActorsToMerge這裏
for(TActorIterator
{
AStaticMeshActor* StaticMeshActor = World->SpawnActor
StaticMeshActor->GetStaticMeshComponent()->SetStaticMesh(ActorItr->GetLandscapeMeshProxyComponent()->GetStaticMesh());
ActorsToMerge.Add(StaticMeshActor);
}
3.合并多個SplineMeshActor
TArray
for(TActorIterator
{
AllComponents.Add(SMA->GetSplineMeshComponent());
}
const IMeshMergeUtilities& MeshUtilities = FModuleManager::Get().LoadModuleChecked
FEditorScriptingMergeStaticMeshActorsOptions MergeOptions;
FString FailureReason;
FString PackageName = EditorScriptingUtils::ConvertAnyPathToLongPackagePath(MergeOptions.BasePackageName, FailureReason);
FVector MergedActorLocation;
TArray
const float ScreenAreaSize = TNumericLimits
MeshUtilities.MergeComponentsToStaticMesh(AllComponents, World, MergeOptions.MeshMergingSettings, nullptr, nullptr, PackageName, CreatedAssets, MergedActorLocation, ScreenAreaSize, true);
4.合并多个SkeletonMesh
bool AwwaCharacter::MyMerge2Char(AActor* PlayerPawn, TArray
{
if (!PlayerPawn || !SkeletalComp || SrcMeshList.Num() == 0) return false;
TArray
auto CompositeMesh = NewObject
TArray
FSkeletalMeshMerge MeshMergeUtil(CompositeMesh, SourceMeshList, InForceSectionMapping, 0);
if (!MeshMergeUtil.DoMerge())
{
UE_LOG(LogTemp, Log, TEXT("DoMerge Error: Merge Mesh Test Failed"));
return false;
}
CompositeMesh->Skeleton = SkeletalComp->SkeletalMesh->Skeleton; //设置新的 *SkeletalMesh* 的骨架
SkeletalComp->SetSkeletalMesh(CompositeMesh); //用新组合成的 SkeletalMesh 替换旧的
return true;
}