feat: support PLY meshes in vehicle registration
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user