Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #delete objects that are intersecting
- def delInter():
- #check every object for intersection with every other object
- for obj_now in obj_list:
- for obj_next in obj_list:
- print()
- if obj_now == obj_next:
- continue
- #create bmesh objects
- bm1 = bmesh.new()
- bm2 = bmesh.new()
- #fill bmesh data from objects
- bm1.from_mesh(scene.objects[obj_now].data)
- bm2.from_mesh(scene.objects[obj_next].data)
- #fixed it here:
- bm1.transform(scene.objects[obj_now].matrix_world)
- bm2.transform(scene.objects[obj_next].matrix_world)
- #make BVH tree from BMesh of objects
- obj_now_BVHtree = BVHTree.FromBMesh(bm1)
- obj_next_BVHtree = BVHTree.FromBMesh(bm2)
- #get intersecting pairs
- inter = obj_now_BVHtree.overlap(obj_next_BVHtree)
- #if list is empty, no objects are touching
- if inter != []:
- print(obj_now + " and " + obj_next + " are touching!")
- else:
- print(obj_now + " and " + obj_next + " NOT touching!")
- bm1.transform(scene.objects[obj_now].matrix_world)
- bm2.transform(scene.objects[obj_next].matrix_world)
- import bpy #addbpy <<ADD
- import bmesh #addbmesh <<ADD
- import mathutils #add mathutils <<ADD
- # get the current meshes <<ADD
- obj_list = bpy.data.meshes
- # get the current scene <ADD
- scn = bpy.context.scene
- # Define the BVH Tree <ADD
- BVHTree = mathutils.bvhtree.BVHTree
- #Print objects that are intersecting
- def delInter():
- #check every object for intersection with every other object
- for obj_now in obj_list:
- for obj_next in obj_list:
- print()
- if obj_now == obj_next:
- continue
- #create bmesh objects
- bm1 = bmesh.new()
- bm2 = bmesh.new()
- #fill bmesh data from objects
- bm1.from_mesh(scn.objects[obj_now.name].data) #<< Add .name on both
- lines.
- bm2.from_mesh(scn.objects[obj_next.name].data) #<< Add .name on both
- lines.
- #fixed it here:
- bm1.transform(scn.objects[obj_now.name].matrix_world) #<< Add .name
- on both lines.
- bm2.transform(scn.objects[obj_next.name].matrix_world) #<< Add .name
- on both lines.
- #make BVH tree from BMesh of objects
- obj_now_BVHtree = BVHTree.FromBMesh(bm1)
- obj_next_BVHtree = BVHTree.FromBMesh(bm2)
- #get intersecting pairs
- inter = obj_now_BVHtree.overlap(obj_next_BVHtree)
- #if list is empty, no objects are touching
- if inter != []:
- print(obj_now.name + " and " + obj_next.name + " are touching!") #
- << Add .name on both lines.
- else:
- print(obj_now.name + " and " + obj_next.name + " NOT touching!")
- #<< Add .name on both lines.
- delInter() #Call FN
- import bpy, bmesh
- from mathutils.bvhtree import BVHTree
- list_of_obj = [ o for o in bpy.context.scene.objects]
- the_object = list_of_obj[0]
- the_other_object = list_of_obj[1]
- BMESH_1 = bmesh.new()
- BMESH_1.from_mesh(bpy.context.scene.objects[the_object.name].data)
- BMESH_1.transform(the_object.matrix_world)
- BVHtree_1 = BVHTree.FromBMesh(BMESH_1)
- BMESH_2 = bmesh.new()
- BMESH_2.from_mesh(bpy.context.scene.objects[the_other_object.name].data)
- BMESH_2.transform(the_other_object.matrix_world)
- BVHtree_2 = BVHTree.FromBMesh(BMESH_2)
- inter = BVHtree_1.overlap(BVHtree_2)
- print(inter)
Add Comment
Please, Sign In to add comment