Type arrays manipulation ?

Hello,

I’ve been encountering some serious headache with manipulation of arrays like Mesh.vertices or Mesh.triangles …

Isn’t there a simple way to just add more Vector3 entries to an existing Mesh.vertices array ?

It doesn’t support Array class vital methods, like Push() … So actually I have to manually create a transaction array with a fixed size, like this :

_sprite_quad = new Vector3[_Old_Mesh.vertices.length+_New_Mesh.vertices.length];

i = 0;
	while (i < _sprite_quad.length) {
		if (i < _HUD_Mesh.vertices.length) {
		_sprite_quad[i] = _Old_Mesh.vertices[i];
		} else {
		_sprite_quad[i] = _New_Mesh.vertices[i-_Old_Mesh.vertices.length];
		}
	i++;	
	}

Yes, a manual Concat() …

It’s so stupid to have to do things like this, I’m sure there’s a method I don’t know which would save me precious time … Is there ? :slight_smile:

You can convert built-in arrays to and from Javascript arrays, so you can convert vertex arrays to “normal” arrays and do Push() etc., and then back again as needed. However, built-in arrays are so much faster that it might be worth sticking to doing things the “hard” way. Depends on the situation. (And one reason they’re so much faster is because of not being dynamic and having all the conveniences of normal arrays, which are nice but slow…it’s not stupid, it’s efficient. :wink: )

–Eric

Ok, as performance is a priority in iPhone dev, I will stick to that “hard” way.

Thank you very much Eric :wink: