for a pickup trigger I want the BoundingBox of an item to appear when the player is close enough to pick up that item.
It should be exactly like when you click on the root node of your model (in SceneComposer).
Here you see, what I want to have in the end (captured in SceneComposer):
The created geometry is attached to the parent node of the models root node.
The following screenshot shows how it looks ingame:
It seems, like the BoundingBox geometry could need an offset with half of the models size. Am I wrong? But I don’t want to this for all the pickupable items.
Could someone show me how the BoundingBox creation is done in the SDK? That would be really helpful!
…you got the bounds in world space… then arbitrarily moved it to Spatial-local space… then attached it to the Spatial’s parent. Some offset was lost in this process.
If you get the bound in world space (and you should because there is nothing else you can do) then you will have to worldToLocal() its location on whatever Spatial you want to attach it to. You’re going to have to do that with its rotation, also. Scale is trickier but the math isn’t hard.
“bounding box” often means “Axis-Aligned bounding box in worldspace”. That’s because that leads to the fastest computation in many cases (“static geometry that fits tight into a AA box”). I think there should be a non-axis-aligned bounding box like those often found in level-editors and 3D modeling software. Back when I started (with jME2) jME used bounding spheres per default (which can be great in some cases but are slow when geometry changes or is not of isotropic shape).
He’s already using the wire box that JME provides.
You are right that he probably wants to be using the Geometry’s model bound (assuming he doesn’t want it axis-aligned)… and in that case it will already be oriented properly (and located properly) for adding to the Geometry’s parent.
Ah okay, then nevermind. I was irritated by the fact that there is a Spatial.getWorldBound and no “Spatial.getModelBound” - so I must have missed something.
world bound is needed by the scene graph itself so is calculated. Model bound is not propagated because 99% of users will never need it and it’s actually really difficult to calculate (what is the ‘model bound’ of two children, one with a rotated cube and the other with a sphere?.. etc.). If you have the Geometry (which OP does) then you can get the Geometry model bound with… Geometry.getModelBound()