兼容数据修复

This commit is contained in:
hesuicong committed 2026-11-12 17:32:13 +08:00
1 parent 46bf872bac
commit 7a5dfb3ec3
1 file changed
+13 -8
+13 -8
View File
@@ -103,7 +103,7 @@ class FillMeshGenerator:
CLAMP_BACK = 0.3 # 距最后表面的安全距离(防穿出后脑)
GAP_MIN = 0.25 # 填充最小厚度
SIGMA = 2.0 # 高度场平滑 sigma(格)
ERODE = 4 # 足迹腐蚀(格) 0.2, 与膨胀0.3配合净外扩0.1(补偿边界平滑收缩)
ERODE = 2 # 足迹腐蚀(格) 0.2, 与膨胀0.3配合净外扩0.1(补偿边界平滑收缩)
BSTEP = 0.18 # 边界重采样步长
BITER = 25 # 边界 Laplacian 平滑迭代
BLAM = 0.6 # 边界平滑系数
@@ -657,7 +657,12 @@ class FillMeshGenerator:
self.log(f" 镜框带补栅格化角落缺口: {nfill} 格")
# ---- 框前面拟合 ----
mfit = g1c & R & (gz1f >= 7.0)
# 自适应阈值:取眼镜表面格 Z 值的 70% 分位数作为下限
if have_g1.sum() > 0:
z_thresh = np.percentile(gz1f[have_g1], 70)
else:
z_thresh = 7.0 # fallback
mfit = g1c & R & (gz1f >= z_thresh)
# 框带定义
eR = self.erode_4(R, 3)
@@ -832,7 +837,7 @@ class FillMeshGenerator:
hb = np.where(R & ~real_f, np.maximum(hb, cap), hb)
self.log(f" 厚度上限(无真实脸面处, 距前面>{self.SHELL_MAX})生效格数: {ncap}")
hb = np.where(R & real_f, np.minimum(hb, fz - 0.25), hb)
hb = np.where(R & real_f, np.minimum(hb, fz - self.EMBED_BOT), hb)
bzs = self.smooth_valid(np.where(have_b, bz, np.nan), have_b)
hb = np.where(R, hb, np.nan)
hb = np.where(have_b, np.maximum(hb, bzs + self.CLAMP_BACK), hb)
@@ -841,16 +846,16 @@ class FillMeshGenerator:
# ===== 在这里添加后表面钳制 =====
# 后表面下界(真实脸面 - 嵌入量)
floor_b = np.where(R & (real_f > -1e29), real_f - self.EMBED_BOT, -np.inf)
floor_b = np.where(R & real_f, fz - self.EMBED_BOT, -np.inf)
# 后表面上界(防穿出后脑,但允许贴脸)
ceil_b = np.where(R & (real_f > -1e29), real_f + self.CLAMP_BACK, np.inf)
ceil_b = np.where(R & real_f, fz + self.CLAMP_BACK, np.inf)
hb = np.minimum(np.maximum(hb, floor_b), ceil_b)
# ===== 结束后表面钳制 =====
# ===== 墙区额外压低贴脸 =====
edge_in = self.erode_4(R, 4)
wall_zone = R & ~edge_in
hb = np.where(wall_zone, np.minimum(hb, real_f - self.EMBED_BOT * 0.8), hb)
hb = np.where(wall_zone, np.minimum(hb, fz - self.EMBED_BOT * 0.8), hb)
# ===== 结束墙区压低 =====
# 外扩填充 NaN
@@ -1587,14 +1592,14 @@ class FillMeshGenerator:
self.log("== 9. 输出 ==")
# 输出填充网格
with open(self.OUT_FILL, "w") as f:
with open(self.OUT, "w") as f:
f.write("# fill mesh between glasses and face\n")
f.write("o fill\n")
for p in Pall:
f.write(f"v {p[0]:.5f} {p[1]:.5f} {p[2]:.5f}\n")
for a, b, c in Ff:
f.write(f"f {a+1} {b+1} {c+1}\n")
self.log(f" {self.OUT_FILL}: {len(Pall)} 顶点, {len(Ff)} 面")
self.log(f" {self.OUT}: {len(Pall)} 顶点, {len(Ff)} 面")
# 输出合并模型
with open(self.OBJ) as f: