Bounding Volume question

Hi,

I just noticed that when calling show_bounds on the GeoMipTerrain chunks, infinitely-tall cylinders appeared. That kind of disturbed me. Would it be a performance benefit if I made it tight boxes just small enough to fit the terrain? I guess the culling would be better, then?

However, when calling set_bounds on the GeomNode, I can’t see any difference with a show_bounds or show_tight_bounds. The same cylinders still appear. How is it possible to set my own bounds?

Infinitely tall? Or just really tall?

In any case, each Geom has its own bounding volume, too. Changing the bounding volume on the GeomNode does not change the bounding volume of the Geoms; you should consider changing those individually. You could also call geomNode.setFinal(True), which tells Panda to consider the bounding volume of the GeomNode the authoritative bounding volume, and to ignore the bounding volumes of the individual Geoms. They’ll still be drawn when you do showBounds, though.

David

Hmm, when I set my own bounds (on the Geom) my own bounds appear, but the old cylinders are still there too. I tried a clear_bounds, I even tried to set the bounds on both the GeomNode and Geom, but it didn’t help, both showed up.
Also, the bounds do not appear to be relative to the parent node, is that right?

By the way, can it really be a performance benefit in setting the bounding volumes myself? They are used for culling, right?

I believe the bounds are in the same space as the parent node (already transformed by the current node’s transform). It can be a performance optimization to set them yourself, if you can do a better job than Panda’s automatic computation.

I’m not sure where your cylinders are coming from. Try getBounds() on the node and on each Geom to see if you can find them. I’m also a little confused by the use of the word “cylinder”; panda’s bounding volumes are almost always spheres.

David

Hmm, they seem to be spheres indeed, but scaled with a very high factor in the Z. Since terrains are by default very flat and have to be scaled with quite a high value in the Z, the bounding spheres became very tall as well:
pro-rsoft.com/screens/GeoMipTerr … olumes.png

So, in this case, I can certainly do it better myself. :slight_smile:
The show_bounds still shows up spheres, but the culling itself is performed as I want. So I guess it doesn’t really matter.
However, now I’ve made the bounds very tight, I’ve noticed that volumes are only rendered when they are entirely in view. How can I set it that stuff is also rendered when it’s partially in view? Now, if one looks at the screen edges, one can see missing terrain blocks.

No, volumes are rendered when they are only partially in view. It’s possible that the extreme Z scaling is confusing this logic, which would indicate a bug somewhere.

David

Hmm. If I try this simple code:

from direct.directbase import DirectStart
from pandac.PandaModules import *

format=GeomVertexFormat.getV3()
vdata=GeomVertexData("square", format, Geom.UHStream)
vertex=GeomVertexWriter(vdata, "vertex")
vertex.addData3f(0, 0, 0)
vertex.addData3f(0, 1, .5)
vertex.addData3f(1, 1, 1)
vertex.addData3f(1, 0, .5)
tri=GeomTriangles(Geom.UHStream)
tri.addVertex(0)
tri.addVertex(1)
tri.addVertex(3)
tri.closePrimitive()
tri.addConsecutiveVertices(1,3)
tri.closePrimitive()
geom=Geom(vdata)
geom.addPrimitive(tri)

box = BoundingBox(Point3(0, 0, 0), Point3(1, 1, 1))
geom.setBounds(box)

node = GeomNode("blah");
node.addGeom(geom);

NP = render.attachNewNode(node)
NP.showBounds()
base.toggleWireframe()

base.cam.setPos(0.5, -3, 3)
base.cam.lookAt(0.5, 0.5, .5)

run()

Both the box and the sphere show up, instead of just the box. Any idea how that could be happening (and how I could prevent it from happening?)

You are seeing the bounding volume the GeomNode itself, in addition to the bounding volume of its individual Geoms. The internal bounding volume of a node is automatically computed, and you can’t directly change it. (You can call node.setBounds(), but the bounding volume you specify to setBounds() is only added to the set of bounding volumes that contribute to the overall bounding volume.)

If you really want the node to have a bounding box instead of a bounding sphere, you can put this in your Config.prc file:

bounds-type best

which means that the automatically-computed bounding volume type is based on the types of bounding volumes that contributed to it, so that if you put a BoundingBox on all of the Geoms in a GeomNode, then the GeomNode itself will also have a BoundingBox. (The default bounds-type is sphere, which means that all nodes will always have a BoundingSphere. You can also set bounds-type box, which means that all nodes will always have a BoundingBox.)

I’m not sure if your scale problem is related to the fact that the bounds shape is a sphere, though, but this is a worthwhile experiment.

David

Hmm, I’m actually trying to get better bounding volumes in the GeoMipTerrain. The reason for this is that the auto-generated ones are highly inefficient. I’ve run some tests and it gives a great performance boost. I don’t want it to be messing with config vars from the inside.
Would it help if I set this bounding volume on the GeomNode as well? Is there really no other way to force panda to use my bounding volumes instead of Panda’s own? If not, that kind of defeats the purpose, IMHO.

Yeah, it does seem like there should be some interface to completely override the auto-generating bounding volume, or at least to specify the preferred type of bounding volume for a particular node. Let me think on this a bit.

Davdi

I’ve just checked in changes to Geom and PandaNode that add the method setBoundsType(BoundingVolume.BTBox), so you can override the bounding volume type on a per-object level, instead of only globally.

David

Yay! Now I don’t have to calculate one myself. I’ve set that on both the GeomNode and the Geom, but now I get: (click to enlarge)

The ones on the GeomNode are correctly wrapped around the terrain chunks, while the ones on the Geom are all in the corner. It looks like they don’t respect transforms.
Sounds to me like a bug in the showBounds system?

Here’s some sample code to reproduce:

from direct.directbase import DirectStart
from pandac.PandaModules import *

format=GeomVertexFormat.getV3()
vdata=GeomVertexData("square", format, Geom.UHStream)
vertex=GeomVertexWriter(vdata, "vertex")
vertex.addData3f(0, 0, 0)
vertex.addData3f(0, 1, .5)
vertex.addData3f(1, 1, 1)
vertex.addData3f(1, 0, .5)
tri=GeomTriangles(Geom.UHStream)
tri.addVertex(0)
tri.addVertex(1)
tri.addVertex(3)
tri.closePrimitive()
tri.addConsecutiveVertices(1,3)
tri.closePrimitive()
geom=Geom(vdata)
geom.addPrimitive(tri)

box = BoundingBox(Point3(0, 0, 0), Point3(1, 1, 1))
geom.setBounds(box)

node = GeomNode("blah");
node.addGeom(geom);

NP = render.attachNewNode(node)
NP.showBounds()
NP.setPos(1, 1, 0)
base.toggleWireframe()

base.cam.setPos(0.5, -3, 3)
base.cam.lookAt(0.5, 0.5, .5)

run()

As you can see, the box that’s on the geom doesn’t show up transformed by the NP position.

You’re right, there was a bug in the ShowBoundsEffect handling when there was a transform directly on the GeomNode. Fixed.

David

Excellent, thanks alot! And all the time I thought I was doing something wrong with my bounding volume computations :slight_smile: