Skip to content

Commit f5b8230

Browse files
committed
A couple of small performance tweaks to model collection
1 parent e801633 commit f5b8230

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

src/flitter/render/window/canvas3d.pyx

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,26 @@ cdef Model get_model(Node node, bint top):
468468
model = Model._vector(vertices, faces)
469469
if model is not None and node.get_bool('repair', False):
470470
model = model.repair()
471+
elif not top and node.kind is 'transform':
472+
transform_matrix = update_transform_matrix(node, IdentityTransform)
473+
model = Model._boolean('union', [get_model(child, False)._transform(transform_matrix) for child in node._children], 0, 0, 0)
474+
elif node.kind is 'trim' or node.kind is 'slice':
475+
normal = node.get_fvec('normal', 3, null_)
476+
origin = node.get_fvec('origin', 3, Zero3)
477+
if len(node._children) == 1:
478+
model = get_model(node._children[0], False)
479+
else:
480+
model = Model._boolean('union', [get_model(child, False) for child in node._children], 0, 0, 0)
481+
if model is not None and normal.as_bool():
482+
model = model._trim(origin, normal,
483+
node.get_float('smooth', 0),
484+
node.get_float('fillet', 0),
485+
node.get_float('chamfer', 0))
486+
elif node.kind in ('union', 'intersect', 'difference'):
487+
model = Model._boolean(node.kind, [get_model(child, False) for child in node._children],
488+
node.get_float('smooth', 0),
489+
node.get_float('fillet', 0),
490+
node.get_float('chamfer', 0))
471491
elif node.kind is 'sdf':
472492
maximum = node.get_fvec('maximum', 3, node.get_fvec('max', 3, One3))
473493
minimum = node.get_fvec('minimum', 3, node.get_fvec('min', 3, maximum.neg()))
@@ -483,23 +503,6 @@ cdef Model get_model(Node node, bint top):
483503
model = Model._sdf(None, model, minimum, maximum, resolution)
484504
elif node.kind is 'mix':
485505
model = Model._mix([get_model(child, False) for child in node._children], node.get_fvec('weights', 0, true_))
486-
elif not top and node.kind is 'transform':
487-
transform_matrix = update_transform_matrix(node, IdentityTransform)
488-
model = Model._boolean('union', [get_model(child, False)._transform(transform_matrix) for child in node._children], 0, 0, 0)
489-
elif node.kind in ('union', 'intersect', 'difference'):
490-
model = Model._boolean(node.kind, [get_model(child, False) for child in node._children],
491-
node.get_float('smooth', 0),
492-
node.get_float('fillet', 0),
493-
node.get_float('chamfer', 0))
494-
elif node.kind is 'trim' or node.kind is 'slice':
495-
normal = node.get_fvec('normal', 3, null_)
496-
origin = node.get_fvec('origin', 3, Zero3)
497-
model = Model._boolean('union', [get_model(child, False) for child in node._children], 0, 0, 0)
498-
if model is not None and normal.as_bool():
499-
model = model._trim(origin, normal,
500-
node.get_float('smooth', 0),
501-
node.get_float('fillet', 0),
502-
node.get_float('chamfer', 0))
503506
elif (cls := get_plugin('flitter.render.window.models', node.kind)) is not None:
504507
model = cls.from_node(node)
505508
if model is not None:

src/flitter/render/window/models.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ cdef class Transform(UnaryOperation):
527527

528528
@staticmethod
529529
cdef Model _get(Model original, Matrix44 transform_matrix):
530-
cdef str name = f'{original.name}@{hex(transform_matrix.hash(False))[2:]}'
530+
cdef str name = f'{original.name}@{transform_matrix.hash(False):x}'
531531
cdef Transform model = <Transform>ModelCache.get(name, None)
532532
if model is None:
533533
model = Transform.__new__(Transform)
@@ -646,7 +646,7 @@ cdef class Trim(UnaryOperation):
646646
cdef Trim _get(Model original, Vector origin, Vector normal, double smooth, double fillet, double chamfer):
647647
if origin.numbers == NULL or origin.length != 3 or normal.numbers == NULL or normal.length != 3:
648648
return None
649-
cdef str name = f'trim({original.name}, {hex(origin.hash(False) ^ normal.hash(False))[2:]}'
649+
cdef str name = f'trim({original.name}, {origin.hash(False) ^ normal.hash(False):x}'
650650
if smooth:
651651
name += f', smooth={smooth}'
652652
elif fillet:
@@ -956,7 +956,7 @@ cdef class Box(PrimitiveModel):
956956
@staticmethod
957957
cdef Box _get(str uv_map):
958958
uv_map = uv_map if uv_map in Box.VertexUV else 'standard'
959-
cdef str name = '!box' if uv_map == 'standard' else f'!box({uv_map})'
959+
cdef str name = '!box' if uv_map is 'standard' else f'!box-{uv_map}'
960960
cdef Box model = <Box>ModelCache.get(name, None)
961961
if model is None:
962962
model = Box.__new__(Box)

0 commit comments

Comments
 (0)