+ self.faces = reordered_faces
+ for i, f in enumerate(self.faces):
+ f.index = i
+
+ def reorder_vertices(self):
+ for v in self.vertices:
+ v.index = -1
+
+ reordered_vertices = []
+ for s in self.vertex_sequence:
+ for v in s:
+ if v.index<0:
+ v.index = len(reordered_vertices)
+ reordered_vertices.append(v)
+
+ self.vertices = reordered_vertices
+
+ for e in self.edges:
+ e.key = make_edge_key(e.vertices[0].index, e.vertices[1].index)
+
+
+def create_mesh_from_object(context, obj, progress, *, material_atlas=None):
+ if obj.type!="MESH":
+ raise Exception("Object is not a mesh")
+
+ progress.push_task("Preparing mesh", 0.0, 0.2)
+
+ objs = [(obj, mathutils.Matrix())]
+ i = 0
+ while i<len(objs):
+ o, m = objs[i]
+ i += 1
+ for c in o.children:
+ if c.type=="MESH" and c.compound:
+ objs.append((c, m*c.matrix_local))
+
+ dg = context.evaluated_depsgraph_get()
+
+ mesh = None
+ for o, m in objs:
+ eval_obj = o.evaluated_get(dg)
+ bmesh = eval_obj.to_mesh()
+
+ # Object.to_mesh does not copy custom properties
+ bmesh.winding_test = o.data.winding_test
+ bmesh.smoothing = o.data.smoothing
+ bmesh.use_lines = o.data.use_lines
+ bmesh.vertex_groups = o.data.vertex_groups
+ bmesh.max_groups_per_vertex = o.data.max_groups_per_vertex
+ bmesh.use_uv = o.data.use_uv
+ bmesh.tbn_vecs = o.data.tbn_vecs
+ bmesh.tbn_uvtex = o.data.tbn_uvtex
+
+ me = Mesh(bmesh)
+ me.transform(m)
+
+ for i, s in enumerate(eval_obj.material_slots):
+ if s.link=='OBJECT':
+ me.materials[i] = s.material
+
+ if mesh:
+ mesh.splice(me)
+ else:
+ mesh = me
+
+ mesh.name = obj.data.name
+
+ if material_atlas:
+ mesh.apply_material_atlas(material_atlas)
+
+ progress.set_task("Triangulating", 0.2, 0.3)
+ mesh.prepare_triangles(progress)
+ progress.set_task("Smoothing", 0.3, 0.5)
+ mesh.prepare_smoothing(progress)
+ progress.set_task("Vertex groups", 0.5, 0.6)
+ mesh.prepare_vertex_groups(obj)
+ progress.set_task("Preparing UVs", 0.6, 0.75)
+ mesh.prepare_uv(progress)
+ progress.set_task("Preparing vertex colors", 0.75, 0.85)
+ mesh.prepare_colors(progress)
+ progress.set_task("Render sequence", 0.85, 1.0)
+ mesh.prepare_sequence(progress)
+
+ progress.pop_task()