feat: 完善参数化编辑和孔修改稳定性
This commit is contained in:
+36
-1
@@ -9,7 +9,8 @@ from OCC.Core.BRepAdaptor import BRepAdaptor_Curve, BRepAdaptor_Surface
|
||||
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut, BRepAlgoAPI_Defeaturing, BRepAlgoAPI_Fuse
|
||||
from OCC.Core.BRepBndLib import brepbndlib
|
||||
from OCC.Core.BOPAlgo import BOPAlgo_GlueFull
|
||||
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_Transform
|
||||
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeVertex, BRepBuilderAPI_Transform
|
||||
from OCC.Core.BRepExtrema import BRepExtrema_DistShapeShape
|
||||
from OCC.Core.BRepCheck import BRepCheck_Analyzer
|
||||
from OCC.Core.BRepClass3d import BRepClass3d_SolidClassifier
|
||||
from OCC.Core.BRepFilletAPI import BRepFilletAPI_MakeChamfer, BRepFilletAPI_MakeFillet
|
||||
@@ -948,6 +949,40 @@ class StepModel(FeatureMixin, ExportMixin, TransformMixin, OperationMixin, Polyd
|
||||
best_edge_id = edge_id
|
||||
return best_edge_id if best_edge_id is not None else valid_edge_ids[0]
|
||||
|
||||
def nearest_face_id_to_point(
|
||||
self,
|
||||
face_ids: Iterable[int],
|
||||
point: tuple[float, float, float] | None,
|
||||
) -> int | None:
|
||||
valid_face_ids = [int(face_id) for face_id in face_ids if 0 <= int(face_id) < len(self.faces)]
|
||||
if not valid_face_ids:
|
||||
return None
|
||||
if point is None:
|
||||
return valid_face_ids[0]
|
||||
|
||||
point_vertex = BRepBuilderAPI_MakeVertex(gp_Pnt(float(point[0]), float(point[1]), float(point[2]))).Vertex()
|
||||
best_face_id: int | None = None
|
||||
best_distance = math.inf
|
||||
for face_id in valid_face_ids:
|
||||
try:
|
||||
extrema = BRepExtrema_DistShapeShape(point_vertex, self.faces[face_id])
|
||||
extrema.Perform()
|
||||
if not extrema.IsDone():
|
||||
continue
|
||||
distance = float(extrema.Value())
|
||||
except Exception:
|
||||
center = _surface_center(self.faces[face_id])
|
||||
distance = math.sqrt(
|
||||
_point_distance_sq(
|
||||
(float(point[0]), float(point[1]), float(point[2])),
|
||||
_point_tuple(center),
|
||||
)
|
||||
)
|
||||
if distance < best_distance:
|
||||
best_distance = distance
|
||||
best_face_id = face_id
|
||||
return best_face_id if best_face_id is not None else valid_face_ids[0]
|
||||
|
||||
def _adjacent_face_ids_for_edges(self, edge_ids: list[int], face_id: int) -> list[int]:
|
||||
if not edge_ids:
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user