Created
October 3, 2022 19:00
-
-
Save UuuNyaa/f401120830def6114cde9f8dd32587a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import mathutils | |
| from mathutils import Matrix | |
| import bpy | |
| from typing import List, Dict, Tuple, Optional | |
| target_mesh_objects: List[bpy.types.Object] = [o for o in C.selected_objects if o.type == 'MESH' and not o.hide] | |
| i2vm: Dict[int, Tuple[bpy.types.MeshVertex, bpy.types.Object]] = dict(enumerate((v, m) for m in target_mesh_objects for v in m.data.vertices if v.select)) | |
| mesh_object: Optional[bpy.types.Object] = None | |
| mesh_matrix: Matrix = Matrix() | |
| vertex_index = mathutils.kdtree.KDTree(len(i2vm)) | |
| for i, (v, m) in i2vm.items(): | |
| if m != mesh_object: | |
| mesh_object = m | |
| mesh_matrix = m.matrix_world | |
| vertex_index.insert(mesh_matrix @ v.co, i) | |
| vertex_index.balance() | |
| import bmesh | |
| for m in target_mesh_objects: | |
| mesh_matrix = m.matrix_world | |
| me = m.data | |
| bm = bmesh.from_edit_mesh(me) | |
| for v in bm.verts: | |
| _co, index, distance = vertex_index.find(v.co) | |
| if distance < 0.001: | |
| v.select_set(True) | |
| bm.select_mode |= {'VERT'} | |
| bm.select_flush_mode() | |
| bmesh.update_edit_mesh(me) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment