Skip to content

Commit 362091c

Browse files
committed
Small tidy-up
1 parent 87efee6 commit 362091c

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/flitter/render/window/models.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ cdef class Model:
1515
cdef bint is_constructed(self)
1616
cdef bint check_valid(self)
1717
cdef void build_trimesh_model(self)
18+
cdef object get_watertight_trimesh_model(self)
1819
cdef Vector get_bounds(self)
1920
cdef tuple get_buffers(self, object glctx, dict objects)
2021
cdef tuple instance(self, Matrix44 model_matrix)

src/flitter/render/window/models.pyx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)