Terrain height detection

Hello,

I currently have a model rendered as a “terrain”, in which I want to place buildings on.
Since I have specific (x, y) coordinates that I want to place my buildings on, the only problem left is to get the Z-axis of the terrain so that I can offset my building accordingly.
I tried using the GeomVertexReader as such:

geomNodeCollection = self.terrain.findAllMatches('**/+GeomNode')
    for nodePath in geomNodeCollection:
        geomNode = nodePath.node()
        for i in range(geomNode.getNumGeoms()):
            geom = geomNode.getGeom(i)
            vdata = geom.getVertexData()
            vertex = GeomVertexReader(vdata, 'vertex')
            while not vertex.isAtEnd():
                v = vertex.getData3f()

However, I could not get a decent conversion from LVecBase3 to actual Points that I can use to offset the building. Is there a possible solution to this? Any built-in functions that I’m missing?

Thanks for you help!

I do not know if I understand correctly ? Here is an example .

Clicks on the surface , in the console are the coordinates

import direct.directbase.DirectStart

from pandac.PandaModules import CollisionTraverser,CollisionNode   
from pandac.PandaModules import CollisionHandlerQueue,CollisionRay, BitMask32  

def pick(): 
    if base.mouseWatcherNode.hasMouse():
        mpos = base.mouseWatcherNode.getMouse() 
        pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())   
        picker.traverse(render)     
        for i in xrange(pickerQ.getNumEntries()): 
            entry = pickerQ.getEntry(i)   
            print 'entry '+str(entry.getSurfacePoint(render))  

terrain = loader.loadModel("Plane.egg")
terrain.setPos(0, 0, 0)
terrain.reparentTo(render)
 
picker = CollisionTraverser()   
pickerQ = CollisionHandlerQueue()  
pickerCollN = CollisionNode('mouseRay')  
pickerCamN = base.camera.attachNewNode(pickerCollN)      
pickerCollN.setFromCollideMask(BitMask32.bit(1))
pickerCollN.setIntoCollideMask(BitMask32.allOff())   
pickerRay = CollisionRay()     
pickerCollN.addSolid(pickerRay)     
picker.addCollider(pickerCamN, pickerQ)  
base.accept('mouse1', pick) 
 
run()

Another wonderful example:


Plane.egg (23 KB)