Getting the size of a mesh/node

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
KungFuLu
Posts: 27
Joined: Sat May 15, 2010 9:41 pm

Getting the size of a mesh/node

Post 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
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post 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.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
KungFuLu
Posts: 27
Joined: Sat May 15, 2010 9:41 pm

Post by KungFuLu »

Thank you very much Sudi, with the edges of the aabbox I could get the size of a mesh.
raveneyex
Posts: 19
Joined: Thu Jul 15, 2010 8:16 am
Contact:

Post 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!
Zurzaza
Posts: 153
Joined: Fri Mar 26, 2010 9:41 pm
Location: Filo (FE), Italy
Contact:

Post 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...
raveneyex
Posts: 19
Joined: Thu Jul 15, 2010 8:16 am
Contact:

Thanks!

Post 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 ;)
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post 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.
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
raveneyex
Posts: 19
Joined: Thu Jul 15, 2010 8:16 am
Contact:

Oh...

Post by raveneyex »

Oh sh*t!
I didn't know...

:/

well, It's already done so ;)
Thanks anyway :D
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

I think getExtent is only half the size of the actual box, I can't remember though
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post 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.
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
Zurzaza
Posts: 153
Joined: Fri Mar 26, 2010 9:41 pm
Location: Filo (FE), Italy
Contact:

Post 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 ;)
fabietto
Posts: 93
Joined: Wed Sep 24, 2008 4:38 pm
Location: Plymouth, UK
Contact:

Post by fabietto »

Zurzaza wrote:You can easily take the 8 edges of the bounding box, using a code like this:
[cut]
Excellent post. Thanks!
Post Reply