@@ -39,6 +39,22 @@ cdef class Model:
3939 cdef void build_trimesh_model(self ):
4040 raise NotImplementedError ()
4141
42+ cdef object get_watertight_trimesh_model(self ):
43+ if not self .check_valid():
44+ self .build_trimesh_model()
45+ if self .trimesh_model is None :
46+ return None
47+ trimesh_model = self .trimesh_model.copy()
48+ if not trimesh_model.is_watertight:
49+ trimesh_model = trimesh_model.process(validate = True , merge_tex = True , merge_norm = True )
50+ if not trimesh_model.is_watertight:
51+ if trimesh_model.fill_holes():
52+ logger.debug(" Filled holes in non-watertight mesh: {}" , self .name)
53+ else :
54+ logger.warning(" Computing convex hull of: {}" , self .name)
55+ trimesh_model = trimesh_model.convex_hull
56+ return trimesh_model
57+
4258 cdef Vector get_bounds(self ):
4359 if self .check_valid() and self .bounds is not None :
4460 return self .bounds
@@ -427,20 +443,8 @@ cdef class BooleanOperationModel(Model):
427443 cdef Model model
428444 self .trimesh_model = None
429445 for model in self .models:
430- if not model.check_valid():
431- model.build_trimesh_model()
432- trimesh_model = model.trimesh_model
433- if trimesh_model is None :
434- continue
435- if not trimesh_model.is_watertight:
436- trimesh_model = trimesh_model.copy().process(validate = True , merge_tex = True , merge_norm = True )
437- if not trimesh_model.is_watertight:
438- if trimesh_model.fill_holes():
439- logger.debug(" Filled holes in non-watertight mesh: {}" , model.name)
440- else :
441- logger.warning(" Computing convex hull of: {}" , model.name)
442- trimesh_model = trimesh_model.convex_hull
443- trimesh_models.append(trimesh_model)
446+ if (trimesh_model := model.get_watertight_trimesh_model()) is not None :
447+ trimesh_models.append(trimesh_model)
444448 if trimesh_models:
445449 if self .operation == ' difference' and len (trimesh_models) > 2 :
446450 union_models = trimesh.boolean.boolean_manifold(trimesh_models[1 :], ' union' )
0 commit comments