How to get width and height of an object?

I started playing around with Panda3D and I decided to start with a 2D emulation (a character, made of several planes with textures). So, I have two planes with a texture on each. They are scaled a bit. I was looking in the manual for some function, that would return width and height of a plane, so I could position the bottom of the first plane (like the head plane) to the top of the second plane (like the body) exactly and not by eye and trial by error (like starting the “game” several times while adjusting the position manualy). Is there a way to get the width and height of the plane?

Sub-question: position (the one you set via setPos() ) of the object is in the upper-left corner of the object or in the center of it?

I’d be very happy for any help!

I thought I remembered a nodepath method called getTightBounds, but I couldn’t find it in the documentation. You could try it anyway, its supposed to give you the two diagonal points of a rectangular solid that completely surrounds the model. If it doesn’t work, you could just get the actual vertices of the planes, since they should be the same

for the sub-question, the point specified depends on where the origin is when the object is modelled. You can place the objet anywhere in the modelling software and when you export it to egg format, it will transform about the point that would have been the origin relative to how it was modelled.

yes, NodePath.getThightBounds works fine. you can use something like this in your code:

    pt1, pt2 = nodePath.getTightBounds()
    width = pt2.getX()  - pt1.getX()
    height = pt2.getY() - pt1.getY()

be aware that NodePath.getTightBounds can be quite slow, depending on the number of vertices of your model, because it will search through the model to find the two points. you might want to do a pre-step and caches these values.


I played around with getBounds, but I had a sphere to play with instead of a rectangular plane and when I got to the legs, it became a bit complicated. It will be more simple with this function now.

Big thanks to both of you :slight_smile:

You can use getScale