From fa617f1d2ab5fda23c48b043607dc8416b49c083 Mon Sep 17 00:00:00 2001 From: Luke Frisken Date: Tue, 18 Dec 2012 10:43:06 +0000 Subject: [PATCH] Fixed operator_modal_view3d_raycast.py template so that it uses hit points in world space to give correct selection. Also set selected object to active. --- release/scripts/templates/operator_modal_view3d_raycast.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/release/scripts/templates/operator_modal_view3d_raycast.py b/release/scripts/templates/operator_modal_view3d_raycast.py index 3236c08cc8c..eac76922187 100644 --- a/release/scripts/templates/operator_modal_view3d_raycast.py +++ b/release/scripts/templates/operator_modal_view3d_raycast.py @@ -16,7 +16,6 @@ def main(context, event, ray_max=10000.0): ray_origin = view3d_utils.region_2d_to_origin_3d(region, rv3d, coord) ray_target = ray_origin + (view_vector * ray_max) - scene.cursor_location = ray_target def visible_objects_and_duplis(): """Loop over (object, matrix) pairs (mesh only)""" @@ -58,7 +57,9 @@ def main(context, event, ray_max=10000.0): if obj.type == 'MESH': hit, normal, face_index = obj_ray_cast(obj, matrix) if hit is not None: - length_squared = (hit - ray_origin).length_squared + hit_world = matrix * hit + scene.cursor_location = hit_world + length_squared = (hit_world - ray_origin).length_squared if length_squared < best_length_squared: best_length_squared = length_squared best_obj = obj @@ -67,6 +68,7 @@ def main(context, event, ray_max=10000.0): # we could do lots of stuff but for the example just select. if best_obj is not None: best_obj.select = True + context.scene.objects.active = best_obj class ViewOperatorRayCast(bpy.types.Operator): @@ -105,3 +107,4 @@ def unregister(): if __name__ == "__main__": register() +