Is it possible to fetch the position of model geometry?

Hello, I was wondering if there is a way to fetch the position of specific geometry on a model. The reason I ask is, that I am working with some 3D audio and the audio is not coming from the object it is attached to. I know why this is the case though, I just wanted to know if it is possible to attach it to a certain part of a model or a point in space.

Why do I need this? I have some objects in a scene where their origin is not the center of the object. I did this, so I could place the objects inside Maya, so I did not have to move them in Panda3D by specifying a position vector. If this is not possible, I will just do it the right way. I just wanted to know if it was possible :slight_smile:

You can use find() to fetch the specific part of the model, then getTightBounds() which returns 2 points. Average those two points to get the center of the geometry of that part.

1 Like

Additionally, with objects that have armatures (such as for the purpose of animation), you can retrieve a specified joint via “exposeJoint”. You can then perhaps attach your sound-object to the retrieved joint, or access the position of the joint and place your sound-object at that point.

1 Like

Thanks a lot! I will check that out :slight_smile:

Thank you for your assistance, again. However, I experienced some issues with this approach, as the getTightBounds() function does not return the expected coordinates. It seems I have issues figuring out world/model coordinates and I cannot understand exactly what is going on here and I hope you have an idea. I have attached an image of my issue, with jerrycans indicating the minimum and maximum tight bounds of the models in the background. As you can see, they do not line up.


I just applied getTightBounds() on the root model, I did not use find() as you suggested, as the models shown is the only geometry which is a part of the model. I hope you can help me. If it is to any help, here is a code snippet, which returns the result above:

        temp = loader.load_model('models/exterior/jerrycan')
        temp.reparent_to(model)
        temp.set_scale(1.5)

        temp2 = loader.load_model('models/exterior/jerrycan')
        temp2.reparent_to(model)
        temp2.set_scale(1.5)

        temp.set_pos(model.get_tight_bounds()[1])
        temp2.set_pos(model.get_tight_bounds()[0])

Thanks again for your assistance :slight_smile:

I note that you’re attaching your “temp”-objects to the “model”-object whose tight-bounds you’re getting, and then setting their positions. However, this means that when you set their positions, you’re setting those positions relative to the “model”-object. If the “model”-object isn’t positioned at (0, 0, 0), and/or has a rotation of other than (0, 0, 0), then your “temp”-objects may not be placed as you expect.

If you want to keep the “temp”-objects parented to the “model”-object, then a simple workaround might be to set their positions relative to “render” (or whatever scene-root you may be using). You can specify that a call to “setPos” or “setHpr” (or their component-specific variants) should be relative to a given NodePath by passing that NodePath in as the first parameter to the call. So, in this case, something like this:

temp.set_pos(render, model.get_tight_bounds()[1])
1 Like

Thanks for your reply!

Finally I got it to work. It seems, that having a child on the “model”-object affects it tight bounds. Therefore, I just changed the parent of the temp object to render and set it to the average position of the bounds. Very nice :slight_smile:

1 Like