[Solved] Projecting a point on the mesh

Is there a built-in functionality to project a point on the mesh in Z direction?

I am aware of Shrinkwrap Modifier, but I need to project a single vertex

Create a vertexgroup with that vertex and define it in the shrinkwrap modifier, it should do the job.

In UI, you would enable snap to face and constrain to Z axis. With python, you can cast a ray:

import bpy

ob = bpy.context.object

# Object space!
start = (0, 0, 100)
end = (0, 0, -100)

co, normal, face_index = ob.ray_cast(start, end)

if face_index != -1:
    co_world = ob.matrix_world * co
    bpy.context.scene.cursor_location = co_world
    print(co, co_world)

CoDEmanX

I’d like to clarify. Are start and end parameters in the object space or in the Blender global coordinate system? The latest documentation says nothing about that.


co, normal, face_index = ob.ray_cast(start, end)

I made a small test and found that start and end parameters for the ray_cast function must be in the object local coordinate system.

Thanks, CoDEmanX and Nadeox1. I’ll mark the thread as solved.

Documentation does say object space:

ray_cast(start, end)

Cast a ray onto in object space

[TABLE=“class: docutils field-list”]
[TR=“class: field-odd field”]
[TH=“class: field-name, colspan: 2”]Return (location, normal, index):[/TH]
[/TR]
[TR=“class: field-odd field”]

location, The hit location of this ray cast, float array of 3 items in [-inf, inf]

normal, The face normal at the ray cast hit location, float array of 3 items in [-inf, inf]

index, The face index, -1 when no intersection is found, int in [-inf, inf]
[/TR]
[/TABLE]