Page Menu
Home
Search
Configure Global Search
Log In
Files
F489387
intersect_bug.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
intersect_bug.py
View Options
#
# RUN THIS FIRST TO MAKE COPIES OF OBJECTS
# SELECT SURFACE AND THEN RUN
#
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"
]
surface
=
bpy
.
context
.
selected_objects
[
0
]
obj_bvh_list
=
[]
num_of_copies
=
30
#user specified number of objects
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
#makes a copy of an object if there is space
def
spawn
(
thing
,
v_loc
,
v_normal
):
print
(
"Making copy of object and object BVH"
)
new_obj
=
thing
.
copy
()
new_obj
.
data
=
thing
.
data
#location
new_obj
.
matrix_world
.
translation
=
surface
.
matrix_world
.
translation
+
v_loc
#rotation
dirVector
=
Vector
(
v_normal
)
new_obj
.
rotation_mode
=
'QUATERNION'
new_obj
.
rotation_quaternion
=
dirVector
.
to_track_quat
(
'Z'
,
'Y'
)
new_obj_bvh
=
makeBVH
(
new_obj
)
if
not
isIntersect
(
new_obj_bvh
):
obj_bvh_list
.
append
(
new_obj_bvh
)
scene
.
objects
.
link
(
new_obj
)
else
:
deleteThis
(
new_obj
)
return
False
return
True
if
__name__
==
"__main__"
:
print
(
"
\n
RUNNING...."
)
verts
=
surface
.
data
.
vertices
i
=
0
#used to prevent using previous vertices
while
i
<
len
(
verts
)
and
len
(
obj_bvh_list
)
<
num_of_copies
:
print
(
"while"
)
for
v
in
verts
[
i
:]:
i
+=
1
if
(
spawn
(
sphere
,
v
.
co
,
v
.
normal
)):
print
(
"Spawn"
)
break
print
(
"FINISHED"
)
File Metadata
Details
Attached
Mime Type
text/x-python
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
93/21/d641d1801b818ea86de5a3b5000c
Attached To
T50721: BVH overlap() failing to detect intersection due to bmesh rotation not updating until script ends
Event Timeline
Log In to Comment