Page 1 of 2

Bounding box in animated scene nodes

Posted: Thu Jan 10, 2008 9:08 pm
by G3LO
Hi, i`ve got problem with bounding boxes in skeletal-animated .x files.
X file was created in 3ds max 9 with X format exporter it includes skeletal animation. Running following program occurs in wrongly placed bounding box. Bounding box does not change during animation.

Code: Select all

#include <irrlicht.h>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

int main()
{
	IrrlichtDevice *device =
		createDevice(EDT_OPENGL, dimension2d<s32>(800, 600), 16,
			false, false, false, 0);

	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();


	IAnimatedMesh* mesh = smgr->getMesh("test.x");
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode ( mesh );

	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setFrameLoop(0, 24);
		node->setAnimationSpeed (25);
	}	
    node->setDebugDataVisible ( EDS_BBOX );
	smgr->addCameraSceneNodeFPS();
	while(device->run())
	{
        driver->beginScene(true, true, SColor(0,200,200,200));
		smgr->drawAll();
		driver->endScene();
	}
	device->drop();
	return 0;
}
What happens:
http://www.geocities.com/analitycznie/edit/bug.JPG


What should i do? i need proper bounding boxes

Posted: Thu Jan 10, 2008 9:56 pm
by rogerborg
Surely you agree that it's better to have the wrong bounding boxes calculated rapidly than the right ones calculated slowly?

Wait... I may have dropped a bit too much acid tonight. ;)

Posted: Thu Jan 10, 2008 10:32 pm
by G3LO
Ok. I get it. Recalculating bounding boxes would slown down any game, but i would like recalculate bounding box once at begining and use more proper then shown at picture. Is it possible?

Posted: Thu Jan 10, 2008 11:56 pm
by hybrid
Yes, we will work on this issue. There should be an initially correct bbox, and the possibility to update the bbox during animation. This part was skipped in the new animation system as of now due to some difficulties which came from the new structure and algorithm.

Posted: Fri Jan 11, 2008 2:36 am
by etcaptor
hybrid wrote:Yes, we will work on this issue.
Great. It's very important for right collision and physics.

Posted: Mon Sep 01, 2008 6:26 am
by qez111
Sorry for bringing this problem back to limelight, but I am wondering if a solution exists for the bounding box problems for .x meshes.
Other formats like .3ds displays correct bounding box, but for the .x the bounding box is incorrectly placed. it shows up somewhere near 0,0,0 origin, whereas my object is located far away from the bounding box.
Also I the bounding box doesn't change while the .x file is animating.

Due to the above problem, my collisions don't work with Bullet properly.

Thanks.

Posted: Mon Sep 01, 2008 7:22 am
by JP
Are you using getBoundingBox or getTransformedBoundingBox? the first one will always give you a bounding box around the origin, the latter should give you a correct bounding box for your model (not necessarily animated though)

Posted: Tue Sep 02, 2008 6:48 am
by qez111
The issue is that I can see that the bb is incorrect just by setting node->setDebugDataVisible(scene::EDS_BBOX);
(This is not even in bullet. Its just plain Irrlicht). That too, the actual mesh is visible at, 0,2,5, but the bounding box is somewhere at 0,0,0. So clearly, there's no relationship between the object and bounding box. And as I said earlier, the same mesh gets correct bounding box if its a .3ds file (non-animated). But if I use .x, it shows incorrect bounding box (both static and animated .x meshes have this problem.) I use Panda Exporter for exporting .x

Posted: Tue Sep 02, 2008 12:25 pm
by qez111
I am wondering if recalculateBoundingBox() will help solve this problem..? If so, is there a particular way I need to adopt to make it work properly?

Posted: Tue Sep 02, 2008 12:27 pm
by JP
Try it yourself and see if it helps ;)

Posted: Tue Sep 09, 2008 4:38 am
by qez111
I tried that before and I didn't help, and that's why I actually posted that question because I thought I may not have used that function properly, and thus I wanted to know if that will help solve the problem.

At this point, I am still confused.. Has anybody else faced such a problem with .X mesh? Or is it only me? If its only me, then what could be the issue?

Posted: Wed Sep 10, 2008 10:28 am
by tprochownik
not only You. I have the same problem, but I export X mesh with scale(100%, 100%, 100%) and use bullet physic to get correctly boundingbox with animation. I had problem with correctly render mesh if I use different (like -100%) scale values.

Posted: Thu Nov 13, 2008 5:17 am
by charles88
Could someone tell me whether this issue has been fixed? I am currently having problem with .x file too, :( the bounding box is below my animated node. :(

Thanks.

Posted: Thu Nov 20, 2008 11:33 am
by darkmaster83
I have the same problem with .ms3d file!
Files .md2 don't have this problem, but they have too many limitations, as you can see in this thread: http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=31047
Any suggestions?

Posted: Thu Nov 20, 2008 4:00 pm
by B@z

Code: Select all

IAnimatedMeshSceneNode* RepairBoundingBox(IAnimatedMeshSceneNode* node)
{
	IAnimatedMesh * mesh = node->getMesh();
		
	aabbox3df box;
	for (u32 i = 0; i < mesh->getMeshBufferCount(); i++)
	{
		mesh->getMesh(1)->getMeshBuffer(i)->recalculateBoundingBox();
		box.addInternalBox(mesh->getMesh(1)->getMeshBuffer(i)->getBoundingBox());
	}
	mesh->setBoundingBox(box);
	node->setMesh(mesh);
	return node;
}
dont know it helps, i used it for make the bounding box equal to the first frame's bounding box.
try it maybe it'll solve your problem