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 ...
随机推荐
- [读后感]Java 控制台执行 Jar 传參的编码问题
下面这版面,太让我纠结了.谁能帮调整一下,... _________________ java -jar test.jar "一二一" 这样传进去的 "一二一" ...
- Android 底部TabActivity(1)——FragmentActivity
先看看效果图: 第一篇Tab系列的文章首先实现这样的风格的底部Tab:背景条颜色不变,我们是用了深灰的颜色,图标会发生对应的变化.当选中某个标签后该标签的背板会由正常的颜色变为不正常,哈哈,是变为加深 ...
- ant 重置(修改)DatePicker MonthPicker Cascader 的值
1.清空值 this.props.form.resetFields(); 2.监听 props 的变化,触发 清空按钮 .
- struts result动态结果集 带参数的结果集
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC &qu ...
- c++对象模型介绍
http://www.cnblogs.com/skynet/p/3343726.html
- /usr/lib64/libssl.so.10: no version information available (required by ./mongod)
启动mongodb时,日志提示以下信息: ./mongod: /usr/lib64/libssl.so.10: no version information available (required b ...
- Application Request Route实现IIS Server Farms集群负载详解(转)
http://www.cnblogs.com/knowledgesea/p/5099893.html http://www.cnblogs.com/smileberry/p/4300849.html
- H5 获取地理位置
只能通过手机浏览器访问,并且用户必须允许访问才可以生效 <!doctype html> <html> <head> <title>Mobile Cook ...
- atitit.企业管理----商业间谍策略的使用与防务
atitit.企业管理----商业间谍策略的使用与防务 1. 间谍的历史 2 1.1. 公元前10世纪,<旧约全书>中的<士师记>里讲述了参孙的故事是最早的间谍故事. 2 1. ...
- 【JS设计模式】装饰者模式
装饰者模式:在不必改变原类文件和使用继承的情况下,动态地扩展一个对象的功能.它是通过创建一个包装对象,也就是装饰来包裹真实的对象 装饰模式的特点 (1) 装饰对象和真实对象有同样的接口.这样clien ...