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 ...
随机推荐
- MySQL的索引及其优化
前言 索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页面大小为4K,并存储100条记录.如果没有索引,查询将对整 ...
- oracle将一个表中字段的值赋值到另一个表中字段(批量)
面积表中数据错误,现将面积表中的sfmj字段的值改为居民信息表中匹配字段的值 update (select s.name name1,s2.name name2 from simple s,simpl ...
- Oem7F7 通用完美激活v7.0绿色版 永久激活Windows7/2008
http://www.21andy.com/blog/20100906/1942.html
- OPC UA的监控项、订阅、和通知
MonitoredItem 每个监控项均指明了要监控的项目(item)和用来发送通知的订阅. item可以是一个节点的属性(node attribute). MonitorItem可以监控一个属性,一 ...
- html5-本地数据库的操作
<script src="jquery-1.8.3.js"></script><script>/* IE11不支持此操作创建数据库 解释一下op ...
- [转]鼠标和键盘模拟API
几乎所有的游戏中都使用了鼠标来改变角色的位置和方向,玩家仅用一个小小的鼠标,就可以使角色畅游天下. 那么,我们如何实现在没有玩家的参与下角色也可以自动行走呢.其实实现这个并不难,仅仅几个Windows ...
- SCUT个人整理的常见问题
1.刚打开redis和服务端,测试时发现明显延时 刚开始会同步数据比较卡,需要进行一次操作才会同步.这个问题暂时没去研究 2.Server failed to start error:The mode ...
- USB3.0测试和使用说明
概述 AC6102上集成了一颗Cypress 推出的高性能USB3.0传输芯片CYUSB3014,Cypress称之为EZ-USBFX3.该芯片性能强劲,功能强大,接口简单,非常适合用于各种需要高速数 ...
- THINKPHP3.2视频教程
http://edu.51cto.com/lesson/id-24504.html lunix视频教程 http://bbs.lampbrother.net/read-htm-tid-161465.h ...
- JS 16进制加密解密
http://www.zc520.cc/js/62.html <script type="text/javascript"> function JavaDe(){ va ...