From 92623900374a7273297fa75ee7519134386dadee Mon Sep 17 00:00:00 2001 From: lipan Date: Fri, 24 Jul 2026 15:38:10 +0800 Subject: [PATCH] feat: support PLY meshes in vehicle registration --- .../translate_align_pointcloud_to_cad.py | 29 ++++++++++++++++++- .../adapters/vehicle_registration_run.py | 2 +- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/alg/整车配准v1.3/translate_align_pointcloud_to_cad.py b/alg/整车配准v1.3/translate_align_pointcloud_to_cad.py index 0717dbc..dc5d6f7 100644 --- a/alg/整车配准v1.3/translate_align_pointcloud_to_cad.py +++ b/alg/整车配准v1.3/translate_align_pointcloud_to_cad.py @@ -173,6 +173,33 @@ def step_to_open3d_mesh(step_path, mesh_deflection=0.1): return mesh +def load_cad_mesh(cad_path, mesh_deflection=0.1): + """根据后缀加载 CAD mesh:STEP 走 OCC 离散化,PLY 直接读取三角网格。""" + ext = os.path.splitext(cad_path)[1].lower() + + if ext in (".step", ".stp"): + return step_to_open3d_mesh(cad_path, mesh_deflection=mesh_deflection) + + if ext == ".ply": + print(f"[INFO] Loading CAD mesh from PLY: {cad_path}") + mesh = o3d.io.read_triangle_mesh(cad_path) + if len(mesh.vertices) == 0 or len(mesh.triangles) == 0: + raise RuntimeError(f"PLY CAD mesh 为空或读取失败: {cad_path}") + + mesh.remove_duplicated_vertices() + mesh.remove_duplicated_triangles() + mesh.remove_degenerate_triangles() + mesh.compute_vertex_normals() + + print( + f"[OK] PLY CAD mesh loaded: {len(mesh.vertices)} vertices, " + f"{len(mesh.triangles)} triangles" + ) + return mesh + + raise RuntimeError(f"不支持的 CAD 格式: {cad_path}(仅支持 .step/.stp/.ply)") + + # ============================================================ # 工具函数 # ============================================================ @@ -529,7 +556,7 @@ def translate_align_by_front_tail( cad_pcd = None if cad_pcd is None: - cad_mesh = step_to_open3d_mesh( + cad_mesh = load_cad_mesh( cad_path, mesh_deflection=mesh_deflection ) diff --git a/server/plugins/adapters/vehicle_registration_run.py b/server/plugins/adapters/vehicle_registration_run.py index 1536503..9652f15 100644 --- a/server/plugins/adapters/vehicle_registration_run.py +++ b/server/plugins/adapters/vehicle_registration_run.py @@ -43,7 +43,7 @@ def main() -> int: pc_path = first_pointcloud(payload) cad_path = inputs.get("cadPath") if not cad_path: - raise RuntimeError("整车配准需要 STEP CAD 文件,请在任务下上传并选中 CAD。") + raise RuntimeError("整车配准需要 CAD 文件(STEP 或 PLY mesh),请在任务下上传并选中 CAD。") axis = str(config.get("axis") or "x") crop_ratio = float(config.get("cropRatio") or 0.01)