[fixed]More polygons when mesh attached to joint node

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
piiichan
Posts: 59
Joined: Thu May 01, 2008 1:20 am
Location: New Caledonia (France - Pacific)
Contact:

[fixed]More polygons when mesh attached to joint node

Post by piiichan »

I want to attach a sword mesh to the hand of a character.

There are 478 polygons in my scene without the sword.
The sword is 34 polygons.
If I add the sword to the scene,

Code: Select all

smgr->addMeshSceneNode(smgr->getMesh("C:\\sword.x"))
I get 512 polygons, which is correct.

Now if I set the parent of the sword node as the joint node of the character hand,

Code: Select all

smgr->addMeshSceneNode(smgr->getMesh("C:\\sword.x"),
			player.getNode()->getJointNode("handR"));
the sword somehow adds 6 times more polygons to the scene :shock: , which gives me 478 + 34*6 = 682.

I tried it with a cube scene node from ISceneManager::addCubeSceneNode(), and the same thing happens: 478 + 12*6 = 550

Then I tried to attach the sword to a different part, let's say the head, and I then get 4 times more polygons for the sword. :?

If I set the parent of the sword as a node other than a joint node, there is no problem.

This "bug" is easily reproducible in only 3-4 or lines of code (load an animated mesh, attach a cube to a joint node and draw the poly count on screen), so try by yourself if you don't believe me...

So my question is: why does this happen? Is it the way it works in Irrlicht? Or is it a bug? Or am I doing something wrong?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I imagine it would just be a bug with calculating the number of polygons (a good catch though, someone should check it out) rather than irrlicht actually magicking up extra polygons as you wouldn't need to do that for parenting.
Image Image Image
piiichan
Posts: 59
Joined: Thu May 01, 2008 1:20 am
Location: New Caledonia (France - Pacific)
Contact:

Post by piiichan »

I've done a bit more testing.

I wanted to know whether the poly count displayed was correct. I've added a mesh with thousands of polygons to the scene to check whether it does affect or not the frame rate. The results are

big mesh not parented
poly count: 8414
FPS: ~700

big mesh parented to joint node
poly count: 48,094
FPS: ~230 :evil:

Conclusion: the polycount is correct. The simple fact of parenting a node to a joint node does add a significant amount of polygons to the scene.

This thread should be moved to the bug forum.
I'm going to report this annoying bug on the sourceforge tracker.
.... meanwhile I can try to see where in the source code this happens, but I don't think I can spot it. Any idea where to look first? [/u]
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

yeah, check that each level in a hierarchy doesn't keep getting redrawn. I don't know why, but it's my gut feeling.
piiichan
Posts: 59
Joined: Thu May 01, 2008 1:20 am
Location: New Caledonia (France - Pacific)
Contact:

Post by piiichan »

I've had a look in the code, but I don't have enough knowledge of the Irrlicht source code, and I found it difficult to spot it.

This bug is a performance killer and affects a very basic feature (attaching a mesh to a bone), that many people I believe use very often.

This is a really nasty bug, and somebody more experienced than myself must fix it ASAP :!:
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

This looks like a valid bug. I have to dash for work, but this test code demonstrates it using the SDK sample resources. With a 0 or IAnimatedMeshSceneNode parent, the expected number of triangles is reported. With a joint as the parent, I get one extra child's worth of triangles reported.

I'll debug it ASAP.

(I'd also get a patch up for getJointNode(u32 jointID), which needs to do a checkJoints())

Code: Select all


#include <irrlicht.h>
#include <assert.h>

#pragma comment(lib, "Irrlicht.lib")

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

int main()
{

    IrrlichtDevice *device =
       createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 16,
          false, false, false, 0);

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

    IAnimatedMeshSceneNode* dwarf = 0;
    dwarf = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/dwarf.x"));

    ISceneNode * joint = 0;
    if(dwarf)
    {
        dwarf->setMaterialFlag(EMF_LIGHTING, false);
        dwarf->setName("dwarf");
        u32 joints = dwarf->getJointCount();
        assert(joints > 0);
        joint = dwarf->getJointNode("base");
        assert(joint);
    }

    // Uncomment either of these lines to see the expected number of triangles
    //joint = 0;
    //joint = dwarf;

    // The the bug report specifies an IMeshSceneNode, but I get the same
    // behaviour with an IAnimatedMeshSceneNode.
    IAnimatedMeshSceneNode * sydney = 
        smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/sydney.md2"),
                                       joint);

    if(sydney)
    {
        sydney->setMaterialFlag(EMF_LIGHTING, false);
        sydney->setName("sydney");
    }

    ICameraSceneNode * cam = smgr->addCameraSceneNodeFPS(0);
    cam->setPosition(vector3df(0,30,-80));
    cam->setName("camera");

    smgr->getRootSceneNode()->setName("root");

    ISceneCollisionManager * collMan = smgr->getSceneCollisionManager();

    while(device->run())
    {
        driver->beginScene(true, true, SColor(255,100,101,140));
        smgr->drawAll();
        driver->endScene();

        static bool loggedOnce = false;
        if(!loggedOnce)
        {
            loggedOnce = true;
            (void)printf("\n\n%d triangles rendered: should be 2575\n", driver->getPrimitiveCountDrawn());
        }
    }

    device->drop();

    return 0;
} 
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Oh, snap. It's CAnimatedMeshSceneNode::OnRegisterSceneNode() registering its joints for rendering twice, once by calling ISceneNode::OnRegisterSceneNode(). Its joints are children of it, so they get registered in there. It then calls OnRegisterSceneNode() explicitly on all of its joints.

This looks to be extraneous unless there are some skinned/skeletal nodes whose joints aren't children of the main node. I've only tested this with the dwarf.X mesh in the SDK; it would be good to verify that it works for other skinned/skeletal meshes.

Code: Select all

Index: source/Irrlicht/CAnimatedMeshSceneNode.cpp
===================================================================
--- source/Irrlicht/CAnimatedMeshSceneNode.cpp	(revision 1402)
+++ source/Irrlicht/CAnimatedMeshSceneNode.cpp	(working copy)
@@ -192,10 +192,6 @@
 			SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
 
 		ISceneNode::OnRegisterSceneNode();
-
-		for (u32 j=0; j<JointChildSceneNodes.size(); ++j)
-			if (JointChildSceneNodes[j])
-				JointChildSceneNodes[j]->OnRegisterSceneNode();
 	}
 }
 


Great bug report, by the way!
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
piiichan
Posts: 59
Joined: Thu May 01, 2008 1:20 am
Location: New Caledonia (France - Pacific)
Contact:

Post by piiichan »

Yep! It works!

No more problems here!

You can post this patch on the tracker!
Good job!
Baz
Posts: 11
Joined: Fri Jul 04, 2008 12:03 pm

Post by Baz »

i can't believe it! it's working!!!
youre a lifesaver, thank you!!
Luke
Admin
Posts: 449
Joined: Fri Jul 14, 2006 7:55 am
Location: Australia
Contact:

Post by Luke »

that's a pretty bad bug, cannot believe I missed it. code left over from the old system I think.

it shouldn't be affecting anything other then when you manually parent to joints but.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Fixed in the 1.4 branch now.
Post Reply