# Procedural model based on Z of other mesh

Hello all,

This is my first post on the forums, and I’ve just recently started playing around with Panda3d, but I’ve been using Python for quite a while both at work and for leisure. Feel free to yell at me if I posted on the wrong board!

I’m having trouble coming up with an efficient way of finding the Z location of a mesh (or collision mesh) given an X,Y coordinate. A little background of what I’m trying to do (in case I’m going about this alllll wrong). I have a nodePath which I want to surround by a circle or torus of sorts. The thing is, I want the vertices of this circle/torus to be a constant z offset from an uneven ground plane that the nodePath sits upon. This made me think I needed to produce this object procedurally (I’m unaware of a way to manipulate vertices of a preloaded node, but this could also be a possibility).

The generation code for the circle/torus is elementary, it’s obtaining a z offset at every vertex of the circle/torus that’s getting me. My first thought was to create a temporary dummy node with a CollisionHandlerQueue to grab the z location at every vertex:

``````def setupGroundCollision(node):
groundRay = PandaModules.CollisionRay()
groundRay.setOrigin(0,0,1000)
groundRay.setDirection(0,0,-1)
groundCol = PandaModules.CollisionNode('groundRay')
groundColNp = node.attachNewNode(groundCol)
groundHandler = PandaModules.CollisionHandlerQueue()
return groundHandler

class SomeClass:
def __init__():
return 0

numPoints = 8
format=GeomVertexFormat.getV3n3cpt2()
vdata=GeomVertexData('square', format, Geom.UHDynamic)

vertex=GeomVertexWriter(vdata, 'vertex')
normal=GeomVertexWriter(vdata, 'normal')
color=GeomVertexWriter(vdata, 'color')
texcoord=GeomVertexWriter(vdata, 'texcoord')

zGetter=render.attachNewNode("dummyNode")
zHandler = setupGroundCollision(zGetter)
for i in range(numPoints):
angle = (i*(math.pi*2/numPoints))
x = self.stats['movement']*math.cos(angle)+self.pandaNode.getX()
y = self.stats['movement']*math.sin(angle)+self.pandaNode.getY()
zGetter.setPos(x,y,1000)
base.cTrav.traverse(render)
if (zHandler.getNumEntries() > 0):
z = zHandler.getEntry(0).getSurfacePoint(render).getZ() + 1.5
else:
z = 1.5
z += -.1
angle = (i*(math.pi*2/numPoints))
x = (self.stats['movement']+.1)*math.cos(angle)+self.pandaNode.getX()
y = (self.stats['movement']+.1)*math.sin(angle)+self.pandaNode.getY()
z += 0
z += .1
zGetter.removeNode()

circle = Geom(vdata)
for i in range(numPoints):
for j in range(4):
tri=GeomTriangles(Geom.UHDynamic)