I have found that the above doesn’t work well when the node is not parented to render itself, but to some other node. The following modification works well in any case:
def nodeCoordIn2d(nodePath):
coord3d = nodePath.getPos(base.cam)
coord2d = Point2()
base.camLens.project(coord3d, coord2d)
coordInRender2d = Point3(coord2d[0], 0, coord2d[1])
coordInAspect2d = aspect2d.getRelativePoint(render2d,
coordInRender2d)
return coordInAspect2d