From 53a2df85226704a38ff306c7377ea02736fce14d Mon Sep 17 00:00:00 2001 From: mckay Date: Wed, 7 May 2025 15:43:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=AD=E7=BB=83=E6=95=B0=E6=8D=AE=E6=89=93?= =?UTF-8?q?=E4=B9=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- brep2sdf/data/sampler.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/brep2sdf/data/sampler.py b/brep2sdf/data/sampler.py index 8f64795..2d5c79a 100644 --- a/brep2sdf/data/sampler.py +++ b/brep2sdf/data/sampler.py @@ -211,11 +211,20 @@ def sample_zero_surface_points_and_normals( # 获取每个点所在的三角面片的法线 normals = trimesh_mesh_ncs.face_normals[face_indices] + + # 检查 face_normals 是否已归一化 + normals_norm = np.linalg.norm(normals, axis=1) + if not np.allclose(normals_norm, 1.0, atol=1e-5): + print("⚠️ 注意:face_normals 未归一化,正在手动归一化...") + normals = normals / (normals_norm.reshape(-1, 1) + 1e-8) + + # 构造 sdf 标签为 0 的列 sdf_zeros = np.zeros((num_samples, 1), dtype=np.float32) # 合并为 (N, 7) 的数组 [xyz, normal, sdf=0] points_with_normals_sdf = np.hstack([points, normals, sdf_zeros], dtype=np.float32) + np.random.shuffle(points_with_normals_sdf) return points_with_normals_sdf