Parsing MD2 files ridiculously slow - but I have a patch

Software: Away3D 4.x

bluntcoder, Newbie
Posted: 25 November 2012 08:43 PM   Total Posts: 19

Hello,

I attempted to load an MD2 file with about 40K vertices and the loading was so slow it froze my flash plug-in and browser for about 10 seconds. The culprit is here:

/**
* Finds the final index corresponding to the original MD2's vertex and uv indices. Returns -1 if it wasn't added yet.
* @param vertexIndex The original index in the vertex list.
* @param uvIndex The original index in the uv list.
* @return The index of the final mesh corresponding to the original vertex and uv index. -1 if it doesn't exist yet.
*/
private function findIndex(vertexIndex uintuvIndex uint) : int
{
var len uint _vertIndices.length;

for (var 
uint 0len; ++i)
if (
_vertIndices[i] == vertexIndex && _uvIndices[i] == uvIndex) return i;

return -
1;

This is present in Md2Parser.as and this issue is still present in GitHub. It’s a trivial fix, all I did was add two dictionaries to keep track of the vertex and index lists so that a linear search is not required like so:

private function findIndex(vertexIndex uintuvIndex uint) : int
  {
   
if (_vertexIndexMap[vertexIndex] != null && _vertexIndexMap[vertexIndex] == _texelIndexMap[uvIndex]) return _vertexIndexMap[vertexIndex]
   
   return -
1;
  


One thing is, I’m not very familiar with the Away3D source code, and I would like to purge those dictionaries on loading complete - but I’m unsure where is the best place to do so. It would probably be easier for someone on the Away3d team who’s handled mesh parsing to just submit it - could someone add this fix into the repo?

(Obviously you need to set the two dictionaries in addIndex() and declare them, but you get the idea).

Thanks!

   

esparano, Newbie
Posted: 24 August 2013 08:25 AM   Total Posts: 1   [ # 1 ]

THANK YOU SO MUCH.  You don’t understand how much trouble this saved me.  I’ve been trying to get this to work for several weeks now and I thought it was a problem with my specific .md2 file or something, or perhaps I was just typing the wrong code. 

I also had a 20k+ .md2 mesh and it took about 20 seconds to load on my laptop.  Now it takes less than a second. 

It was actually a very simple fix so I hope it gets added into the official release very soon, as the MD2 parser is basically unusable without it!


Also, I really think this should have been posted in the “Bugs” section because I think it qualifies as one.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X