Check if OnscreenText object is above the off-screen

While I’m not aware of a method that accurately checks whether an entire object is in view, there is a method that will check whether a point is in view: The “isInView” method of LensNode.

Combined with some additional logic, I could see this providing a reasonably accurate means of determining whether an object were in view.

Alternatively, one could potentially perform an additional rendering of the scene, with the target object displayed in a solid colour and all else in black, and then check for the presence of that colour.

And finally, this forum-post describes an approach that compares the bounds of the camera-frustum against the bounds of the object, as I understand it.

This, however, is easier I believe:

OnscreenText is a wrapper around TextNode, and TextNode has a method that returns the bottom-extent of the object. Thus you should be able to just compare the object’s bottom-extent against the screen’s top: it should be off-screen when its bottom plus its vertical position is higher than the z-coordinate of the top of the screen plus the TextNode’s height.

(OnscreenText is a NodePath, and its TextNode is the node to which it points. Thus you should be able to access an OnscreenText’s TextNode by calling its “node” method, like so: myTextNode = myOnscreenText.node(). The vertical position of the OnscreenText might be retrieved via its “getTextPos” method, or via the normal “getPos”, depending on how you place it, I think.)