x


Remove int[] element

Hi, I have an integer that is something like this:

var verts : int[];
var vertices = mesh.vertices;
for (int i=0; i<vertices.Length; i++) {
verts[i] = vertices[i];
}//this is only an example

but what I want is actually remove some vertices lets say 3,4 and 5.(this is only an example) So I want something that search for that number in the size of the length of the array and remove that element and the others that are bigger than that size cross it 1 number. Example:Lets say I want to remove the element 2 I want in the script to search for it, remove the element 2 and finally cross it 1 number. Something like this:

Element0 = 0,0,0 Element1 = 1,0,0 Element2 = 1,0,1 Element3 = 0,0,1

change it to:

Element0 = 0,0,0 Element1 = 1,0,0 Element2 = 0,0,1

Note: someone could say why you don't easily add if(i >=3 && i <= 5){ but as I say this is an example, that's not the finality of doing this.

more ▼

asked Jan 27 '11 at 01:21 AM

Uriel_96 gravatar image

Uriel_96
930 61 70 81

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
var verts : int[];
var vertices = mesh.vertices;
var j : int = 0;
for (int i=0; i<vertices.Length; i++) {
  if (vertex is ok to copy)
    verts[j++] = vertices[i];
}//this is only an example
more ▼

answered Jan 27 '11 at 01:34 AM

DaveA gravatar image

DaveA
26.4k 151 171 256

what do you mean with vertex is ok to copy?

Jan 27 '11 at 01:49 AM Uriel_96

Whatever you meant by "something that search for that number in the size and remove that element and the others that are bigger than that size cross it 1 number." I assume there will be some test for some vertex size. If it's simply avoiding vertices 3,4 and 5 then it would be if (i >=3 && i <= 5)

Jan 27 '11 at 02:35 AM DaveA

the thing is that I'm trying to search for the : if (vertex is ok to copy). That part is actually what I want to know.

Jan 27 '11 at 03:26 AM Uriel_96

I'm sorry. I don't understand the condition you want to test for. When you say 'size' do you mean the magnitude of the vector? Distance? Or the values of x, y, and/or z being over some limit? Or length of the array?

Jan 27 '11 at 03:52 AM DaveA

I mean with the length of the array

Jan 27 '11 at 09:27 PM Uriel_96
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5059
x3445
x1355
x43

asked: Jan 27 '11 at 01:21 AM

Seen: 1041 times

Last Updated: Jan 27 '11 at 10:14 PM