Guest User

Untitled

a guest
Oct 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. #delete objects that are intersecting
  2. def delInter():
  3. #check every object for intersection with every other object
  4. for obj_now in obj_list:
  5. for obj_next in obj_list:
  6. print()
  7. if obj_now == obj_next:
  8. continue
  9.  
  10. #create bmesh objects
  11. bm1 = bmesh.new()
  12. bm2 = bmesh.new()
  13.  
  14. #fill bmesh data from objects
  15. bm1.from_mesh(scene.objects[obj_now].data)
  16. bm2.from_mesh(scene.objects[obj_next].data)
  17.  
  18. #fixed it here:
  19. bm1.transform(scene.objects[obj_now].matrix_world)
  20. bm2.transform(scene.objects[obj_next].matrix_world)
  21.  
  22. #make BVH tree from BMesh of objects
  23. obj_now_BVHtree = BVHTree.FromBMesh(bm1)
  24. obj_next_BVHtree = BVHTree.FromBMesh(bm2)
  25.  
  26. #get intersecting pairs
  27. inter = obj_now_BVHtree.overlap(obj_next_BVHtree)
  28.  
  29. #if list is empty, no objects are touching
  30. if inter != []:
  31. print(obj_now + " and " + obj_next + " are touching!")
  32. else:
  33. print(obj_now + " and " + obj_next + " NOT touching!")
  34.  
  35. bm1.transform(scene.objects[obj_now].matrix_world)
  36. bm2.transform(scene.objects[obj_next].matrix_world)
  37.  
  38. import bpy #addbpy <<ADD
  39. import bmesh #addbmesh <<ADD
  40. import mathutils #add mathutils <<ADD
  41.  
  42. # get the current meshes <<ADD
  43. obj_list = bpy.data.meshes
  44.  
  45. # get the current scene <ADD
  46. scn = bpy.context.scene
  47.  
  48. # Define the BVH Tree <ADD
  49. BVHTree = mathutils.bvhtree.BVHTree
  50.  
  51.  
  52. #Print objects that are intersecting
  53. def delInter():
  54. #check every object for intersection with every other object
  55. for obj_now in obj_list:
  56. for obj_next in obj_list:
  57. print()
  58. if obj_now == obj_next:
  59. continue
  60.  
  61. #create bmesh objects
  62. bm1 = bmesh.new()
  63. bm2 = bmesh.new()
  64.  
  65. #fill bmesh data from objects
  66. bm1.from_mesh(scn.objects[obj_now.name].data) #<< Add .name on both
  67. lines.
  68. bm2.from_mesh(scn.objects[obj_next.name].data) #<< Add .name on both
  69. lines.
  70.  
  71. #fixed it here:
  72. bm1.transform(scn.objects[obj_now.name].matrix_world) #<< Add .name
  73. on both lines.
  74. bm2.transform(scn.objects[obj_next.name].matrix_world) #<< Add .name
  75. on both lines.
  76.  
  77. #make BVH tree from BMesh of objects
  78. obj_now_BVHtree = BVHTree.FromBMesh(bm1)
  79. obj_next_BVHtree = BVHTree.FromBMesh(bm2)
  80.  
  81. #get intersecting pairs
  82. inter = obj_now_BVHtree.overlap(obj_next_BVHtree)
  83.  
  84. #if list is empty, no objects are touching
  85. if inter != []:
  86. print(obj_now.name + " and " + obj_next.name + " are touching!") #
  87. << Add .name on both lines.
  88. else:
  89. print(obj_now.name + " and " + obj_next.name + " NOT touching!")
  90. #<< Add .name on both lines.
  91.  
  92.  
  93. delInter() #Call FN
  94.  
  95. import bpy, bmesh
  96. from mathutils.bvhtree import BVHTree
  97.  
  98. list_of_obj = [ o for o in bpy.context.scene.objects]
  99. the_object = list_of_obj[0]
  100. the_other_object = list_of_obj[1]
  101.  
  102. BMESH_1 = bmesh.new()
  103. BMESH_1.from_mesh(bpy.context.scene.objects[the_object.name].data)
  104. BMESH_1.transform(the_object.matrix_world)
  105. BVHtree_1 = BVHTree.FromBMesh(BMESH_1)
  106.  
  107.  
  108. BMESH_2 = bmesh.new()
  109. BMESH_2.from_mesh(bpy.context.scene.objects[the_other_object.name].data)
  110. BMESH_2.transform(the_other_object.matrix_world)
  111. BVHtree_2 = BVHTree.FromBMesh(BMESH_2)
  112.  
  113. inter = BVHtree_1.overlap(BVHtree_2)
  114.  
  115. print(inter)
Add Comment
Please, Sign In to add comment