Files
massive-cloud/alg/平整度、平面度、轮廓测量v1.5/archive/CAD2Mesh.py
lipan 29f1d45d66 feat: 算法升级、整车配准集成与性能分析文档
算法更新: delivery v1.2.1、平整度v1.5、测距v2.2、整车配准v1.3
适配器: vehicle-registration 新增、各算法 manifest 和 adapter 更新
后端: taskCadFiles/source 字段迁移、derivedPointClouds 注册、取消任务联动
前端: ElapsedTime 时长显示、两步算法流程、canRun 逻辑修复
文档: 新增5份算法性能分析报告
2026-06-25 08:22:20 +00:00

55 lines
2.4 KiB
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.
from OCC.Core.STEPControl import STEPControl_Reader
from OCC.Core.IFSelect import IFSelect_RetDone
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
from OCC.Core.StlAPI import StlAPI_Writer
import time
import argparse # 命令行参数解析
def step2lightweight_stl(mesh_precision, input_step, output_stl):
"""STEP转轻量化STL,纯后台处理,无显示,体积暴减"""
start_total = time.time()
# 1. 读取STEP文件
print(f"【1/3】读取STEP文件:{input_step}")
step_reader = STEPControl_Reader()
if step_reader.ReadFile(input_step) != IFSelect_RetDone:
raise Exception("STEP文件读取失败!检查路径/文件完整性")
step_reader.TransferRoots()
shape = step_reader.OneShape()
print(f"【1/3】读取完成,耗时:{time.time()-start_total:.2f}秒")
# 2. 核心:网格离散化
print(f"【2/3】网格离散化(精度{mesh_precision}mm),开始轻量化...")
mesh = BRepMesh_IncrementalMesh(shape, mesh_precision, False)
mesh.Perform()
if not mesh.IsDone():
raise Exception("网格离散化失败!")
print(f"【2/3】轻量化完成,耗时:{time.time()-start_total:.2f}秒")
# 3. 保存为STL
print(f"【3/3】保存轻量化STL:{output_stl}")
stl_writer = StlAPI_Writer()
stl_writer.Write(shape, output_stl)
total_time = time.time() - start_total
print(f"✅ 转换完成!总耗时:{total_time:.2f}秒")
print(f"💡 提示:STL文件可直接用FreeCAD/MeshLab/3D Viewer打开")
if __name__ == "__main__":
# ========== 命令行参数定义 ==========
parser = argparse.ArgumentParser(description="STEP 转 轻量化 STL (命令行args版)")
parser.add_argument("--precision", "-p", type=float, default=1.0, help="网格精度 MESH_PRECISION (mm),越大文件越小")
parser.add_argument("--input", "-i", type=str, default="High_Speed_Data/CAD/11.step", help="输入STEP文件路径 INPUT_STEP_PATH")
parser.add_argument("--output", "-o", type=str, default="High_Speed_Data/Mesh/11.stl", help="输出STL文件路径 OUTPUT_STL_PATH")
# 解析参数
args = parser.parse_args()
# 调用转换函数
try:
step2lightweight_stl(
mesh_precision=args.precision,
input_step=args.input,
output_stl=args.output
)
except Exception as e:
print(f"❌ 处理失败:{str(e)}")