ASE and vertex array

Started by
11 comments, last by lem 18 years ago
I´m trying to render ASE with vertex array and DrawElements-function, starting with a simple cube model. The problem is, that I have 8 vertices, 12 faces (thats allright so long), but I have 12 textcoords and 12 indices for textcoords. Am I´m wrong, or do I need 8 texcoords for using the vertex array??? I dont understand. Do I need to reorder ASE texcoords so that they fit to the indices (for the vertices)? Thx for your help
Advertisement
Data in ASE does not map directly to vertex arrays in OpenGL, becasue ASE stores attributes with separate index arrays while OpenGL requires a single index array for all attributes. You need to manually go through all faces and recreate the attribute arrays so all attributes can be indexed with a single index array. Yes, this means you must duplicate certain attributes.

A cube is the worst case scenario when it comes to shared vertices in a vertex array. A cube may have 8 corners, but it actually have 24 vertices. Each corner of the cube have the same position, but different normals for example, therefore they are all different vertices.
:O

So I can´t use vertex arrays with indices???
What is the difference between DrawElements and DrawArrays, if I have to duplicate vertices?

Thanks for your help
Can anyone please hint me, on how to generate indexed vertex arrays?
this is the ASE file, I want to process:

<br> *MESH {<br> *TIMEVALUE 0<br> *MESH_NUMVERTEX 8<br> *MESH_NUMFACES 12<br> *MESH_VERTEX_LIST {<br> *MESH_VERTEX 0 -5.4310 -4.3964 -2.0128<br> *MESH_VERTEX 1 4.5690 -4.3964 -2.0128<br> *MESH_VERTEX 2 -5.4310 5.6036 -2.0128<br> *MESH_VERTEX 3 4.5690 5.6036 -2.0128<br> *MESH_VERTEX 4 -5.4310 -4.3964 7.9872<br> *MESH_VERTEX 5 4.5690 -4.3964 7.9872<br> *MESH_VERTEX 6 -5.4310 5.6036 7.9872<br> *MESH_VERTEX 7 4.5690 5.6036 7.9872<br> }<br> *MESH_FACE_LIST {<br> *MESH_FACE 0: A: 0 B: 2 C: 3 AB: 1 BC: 1 CA: 0 *MESH_SMOOTHING 2 *MESH_MTLID 1<br> *MESH_FACE 1: A: 3 B: 1 C: 0 AB: 1 BC: 1 CA: 0 *MESH_SMOOTHING 2 *MESH_MTLID 1<br> *MESH_FACE 2: A: 4 B: 5 C: 7 AB: 1 BC: 1 CA: 0 *MESH_SMOOTHING 3 *MESH_MTLID 0<br> *MESH_FACE 3: A: 7 B: 6 C: 4 AB: 1 BC: 1 CA: 0 *MESH_SMOOTHING 3 *MESH_MTLID 0<br> *MESH_FACE 4: A: 0 B: 1 C: 5 AB: 1 BC: 1 CA: 0 *MESH_SMOOTHING 4 *MESH_MTLID 4<br> *MESH_FACE 5: A: 5 B: 4 C: 0 AB: 1 BC: 1 CA: 0 *MESH_SMOOTHING 4 *MESH_MTLID 4<br> *MESH_FACE 6: A: 1 B: 3 C: 7 AB: 1 BC: 1 CA: 0 *MESH_SMOOTHING 5 *MESH_MTLID 3<br> *MESH_FACE 7: A: 7 B: 5 C: 1 AB: 1 BC: 1 CA: 0 *MESH_SMOOTHING 5 *MESH_MTLID 3<br> *MESH_FACE 8: A: 3 B: 2 C: 6 AB: 1 BC: 1 CA: 0 *MESH_SMOOTHING 6 *MESH_MTLID 5<br> *MESH_FACE 9: A: 6 B: 7 C: 3 AB: 1 BC: 1 CA: 0 *MESH_SMOOTHING 6 *MESH_MTLID 5<br> *MESH_FACE 10: A: 2 B: 0 C: 4 AB: 1 BC: 1 CA: 0 *MESH_SMOOTHING 7 *MESH_MTLID 2<br> *MESH_FACE 11: A: 4 B: 6 C: 2 AB: 1 BC: 1 CA: 0 *MESH_SMOOTHING 7 *MESH_MTLID 2<br> }<br> *MESH_NUMTVERTEX 12<br> *MESH_TVERTLIST {<br> *MESH_TVERT 0 0.0000 0.0000 0.0000<br> *MESH_TVERT 1 1.0000 0.0000 0.0000<br> *MESH_TVERT 2 0.0000 1.0000 0.0000<br> *MESH_TVERT 3 1.0000 1.0000 0.0000<br> *MESH_TVERT 4 0.0000 0.0000 0.0000<br> *MESH_TVERT 5 1.0000 0.0000 0.0000<br> *MESH_TVERT 6 0.0000 1.0000 0.0000<br> *MESH_TVERT 7 1.0000 1.0000 0.0000<br> *MESH_TVERT 8 0.0000 0.0000 0.0000<br> *MESH_TVERT 9 1.0000 0.0000 0.0000<br> *MESH_TVERT 10 0.0000 1.0000 0.0000<br> *MESH_TVERT 11 1.0000 1.0000 0.0000<br> }<br> *MESH_NUMTVFACES 12<br> *MESH_TFACELIST {<br> *MESH_TFACE 0 9 11 10<br> *MESH_TFACE 1 10 8 9<br> *MESH_TFACE 2 8 9 11<br> *MESH_TFACE 3 11 10 8<br> *MESH_TFACE 4 4 5 7<br> *MESH_TFACE 5 7 6 4<br> *MESH_TFACE 6 0 1 3<br> *MESH_TFACE 7 3 2 0<br> *MESH_TFACE 8 4 5 7<br> *MESH_TFACE 9 7 6 4<br> *MESH_TFACE 10 0 1 3<br> *MESH_TFACE 11 3 2 0<br> }<br> *MESH_NUMCVERTEX 0<br> *MESH_NORMALS {<br> *MESH_FACENORMAL 0 0.0000 0.0000 -1.0000<br> *MESH_VERTEXNORMAL 0 0.0000 0.0000 -1.0000<br> *MESH_VERTEXNORMAL 2 0.0000 0.0000 -1.0000<br> *MESH_VERTEXNORMAL 3 0.0000 0.0000 -1.0000<br> *MESH_FACENORMAL 1 0.0000 0.0000 -1.0000<br> *MESH_VERTEXNORMAL 3 0.0000 0.0000 -1.0000<br> *MESH_VERTEXNORMAL 1 0.0000 0.0000 -1.0000<br> *MESH_VERTEXNORMAL 0 0.0000 0.0000 -1.0000<br> *MESH_FACENORMAL 2 0.0000 0.0000 1.0000<br> *MESH_VERTEXNORMAL 4 0.0000 0.0000 1.0000<br> *MESH_VERTEXNORMAL 5 0.0000 0.0000 1.0000<br> *MESH_VERTEXNORMAL 7 0.0000 0.0000 1.0000<br> *MESH_FACENORMAL 3 0.0000 0.0000 1.0000<br> *MESH_VERTEXNORMAL 7 0.0000 0.0000 1.0000<br> *MESH_VERTEXNORMAL 6 0.0000 0.0000 1.0000<br> *MESH_VERTEXNORMAL 4 0.0000 0.0000 1.0000<br> *MESH_FACENORMAL 4 0.0000 -1.0000 0.0000<br> *MESH_VERTEXNORMAL 0 0.0000 -1.0000 0.0000<br> *MESH_VERTEXNORMAL 1 0.0000 -1.0000 0.0000<br> *MESH_VERTEXNORMAL 5 0.0000 -1.0000 0.0000<br> *MESH_FACENORMAL 5 0.0000 -1.0000 0.0000<br> *MESH_VERTEXNORMAL 5 0.0000 -1.0000 0.0000<br> *MESH_VERTEXNORMAL 4 0.0000 -1.0000 0.0000<br> *MESH_VERTEXNORMAL 0 0.0000 -1.0000 0.0000<br> *MESH_FACENORMAL 6 1.0000 0.0000 0.0000<br> *MESH_VERTEXNORMAL 1 1.0000 0.0000 0.0000<br> *MESH_VERTEXNORMAL 3 1.0000 0.0000 0.0000<br> *MESH_VERTEXNORMAL 7 1.0000 0.0000 0.0000<br> *MESH_FACENORMAL 7 1.0000 0.0000 0.0000<br> *MESH_VERTEXNORMAL 7 1.0000 0.0000 0.0000<br> *MESH_VERTEXNORMAL 5 1.0000 0.0000 0.0000<br> *MESH_VERTEXNORMAL 1 1.0000 0.0000 0.0000<br> *MESH_FACENORMAL 8 0.0000 1.0000 0.0000<br> *MESH_VERTEXNORMAL 3 0.0000 1.0000 0.0000<br> *MESH_VERTEXNORMAL 2 0.0000 1.0000 0.0000<br> *MESH_VERTEXNORMAL 6 0.0000 1.0000 0.0000<br> *MESH_FACENORMAL 9 0.0000 1.0000 0.0000<br> *MESH_VERTEXNORMAL 6 0.0000 1.0000 0.0000<br> *MESH_VERTEXNORMAL 7 0.0000 1.0000 0.0000<br> *MESH_VERTEXNORMAL 3 0.0000 1.0000 0.0000<br> *MESH_FACENORMAL 10 -1.0000 0.0000 0.0000<br> *MESH_VERTEXNORMAL 2 -1.0000 0.0000 0.0000<br> *MESH_VERTEXNORMAL 0 -1.0000 0.0000 0.0000<br> *MESH_VERTEXNORMAL 4 -1.0000 0.0000 0.0000<br> *MESH_FACENORMAL 11 -1.0000 0.0000 0.0000<br> *MESH_VERTEXNORMAL 4 -1.0000 0.0000 0.0000<br> *MESH_VERTEXNORMAL 6 -1.0000 0.0000 0.0000<br> *MESH_VERTEXNORMAL 2 -1.0000 0.0000 0.0000<br> }<br> }<br></code><br><br>
You need to dublicate some vertices yes, because texcoords are not shared between faces like vertices

