replaced my arrays with signed vectors:
var vnData:Vector.<String> = Vector.<String>( trim(a1).split(",") );
also used dictionary (basically it is a hash table) and did the things you suggested, now it works faster then the speed of light - thanks 🙂
here is my optimization function now:
private function OptimizeMesh2(vertices:Vector.<String>,indexes:Vector.<Number>,normals:Vector.<String>,uvMap:Vector.<String>):void
{
trace("vertex number: "+vertices.length);
var dict:Dictionary = new Dictionary();
var _vertices:Vector.<String> = Vector.<String>([]);
var _normals:Vector.<String> = Vector.<String>([]);
var _uvMap:Vector.<String> = Vector.<String>([]);
//var counter:int = 0;
if (bitmapData)
{
//create dictionary
for (var i:int = 0; i<vertices.length; i++)
{
if (!dict[String(vertices[i]+normals[i]+uvMap[i])])
dict[String(vertices[i]+normals[i]+uvMap[i])] = Vector.<int>([i]);
else
dict[String(vertices[i]+normals[i]+uvMap[i])].push(i);
}
//rebuild the arrays from the dictionary
for each (var item:Object in dict)
{
_vertices.push(vertices[item[0] ]);
_normals.push(normals[item[0] ]);
_uvMap.push(uvMap[item[0] ]);
}
}
else
{
//create dictionary
for (var i:int = 0; i<vertices.length; i++)
{
if (!dict[String(vertices[i]+normals[i])])
dict[String(vertices[i]+normals[i])] = Vector.<int>([i]);
else
dict[String(vertices[i]+normals[i])].push(i);
}
//rebuild the arrays from the dictionary
for each (var item:Object in dict)
{
_vertices.push(vertices[item[0] ]);
_normals.push(normals[item[0] ]);
}
}
trace("vertex number: "+_vertices.length);
}
one thing is missing though - how do I rebuild the indexing array without having to loop through the array. I need to take out all the high numbers and reduce those that come after, I used this for loop in the past:
for (var n:int = 0; n<indexes.length; n++)
{
if (indexes[n] == j)
indexes[n] = i;
else if (indexes[n] > j)
indexes[n] -= 1;
}
but now I would like to use dictionary, but can't think of a way to do that. the point is once I take out a number from the index array because I deleted the vertex, I need to offset all the numbers that are higher and how will I do that efficiently? the replacement is easy, but the offset, can you do an offset without a loop? any ideas would be accepted with gratitude.