Files
AIC-Project/Tools/ModelTranslator/bl_decimate.py
T

25 lines
767 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Blender 内运行:FBX 减面到指定三角面数 + Smart UV 重展。
调用:blender -b --factory-startup --python bl_decimate.py -- <src.fbx> <out.fbx> <target_tris>
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
TOLERANCE = 0.03 # 面数相对误差容忍
MAX_RETRY = 2 # ratio 修正轮数上限
def decimate_ratio(target, cur):
"""Decimate collapse ratiocur <= target 或非法时返回 1.0(不减面)。"""
if cur <= 0 or cur <= target:
return 1.0
return target / float(cur)
def within_tolerance(target, actual, tol=TOLERANCE):
"""减面结果是否落在目标 ±tol 内。"""
if target <= 0:
return False
return abs(actual - target) <= target * tol