Page Menu
Home
Search
Configure Global Search
Log In
Files
F8716264
TT_Object_Select_Raycast.py
Matt (Kickflipkid687)
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Matt (Kickflipkid687)
Jul 23 2020, 4:56 PM
Size
2 KB
Subscribers
None
TT_Object_Select_Raycast.py
View Options
bl_info
=
{
"name"
:
"turboTools - Object Select Raycast"
,
"author"
:
"Mattli"
,
"version"
:
(
0
,
1
,
0
),
"blender"
:
(
2
,
80
,
0
),
"location"
:
"Object > Object Select Raycast"
,
"description"
:
"Starts Object Select Raycast"
,
"wiki_url"
:
""
,
"category"
:
"Object"
,
}
import
bpy
import
bmesh
from
bpy_extras
import
view3d_utils
from
bpy_extras.view3d_utils
import
region_2d_to_vector_3d
,
region_2d_to_origin_3d
,
location_3d_to_region_2d
from
bpy.props
import
BoolProperty
,
StringProperty
,
FloatProperty
from
mathutils
import
Vector
,
Matrix
class
TT_OT_Object_Select_RayCast
(
bpy
.
types
.
Operator
):
bl_idname
=
"turbotools.object_select_raycast"
bl_label
=
"Object Select Raycast"
bl_options
=
{
"REGISTER"
,
"UNDO"
}
def
modal
(
self
,
context
,
event
):
context
.
area
.
tag_redraw
()
if
event
.
type
==
'LEFTMOUSE'
:
loc
=
event
.
mouse_region_x
,
event
.
mouse_region_y
if
event
.
value
==
'RELEASE'
:
scene
=
context
.
scene
region
=
context
.
region
rv3d
=
context
.
region_data
coord
=
event
.
mouse_region_x
,
event
.
mouse_region_y
viewlayer
=
context
.
view_layer
view_vector
=
view3d_utils
.
region_2d_to_vector_3d
(
region
,
rv3d
,
coord
)
ray_origin
=
view3d_utils
.
region_2d_to_origin_3d
(
region
,
rv3d
,
coord
)
#If Hit Object, Add to Array and Raycast again from that Hit Point , along same View Vector to see if hit something inside that object/repeat until nothing.
result
,
location
,
normal
,
index
,
object
,
matrix
=
context
.
scene
.
ray_cast
(
viewlayer
,
ray_origin
,
view_vector
)
#ray_target, ray_goal # ray_origin, ray_target
if
(
result
):
if
(
object
.
visible_get
(
view_layer
=
viewlayer
)):
print
(
object
)
else
:
print
(
"Missed"
)
return
{
'RUNNING_MODAL'
}
if
event
.
type
==
'RIGHTMOUSE'
or
event
.
type
==
'ESC'
:
if
event
.
value
==
'PRESS'
:
self
.
report
({
'INFO'
},
"TT - Object Select List : CANCELLED!"
)
return
{
'CANCELLED'
}
return
{
'RUNNING_MODAL'
}
def
invoke
(
self
,
context
,
event
):
context
.
window_manager
.
modal_handler_add
(
self
)
return
{
'RUNNING_MODAL'
}
def
execute
(
self
,
context
):
print
(
"DONE!"
)
return
{
'FINISHED'
}
classes
=
(
TT_OT_Object_Select_RayCast
,
)
def
register
():
for
cls
in
classes
:
bpy
.
utils
.
register_class
(
cls
)
def
unregister
():
for
cls
in
reversed
(
classes
):
bpy
.
utils
.
unregister_class
(
cls
)
if
__name__
==
"__main__"
:
register
()
File Metadata
Details
Attached
Mime Type
text/x-python
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
0e/e5/1263dbdb2d0d57d42668da816190
Attached To
T79194: Scene.Ray_Cast misses/fails against CURVE Objects in multiple cases.
Event Timeline
Log In to Comment