Collision on demand

Im working on a terrain-manager also supporting non-geomip-tiles (egg-models). On geomip getting the height at a point is simple but how to do that on a normal model calling a function?

Here the code is the function im looking for a substitute for existed: (bad code, i know)

def height(x,y,z,modelForCollision):
    ray=CollisionRay(x, y, z, 0, 0, -1)
    ray.reparentTo(render)
    collisionEntriesList=collide(ray,modelForCollision) 
    #i can't find such a function but how to do it instead?
    l=10**10
    out=0
    for entry in collisionEntriesList:
        if l>entry.getSurfacePoint(ray).length():
            l=entry.getSurfacePoint(ray).length()
            out=entry.getSurfacePoint(render).getZ()
    return out

Yes I also want some thing like this exposed. Maybe i should look into it.

try this to see if fit for you.

@astelix
Thanks but that wouldnt help much for me as i want to have one function to get the terrain height fast at geomip (getElevation) and as-fast-as-possible on egg-models (the hight-function i posted) for putting things on them and not just for walking

The problem with arbitrary meshes is that they are just that - arbitrary. They can have overhanging geometry, varying polygon density and, most importantly, they don’t have any given structure. Whilst there are ways of taking advantage of the situation if you were coding in C++ (Project it all to 2D and build a BSP or quad tree for instance.) I’ld be surprised if there is any faster way in python, where you are limited to current Panda functionality, than using the collision system and firing a ray directly down. In other words you need to do what the CollisionHandlerFloor object does, but only when requested rather than all the time.

Thats what i meant…