0.寻找Actor

ALandscape *land=nullptr;
for (TActorIterator<ALandscape> It(GEditor->GetEditorWorldContext().World()); It; ++It) {
if (It) {
FString name = It->GetName();
if (name == "Landscape_0")
{
UE_LOG(LogTemp, Log, TEXT("已找到%s"), *name);
land = *It;
break;
}
}
}
if (land == nullptr)
{
UE_LOG(LogTemp, Log, TEXT("未找到"));
return;
}

1.获取材质球

UMaterialInterface *matInterFace= land->GetLandscapeMaterial();

2.获取材质球属性

UMaterialInterface *matInterFace= land->GetLandscapeMaterial();
UTexture *tex = nullptr;
FName texName="Color01";
matInterFace->GetTextureParameterValue(texName,tex,false);
if (tex != nullptr)
{
FString fullName = tex->GetPathName();
UE_LOG(LogTemp, Log, TEXT("已找到Color01的图为%s"),*fullName);
}

3.动态设置材质球属性

UMaterialInstanceConstant *materialConstantInstance = nullptr;
materialConstantInstance = Cast<UMaterialInstanceConstant>(matInterFace);
materialConstantInstance->SetTextureParameterValueEditorOnly(FName("Color02"), tex);

3.5.创建文件夹

VerifyOrCreateDirectory("D:\\WWW");
bool SLPanel::VerifyOrCreateDirectory(const FString& TestDir)
{ // Every function call, unless the function is inline, adds a small
// overhead which we can avoid by creating a local variable like so.
// But beware of making every function inline!
IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); // Directory Exists?
if (!PlatformFile.DirectoryExists(*TestDir))
{
PlatformFile.CreateDirectory(*TestDir); if (!PlatformFile.DirectoryExists(*TestDir))
{
UE_LOG(LogTemp, Log, TEXT("未能成功创建"));
return false;
//~~~~~~~~~~~~~~
}
}
UE_LOG(LogTemp, Log, TEXT("已成功创建"));
return true;
}

4.创建图片

SaveTextureToDisk(Cast<UTexture2D>(tex),"D:\\Output\\1.png");

void SaveTextureToDisk(UTexture2D* texture, const FString& file)
{
TextureCompressionSettings prevCompression = texture->CompressionSettings;
TextureMipGenSettings prevMipSettings = texture->MipGenSettings;
texture->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
texture->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
texture->UpdateResource();
FTexture2DMipMap* MM = &texture->PlatformData->Mips[]; TArray<FColor> OutBMP;
int w = MM->SizeX;
int h = MM->SizeY; OutBMP.SetNumUninitialized(w*h); FByteBulkData* RawImageData = &MM->BulkData; FColor* FormatedImageData = static_cast<FColor*>(RawImageData->Lock(LOCK_READ_ONLY));
if (FormatedImageData)
{
for (int i = ; i < (w*h); ++i)
{
OutBMP[i] = FormatedImageData[i];
OutBMP[i].A = ;
} RawImageData->Unlock();
FIntPoint DestSize(w, h); FString ResultPath;
FHighResScreenshotConfig& HighResScreenshotConfig = GetHighResScreenshotConfig();
HighResScreenshotConfig.SaveImage(file, OutBMP, DestSize, nullptr);
}
else
{
UE_LOG(LogTemp, Error, TEXT("SaveTextureToDisk: could not access bulk data of texture! Texture: %s"), *texture->GetFullName());
} texture->CompressionSettings = prevCompression;
texture->MipGenSettings = prevMipSettings;
}

5.图片转二维数组

TArray<TArray<FColor>> SLPanel::GetArrayFromLocalTex(const FString &_TexPath)
{
TArray<TArray<FColor>> colorArray; TArray<uint8> OutArray;
if (FFileHelper::LoadFileToArray(OutArray, *_TexPath))
{
int length = OutArray.Num();
int size =FMath::Sqrt(length / );
colorArray.Init(TArray<FColor>(),size);
for (int index = ; index < size; index++)
{
colorArray[index].Init(FColor(), size);
}
int count = ;
for (int i = ; i < size; i++)
for (int j = ; j < size; j++)
{
colorArray[i][j].R = OutArray[count++];
colorArray[i][j].G = OutArray[count++];
colorArray[i][j].B = OutArray[count++];
colorArray[i][j].A = OutArray[count++];
}
}
else
{
colorArray.Init(TArray<FColor>(), );
}
return colorArray;
}

