setBounds() doesn't behave as expected


I’m trying to manually set the bounds of a mesh that is already placed in the correct position in the scene. This is because I’m using hardware instancing and want to affect the bounds of all the instances to the unique mesh placed in the scene.

The following code:

print "old bounds:", mesh.node().getBounds()
print "intended bounds:", new_bounds
print "new bounds:", mesh.node().getBounds()

produces this result:

old bounds: bbox, (769.781 772.387 -8.38252) to (861.366 863.972 83.2025)
intended bounds: bbox, (130.849 129.055 -8.39252) to (861.366 863.972 83.1925)
new bounds: bbox, (769.781 772.387 -8.38252) to (1675.95 1682.22 83.2025)

which is obviously not the result expected. Isn’t setBounds() expecting the bounds in the world coordinate system?


setBounds() sets the bounding volume on that particular node, while getBounds() returns the aggregate bounding volume of that node and all of its children. There is no way to set a node’s bounding volume smaller than its children’s bounding volumes.


OK, but in that case I’m not trying to set a bounding volume smaller than it’s children bounding volumes.

I’m trying to set the bounding volume to X between [130, 861], that is bigger than original [769, 861], and what it does is setting the bounds to [769, 1675]… Does the setBounds() consider the provided bounds in local coordinate system or something like that?


Ah, I understand now.

Right, the bounding volume accepted by setBounds() is understood to be in local coordinate space, which is to say, relative to the node’s parent. This is the way almost all node operations work in Panda; you almost never deal with global coordinate space, which isn’t really a concept in Panda.

(Panda operates in local coordinate space by default, but also allows you to specify a particular coordinate space for many operations, which we call relative operations. This when you do something like node.setPos(render, 0, 0, 0)–you are explicitly specifying the coordinate space of render, which is the closest thing Panda has to the concept of a global coordinate space.)

The volume returned by getBounds() is also in local coordinate space, but this time it is relative to the node itself, so that it includes the node’s transform. This is an exception to other node operations in Panda, which are usually in the node’s parent’s space. The reason for this exception is a small performance optimization: since the bounding volume has already been pre-transformed by the node’s transform, it means that traversals can test against a node’s bounding volume without having to first enter the node’s coordinate space.

This exception does lead to the confusing difference between setBounds() and getBounds(). I hadn’t run into that difference before; I apologize for the confusion.


Many thanks,

I could successfully complete my hardware instancing feature with manually computed bounds rather than OmniBoundingVolume()

Great loading + FPS gain!

Indeed this is a bit intricate that “getFoo” and “setFoo” don’t speak the same language on the same object :slight_smile: