All MicroEvals
SNAP_VGROUP = "Snap3" DIST_VGROUP = "DistZone3" def sele...
Create MicroEval
Header image for SNAP_VGROUP = "Snap3"

DIST_VGROUP = "DistZone3"



def sele...

SNAP_VGROUP = "Snap3" DIST_VGROUP = "DistZone3" def sele...

Prompt

SNAP_VGROUP = "Snap3" DIST_VGROUP = "DistZone3" def select_perfect_island_boundaries(): ctx = bpy.context meshes = [o for o in ctx.selected_objects if o.type == 'MESH'] gen_obj = next((o for o in meshes if o.vertex_groups.get(SNAP_VGROUP)), None) body_obj = next((o for o in meshes if o is not gen_obj), None) if not gen_obj or not body_obj: print("HIBA: Jelöld ki a GenitĂĄliĂĄt ÉS a Body-t is!") return bpy.ops.object.mode_set(mode='OBJECT') M_body = body_obj.matrix_world M_gen = gen_obj.matrix_world body_verts_w = [M_body @ v.co for v in body_obj.data.vertices] # 1. Dupla pontok (varratok) szĂłtĂĄra body_co_dict = defaultdict(list) for i, co in enumerate(body_verts_w): key = (round(co.x, 4), round(co.y, 4), round(co.z, 4)) body_co_dict[key].append(i) kd = KDTree(len(body_verts_w)) for i, co in enumerate(body_verts_w): kd.insert(co, i) kd.balance() vg_snap = gen_obj.vertex_groups.get(SNAP_VGROUP).index vg_dist = gen_obj.vertex_groups.get(DIST_VGROUP).index fence_verts = set() seed_verts = set() # 2. Kezdeti Magok Ă©s KerĂ­tĂ©s (VetĂ­tĂ©ssel) for v in gen_obj.data.vertices: w_snap = w_dist = 0.0 for g in v.groups: if g.group == vg_snap: w_snap = g.weight elif g.group == vg_dist: w_dist = g.weight if w_snap > 0.01: co, idx, dist = kd.find(M_gen @ v.co) exact_co = body_verts_w[idx] key = (round(exact_co.x, 4), round(exact_co.y, 4), round(exact_co.z, 4)) fence_verts.update(body_co_dict[key]) elif w_dist > 0.01: co, idx, dist = kd.find(M_gen @ v.co) seed_verts.add(idx) seed_verts = seed_verts - fence_verts # 3. Él-hĂĄlĂłzat (TopolĂłgia) adj = defaultdict(list) for edge in body_obj.data.edges: adj[edge.vertices[0]].append(edge.vertices[1]) adj[edge.vertices[1]].append(edge.vertices[0]) # 4. TÖKÉLETES FOLT (Patch) lĂ©trehozĂĄsa Flood-Fill-el patch_verts = set(seed_verts) q = deque(seed_verts) while q: curr = q.popleft() for nb in adj[curr]: if nb not in patch_verts: patch_verts.add(nb) if nb not in fence_verts: q.append(nb) patch_verts.update(fence_verts) # 5. A ZÁRT KÖRVONALAK (Sziget hatĂĄrok) kivonĂĄsa a FoltbĂłl boundary_verts = set() for v_idx in patch_verts: is_outer_boundary = False # A) KÜLSƐ HATÁR: Van olyan szomszĂ©dja, ami NINCS benne a Foltban? for nb in adj[v_idx]: if nb not in patch_verts: is_outer_boundary = True break # B) BELSƐ VARRAT: Dupla pont a tĂ©rben? co = body_verts_w[v_idx] key = (round(co.x, 4), round(co.y, 4), round(co.z, 4)) is_seam = len(body_co_dict[key]) > 1 # Ha Outer Boundary VAGY Seam, akkor hozzĂĄadjuk (az ÖSSZES ikrĂ©vel egyĂŒtt!) if is_outer_boundary or is_seam: boundary_verts.update(body_co_dict[key]) # 6. KijelölĂ©s alkalmazĂĄsa for v in body_obj.data.vertices: v.select = False for idx in boundary_verts: body_obj.data.vertices[idx].select = True body_obj.data.update() bpy.ops.object.select_all(action='DESELECT') body_obj.select_set(True) ctx.view_layer.objects.active = body_obj bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.select_mode(type='VERT') print("=" * 50) print("TÖKÉLETESEN ZÁRT SZIGET-KÖRVONALAK KIJELÖLVE!") print(f"Kihagyott pontok szĂĄma: 0") print("=" * 50) if __name__ == "__main__": select_perfect_island_boundaries() Így a testen megtalĂĄltuk, ami egyezni fog a genitĂĄlia letƱzött pontjaival.