6.获取地形混合图3维数组

ULandscapeComponent* landComponent=Cast<ULandscapeComponent>(land->GetComponentByClass(ULandscapeComponent::StaticClass()));
TArray<UTexture2D*> weightTextures = landComponent->WeightmapTextures;
ALandscapeProxy *proxy = landComponent->GetLandscapeProxy();
ULandscapeInfo*LandscapeInfo = proxy->GetLandscapeInfo();
for (int32 i = ; i < LandscapeInfo->Layers.Num(); ++i)
{
ULandscapeLayerInfoObject*LayerInfo = LandscapeInfo->Layers[i].LayerInfoObj;
if (LayerInfo)
{ FString LayerName = "D:/Output/" + LayerInfo->LayerName.ToString() + ".png";
LandscapeInfo->ExportLayer(LayerInfo, LayerName);
}
}

7.动态更换地形材质球

UMaterialInterface* newMat = LoadObject<UMaterialInterface>(NULL, TEXT("MaterialInstanceConstant'/Game/Landscape_2_Inst.Landscape_2_Inst'"));
land->LandscapeMaterial = newMat;

8.脚本创建材质实例

    UMaterial* newMat = LoadObject<UMaterial>(NULL, TEXT("Material'/Game/Landscape.Landscape'"));
FAssetToolsModule &AssetToolsModule = FModuleManager::Get().LoadModuleChecked<FAssetToolsModule>("AssetTools");
UMaterialInstanceConstantFactoryNew* Factory = NewObject<UMaterialInstanceConstantFactoryNew>();
Factory->InitialParent = newMat;
FString AssetPath = TEXT("/Game/");
UMaterialInstanceConstant *MInst = CastChecked<UMaterialInstanceConstant>(AssetToolsModule.Get().CreateAsset(TEXT("MatInstance"), FPackageName::GetLongPackagePath(AssetPath), UMaterialInstanceConstant::StaticClass(), Factory)); if (MInst)
{
MInst->SetFlags(RF_Standalone);
MInst->MarkPackageDirty();
MInst->PostEditChange();
}

9.脚本创建dds

UE_LOG(LogTemp, Error, TEXT("开始合并dds"));
//FString exeStr = "D:\\software\\PowerVR\\Tool\\PVRTexTool\\CLI\\Windows_x86_64\\PVRTexToolCLI.exe";
//FString exeStr = "G:\\UEProject\\UESource\\LocalBuilds\\Engine\\Windows\\Engine\\Binaries\\ThirdParty\\ImgTec\\PVRTexToolCLI.exe";
FString exeStr = FPaths::EngineDir()+"Binaries/ThirdParty/ImgTec/PVRTexToolCLI.exe";
const TCHAR* url= *exeStr; FString paraStr = "C:\\Users\\Administrator> PVRTexToolCLI -m 1 -f b8g8r8a8 -i D:\\Texs\\0.tga,D:\\Texs\\1.tga,D:\\Texs\\2.tga,D:\\Texs\\3.tga -array -r 512,512 -o D:\\Output\\2dArray.dds";
const TCHAR* paras=*paraStr;
FPlatformProcess::CreateProc(url,paras, true, false, false, nullptr, -, nullptr, nullptr);

10.脚本创建LayerInfo

FName LayerName = FName("layer03");
FName LayerObjectName = FName("Layer03_LayerInfo");
FString PackageName =FString("/Game/") + LayerObjectName.ToString();
UPackage* Package = CreatePackage(nullptr, *PackageName);
ULandscapeLayerInfoObject* LayerInfo = NewObject<ULandscapeLayerInfoObject>(Package, LayerObjectName, RF_Public | RF_Standalone | RF_Transactional);
LayerInfo->LayerName = LayerName;
LayerInfo->bNoWeightBlend =false;
const UObject* LayerInfoAsUObject = LayerInfo; // HACK: If SetValue took a reference to a const ptr (T* const &) or a non-reference (T*) then this cast wouldn't be necessary
//ensure(PropertyHandle_LayerInfo->SetValue(LayerInfoAsUObject) == FPropertyAccess::Success);
// Notify the asset registry
FAssetRegistryModule::AssetCreated(LayerInfo);
// Mark the package dirty...
Package->MarkPackageDirty();
// Show in the content browser
TArray<UObject*> Objects;
Objects.Add(LayerInfo);
GEditor->SyncBrowserToObjects(Objects);

