Changeset View
Changeset View
Standalone View
Standalone View
io_mesh_stl/blender_utils.py
| Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | def create_and_link_mesh(name, faces, face_nors, points, global_matrix): | ||||
| mesh.update() | mesh.update() | ||||
| obj = bpy.data.objects.new(name, mesh) | obj = bpy.data.objects.new(name, mesh) | ||||
| bpy.context.collection.objects.link(obj) | bpy.context.collection.objects.link(obj) | ||||
| bpy.context.view_layer.objects.active = obj | bpy.context.view_layer.objects.active = obj | ||||
| obj.select_set(True) | obj.select_set(True) | ||||
| def faces_from_mesh(ob, global_matrix, use_mesh_modifiers=False): | def faces_from_mesh(ob, global_matrix, use_mesh_modifiers=False, use_global_frame=True): | ||||
| """ | """ | ||||
| From an object, return a generator over a list of faces. | From an object, return a generator over a list of faces. | ||||
| Each faces is a list of his vertexes. Each vertex is a tuple of | Each faces is a list of his vertexes. Each vertex is a tuple of | ||||
| his coordinate. | his coordinate. | ||||
| use_mesh_modifiers | use_mesh_modifiers | ||||
| Apply the preview modifier to the returned liste | Apply the preview modifier to the returned liste | ||||
| Show All 19 Lines | def faces_from_mesh(ob, global_matrix, use_mesh_modifiers=False, use_global_frame=True): | ||||
| try: | try: | ||||
| mesh = mesh_owner.to_mesh() | mesh = mesh_owner.to_mesh() | ||||
| except RuntimeError: | except RuntimeError: | ||||
| return | return | ||||
| if mesh is None: | if mesh is None: | ||||
| return | return | ||||
| if use_global_frame: | |||||
| mat = global_matrix @ ob.matrix_world | mat = global_matrix @ ob.matrix_world | ||||
| else: | |||||
| mat = global_matrix | |||||
| mesh.transform(mat) | mesh.transform(mat) | ||||
| if mat.is_negative: | if mat.is_negative: | ||||
| mesh.flip_normals() | mesh.flip_normals() | ||||
| mesh.calc_loop_triangles() | mesh.calc_loop_triangles() | ||||
| vertices = mesh.vertices | vertices = mesh.vertices | ||||
| for tri in mesh.loop_triangles: | for tri in mesh.loop_triangles: | ||||
| yield [vertices[index].co.copy() for index in tri.vertices] | yield [vertices[index].co.copy() for index in tri.vertices] | ||||
| mesh_owner.to_mesh_clear() | mesh_owner.to_mesh_clear() | ||||