Skip to content

Instantly share code, notes, and snippets.

@Dodotree
Last active September 2, 2023 18:39
Show Gist options
  • Save Dodotree/a9db353514bf08fd1ed9c48ab5620b8d to your computer and use it in GitHub Desktop.
Save Dodotree/a9db353514bf08fd1ed9c48ab5620b8d to your computer and use it in GitHub Desktop.
import bpy, bmesh
from mathutils import Vector
'''
For simple situations where boxes are not rotated and you only need to detect overlap in bounding boxes
'''
def boundingBoxCollide(c1, c2):
bb = [c1.matrix_world * Vector(corner) for corner in c1.bound_box]
bb2 = [c2.matrix_world * Vector(corner2) for corner2 in c2.bound_box]
l1 = (bb[0]+bb[6])/2
l2 = (bb2[0]+bb2[6])/2
d1 = c1.dimensions
d2 = c2.dimensions
return (abs(l1[0]-l2[0]) < (d1[0] + d2[0])/2 and abs(l1[1]-l2[1]) < (d1[1] + d2[1])/2 and abs(l1[2]-l2[2]) < (d1[2] + d2[2])/2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment