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 : uint, uvIndex : uint) : int
{
var len : uint = _vertIndices.length;
for (var i : uint = 0; i < len; ++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 : uint, uvIndex : 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!