-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimporter.py
More file actions
713 lines (578 loc) · 22.4 KB
/
Copy pathimporter.py
File metadata and controls
713 lines (578 loc) · 22.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2021 Tommi Hyppänen
#
# Modified 2025 Romain Guimbal
import os
import numpy as np
from collections import OrderedDict
from dataclasses import dataclass, field
from OCP.BRep import BRep_Tool
from OCP.BRepAdaptor import BRepAdaptor_Surface
from OCP.BRepLProp import BRepLProp_SLProps
from OCP.BRepMesh import BRepMesh_IncrementalMesh
from OCP.BRepTools import BRepTools
from OCP.gp import gp
from OCP.IFSelect import IFSelect_RetDone
from OCP.Quantity import Quantity_Color, Quantity_TOC_RGB
from OCP.STEPCAFControl import STEPCAFControl_Reader
from OCP.STEPControl import STEPControl_Reader
from OCP.TCollection import TCollection_ExtendedString
from OCP.TColStd import TColStd_SequenceOfAsciiString
from OCP.TDataStd import TDataStd_Name
from OCP.TDF import TDF_Label, TDF_LabelSequence
from OCP.TDocStd import TDocStd_Document
from OCP.TopAbs import (
TopAbs_COMPOUND,
TopAbs_EDGE,
TopAbs_FACE,
TopAbs_FORWARD,
TopAbs_REVERSED,
TopAbs_SHELL,
TopAbs_SOLID,
TopAbs_VERTEX,
TopAbs_WIRE,
)
from OCP.TopExp import TopExp_Explorer
from OCP.TopLoc import TopLoc_Location
from OCP.TopoDS import TopoDS_Shape, TopoDS
from OCP.XCAFApp import XCAFApp_Application
from OCP.XCAFDoc import (
XCAFDoc_DocumentTool,
XCAFDoc_ColorGen,
XCAFDoc_ColorSurf,
XCAFDoc_ColorCurv,
)
from OCP.XSControl import XSControl_WorkSession
from OCP.UnitsMethods import (
UnitsMethods_LengthUnit_Meter,
)
# from OCP.Interface import Interface_Static
from OCP.IMeshTools import IMeshTools_Parameters #, IMeshTools_MeshAlgoType
from OCP.Precision import Precision
from .trimesh import TrianglesData, TriMesh
def b_colorname(col):
return Quantity_Color.StringName_s(Quantity_Color.Name(col))
def b_XYZ(v):
x = v.XYZ()
return (x.X(), x.Y(), x.Z())
def b_RGB(c):
return (c.Red(), c.Green(), c.Blue())
def trsf_matrix(shp):
trsf = shp.Location().Transformation()
matrix = np.zeros((3, 4), dtype=np.float32)
for row in range(1, 4):
for col in range(1, 5):
matrix[row - 1, col - 1] = trsf.Value(row, col)
return matrix
def _test_shape(sh):
tmr = trsf_matrix(sh)
if np.any(tmr != np.eye(4, dtype=np.float32)[:3, :4]):
print(tmr)
def force_ascii(i_file):
from pathlib import Path
print("Attempting to format STEP file as ASCII 7-bit")
p = Path(i_file)
print(p.stat().st_size // 1024, "kB")
import tempfile
with tempfile.NamedTemporaryFile("w", encoding="ASCII") as fo:
temp_name = fo.name
print(temp_name)
with p.open("rb") as f:
while il := f.readline():
fo.write(il.decode("ASCII"))
print("done ASCII conversion.")
return temp_name
# TODO: proper parametrization
def equalize_2d_points(pts):
"""Equalize aspect ratio of 2D point dimensions"""
x_a, x_b = 1.0, 0.0
y_a, y_b = 1.0, 0.0
for i, uv in enumerate(pts):
if uv[0] < x_a:
x_a = uv[0]
if uv[0] > x_b:
x_b = uv[0]
if uv[1] < y_a:
y_a = uv[1]
if uv[1] > y_b:
y_b = uv[1]
rx = abs(x_b - x_a)
ry = abs(y_b - y_a)
if rx != 0.0 and ry != 0.0:
ratio = rx / ry
else:
ratio = 1.0
ratio1 = 1 / ratio
for i, uv in enumerate(pts):
pts[i] = (pts[i][0] * ratio1, pts[i][1])
return pts
def get_label_name(label):
"""Return the name of a TDF_Label as a string, fallback to EntryDumpToString or Tag if needed."""
# Try to use name label if available
name_attr = TDataStd_Name()
if label.FindAttribute(TDataStd_Name.GetID_s(), name_attr):
return name_attr.Get().ToExtString()
# Fallback: use EntryDumpToString or Tag
if hasattr(label, "EntryDumpToString"):
return label.EntryDumpToString()
elif hasattr(label, "Tag"):
return str(label.Tag())
else:
return str(label)
@dataclass
class ShapeTreeNode:
"""
A node for the OpenCASCADE CAD data ShapeTree
"""
parent: int
index: int
tag: int
name: str
children: list[int] = field(default_factory=list)
local_transform: np.ndarray = field(default_factory=np.eye(4, dtype=np.float32))
global_transform: np.ndarray = field(default_factory=np.eye(4, dtype=np.float32))
shape: TopoDS_Shape = None
def __init__(self, parent, index, tag, name):
self.parent = parent
self.index = index
self.tag = tag
self.name = name
self.children = []
self.local_transform = np.eye(4, dtype=np.float32)
self.global_transform = np.eye(4, dtype=np.float32)
self.shape = None
def get_values(self):
"""
parent, index, tag, name
"""
return (
self.parent,
self.index,
self.tag,
self.name,
self.shape,
self.local_transform,
self.global_transform,
)
def set_shape(self, shape):
if shape:
if not isinstance(shape, TopoDS_Shape):
raise ValueError("Input shape is not OpenCASCADE TopoDS_Shape")
self.shape = shape
else:
self.shape = None
class ShapeTree:
"""
Intermediary data structure to partially abstract OpenCASCADE away from the rest of the program
"""
def __init__(self):
self.nodes = []
# Root node has special values
self.nodes.append(ShapeTreeNode(-1, 0, -1, "root"))
def get_root_id(self):
return 0
def get_max_id(self):
return len(self.nodes) - 1
def add(self, parent, lab) -> ShapeTreeNode:
"""
Args:
lab: Shape label
"""
loc = len(self.nodes)
node = ShapeTreeNode(parent, loc, lab.Tag(), get_label_name(lab))
self.nodes[parent].children.append(loc)
self.nodes.append(node)
return self.nodes[-1]
def get_shapes(self):
# return {i.shape: i.index for i in self.nodes if i.shape}
return [(i.shape, i.index) for i in self.nodes]
def print_transforms(self):
for i in self.nodes:
print(i.local_transform)
class ReadSTEP:
def __init__(self, filepath):
self.filepath = filepath
self.read_file()
def query_color(self, lab, overwrite=False):
"""
Args:
lab: shape label
"""
# default color = pink
color = Quantity_Color(1.0, 0.0, 1.0, Quantity_TOC_RGB)
iscolorset = False
colortype = None
shape = self.shape_tool.GetShape_s(lab)
# print(shape.ShapeType())
# Overwrites each type
c_gen_exists = self.color_tool.GetColor(shape, XCAFDoc_ColorGen, color)
c_surf_exists = self.color_tool.GetColor(shape, XCAFDoc_ColorSurf, color)
c_curv_exists = False # self.color_tool.GetColor(shape, XCAFDoc_ColorCurv, color) Supposed to be a fallback but overwrite't
if c_gen_exists or c_surf_exists or c_curv_exists:
iscolorset = True
# Color priority (1/type) is the same as CAD assistant material tree display
colortype = c_gen_exists * 1 + c_surf_exists * 2 + c_curv_exists * 3
return color, colortype, iscolorset
def print_all_colors(self):
tcol = Quantity_Color(1.0, 0.0, 1.0, Quantity_TOC_RGB)
clabs = TDF_LabelSequence()
self.color_tool.GetColors(clabs)
for i in range(clabs.Length()):
res = self.color_tool.GetColor(clabs.Value(i + 1), tcol)
if res:
print(b_colorname(tcol))
def label_matrix(self, lab):
trsf = self.shape_tool.GetLocation_s(lab).Transformation()
matrix = np.eye(4, dtype=np.float32)
for row in range(1, 4):
for col in range(1, 5):
matrix[row - 1, col - 1] = trsf.Value(row, col)
# print(matrix)
return matrix
def explore_partial(self, shp, te_type):
c_set = set([])
ex = TopExp_Explorer(shp, te_type)
# Todo: use label->tag
while ex.More():
c = ex.Current()
if c not in c_set:
c_set.add(c)
ex.Next()
return len(c_set)
def explore_shape(self, shp):
return (
self.explore_partial(shp, TopAbs_COMPOUND),
self.explore_partial(shp, TopAbs_SOLID),
self.explore_partial(shp, TopAbs_SHELL),
self.explore_partial(shp, TopAbs_FACE),
self.explore_partial(shp, TopAbs_WIRE),
self.explore_partial(shp, TopAbs_EDGE),
self.explore_partial(shp, TopAbs_VERTEX),
)
def shape_info(self, shp):
st = self.shape_tool
lab = self.shape_label[shp]
vals = (
st.IsAssembly_s(lab),
st.IsFree_s(lab),
st.IsShape_s(lab),
st.IsCompound_s(lab),
st.IsComponent_s(lab),
st.IsSimpleShape_s(lab),
shp.Locked(),
)
lookup = ["A", "F", "S", "C", "T", "s", "L"]
res = "".join([lookup[i] for i, v in enumerate(vals) if v])
# res += f", C:{shp.NbChildren()}"
res += ", C:{} So:{} Sh:{} F:{} Wi:{} E:{} V:{}".format(
*self.explore_shape(shp)
)
return " " + res + " "
def transfer(self):
file = self.filepath
# Create the XCAF document
app = XCAFApp_Application.GetApplication_s()
doc = TDocStd_Document(TCollection_ExtendedString("XmlXCAF"))
app.NewDocument(TCollection_ExtendedString("MDTV-XCAF"), doc)
# Init new doc and reader
reader = STEPCAFControl_Reader()
reader.SetColorMode(True)
reader.SetNameMode(True)
# reader.SetMatMode(True)
# reader.SetLayerMode(True)
# Scale
XCAFDoc_DocumentTool.SetLengthUnit_s(doc, 1, UnitsMethods_LengthUnit_Meter)
# Read
status = reader.ReadFile(file)
if status != IFSelect_RetDone:
raise RuntimeError(f"Failed to read STEP file: {file}")
if not reader.Transfer(doc):
raise RuntimeError(
f"Failed to transfer STEP data into XCAF document: {file}"
)
else:
print("DataExchange: Transfer done")
self.doc = doc
def read_file(self):
"""Returns list of tuples (topods_shape, label, color)
Use OCAF.
"""
# Init Reader
if not os.path.isfile(self.filepath):
raise FileNotFoundError("%s not found." % self.filepath)
self.transfer()
# self.transfer_simple(self.filename)
self.shape_tool = XCAFDoc_DocumentTool.ShapeTool_s(self.doc.Main())
self.color_tool = XCAFDoc_DocumentTool.ColorTool_s(self.doc.Main())
# material_tool = XCAFDoc_DocumentTool_MaterialTool(doc.Main())
# layer_tool = XCAFDoc_DocumentTool_LayerTool(doc.Main())
# use OrderedDict and make sure the order is maintained through the entire pipeline
self.shape_label = {}
self.sub_shapes = OrderedDict()
self.face_colors = {}
self.face_color_priority = {}
self.tag_info = {}
self.skipped_shapes = set([])
self.import_problems = {
"Triangulation": 0,
"Undefined normals": 0,
"Empty shape": 0,
}
def _set_color_and_get_priority(shape_label, shape):
"""Type == Priority here"""
c, color_type, has_color = self.query_color(shape_label)
self.face_colors[shape] = c if has_color else None
if has_color:
return color_type
else:
return 0
def _get_sub_shapes(lab, level, tree, leaf_id):
# print(" " * (2 * level) + get_label_name(lab))
master_leaf = tree.nodes[leaf_id]
# l_comps = TDF_LabelSequence()
# self.shape_tool.GetComponents_s(lab, l_comps)
if self.shape_tool.IsAssembly_s(lab):
# Get transform for pure transform (empty)
# Empty has eye transform, inherit global from parent
# empty = tree.add(leaf.index, lab, empty=True)
# output_shapes[shape] = empty
# Read contained shapes
l_c = TDF_LabelSequence()
self.shape_tool.GetComponents_s(lab, l_c)
for i in range(l_c.Length()):
label = l_c.Value(i + 1)
if self.shape_tool.IsReference_s(label):
label_reference = TDF_Label()
self.shape_tool.GetReferredShape_s(label, label_reference)
label_transform = self.label_matrix(label)
node = tree.add(master_leaf.index, label_reference)
new_leaf = tree.nodes[node.index]
new_leaf.local_transform = label_transform
new_leaf.global_transform = (
master_leaf.global_transform @ label_transform
)
_get_sub_shapes(label_reference, level + 1, tree, node.index)
else:
# TODO: process rest of the data
pass
elif self.shape_tool.IsSimpleShape_s(lab):
# TODO: self.shape_label stops being unique when shapes aren't transformed
shape = self.shape_tool.GetShape_s(lab)
master_leaf.set_shape(shape)
if shape in self.shape_label:
# Shape already in
return
self.shape_label[shape] = lab
# TODO Color priority usage looks non-implemented
self.face_color_priority[shape] = _set_color_and_get_priority(
lab, shape
)
l_subss = TDF_LabelSequence()
self.shape_tool.GetSubShapes_s(lab, l_subss)
self.sub_shapes[shape] = []
for i in range(l_subss.Length()):
lab_subs = l_subss.Value(i + 1)
shape_sub = self.shape_tool.GetShape_s(lab_subs)
self.shape_label[shape_sub] = lab_subs
self.sub_shapes[shape].append(shape_sub)
self.face_color_priority[shape_sub] = _set_color_and_get_priority(
lab_subs, shape_sub
)
else:
print("DataExchange error: Item is neither assembly or a simple shape")
def _get_shapes():
"""
Root shapes are not part of shapes
"""
# self.shape_tool.UpdateAssemblies()
# Get free shapes labels
labels = TDF_LabelSequence()
self.shape_tool.GetFreeShapes(labels)
# Get sub shapes of each free shape and add to tree
tree = ShapeTree()
for i in range(labels.Length()):
print(f"DataExchange: Reading shape ({i + 1}/{labels.Length()})")
root_item = labels.Value(i + 1)
node = tree.add(tree.get_root_id(), root_item)
_get_sub_shapes(root_item, 0, tree, node.index)
return tree
tree = _get_shapes()
self.tree = tree
def triangulate_face(self, face, tform, brep_tool):
location = TopLoc_Location()
facing = brep_tool.Triangulation_s(face, location)
if facing is None:
# Mesh error, no triangulation found for part
self.import_problems["Triangulation"] += 1
return None
# nsurf = brep_tool.Surface(face)
surface = BRepAdaptor_Surface(face)
prop = BRepLProp_SLProps(surface, 2, gp.Resolution_s())
# prop = BRepLProp_SLProps(surface, 2, 1e-4)
# face_uv = facing.UVNode()
# Calculate UV bounds
Umin, Umax, Vmin, Vmax = 0.0, 0.0, 0.0, 0.0
# for t in range(1, face_uv.Length()):
for t in range(1, facing.NbNodes() + 1):
# v = face_uv.Value(t)
v = facing.UVNode(t)
x, y = v.X(), v.Y()
if t == 1:
Umin, Umax, Vmin, Vmax = x, x, y, y
if x < Umin:
Umin = x
if x > Umax:
Umax = x
if y < Vmin:
Vmin = y
if y > Vmax:
Vmax = y
Ucenter = (Umin + Umax) * 0.5
Vcenter = (Vmin + Vmax) * 0.5
# tab = facing.Nodes()
tri = facing.Triangles()
verts = []
norms = []
tris = []
uvs = []
undef_normals = False
itform = tform.Inverted()
# Build normals
d_nbnodes = facing.NbNodes()
for t in range(1, d_nbnodes + 1):
# pt = tab.Value(t)
pt = facing.Node(t)
loc = b_XYZ(pt)
# nvert = bm.verts.new(loc)
# nvert.index = t - 1
# assert len(loc) == 3
# assert loc[0] is float
# assert loc is tuple
verts.append(loc)
# Get triangulation normal
# pt = gp_Pnt(loc[0], loc[1], loc[2])
# pt_surf = GeomAPI_ProjectPointOnSurf(pt, nsurf)
# fU, fV = pt_surf.Parameters(1)
# prop = GeomLProp_SLProps(nsurf, fU, fV, 2, gp.Resolution_s())
uv = facing.UVNode(t)
u, v = uv.X(), uv.Y()
uvs.append((u, v))
# The edges of UV give invalid normals, hence this
prop.SetParameters(
(u - Ucenter) * 0.999 + Ucenter, (v - Vcenter) * 0.999 + Vcenter
)
if prop.IsNormalDefined():
normal = prop.Normal().Transformed(itform)
# normal = prop.Normal()
nn = np.array(b_XYZ(normal))
if face.Orientation() == TopAbs_REVERSED:
nn = -nn
else:
nn = np.array((0.0, 0.0, 1.0))
undef_normals = True
# norms.append(tuple(float(nnn) for nnn in nn))
norms.append(np.float32(nn))
# Build triangulation
d_nbtriangles = facing.NbTriangles()
for t in range(1, d_nbtriangles + 1):
T1, T2, T3 = tri(t).Get()
if face.Orientation() != TopAbs_FORWARD:
T1, T2 = T2, T1
# v_list = (verts[T1 - 1], verts[T2 - 1], verts[T3 - 1])
# nf = bm.faces.new(v_list)
# nf.smooth = True
# nf.normal_update()
tris.append((T1 - 1, T2 - 1, T3 - 1))
# for v in (T1, T2, T3):
# if norms[v - 1] is None:
# added_norms.append(np.array(nf.normal))
# else:
# added_norms.append(norms[v - 1])
# new_norms.append(norms[v - 1])
if undef_normals:
self.import_problems["Undefined normals"] += 1
tris_data = TrianglesData(
indices=tris,
# TODO : probably optimizable
norms=[(norms[t[0]], norms[t[1]], norms[t[2]]) for t in tris],
uvs=[(uvs[t[0]], uvs[t[1]], uvs[t[2]]) for t in tris],
colors=[None] * len(tris), # None means no color
material=[None] * len(tris),
material_name=[None] * len(tris),
batch=[None] * len(tris),
)
return TriMesh(verts=verts, tris=tris_data)
def build_trimesh(
self, shape, lin_def_bl_unit=0.8, ang_def=0.5, hacks=set([])
) -> TriMesh:
out_mesh = TriMesh()
out_mesh.matrix = np.eye(4, dtype=np.float32)
# TODO: this is hack
if "skip_solids" in hacks and self.explore_partial(shape, TopAbs_SOLID) == 0:
self.skipped_shapes.add(get_label_name(self.shape_label[shape]))
return out_mesh
iter_shapes = [shape] + self.sub_shapes[shape]
iter_shapes.sort(key=lambda x: x.Checked())
face_data = OrderedDict()
batch = 0
brep_tool = BRep_Tool()
# Iterate over the main shape and its sub shapes
for _, shp in enumerate(iter_shapes):
col = self.face_colors[shp]
if col is not None:
col_rgb = b_RGB(col)
col_name = b_colorname(col)
else:
col_name = ""
# Clean all previous triangulations
BRepTools.Clean_s(shp)
# Subshape transforms can be different from the mainshape transform
ex = TopExp_Explorer(shp, TopAbs_FACE)
if not ex.More():
self.import_problems["Empty shape"] += 1
continue
param = IMeshTools_Parameters()
param.Deflection = (
lin_def_bl_unit * 2
) # probably because tolerence range and not max distance)
param.Angle = ang_def
param.InParallel = True
param.Relative = False
param.MinSize = Precision.Confusion_s()
# param.MeshAlgo = IMeshTools_MeshAlgoType.IMeshTools_MeshAlgoType_Delabella
brepmesh = BRepMesh_IncrementalMesh(shp, param)
brepmesh.Perform()
trf = shp.Location().Transformation()
# Iterate through faces
while ex.More():
exc = ex.Current()
face = TopoDS.Face_s(exc)
mesh = self.triangulate_face(face, trf, brep_tool)
if mesh:
# If shape or sub-shape has defined color, set it so
mesh.set_batch(batch)
if col is not None:
mesh.colorize(col_rgb)
mesh.set_material_name(col_name)
# First filter in overwriting a face/color
face_data[face] = (0, mesh, "EMPTY")
ex.Next()
batch += 1
for _, b in face_data.items():
_, mesh, col_name = b
if len(mesh.verts) > 0:
out_mesh.add_mesh(mesh)
print("[l]", end="", flush=True)
return out_mesh