+ 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)
+
+ for v in self.vertices:
+ 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(ctx, obj, material_atlas):
+ if obj.type!="MESH":
+ raise Exception("Object {} is not a mesh".format(obj.name))
+
+ task = ctx.task("Collecting mesh data", 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 = ctx.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.tangent_vecs = o.data.tangent_vecs
+ bmesh.tangent_uvtex = o.data.tangent_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)
+
+ task = ctx.task("Triangulating", 0.3)
+ mesh.prepare_triangles(task)
+ task = ctx.task("Smoothing", 0.5)
+ mesh.prepare_smoothing(task)
+ task = ctx.task("Vertex groups", 0.6)
+ mesh.prepare_vertex_groups(obj)
+ task = ctx.task("Preparing UVs", 0.75)
+ mesh.prepare_uv(task)
+ task = ctx.task("Preparing vertex colors", 0.85)
+ mesh.prepare_colors(task)
+ task = ctx.task("Render sequence", 1.0)
+ mesh.prepare_sequence(task)
+
+ return mesh