This commit is contained in:
2026-03-07 01:40:37 +08:00
parent 57a67309bd
commit 4ce0662df1
2 changed files with 39 additions and 22 deletions
+11 -6
View File
@@ -3,6 +3,7 @@ import logging
import numpy as np
from typing import Dict, List, Optional, Any
import trimesh
from trimesh import sample as trimesh_sample
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_FACE
@@ -23,7 +24,7 @@ class MeshGenerator:
}
self.quality = self.quality_settings.get(quality, 0.3)
def generate_mesh_from_shape(self, shape, num_points: int = 50000) -> Dict:
def generate_mesh_from_shape(self, shape, num_points: int = 20000) -> Dict:
"""从PythonOCC形状生成点云数据"""
try:
# 生成网格 - 使用更精细的网格
@@ -68,7 +69,7 @@ class MeshGenerator:
pnt = face_triangulation.Node(i)
# 应用位置变换
pnt.Transform(trsf)
face_vertices.append([pnt.X(), pnt.Y(), pnt.Z()])
face_vertices.append([float(pnt.X()), float(pnt.Y()), float(pnt.Z())])
# 提取三角形索引
face_indices = []
@@ -103,8 +104,12 @@ class MeshGenerator:
# 创建Trimesh对象
tri_mesh = trimesh.Trimesh(vertices=vertices, faces=faces, process=True)
# 根据网格大小动态调整采样点数
actual_num_points = min(num_points, len(faces) * 2)
logger.info(f"采样点数: {actual_num_points}")
# 在网格表面采样点云
points, face_idx = trimesh.sample.sample_surface(tri_mesh, num_points)
points, face_idx = trimesh.sample.sample_surface(tri_mesh, actual_num_points)
# 获取法向量
normals = tri_mesh.face_normals[face_idx]
@@ -116,9 +121,9 @@ class MeshGenerator:
"faces": faces.tolist(),
"points": points.tolist(),
"normals": normals.tolist(),
"point_count": len(points),
"vertex_count": len(vertices),
"face_count": len(faces)
"point_count": int(len(points)),
"vertex_count": int(len(vertices)),
"face_count": int(len(faces))
}
except Exception as e: