BoundingVolume

BoundingVolume shifted relative to the TextNode geometry. [color=red]forceRecomputeBounds()- doesn’t help. I need correct this.

app=ShowBase('main_app')
class ImageLabel(TextNode):
    def __init__(self, sceen_name):
        TextNode.__init__(self, sceen_name)
        self.setText(' ') 
        #self.setCardImg()
        aspect2d.attachNewNode(self)
        print 'img node: ', self.getName()
        
    def setCardImg(self, bounds=(-0.5,0.5,-0.5,0.5),img=None, color=None):
        self.setCardActual(*bounds)
        self.setBoundsType(BoundingVolume.BTBox)
        if color is not None: self.setCardColor(*color)
        if img is not None:
            tex=Texture(str(self.getName())+'_img')
            tex.read(img)
            print 'texture: ', tex.getFilename()
            self.setCardTexture(tex)

class Marker(ImageLabel):
   def __init__(self, sceen_name):
      ImageLabel.__init__(self, sceen_name)
      self.setCardImg(bounds=(-0.01,0.01,-0.01,0.01), img=None, color=(0.9,0,0,1))
      
   def moveTo(self, target=None):
      if target is None: return
      NodePath(self).setPos(NodePath(target).getPos())

#__________test_____________________________
lblImg=ImageLabel('fon1')
lblImg.setCardImg(bounds=(-0.0,0.3,0.0,0.3), img='control_template.png', color=None)
#**********************************************
print 'Initial coordinates: (-0.0,0.3,0.0,0.3)'
print 'Bounds1 /getBounds()/ of Img: ', str(lblImg.getBounds())[:-1]
# SHIFTED
temp_np=NodePath(lblImg)
temp_np.flattenStrong()
temp_np.forceRecomputeBounds()
temp_np.showBounds()
#**********************************************
print 'Bounds2 /NodePath.getBounds/ of Img: ', str(NodePath(lblImg).getBounds())[:-1]
#it must be BTBox
print 'Bounds3 /getInternalBounds()/ of Img: ', str(lblImg.getInternalBounds ())[:-1]
lg=lblImg.generate()
print 'is GeomNode: ', lg.isGeomNode()
NodePath(lg).showBounds()
print 'Bounds4 /GeomNode/ of Img: ', str(lg.getBounds())[:-1]
lg.setBoundsType(BoundingVolume.BTBox)
print 'Bounds5 /GeomNode, BTBox/ of Img: ', str(lg.getBounds())[:-1]
print 'Bounds6 /Geom/ of Img: ', str(lg.getGeom(0).getBounds())[:-1]

app.run()

What’s the problem, exactly?

BonbingVolume is shifted to the side (green frame), does not match the geometry. I can not recalculate it automaticaly.

Ok, i did it. Is this right, can i do it shorter ?


p1,p2=Point3(),Point3()
temp_np=NodePath(lblImg)
temp_np.flattenStrong()
temp_np.calcTightBounds(p1,p2)
bv=BoundingBox(p1,p2)
lblImg.setBounds(bv)

That’s the right idea. In general, the automatic bounding volume returned by getBounds() is not intended to be a very tight bounds. That is, while it should always completely enclose its geometry, it may be considerably larger than the geometry itself is.

getTightBounds() (or calcTightBounds()), on the other hand, is intended to return the tightest possible axis-aligned bounding volume for your geometry.

David

Again BoundingVolume

‘BV’ - BoundingVolume
‘handly’ - manually
‘internl’- getInternalBounds() used

I installed TextNodes BV in three ways, as seen from the figure.

  1. In the case of ‘auto’ and ‘intrnal’ modes, BV corresponds to the text only. When the BV outside review
    the picture is still visible. How BV is involved in cutting off invisible objects?

  1. When using TextNode to setup PGButton states, in the case of the BV-auto the active zone (the click area) calculated separately for text and card. In the case of BV-manually the zone is total. How to be if visualy the graphics not intersect, and active zones overlap, gui-elements must always be parallel to the axes? What is the principle of definition of the active zone? (Active zone - a blue frame, the first figure.)

  2. For BV-manually, when moving the object to 1.0, becomes noticeable unexpected shift of BV. Recalculation is not help, what went wrong? In this case the active zone is still correct.

setBounds () does not fully disable automatic BV recount, the scale is change under the transformation (rotation).

Source:http://panda3d.org.ru/_fr/1/text_bounds_cli.zip

I don’t fully understand your text, but I will do my best to answer.

  1. I think you are saying that the auto-computed bounding volume does not include the card behind the text. If that’s so, it’s a minor mistake in Panda, and is probably based on the assumption that the card is close to the size of the text.

But even if it is true, probably no one noticed because the bounding volume cull is not that precise. Even if a bounding volume is just outside of the viewing frustum, it might not be culled until it is farther outside. This is because the intersection test is designed to be fast, not precise, and it errs on the side of drawing too much.

  1. I don’t really understand your questions here. It is true that PGButton (and therefore DirectGui) assumes the GUI elements are parallel to the axes, and not rotated at a crazy angle. The clickable zones are computed by taking the minmax of the vertices.

  2. A bounding volume (as returned by getBounds()) should already be transformed by the node’s transform. So when you call setPos() on a node, you have to transform the bounding volume as well by the same amount. This principle allows the cull traverser to avoid having to transform a bounding volume for a node that it doesn’t have to visit.

  3. Yes, setBounds() does not replace getBounds(); the children of the node still contribute to the bounding volume returned by getBounds().

David

All-in-point, thank you.

how transform bounding volume ?

Transforming a bounding volume is only necessary when you have created a custom bounding volume, since the automatic bounding volumes that Panda creates are transformed for you. When you have created a custom bounding volume, it should be easy to transform it, because you just have to transform whatever inputs you use to create it.

For the record, though, you can also transform a GeometricBoundingVolume with a sequence like this:

bv = bv.makeCopy()
bv.xform(mat)

You shouldn’t do this repeatedly on the same volume, though; errors will accumulate.

David