0
$\begingroup$

After a few runs, it is quite certain that the overlap() function is causing blender to quit unexpectedly, I am not sure if the for loop is making blender to run on an infinite loop that cause that.

Or is there a way to write overlap() in a more elegant way to detect if an object is overlaping with another and get the the overlaping object in return.

import bpy
from mathutils.bvhtree import BVHTree
dgraph=bpy.context.evaluated_depsgraph_get()
for obj in bpy.context.scene.objects:
    if obj.name.startswith("M"):
        for obj2 in bpy.context.scene.objects:
            print(BVHTree.FromObject(obj, dgraph).overlap(BVHTree.FromObject(obj2, dgraph)))

there's only 6 objects in the scene with some cubes and cylinders for test.

$\endgroup$
  • $\begingroup$ What's your question? Please read: blender.stackexchange.com/help/how-to-ask and report bugs here: developer.blender.org $\endgroup$ – brockmann Apr 6 '20 at 7:38
  • $\begingroup$ edited the question and tried to be a little bit more specific... and i am not sure if that's a bug or me coding bad. $\endgroup$ – adrian li Apr 7 '20 at 11:59
  • $\begingroup$ Can confirm, this crashes. The script also tries to determine the overlap for non-mesh objects, which you shouldn't do. $\endgroup$ – Robert Gützkow Apr 7 '20 at 15:10
1
$\begingroup$

The script iterates over all objects, including those that aren't meshes. Only determine the overlap for objects with type set to "MESH" and it will work properly.

Your script with the suggested fix:

import bpy
from mathutils.bvhtree import BVHTree

dgraph = bpy.context.evaluated_depsgraph_get()

for obj in bpy.context.scene.objects:
    if obj.name.startswith("M") and obj.type == "MESH":
        for obj2 in bpy.context.scene.objects:
            if obj2.type == "MESH":
                print(BVHTree.FromObject(obj, dgraph).overlap(BVHTree.FromObject(obj2, dgraph)))
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.