I'm trying to avoid calculating this with python because that would be slow, processing the vertices of each recursive compound mesh.

So is there a way to gather the transformed bounds of a tree of compound meshes??

I'm trying to use it for post vertex transformation of the root object.

  • $\begingroup$ The BGE does not even provide the bounding box on a single object. You need to calculate on your own. $\endgroup$
    – Monster
    Jul 29, 2016 at 6:00
  • $\begingroup$ Well ouch... you'd think the devs would know better... Or actually, maybe not, considering they think tables stand on walls (the 3rd dimension being Height instead of Depth)... Thanks for clarifying, and as if things weren't bad enough, I've just found out all sub-objects return their verts in local relation... so much for optimization. -.- $\endgroup$
    – Tcll
    Jul 30, 2016 at 0:50
  • $\begingroup$ Btw, I'm not done with this, I'm working on a class which hijacks the proxy once and adds a few needed attributes, while applying some perfomance hackery to make the proxy methods as direct as the proxy itself. Once I finish, I'll post the class as my answer. (Warning! Due to the hackery, it will look ugly, but won't slow anything down) $\endgroup$
    – Tcll
    Jul 30, 2016 at 2:08

1 Answer 1


Using a wrapper class, it's possible to calculate the total bounds of all sub-objects in a somewhat efficient manner. (Now there probably are better methods, but this is the best I could think of)

When the sub-objects are added to the root object, wrap their vertex proxies with this class and store them locally:

class VProxy (object):
    """Make vertex proxies a little more usable."""
    __slots__ = ['owner', 'mesh', 'proxy', 'XYZ', '__eq__', ]

    def __init__(this, owner, mesh, matid, vertid ):
        this.owner = owner # mesh object can't be accessed from the mesh proxy.
        this.mesh = mesh # mesh proxy 
        this.proxy = proxy = mesh.getVertex( matid, vertid )

        # now for some hackery
        this.XYZ = proxy.XYZ # direct access to the updated Vector object.
        this.__eq__ = proxy.__eq__ # compared as the vertex proxy it holds. (speedy)

        # more magic can be added if needed.

    getXYZ = lambda this: this.owner.worldTransform * this.XYZ
    getXYZ.__doc__ = "Gets the position of this vertex in world coordinates."

And in the frame, simply retrieve that local store and calculate the bounds:

x,X, y,Y, z,Z = sum(map( minmax, zip(*(itrans*subProxy.getXYZ() for subProxy in subVerts)) ))


minmax = lambda axis: [min(axis), max(axis)]

Where subVerts is of course the collection for a particular sub-object, and itrans is the inverse of the world transform matrix for our root object.

Now as for performance, since getXYZ is a lambda, it's faster than a basic function, but overall still slow... The only speed we get comes from the optimised Vector and Matrix classes.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .