How do you identify the location and orientation of a polygon?

I have a terrain mesh and a ‘mesh’ of vertices which are some distance above the terrain. The vertices represent locations where I want to place an object, except I want the object to sit neatly on the terrain surface and be aligned to the orientation of the particular polygons it is sitting on. I have too many objects to place by hand. I can’t shrinkwrap my vertices to the terrain mesh because that doesn’t give me the orientation, just position. I suppose it’s a bit like using the particle system except I have my own specific locations instead of the having Blender randomly generate them for me.

I guess I am looking for a function like the rayCast from BGE that I can use under BPY (i.e. NOT in a game). So the question is: how do I find the surface location and orientation of a face (polygon) in one object directly below (or at some specified angle to) a vertex in another object?

I’d greatly appreciate it if anybody can point me in the right direction. Many thanks!

Just found

bpy.types.Object.ray_cast

! This could be exactly what I want. I KNEW there would be something in BPY, I just missed it first in my trawl of the documentation :o

BPY can’t be used in the Game Engine, you know: that tripped me up, too. :S

Yes! That was exactly my problem but in reverse - that BGE can’t be used in BPY - but it doesn’t matter because the bpy.types.Object.ray_cast is exactly what I needed. I’m just a bit more familiar with BGE than BPY :slight_smile:

i remember there was a script in older blender-versions to drop objects to a surface …
– cant remember the name -
and
another point, if you know the position above the surface and the surface below is like a terrain, then you can identify the face of the surface and every surface of a mesh has its normal-vector (= orientation), a vector vertical to the face-plane.
This normal vector would be the orientation for the object and if the objects location is its base-point, then you can set the location to the face-center (for a terrain with small faces its nearly the same) or calculate the vertical crosspoint.