MESH_TFACELIST are indexes to texcoords for every face just like MESH_FACE_LIST specifies indices for vertices.

Loop thrue MESH_FACE_LIST and pick all data and build your vertexbuffer
Quote:Original post by lem
:O

So I can´t use vertex arrays with indices???

You can. But you must use a single index array for all attributes, not one index array per attribute.

Quote:Original post by lem
What is the difference between DrawElements and DrawArrays, if I have to duplicate vertices?

Thanks for your help

glDrawElements takes an arbitrary index array, and glDrawArrays assumes a linear index array (index starts from 0 and increases by 1 for each index).

Now note the difference between duplicating vertices and duplicating attributes. You don't have to duplicate whole vertices, but only certain attributes. The reason you have to duplicate certain attributes is simply becuase OpenGL indexes a vertex, and if two vertices have same position but different normal, they are different vertices and the position attribute must be duplicated. The vertex cannot be shared simply because the two vertices are not the same.

Quote:Original post by lem
Can anyone please hint me, on how to generate indexed vertex arrays?

The simplest way to flatten the vertex array is to create a linear vertex array suitable for glDrawArrays and ignore shared vertices. In this case, assuming it really is the worst case scenario cube, this is likely the best you can get anyway.

Simple algorithm:

  1. Create a vertex array large enough to contain 3*MESH_NUMFACES vertices.

  2. Go through each face index, call it i in this example.

  3. Take the corresponding position, normal, texture coordinate and whatever attributes you have, and put it in position i in the vertex array.


