C++ 在虚幻中创建地形时,使用ALandscape::Improt API导入,图层信息设置失败
当使用ALandscape::Improt API时,我想将层信息设置为之前保存的层,但设置失败,下面是我的代码C++ 在虚幻中创建地形时,使用ALandscape::Improt API导入,图层信息设置失败,c++,unreal-engine4,unrealscript,C++,Unreal Engine4,Unrealscript,当使用ALandscape::Improt API时,我想将层信息设置为之前保存的层,但设置失败,下面是我的代码 void FImpotLandModule::CreatLandScape(FString heightMapPath) { UWorld* world = GEditor->GetEditorWorldContext().World(); FVector location(0.0f, 0.0f, 0.0f); FRotator rotator(0.0
void FImpotLandModule::CreatLandScape(FString heightMapPath)
{
UWorld* world = GEditor->GetEditorWorldContext().World();
FVector location(0.0f, 0.0f, 0.0f);
FRotator rotator(0.0f, 0.0f, 0.0f);
FActorSpawnParameters SpawnInfo;
ALandscape* landscape = world->SpawnActor<ALandscape>(location, rotator);
ALandscapeProxy* proxy = Cast<ALandscapeProxy>(landscape);
int section_size = 63;
int section_per_component = 2;
int component_x = 4;
int component_y = 4;
int quads_per_component = section_per_component * section_size;
int size_x = component_x * quads_per_component + 1;
int size_y = component_y * quads_per_component + 1;
TArray<uint16> ImportLandscape_Data;
ILandscapeEditorModule& editorModule = FModuleManager::GetModuleChecked<ILandscapeEditorModule>("LandscapeEditor");
const ILandscapeHeightmapFileFormat* heightmapFormat = editorModule.GetHeightmapFormatByExtension(*FPaths::GetExtension(heightMapPath,true));
if (heightmapFormat)
{
FLandscapeHeightmapImportData HeightmapImportData = heightmapFormat->Import(*heightMapPath, { 505,505 });
ImportLandscape_Data = MoveTemp(HeightmapImportData.Data);
}
TMap<FGuid,TArray<uint16>> heightmapDataPerLayers;
heightmapDataPerLayers.Add(FGuid(), ImportLandscape_Data);
TMap<FGuid,TArray<FLandscapeImportLayerInfo>> landscapeLayersInfo;
TArray<FLandscapeImportLayerInfo> importLandInfo;
UMaterialInterface* landscapeMaterial = LoadObject<UMaterialInterface>(nullptr,TEXT("/Game/mapmaterial"));
proxy->LandscapeMaterial = landscapeMaterial;
if (landscapeMaterial != nullptr)
{
TArray<FName> layerNames = ALandscapeProxy::GetLayersFromMaterial(landscapeMaterial);
importLandInfo.Reserve(layerNames.Num());
for (int32 i = 0; i < layerNames.Num() - 1; ++i)
{
FLandscapeImportLayerInfo ILayerInfo = FLandscapeImportLayerInfo(layerNames[i]);
ULandscapeLayerInfoObject* newLayerInfo = NewObject<ULandscapeLayerInfoObject>(proxy);
FString layerInfoPath = "/Game/0" + FString::FromInt(i + 1) + "_LayerInfo";
newLayerInfo = LoadObject<ULandscapeLayerInfoObject>(NULL, *layerInfoPath);
ILayerInfo.LayerInfo = newLayerInfo;
ILayerInfo.SourceFilePath = "d:/0" + FString::FromInt(i + 1) + ".png";
importLandInfo.Add(MoveTemp(ILayerInfo));
}
}
landscapeLayersInfo.Add(FGuid(), importLandInfo);
proxy->Import(FGuid::NewGuid(),0,0,size_x - 1,size_y - 1,section_per_component,section_size,heightmapDataPerLayers,TEXT("MapHeightMap"),landscapeLayersInfo,ELandscapeImportAlphamapType::Additive);
}
void-FImpotLandModule::creatscape(FString-heightMapPath)
{
UWorld*world=GEditor->GetEditorWorldContext().world();
FVector位置(0.0f、0.0f、0.0f);
转子转子(0.0f,0.0f,0.0f);
因子参数产卵信息;
ALandscape*景观=世界->演员