Page MenuHome

testing_bug_intersect.py

testing_bug_intersect.py

#
# SELECT OBJECTS TO TEST INTERSECTION
# SAME SCRIPT AS ABOVE, JUST DOES NOT COPY MESHES
#
import bpy
import bmesh
import time
from mathutils.bvhtree import BVHTree
from mathutils import Vector
from random import randint
scene = bpy.context.scene
sphere = scene.objects["Sphere"]
def deleteThis(obj):
if bpy.context.mode != 'OBJECT':
print("Error: Change to Object Mode before running script!")
bpy.ops.object.select_all(action = 'DESELECT')
bpy.data.objects[obj.name].select = True
bpy.ops.object.delete(use_global=False)
def makeBVH(obj):
bm = bmesh.new()
bm.from_mesh(obj.data)
bm.transform(obj.matrix_world)
obj_bvh = BVHTree.FromBMesh(bm)
bm.free()
return obj_bvh
def isIntersect(target_bvh):
for o in obj_bvh_list:
inter = target_bvh.overlap(o)
if inter != []:
return True
return False
def checkIfSelectedIntersect(objects):
#check every object for interesection with every other object
i = 0
intersections = 0
for o in objects:
o_bvh = makeBVH(o)
for o2 in objects[i:]:
if o == o2:
continue
o2_bvh = makeBVH(o2)
#get intersecting pairs
inter = o_bvh.overlap(o2_bvh)
#if list is empty, no objects are touching
if inter != []:
print("{} and {} IS intersecting".format(o.name, o2.name))
intersections += 1
else:
print("{} and {} NOT inter".format(o.name, o2.name))
i += 1
print("\nIntersections: ", intersections)
if __name__ == "__main__":
print("\nRUNNING....")
checkIfSelectedIntersect(bpy.context.selected_objects)
print("FINISHED")

File Metadata

Mime Type
text/x-python
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
47/e8/d067fc3cc3a3e6c55e2195cc0ce1

Event Timeline