Callback when in the camera


#1

In general, I conceived such an experiment. I need to get a callback only when the object is in the pyramid of the camera visibility, and not cropped. I made a simple example, but it does not work, since the CallbackNode node is always called when it passes through the render tree. Of course, can use mathematics, but it is expensive in terms of resources.

from panda3d.core import CallbackNode, OccluderNode, Point3
import direct.directbase.DirectStart

def init(cbdata):
    print ("Render")

cbnode = CallbackNode("cbnode")
cbnode.setDrawCallback(init)
cbnp = render.attachNewNode(cbnode)

mpanda = loader.loadModel("panda")
mpanda.reparentTo(cbnp)
mpanda.setPos(50, 50, -20)

occluder = OccluderNode("1")
occluder.setVertices(Point3(0, 0, 0), Point3(100, 0, 0), Point3(100, 100, 0), Point3(0, 100, 0))
occluder_nodepath = render.attachNewNode(occluder)
occluder_nodepath.show()

cbnp.setOccluder(occluder_nodepath)

base.run()

#2

By default, a CallbackNode has an infinite bounding volume. Just assign your own bounding volume to it using setBounds.

You could also try calling setFinal(True) an the callback node’s parent, which I think means that Panda will ignore the bounding volume on the callback node, but I’m not 100% sure on that.


#3

I’m glad that this is possible, so the panda simplifies the control of the content, and makes the implementation of entities very easy (in my understanding)

Solved:

from panda3d.core import CallbackNode, OccluderNode, Point3, BoundingBox
import direct.directbase.DirectStart

def init(cbdata):
    print ("Render")

cbnode = CallbackNode("cbnode")
cbnode.setBounds(BoundingBox())
cbnode.setDrawCallback(init)
cbnp = render.attachNewNode(cbnode)
cbnp.showBounds()

mpanda = loader.loadModel("panda")
mpanda.reparentTo(cbnp)
mpanda.setPos(50, 50, -20)

occluder = OccluderNode("1")
occluder.setVertices(Point3(0, 0, 0), Point3(100, 0, 0), Point3(100, 100, 0), Point3(0, 100, 0))
occluder_nodepath = render.attachNewNode(occluder)
occluder_nodepath.show()

render.setOccluder(occluder_nodepath)

base.run()

ADD

100% working option. It was necessary Occluder install for the render node.