Animated .x mesh long loading times

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
ichtyander
Posts: 4
Joined: Sat Mar 16, 2013 2:38 pm

Animated .x mesh long loading times

Post by ichtyander »

Hi, I have an animated character model with about 5000 frames in the .x format and the loading times are pretty long (~23 seconds). DxViewer loads the file almost instantly.

The animation is done in Maya, transfered to 3DS Max, then exported to FBX, loaded the FBX in Fragmotion and finally exported to the .x format. This is a process that's given the best results after a long time of testing various export methods.

Since 20 seconds is quite a lot in this situation, is there a way to shorten the loading times? Are baked keyframes an issue? Perhaps there is something I'm missing in the export process that can drastically expand loading times, but I'm a bit confused since DxViewer loads the file instantly.

Here's a download link to the animated mesh in question (both in binary and text format) so you can take a look at the files:
https://drive.google.com/file/d/0B82zDr ... sp=sharing

I'd really appreciate any pointers and ideas you may have, thanks.
wing64
Competition winner
Posts: 242
Joined: Wed Jul 23, 2008 2:35 am
Location: Thailand
Contact:

Re: Animated .x mesh long loading times

Post by wing64 »

Maybe this help you, Try disable optimize and check keyframes in CSkinnedMesh.cpp line 946.
Load in release mode < 1 sec and debug mode

Code: Select all

Time to load binary X file: 9005ms
Loaded mesh: C:/character_bin.x
CuteAlien
Admin
Posts: 9809
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Animated .x mesh long loading times

Post by CuteAlien »

Too many identical key-frames (especially for scaling in this case). Irrlicht is erasing them one-by-one in CSkinnedMesh::finalize() which is too slow. Can probably be rewritten to be faster - but if you have a way to kick them out before export then you can also speed it up.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9809
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Animated .x mesh long loading times

Post by CuteAlien »

It's now a lot faster in svn trunk revision 4622 (less than 1 second now). Thanks for the report and the nice testcase!
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Animated .x mesh long loading times

Post by hendu »

I commend you for that elegance. In-place, and with less copies than a straightforward "copy OK elements to another array" implementation. Quite possibly the best possible choice.

Shamelessly stolen from somewhere, or invented on the spot? ;)
CuteAlien
Admin
Posts: 9809
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Animated .x mesh long loading times

Post by CuteAlien »

Thanks, very cool when you go the extra mile and someone notices it! Copy ok elements was also my first idea, but then I realized it would add a memory allocation for "nice" models which are cleaned up beforehand. And not stolen, just rewritten all afternoon long ;-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9809
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Animated .x mesh long loading times

Post by CuteAlien »

Argh, now I looked again and found a bug in dropBadKeys (j and n mixed up in one place ...) . That's the risk of clever code :-( Too tired already, will fix that tomorrow.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Animated .x mesh long loading times

Post by hendu »

Where? I don't see that.

One thing to note, as array.size() isn't changing, that's a few thousand pointless function calls (or if the compiler manages to inline, pointless checks through a pointer). You should move it outside the loop in these cases.
CuteAlien
Admin
Posts: 9809
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Animated .x mesh long loading times

Post by CuteAlien »

dropBadKeys checks for the previous frame, not the previous frame used (frame 10 , 5, 7, 11 should be 10->11 not 10, 7, 11). Works mostly... (edit: fix checked in now)

array.size() is inlined, so only a little slower in debug, in release you don't get overhead for this with any modern compiler (I checked both variants with a little test program and the resulting asm was identical). So no more need for adding unnecessary local variables - compiler is clever enough already. Note that this is only the case because size() is a simple getter - otherwise you would be right.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Animated .x mesh long loading times

Post by hendu »

You're right, the asm is the same in this case. I've just been bitten by that many times before, and there's little harm in being safe vs testing each container if it happens to be inlined.
Post Reply