11.动态指定LayerInfo(目前还无法做到刷新,但点击其他模式就行了)

    ULandscapeComponent* landComponent = Cast<ULandscapeComponent>(land->GetComponentByClass(ULandscapeComponent::StaticClass()));
TArray<UTexture2D*> weightTextures = landComponent->WeightmapTextures;
ALandscapeProxy *proxy = landComponent->GetLandscapeProxy();
ULandscapeInfo*LandscapeInfo = proxy->GetLandscapeInfo(); ULandscapeLayerInfoObject* obj= LoadObject<ULandscapeLayerInfoObject>(NULL, TEXT("LandscapeLayerInfoObject'/Game/ALayer03_LayerInfo.ALayer03_LayerInfo'"));
LandscapeInfo->ReplaceLayer(LandscapeInfo->Layers[].LayerInfoObj,obj);
FLandscapeInfoLayerSettings& LayerSettings = LandscapeInfo->Layers[];
LayerSettings.LayerInfoObj =obj;

12.自动import资源https://www.cnblogs.com/username/p/7483340.html

FAssetToolsModule &AssetToolsModule = FModuleManager::Get().LoadModuleChecked<FAssetToolsModule>("AssetTools");
IAssetTools& AssetTool = AssetToolsModule.Get();
TArray<FString> fileArray;
fileArray.Init(FString("D://Output//Layer01.png"),);
AssetTool.ImportAssets(fileArray, FString("/Game"),NULL);

设置权重数据bool LandscapeEditorUtils::SetWeightmapData(ALandscapeProxy* Landscape, ULandscapeLayerInfoObject* LayerObject, const TArray<uint8>& Data)

获得权重数据 void GetWeightData(ULandscapeLayerInfoObject* LayerInfo, int32& X1, int32& Y1, int32& X2, int32& Y2, TMap<FIntPoint, uint8>& SparseData);

或者 LandscapeEdit文件中:void ULandscapeComponent::InitWeightmapData(TArray<ULandscapeLayerInfoObject*>& LayerInfos, TArray<TArray<uint8> >& WeightmapData)

这里面貌似高度图之类的东西都有,以后可以参考

FEdModeLandscape* LandscapeEdMode = (FEdModeLandscape*)GLevelEditorModeTools().GetActiveMode(FBuiltinEditorModes::EM_Landscape); 这个为nullptr就表示当前不在刷地形栏

void FLandscapeEditorCustomNodeBuilder_TargetLayers::OnTargetLayerCreateClicked(const TSharedRef<FLandscapeTargetListInfo> Target, bool bNoWeightBlend) 创建Layer

