Edit: Attaching a sample blend file with the script I am trying to run. If you run the modal operator from the perspective view and move the mouse pointer, the Bezier line always lies on the plane (which is the desired functionality). But the same operator from orthographic view does not produce any movement.
The code can be the following.
We principally need the view vector (axis from the camera) and the view point (cam/eye position) which are given by
Then we cast on the plane coordinates in two parts as the plane is two tris.
# Get mouse position mouse_pos = event.mouse_region_x, event.mouse_region_y # Get object and region 3D object = context.object region = context.region region3D = context.space_data.region_3d # The target plane in order to have coordinates plane = bpy.data.objects.get('Plane') # All Transforms applied, so global space coordinates # (Plane is used just to get the points, in actual situation only # points will be available) p1 = plane.data.vertices.co p2 = plane.data.vertices.co p3 = plane.data.vertices.co p4 = plane.data.vertices.co # View vector (view axis) from the mouse pos view_vector = view3d_utils.region_2d_to_vector_3d(region, region3D, mouse_pos) # View point (eye position) in 3D view_point = view3d_utils.region_2d_to_origin_3d(region, region3D, mouse_pos) # Cast on plane defined by points above (2 counterclockwise tris) loc = geometry.intersect_ray_tri(p1, p2, p3, view_vector, view_point, True) if not loc: loc = geometry.intersect_ray_tri(p2, p4, p3, view_vector, view_point, True)
Note: have left the plane coordinates part as it was, but can also use the plane world matrix to translate coordinates to world.