Page Menu
Home
Search
Configure Global Search
Log In
Files
F489386
testing_bug_intersect.py
Valeri Barashkov (valera)
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Valeri Barashkov (valera)
Feb 19 2017, 3:16 AM
Size
1 KB
Subscribers
None
testing_bug_intersect.py
View Options
#
# 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
(
"
\n
Intersections: "
,
intersections
)
if
__name__
==
"__main__"
:
print
(
"
\n
RUNNING...."
)
checkIfSelectedIntersect
(
bpy
.
context
.
selected_objects
)
print
(
"FINISHED"
)
File Metadata
Details
Attached
Mime Type
text/x-python
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
47/e8/d067fc3cc3a3e6c55e2195cc0ce1
Attached To
T50721: BVH overlap() failing to detect intersection due to bmesh rotation not updating until script ends
Event Timeline
Log In to Comment