项目中经过houdini engine bake之后,StaticMesh的LOD没有同步过去,要是全部手动设置会很麻烦(一般都有6个不同的lod,要分别设置各自的屏幕尺寸和三角百分比,如图红框所示)。
把bake前的静态网格叫做SM_1,bake 之后的静态网格叫做SM_2, 写了个脚本,把SM_1的LOD赋值给SM-2:
#复制sm_1的参数到sm_2
def copy_lods(static_mesh1,static_mesh2):
print("[HDA Baker]treating asset: " + static_mesh1.get_name())
print("[HDA Baker]existing LOD count: " + str(unreal.EditorStaticMeshLibrary.get_lod_count(static_mesh1)))
options = unreal.EditorScriptingMeshReductionOptions()
# 读屏幕尺寸(数组)
lod_sizes = unreal.EditorStaticMeshLibrary.get_lod_screen_sizes(static_mesh1)
options.reduction_settings = []
for lod_num,lod_size in zip(range(unreal.EditorStaticMeshLibrary.get_lod_count(static_mesh1)),lod_sizes):
# 读三角百分比
sm1_MeshReductionSettings = unreal.EditorStaticMeshLibrary.get_lod_reduction_settings(static_mesh1,lod_num)
lod_triangle = sm1_MeshReductionSettings.percent_triangles
# 读SM_1
print("[HDA Baker]sm1 lod tri per: " + str(lod_triangle) + ",sm1 lod size: " + str(lod_size) )
# 赋值到SM_2
options.reduction_settings.append(unreal.EditorScriptingMeshReductionSettings(lod_triangle, lod_size))
options.auto_compute_lod_screen_size = False
unreal.EditorStaticMeshLibrary.set_lods(static_mesh2, options)
#保存SM_2
unreal.EditorAssetLibrary.save_loaded_asset(static_mesh2)
print("[HDA Baker]new LOD count: " + str(unreal.EditorStaticMeshLibrary.get_lod_count(static_mesh2)))
# 全部copy lod
def final_copy_lod():
copy_sm1_paths = get_all_sm1()
for copy_sm1_path in copy_sm1_paths:
asset = unreal.find_object(None, copy_sm1_path)
copy_sm2_path = copy_sm1_path.replace('SM_1.SM_1', 'SM_2.SM_2')
print('[HDA Baker]SM_2 Path:' + copy_sm2_path)
asset2 = unreal.find_object(None, copy_sm2_path)
copy_lods(asset, asset2)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)