import bpy
print()
print()
# 遍歷場(chǎng)景中的所有物體
for obj in bpy.data.objects:
# 檢查物體是否為網(wǎng)格
if obj.type == 'MESH':
# 計(jì)算物體的面數(shù)
face_count = len(obj.data.polygons)
# 如果面數(shù)大于 xxx,則進(jìn)行減面操作
if face_count > 800:
print(f"物體 {obj.name} 的面數(shù)為:{face_count}")
# 選中物體
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
# 切換到編輯模式
# bpy.ops.object.mode_set(mode='EDIT')
# 添加 Decimate 修改器
bpy.ops.object.modifier_add(type='DECIMATE')
# 設(shè)置 Decimate 修改器的參數(shù)
bpy.context.object.modifiers["Decimate"].ratio = 0.4
# 應(yīng)用 Decimate 修改器
bpy.ops.object.modifier_apply(modifier="Decimate")
# 切換回物體模式
# bpy.ops.object.mode_set(mode='OBJECT')
face_count_after = len(obj.data.polygons)
print(f"減面后: {face_count}")
print()