|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2023-1-28 00:14:16
|
显示全部楼层
本帖最后由 tzbm123456 于 2023-1-29 13:59 编辑
1、资源是否存在:
aa='/Game/Mesh/MyMesh01'
print(unrealm.EditorAssetLibrary.does_asset_exist(aa))
2、目录是否存在:
tmpDir='/Game/Mesh'
print(unrealm.EditorAssetLibrary.does_directory_exist(tmpDir))
3、选择资源操作集
#1、 选择给定名称静态网格资源
asset=['/Game/Mesh/MyMesh'];
tmpEnt=unreal.EditorAssetLibrary.sync_browser_to_objects(asset);
print(tmpEnt);
#2、获取已选择的资源数组
editor_util=unreal.EditorUtilityLibrary();
selected_assets=editor_util.get_selected_assets();
#3、获取资源数组第一个元素的类型名称tmpAssetTypeName
tmpAssetTypeName=selected_assets[0].get_class().get_name();
print(tmpAssetTypeName);
# 打印出:StaticMesh
#4、获取静态网格资源的材质数组tmpMatArr
tmpMatArr=selected_assets[0].static_materials;
print(tmpMatArr);
# 打印出:[{material_interface: Material'"/Game/Material/MyMat_01.MyMat_01"', material_slot_name: "BasicShapeMaterial", uv_channel_data: {}}]
#5、获取静态网格材质数量tmpMatNum
tmpStaicMesh=selected_assets[0];
tmpMeshLib=unreal.EditorStaticMeshLibrary();
tmpMatNum=tmpMeshLib.get_number_materials(tmpStaicMesh);
print(tmpMatNum);
# 打印出:1
#6、获取材质数组tmpMatArr中第一个材质的类型名称tmpMatTypeName
tmpMatTypeName=tmpMatArr[0].material_interface.get_class().get_name();
print(tmpMatTypeName);
# 打印出:Material 或 MaterialInstanceConstant
#7、创建名称assetname
asset_type="Type";
asset_name="assetName";
index=0;
asset_variation="VA";
assetname = ("{}_{}_{}_{}").format(asset_type,asset_name,index,asset_variation)
#8、获取材质中的贴图数组tmpTextureArr
tmpMatLib = unreal.MaterialEditingLibrary();
tmpMat = tmpMatArr[0].material_interface;
tex_set = set();
tmpMatType = tmpMat.get_class().get_name()
if tmpMatType == "Material": tex_group = tmpMatLib.get_used_textures(tmpMat)
for item in tex_group:
tex_set.add(item)
tmpStr=item.get_full_name();
#tmpStr为'Texture2D /Game/Material/biaozhu.biaozhu'字符
tmpArr=tmpStr.split(" ");
tmpPath=tmpArr[1];
print("Texture路径:"+tmpPath);
if tmpMatType == 'MaterialInstanceConstant': # 获取材质实例tmpMat的父项材质的贴图组tex_group
tex_group = tmpMatLib.get_used_textures(tmpMat.parent)
for item in tex_group:
tmpStr=item.get_full_name();
#tmpStr为'Texture2D /Game/Material/biaozhu.biaozhu'字符
tmpArr=tmpStr.split(" ");
tmpPath=tmpArr[1];
print("Texture路径:"+tmpPath);
# if tmpMatType == 'MaterialInstanceConstant':
# tex_group = tmpMat.get_editor_property('texture_parameter_values')
# for item in tex_group:
# tex_set.add(item.parameter_value)
# print(item.parameter_value.get_name())
print('相关贴图数目为:' + str(len(tex_set)))
|
|