[UE4]C++合并StaticMesh,SkeletonMesh,Landscape的方法

1.合并多个StaticMesh

这个比较简单

#include "Public/EditorLevelLibrary.h"

.cs里面加入“EditorScriptingUtilities"

TArrayActorsToMerge;

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("MeshMergeUtilities").GetUtilities();
 

MeshUtilities.MergeComponentsToStaticMesh(AllComponents, world, MergeOptions.MeshMergingSettings, nullptr, nullptr, PackageName, OutAssetsToSync, MergedActorLocation, ScreenAreaSize, true);
 

 

 

 

 

2.合并多个Landscape

方法同合并多个StaticMesh类似,只是需要先生成一步

Landscape LOD,得到每一块地形的StaticMesh,再合并

不同的是添加ActorsToMerge這裏

for(TActorIterator ActorItr(World); ActorItr; ++ActorItr)

{

AStaticMeshActor* StaticMeshActor = World->SpawnActor(ActorItr->GetActorLocation(), ActorItr->GetActorRotation());

StaticMeshActor->GetStaticMeshComponent()->SetStaticMesh(ActorItr->GetLandscapeMeshProxyComponent()->GetStaticMesh());

ActorsToMerge.Add(StaticMeshActor);

}

 

 

3.合并多個SplineMeshActor

 

TArrayAllComponents;

for(TActorIterator SMA(World); SMA; ++SMA)

{

AllComponents.Add(SMA->GetSplineMeshComponent());

}

const IMeshMergeUtilities& MeshUtilities = FModuleManager::Get().LoadModuleChecked("MeshMergeUtilities").GetUtilities();

FEditorScriptingMergeStaticMeshActorsOptions MergeOptions;

FString FailureReason;

FString PackageName = EditorScriptingUtils::ConvertAnyPathToLongPackagePath(MergeOptions.BasePackageName, FailureReason);

FVector MergedActorLocation;

TArrayCreatedAssets;

const float ScreenAreaSize = TNumericLimits::Max();

MeshUtilities.MergeComponentsToStaticMesh(AllComponents, World, MergeOptions.MeshMergingSettings, nullptr, nullptr, PackageName, CreatedAssets, MergedActorLocation, ScreenAreaSize, true);

 

4.合并多个SkeletonMesh

bool AwwaCharacter::MyMerge2Char(AActor* PlayerPawn, TArray SrcMeshList, USkeletalMeshComponent* SkeletalComp)
{
    if (!PlayerPawn || !SkeletalComp || SrcMeshList.Num() == 0) return false;
    
    TArray& SourceMeshList = SrcMeshList;
    auto CompositeMesh = NewObject(GetTransientPackage(), NAME_None, RF_Transient);
    TArray InForceSectionMapping;
    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;
}

 

 

你可能感兴趣的:([UE4]C++合并StaticMesh,SkeletonMesh,Landscape的方法)