Now you have a vertex array you can pass draw as GL_TRIANGLES with glDrawArrays.
Thanks for your help, but I dont understand, why to use indeces ...
If number of faces equals number of text faces, I always have to build the array from scratch? So I dont need index/DrawElements - I can build the array and use DrawArray?
Quote:Original post by Brother Bob

Quote:Original post by lem
Can anyone please hint me, on how to generate indexed vertex arrays?

The simplest way to flatten the vertex array is to create a linear vertex array suitable for glDrawArrays and ignore shared vertices. In this case, assuming it really is the worst case scenario cube, this is likely the best you can get anyway.

Simple algorithm:

  1. Create a vertex array large enough to contain 3*MESH_NUMFACES vertices.

  2. Go through each face index, call it i in this example.

  3. Take the corresponding position, normal, texture coordinate and whatever attributes you have, and put it in position i in the vertex array.


Now you have a vertex array you can pass draw as GL_TRIANGLES with glDrawArrays.


Thanks for your help, but I would like to use indexed vertex array (by using DrawElements) and I need a generic algorithm for building an array.
Your solution means, always building a numfaces*3 (in this case 36) array, which means, that i don´t need indices...


maybe ASE is not the right format? :)
are there any 3d editors/formats that save their data in a way, i can use DrawElements?
By looking at how the data is exported, no, maybe ASE isn't the best format. But if you already have functions to extract the data from the file, and you can transform the data into a linear vertex array for drawing with glDrawArrays, is this REALLY a problem that MUST be solved? I mean, after all, you said you would like to use indexed vertex arrays, not that you must use them.

This topic is closed to new replies.

Advertisement