lux112

10-22-2011, 06:39 AM

Hello

I use VBO's to create a mesh grid. Everything works fine but I want to optimize my array creation. My code is written in python.

I have this kind of mesh (the number in the corner is the number of the vertice) :

1 ------- 2=4

| ------*-- |

| ----*---- |

| --*------ |

3=5=7 --- 6=8

| ------*

| ----*

| --*

9

The array looks like this :

(x1,y1,z1),(x2,y2,z2),(x3,y3,z3) --> triangle 1

(x4,y4,z4),(x5,y5,z5),(x6,y6,z6) --> triangle 2

(x7,y7,z7),(x8,y8,z8),(x9,y9,z9) --> triangle 3

and so on ...

Now, I want to create two new arrays from this big one :

- One vertices array without duplicate vertices (as vertice 2 = vertice 4 and so on …)

- An index array which will look like this : (1,2,3,2,3,4,3,4,5,….)

So, what I do is to parse the big vertices array with for loops an check at every turn if the vertice is already in my new vertices array, and fill the index array + new vertices array. This step is very slow as I have a big array at the beginning. Are there some algorithms or tricks to speed the things up ?

There is one more thing; the mesh is not full, there are are some "holes" in it with triangles missing. (Just to make it a little bit more complicated :d).

Most people fill these arrays with 5-10 values in their tutorials; but never talk how it would work in the "real" world with a lot of vertices.

I use VBO's to create a mesh grid. Everything works fine but I want to optimize my array creation. My code is written in python.

I have this kind of mesh (the number in the corner is the number of the vertice) :

1 ------- 2=4

| ------*-- |

| ----*---- |

| --*------ |

3=5=7 --- 6=8

| ------*

| ----*

| --*

9

The array looks like this :

(x1,y1,z1),(x2,y2,z2),(x3,y3,z3) --> triangle 1

(x4,y4,z4),(x5,y5,z5),(x6,y6,z6) --> triangle 2

(x7,y7,z7),(x8,y8,z8),(x9,y9,z9) --> triangle 3

and so on ...

Now, I want to create two new arrays from this big one :

- One vertices array without duplicate vertices (as vertice 2 = vertice 4 and so on …)

- An index array which will look like this : (1,2,3,2,3,4,3,4,5,….)

So, what I do is to parse the big vertices array with for loops an check at every turn if the vertice is already in my new vertices array, and fill the index array + new vertices array. This step is very slow as I have a big array at the beginning. Are there some algorithms or tricks to speed the things up ?

There is one more thing; the mesh is not full, there are are some "holes" in it with triangles missing. (Just to make it a little bit more complicated :d).

Most people fill these arrays with 5-10 values in their tutorials; but never talk how it would work in the "real" world with a lot of vertices.