1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
import bpy import mathutils import random
objects = list(bpy.context.scene.objects)
bpy.ops.object.select_all(action='DESELECT')
deleted_objects = set()
overlap_pairs = []
for i, obj in enumerate(objects): if obj.name in deleted_objects: continue bbox_corners = [obj.matrix_world @ mathutils.Vector(corner) for corner in obj.bound_box] for j, other_obj in enumerate(objects): if i >= j or other_obj.name in deleted_objects: continue other_bbox_corners = [other_obj.matrix_world @ mathutils.Vector(corner) for corner in other_obj.bound_box] if (min(c[0] for c in bbox_corners) <= max(c[0] for c in other_bbox_corners) and max(c[0] for c in bbox_corners) >= min(c[0] for c in other_bbox_corners) and min(c[1] for c in bbox_corners) <= max(c[1] for c in other_bbox_corners) and max(c[1] for c in bbox_corners) >= min(c[1] for c in other_bbox_corners) and min(c[2] for c in bbox_corners) <= max(c[2] for c in other_bbox_corners) and max(c[2] for c in bbox_corners) >= min(c[2] for c in other_bbox_corners)): overlap_pairs.append((obj.name, other_obj.name))
for obj_name, other_obj_name in overlap_pairs: to_delete_name = random.choice([obj_name, other_obj_name]) deleted_objects.add(to_delete_name) to_delete = bpy.data.objects.get(to_delete_name) if to_delete: bpy.data.objects.remove(to_delete, do_unlink=True)
|
评论