Size of Geometry

How can I get size of box bounding the Geometry?

Try this:

[java]
BoundingBox box = (BoundingBox)yourGeometry.getModelBound();
Vector3f boxSize;
box.getExtent(boxSize);
[/java]

1 Like

It works. Thank you.
And what about Nodes? Can I find size of box bounding all content of the Node?

http://hub.jmonkeyengine.org/javadoc/

In other words, if you read the JavaDoc you’ll discover that Node has a getWorldBound() method too, inherited from Spatial, which is a superclass to both Geometry and Node.

Caveat #1: getWorldBound() is intended for optimizations. I don’t believe it’s guaranteed to provide the minimal bound in all cases, so test it thoroughly before relying on it.

Caveat #2: it may not always be possible to cast yourGeometry.getModelBound() to a BoundingBox. SkyFactory, for instance, generates a BoundingSphere instead.

1 Like

Yep. In this case, I was putting as much effort into the response as the asker put into the question. Since no information was provided on why the bounding box is needed then it’s hard to provide good advice without lots of speculation.

…and it seemed like OP was unaware that there is javadoc.

I do not presume to criticize the amount of effort you put into this forum, @pspeed.

So, @raid, has your question been addressed? If not, please tell us why your application needs bounding box information.

@pspeed said: and it seemed like OP was unaware that there is javadoc.
I read javadoc and noted that getWorldBound method returns BoundingVolume object and I can not be sure that it is BoundingBox but BoundingVolume class contains no methods that allow to get size of the object.

In general I understand things that interest me. Thanks for the replies.

@sgold said: Please tell us why your application needs bounding box information.
Ok. I want to cut the game map into parts and load them dinamically because it is possible that in future the map will be too big. So I need way to know when player will near to the next part.
@pate5 said: Try this:

[java]
BoundingBox box = (BoundingBox)yourGeometry.getModelBound();
Vector3f boxSize;
box.getExtent(boxSize);
[/java]

bofore doing this i think you need to clear rotation of the spatial…

In the case of a player, I believe it is almost certain the BoundingVolume will be a BoundingBox. And since you’re using it for scene optimization, the possibility that it’s non-minimal should not worry you too much. Try it and let us know.

Are you trying to get the size of your player or the size of parts of the world or both?

You may not need anything more specific than bounding volume since it seems like what you will be doing with it is either seeing if it is close to something (distance()) or if something collides with (intersects()).