UE问题分部解决的更多相关文章

  1. 5G/NR 波束管理

    原文链接:http://www.sharetechnote.com/html/5G/5G_Phy_BeamManagement.html 1 为什么光束管理/光束控制? 我不认为高频部署中的波束传输信 ...

  2. 解决:百度编辑器UEditor,怎么将图片保存到图片服务器,或者上传到ftp服务器的问题(如果你正在用UE,这篇文章值得你看下)

    在使用百度编辑器ueditor的时候,怎么将图片保存到另一个服务器,或者上传到ftp服务器?这个问题,估计很多使用UE的人会遇到.而且我百度过,没有找到这个问题的解决方案.那么:本篇文章就很适合你了. ...

  3. ue标签不见了,如何解决?

    小问题,但是很恶心...如下图: 解决方法: 右键点击[菜单栏]右边的空白处,选择advanced,默认是basic,这时菜单栏中的菜单条目会变多,然后选择[视图]---[视图/列表]---[打开文件 ...

  4. 百度ue富文本编辑器setContent方法报错初始化加载内容失败解决办法

    解决方案: 不能创建editor之后马上使用ueditor.setContent('文本内容');要等到创建完成之后才可以使用 ueditor.addListener("ready" ...

  5. 探索ASP.NET MVC5系列之~~~2.视图篇(上)---包含XSS防御和异步分部视图的处理

    其实任何资料里面的任何知识点都无所谓,都是不重要的,重要的是学习方法,自行摸索的过程(不妥之处欢迎指正) 汇总:http://www.cnblogs.com/dunitian/p/4822808.ht ...

  6. 【兼容写法】HttpServerUtility.Execute 在等待异步操作完成时被阻止。关键词:MVC,分部视图,异步

    异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html MVC6之前的版本,对分部视图的异步支持不是很好 问题: 视图里面有分布视图:@{ ...

  7. Juniper SSG5 PPTP VPN 619错误解决

    公司分部的客户端需要使用PPTP VPN连接总部,将网关更换为Juniper SSG5后,客户端出现了每几个小时自动断开的现象,错误619. 解决:Security —— ALG —— 开启PPTP协 ...

  8. 在IIS下部署Thinkphp项目,验证码不能显示的解决办法

    由于公司租用的是虚拟空间,而且用的是IIS服务器,所以部署PHP的时候就出现很多问题:比如昨天就碰到这个问题:在IIS下部署Thinkphp项目,验证码不能显示 这是生成验证码的方法: // 制作专门 ...

  9. MVC学习系列6--使用Ajax加载分部视图和Json格式的数据

    Ajax的应用在平时的工作中,很是常见,这篇文章,完全是为了,巩固复习. 我们先看看不使用json格式返回分部视图: 先说需求吧: 我有两个实体,一个是出版商[Publisher],一个是书[Book ...

随机推荐

  1. 【一步一步走(1)】远程桌面软件VNC的安装与配置

    近期在VPS上搭建Python Web环境.走了非常多弯路,借此记下. 先说说购买的VPS(PhotonVPS),我可不是打广告.仅仅是感觉这个VPS服务提供商还不错推荐给你大家,我之前也是体验过阿里 ...

  2. odoo8.0下selection_add的使用

    在odoo中有selection类型的字段,用于限定字段的值在某些范围之内,在view上面显示此字段时,会显示一个下拉的列表. 如果是自己新定义的字段,这个列表的内容可以自己定义,但如果是继承自某个对 ...

  3. MVC 强类型传值Model。和弱类型传值ViewData[&quot;&quot;]。及用EF进行增删查改(母版页的使用)

    <1> 控制器 </pre><pre name="code" class="csharp">using MvcTest.Mo ...

  4. Android权限说明 system权限 root权限

    原文链接:http://blog.csdn.net/rockwupj/article/details/8618655 Android权限说明 Android系统是运行在Linux内核上的,Androi ...

  5. php json_decode失败,返回null

    在使用json_decode之前,一定得保证字符串是utf-8编码,而执行json_decode失败的原因有很多,罗列如下: 1)编码不对: 2)字符串格式不对: 3)字符串格式对,但是有异常字符: ...

  6. Lintcode---二叉树的前序、中序、后序遍历

    给出一棵二叉树,返回其节点值的后序遍历. 您在真实的面试中是否遇到过这个题? Yes 样例 给出一棵二叉树 {1,#,2,3}, 1 \ 2 / 3 返回 [3,2,1] 思路:二叉树的后序遍历,简单 ...

  7. python list.remove(),del()和filter &amp; lambda

    面试题之中的一个. 下面代码能执行吗? l = [1,2,3,4,5] for i in range(0,len(l)): print i if l[i] % 2 == 0: del l[i] pri ...

  8. ATITIT.翻译模块的设计与实现 api attilax 总结

    ATITIT.翻译模块的设计与实现 api attilax 总结 1. 翻译原理1 2. TMX格式是国际通用格式(xml)1 2.1. 方法/步骤2 3. TRADOS2 4. ATITIT.翻译软 ...

  9. iOS获取当前设备方向

    三种方式: self.interfaceOrientation [[UIApplication sharedApplication] statusBarOrientation] [[UIDevice ...

  10. C# 版 防止 DNS 污染,获取域名真实 IP 地址

    using System; using System.Collections.Generic; using System.IO; using System.Net; using System.Net. ...