cad_to_dagmc
cad_to_dagmc copied to clipboard
use cadquery to facet
instead of installing gmsh we could potential use cadquery to facet the geometry.
here is some code that doesn't quite produce watertight geometry but looks like it is close
this didn't produce non overlapping water tight parts when the geometry was in contact with other surfaces
def tessellate(parts, tolerance: float = 0.1, angularTolerance: float = 0.1):
"""Creates a mesh / faceting / tessellation of the surface"""
parts.mesh(tolerance, angularTolerance)
offset = 0
vertices: List[Vector] = []
triangles = {}
for f in parts.Faces():
loc = TopLoc_Location()
poly = BRep_Tool.Triangulation_s(f.wrapped, loc)
Trsf = loc.Transformation()
reverse = (
True
if f.wrapped.Orientation() == TopAbs_Orientation.TopAbs_REVERSED
else False
)
# add vertices
face_verticles = [
(v.X(), v.Y(), v.Z()) for v in (v.Transformed(Trsf) for v in poly.Nodes())
]
vertices += face_verticles
face_triangles = [
(
t.Value(1) + offset - 1,
t.Value(3) + offset - 1,
t.Value(2) + offset - 1,
)
if reverse
else (
t.Value(1) + offset - 1,
t.Value(2) + offset - 1,
t.Value(3) + offset - 1,
)
for t in poly.Triangles()
]
triangles[f.hashCode()] = face_triangles
offset += poly.NbNodes()
list_of_triangles_per_solid = []
for s in parts.Solids():
triangles_on_solid = []
for f in s.Faces():
triangles_on_solid += triangles[f.hashCode()]
list_of_triangles_per_solid.append(triangles_on_solid)
for vert in vertices:
for tri in list_of_triangles_per_solid:
return vertices, list_of_triangles_per_solid