教程地址:Unreal Engine Automation - Automated Python Texture Parameter Setter
很棒的一套教程,感谢下老师!
自己捣鼓脚本没成功,回来继续跟着教程学习
这个视频教程用来设置贴图参数
- 通过路径获取Asset列表
- 循环遍历每个Asset,检查名称中是否包含定义的关键字
- 参数设置
这里是前两步的代码块,1通过路径获取Asset列表,循环遍历每个Asset,检查名称中是否包含定义的关键字
import unreal
# 实例化unreal类
editor_asset_lib = unreal.EditorAssetLibrary() # 实例化编辑资产类
string_lib = unreal.StringLibrary() # 实例化字符类
# 在源目录中获取所有资产对象
source_dir = "/Game/Material/" # 目标路径
include_subfolders = True # 定义查找Asset列表时是否递归查找子文件夹
set_textures = 0 # 计数
assets = editor_asset_lib.list_assets(source_dir, recursive=include_subfolders) # 获取Asset列表
color_patterns = ["_ORM", "_occlusion", "_metallic", "_roughness", "_mask"] # 定义名称关键字
for asset in assets:
# 循环每个资产对象确认参数是否需要修改
for pattern in color_patterns: # 循环每个名称关键字
if string_lib.contains(asset, pattern): # 如果Asset包含该名称关键字
unreal.log("Setting TC_Masks and turning off sRGB for asset {}".format(asset)) # 输出信息
set_textures += 1 # 计数
unreal.log("Linear color for matching textures set for {} assets".format(set_textures)) # 输出结果
接下来是设置Asset属性,首先需要使用load_asset加载资产对象
然后调用对象方法set_editor_property设置参数 (详阅-unreal._ObjectBase)
这里需要注意压缩方式的设置并不能直接设置值,而是需要搭配使用unreal.TextureCompressionSettings函数 (详阅-unreal.TextureCompressionSettings)
import unreal
# 实例化unreal类
editor_asset_lib = unreal.EditorAssetLibrary() # 实例化编辑资产类
string_lib = unreal.StringLibrary() # 实例化字符类
# 在源目录中获取所有资产对象
source_dir = "/Game/Material/" # 目标路径
include_subfolders = True # 定义查找Asset列表时是否递归查找子文件夹
set_textures = 0 # 计数
assets = editor_asset_lib.list_assets(source_dir, recursive=include_subfolders) # 获取Asset列表
color_patterns = ["_ORM", "_occlusion", "_metallic", "_roughness", "_mask"] # 定义名称关键字
for asset in assets:
# 循环每个资产对象确认参数是否需要修改
for pattern in color_patterns: # 循环每个名称关键字
if string_lib.contains(asset, pattern): # 如果Asset包含该名称关键字
# 读取资产对象,关闭sRGB并设置compression为TC_Mask
asset_obj = editor_asset_lib.load_asset(asset) # 加载Asset
asset_obj.set_editor_property("sRGB", False) # 设置sRGB参数
asset_obj.set_editor_property("CompressionSettings", unreal.TextureCompressionSettings.TC_MASKS) # 设置压缩设置
unreal.log("Setting TC_Masks and turning off sRGB for asset {}".format(asset)) # 输出信息
set_textures += 1 # 计数
break
unreal.log("Linear color for matching textures set for {} assets".format(set_textures)) # 输出结果
希望这点笔记能帮助到你
乾杯 ( ゜- ゜)つロ