UE问题分部解决
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问题分部解决的更多相关文章
- 5G/NR 波束管理
原文链接:http://www.sharetechnote.com/html/5G/5G_Phy_BeamManagement.html 1 为什么光束管理/光束控制? 我不认为高频部署中的波束传输信 ...
- 解决:百度编辑器UEditor,怎么将图片保存到图片服务器,或者上传到ftp服务器的问题(如果你正在用UE,这篇文章值得你看下)
在使用百度编辑器ueditor的时候,怎么将图片保存到另一个服务器,或者上传到ftp服务器?这个问题,估计很多使用UE的人会遇到.而且我百度过,没有找到这个问题的解决方案.那么:本篇文章就很适合你了. ...
- ue标签不见了,如何解决?
小问题,但是很恶心...如下图: 解决方法: 右键点击[菜单栏]右边的空白处,选择advanced,默认是basic,这时菜单栏中的菜单条目会变多,然后选择[视图]---[视图/列表]---[打开文件 ...
- 百度ue富文本编辑器setContent方法报错初始化加载内容失败解决办法
解决方案: 不能创建editor之后马上使用ueditor.setContent('文本内容');要等到创建完成之后才可以使用 ueditor.addListener("ready" ...
- 探索ASP.NET MVC5系列之~~~2.视图篇(上)---包含XSS防御和异步分部视图的处理
其实任何资料里面的任何知识点都无所谓,都是不重要的,重要的是学习方法,自行摸索的过程(不妥之处欢迎指正) 汇总:http://www.cnblogs.com/dunitian/p/4822808.ht ...
- 【兼容写法】HttpServerUtility.Execute 在等待异步操作完成时被阻止。关键词:MVC,分部视图,异步
异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html MVC6之前的版本,对分部视图的异步支持不是很好 问题: 视图里面有分布视图:@{ ...
- Juniper SSG5 PPTP VPN 619错误解决
公司分部的客户端需要使用PPTP VPN连接总部,将网关更换为Juniper SSG5后,客户端出现了每几个小时自动断开的现象,错误619. 解决:Security —— ALG —— 开启PPTP协 ...
- 在IIS下部署Thinkphp项目,验证码不能显示的解决办法
由于公司租用的是虚拟空间,而且用的是IIS服务器,所以部署PHP的时候就出现很多问题:比如昨天就碰到这个问题:在IIS下部署Thinkphp项目,验证码不能显示 这是生成验证码的方法: // 制作专门 ...
- MVC学习系列6--使用Ajax加载分部视图和Json格式的数据
Ajax的应用在平时的工作中,很是常见,这篇文章,完全是为了,巩固复习. 我们先看看不使用json格式返回分部视图: 先说需求吧: 我有两个实体,一个是出版商[Publisher],一个是书[Book ...
随机推荐
- Android图片下载以及缓存框架
实际开发中进行图片下载以及缓存的框架 介绍一下开发中常见图片加载框架的使用和对比一下优缺点. 1.Picasso 框架 在Android中开发,常需要从远程获取图片并显示在客户端,当然我们可以使用原生 ...
- Unity3D系列教程--使用免费工具在Unity3D中开发2D游戏 第一节
声明: 本博客文章翻译类别的均为个人翻译,版权全部.出处: http://blog.csdn.net/ml3947,个人博客:http://www.wjfxgame.com. 译者说明:这是一个系 ...
- 在进程中执行新代码 execl、execle、execlp、execv、execve和execvp函数
摘要:本文主要讲述怎样在进程中执行新代码,以及exec系列函数的基本用法. 在进程中执行新代码 用函数fork创建子进程后,假设希望在当前子进程中运行新的程序,能够调用exec函数运行还有一个程序.当 ...
- C#创建COM组件供VB,PB,Delphi调用
1 COM组件概述 COM是微软公司为了计算机工业的软件生产更加符合人类的行为方式开发的一种新的软件开发技术.在COM构架下,人们可以开发出各种各样的功能专一的组件,然后将它们按照需要组合起来,构成 ...
- Mysql删除重复数据保留最小的id
在网上查找删除重复数据保留id最小的数据,方法如下: DELETE FROM people WHERE peopleName IN ( SELECT peopleName FROM people GR ...
- python-创建列表
创建个空列表 album = [] 创建非空列表 album = ['Black Star','David Bowie',25.True] 向列表中添加新的元素 append 方法,元素自动地排列到列 ...
- Microsoft Team Foundation Server 2010 安装 序列号 注册码(转载)
安装过程: 一.安装操作系统 安装Windows 2008 R2简体中文版 二.准备安装过程中的需要的用户账户,并设置相应权限. 具体流程如下: 1.点击“开始”——“管理工具”——“计算机管理” 2 ...
- makefile之强制目标
强制目标 1. 定义 如果一个规则(rule_A)既没有依赖也没有命令,仅有目标(Targe_A),并且目标名不冲突.那么,在执行这个规则的时候,目标总被认为是更新过的.如果这个目标(Target_A ...
- (转)Python开发规范
转自:https://www.jianshu.com/p/d414e90dc953 Python风格规范 本项目包含了部分Google风格规范和PEP8规范,仅用作内部培训学习 Python风格规范 ...
- jquery 操作input radio 单选框
1.jquery选中单选框 2.jquery 取消单选框 3.判断是否选中 4.设置不可编辑