Page 1 of 1

Getting the size of a mesh/node

Posted: Tue May 18, 2010 7:16 pm
by KungFuLu
Hi,

I'm wondering how to get the size (not the scale) of a mesh or a node. For example if I make a box in Blender that is 4 units long, 1 unit high and 2 units wide, how do then I get these values within Irrlicht?

Thanks in advance,
Lu

Posted: Tue May 18, 2010 7:33 pm
by sudi
on the mesh you can call getBoundingBox that will return the actual boundingbox of the mesh. on a scenenode you can also call getTransformedBoundingBox which will give you the scaled and positioned bounding box. everything axis aligned.

Posted: Tue May 18, 2010 7:48 pm
by KungFuLu
Thank you very much Sudi, with the edges of the aabbox I could get the size of a mesh.

Posted: Thu Jul 15, 2010 1:05 pm
by raveneyex
Hey KungFuLu...

I'm just starting to work with Irrlicht and I have the exact problem you had, and I was wondering if you could point me out in the right direction to solve it...

I'm doing kind of a mesh viewer, and I need that all the models that I load have more or less the same size (i.e. fill the screen)...
Problem is some models are just too small and some others too huge, hence I can't scale them always by the same factor...

Did you manage to find a way to get the mesh size?
If i can get the size of a mesh, I can do some calculations as to what is the right scaling factor to make 'em fill the screen; but so far, I'm completely blank as to how can I get the size...

Any help would be appreciated.
Thanks!

Posted: Thu Jul 15, 2010 1:19 pm
by Zurzaza
raveneyex wrote:Hey KungFuLu...

I'm just starting to work with Irrlicht and I have the exact problem you had, and I was wondering if you could point me out in the right direction to solve it...

I'm doing kind of a mesh viewer, and I need that all the models that I load have more or less the same size (i.e. fill the screen)...
Problem is some models are just too small and some others too huge, hence I can't scale them always by the same factor...

Did you manage to find a way to get the mesh size?
If i can get the size of a mesh, I can do some calculations as to what is the right scaling factor to make 'em fill the screen; but so far, I'm completely blank as to how can I get the size...

Any help would be appreciated.
Thanks!
You can easily take the 8 edges of the bounding box, using a code like this:

Code: Select all

ISceneNode* mesh;
[..]
vector3d<f32> * edges = new vector3d<f32>[8]; //Bounding BOX edges
aabbox3d<f32> boundingbox ; //Mesh's bounding box
boundingbox=mesh->getTransformedBoundingBox(); //Let's get BB...
boundingbox.getEdges(edges); //Fill the array with edges's coords...
In this array (edges), you'll have 8 values, everyone rapresents a edge of the bounding box of the mesh:

Code: Select all

                   /3--------/7
                  / |       / |
                 /  |      /  |
                1---------5   |
                |  /2- - -|- -6
                | /       |  /
                |/        | /
                0---------4/
next you simply need to calculate the distance beetween every edge...

Thanks!

Posted: Mon Jul 19, 2010 9:11 am
by raveneyex
Thank you very much Zurzaza!
You were absolutely right :D

Here's the code I made:

Code: Select all

void getMeshSize(scene::ISceneNode* mesh)
{
	core::vector3d<f32> * edges = new core::vector3d<f32>[8]; 
	core::aabbox3d<f32> boundingbox = mesh->getTransformedBoundingBox(); 
	boundingbox.getEdges(edges);

	f32 height = edges[1].Y - edges[0].Y; //OK
	std::cout<<"height: "<<height<<std::endl;

	f32 width = edges[5].X - edges[1].X;
	std::cout<<"width: "<<width<<std::endl;

	f32 depth = edges[2].Z - edges[0].Z;
	std::cout<<"depth: "<<depth<<std::endl;
}
Just in case anyone else need this ;)

Posted: Mon Jul 19, 2010 9:23 am
by ent1ty
you can do this much easily

Code: Select all

vector3df extent= node->getTransformedBoundingBox.getExtent();
//now extent.X is the X size of the box, .Y is Y etc.

Oh...

Posted: Mon Jul 19, 2010 10:10 am
by raveneyex
Oh sh*t!
I didn't know...

:/

well, It's already done so ;)
Thanks anyway :D

Posted: Mon Jul 19, 2010 7:06 pm
by Lonesome Ducky
I think getExtent is only half the size of the actual box, I can't remember though

Posted: Mon Jul 19, 2010 7:55 pm
by ent1ty
No, it is not.
Get extent of the box (maximal distance of two points in the box).
You can always use API documentation if you'r not sure.

Posted: Tue Jul 20, 2010 8:40 am
by Zurzaza
raveneyex you forgot to delete the pointer!
So, before the ending of your function, you must add "delete [] edges" to avoid memory leaks ;)

Posted: Tue Nov 02, 2010 2:54 pm
by fabietto
Zurzaza wrote:You can easily take the 8 edges of the bounding box, using a code like this:
[cut]
Excellent post. Thanks!