def colTree (incomingNode): 
    
    maxLevels=10
    top=NodePath(CollisionNode('colTreeTop'))
    b=incomingNode.getBounds()
    if b.isEmpty(): return top
    
    maxSize=b.getCenter().length()+b.getRadius()
    maxSize*=1.1
    levels=[{} for i in range(maxLevels)]
    
    levels[0][(0,0,0)]=top
    
    offset=Point3(maxSize,maxSize,maxSize)
    
    def fillNode(level,key):
        if level==0:
            assert key==(0,0,0)
        d=levels[level]
        cell=d.get(key)
        if cell is None:
            cell=NodePath(CollisionNode(""))
            d[key]=cell
            if level>0:
                aboveKey=(key[0]/2,key[1]/2,key[2]/2)
                aboveCell=fillNode(level-1,aboveKey)
                cell.reparentTo(aboveCell)
        return cell
        
    for c in incomingNode.findAllMatches('**/+CollisionNode'): 
        cNode = c.node() 
        for i in range(cNode.getNumSolids()): 
            s=cNode.getSolid(i)
            b=s.getBounds()
            if not b.isEmpty():
                center,size=_toCenterBox(b)
                if size>0:
                    size=size/maxSize
                    level=math.log(1/size,2)
                    level+=3
                    level=min(level,maxLevels-1)
                    level=max(level,0)
                    level=int(math.ceil(level))
                    
                    center=center+offset
                    center=center/(maxSize*2)
                    
                    center=center*(2**level)
                    key=tuple(int(math.floor(center[i])) for i in [0,1,2])
                    cell=fillNode(level,key).node()
                    cell.addSolid(s)
    
    _mergeCol(top)          
    return top
assumes all passed nodes are collision nodes with no transforms
dataset/ETHPy150Open Craig-Macomber/Panda3D-Terrain-System/collisionUtil.py/colTree