Marco Tarini - univ insubria AA 2016/2017
Computer Graphics: meshes (2) 1
Come rappresento una mesh?
(quali strutture dati)
• Una tri-mesh è un insieme di triangoli adiacenti
• Modo diretto:
– un vettore di triangoli
– e per ogni triangolo tre vertici – e per ogni vertice tre coordinate – Ma: replicazione dati
• poco efficiente in spazio
• oneroso fare updates
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 6 / 1 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Come rappresento una mesh?
(quali strutture dati)
• Modo indexed:
– Geometria: array di vertici
• in ogni vertice, posizione e attributi – Attributi:
• coi vertici
– (e.g. campi della classe “vertice”)
– Connettività: (a volte anche: “topologia”)
• Array di triangoli
• Per ogni triangolo:
– tripletta di indici a vertice
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 6 / 1 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Marco Tarini - univ insubria AA 2016/2017
Computer Graphics: meshes (2) 2
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 6 / 1 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Mesh: strutture dati
• Sturtture dati indexed (mesh indicizzata)
– Inseme di vertici
• per ogni vertice, la posizione
– Iniseme di facce
• per ogni faccia, 3 indici di vertici
– Se serve: lista ordinata di edges
• per ogni edge, 2 indici ai vertici
Mesh: strutture dati
• indexed mesh
V2
V3
V5 V4
V1
T1
T2 T3
Tri: Wedge 1: Wedge
2: Wedge 3:
T1 V4 V1 V2
T2 V4 V2 V5
T3 V5 V2 V3
vert X Y Z R G B
V1 x1 y1 z1 r1 g1 b1 V2 x2 y2 z2 r2 g2 b2 V3 x3 y3 z3 r3 g3 b3 V4 x4 y4 z4 r4 g4 b4 V5 x5 y5 z5 r5 g5 b5 GEOMETRIA + ATTRIBUTI
CONNETTIVITA’
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 6 / 1 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Marco Tarini - univ insubria AA 2016/2017
Computer Graphics: meshes (2) 3
LetteraL.off
Indexed mesh:
as a file format (here: formato OFF file format)
1 5 1 0 5 1 4 3 2 1 0 4 5 4 3 0 4 6 7 8 9 4 6 9 10 11 4 0 1 7 6 4 1 2 8 7 4 2 3 9 8 4 3 4 10 9 4 4 5 11 10 4 5 0 6 11 OFF
12 10 40 0 0 0 3 0 0 3 1 0 1 1 0 1 5 0 0 5 0 0 0 1 3 0 1 3 1 1 1 1 1
# vertici
# facce # edges
x,y,z 2ndo vert
prima faccia:
4 vertici:
con indici 3, 2, 1 e 0 indice 0
indice 3 indice 2 indice 1
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 6 / 1 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Indexed mesh:
as a class (here: in C++)
class Vertex { vec3 pos;
rgb color; /* attribute 1 */
vec3 normal; /* attribute 2 */
};
class Face{
int vertexIndex[3];
};
class Mesh{
vector<Vertex> vert; /* geom + attr */
vector<Face> tris; /* connettivita’ */
};
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 6 / 1 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Marco Tarini - univ insubria AA 2016/2017
Computer Graphics: meshes (2) 4
Indexed mesh:
in GPU memory, with OpenGL / WebGL
• indexed mesh
V2
V3
V5 V4
V1
T1
T2 T3
Tri: Wedge
1: Wedge
2: Wedge
3:
T1 V4 V1 V2
T2 V4 V2 V5
T3 V5 V2 V3
vert X Y Z R G B
V1 x1 y1 z1 r1 g1 b1 V2 x2 y2 z2 r2 g2 b2 V3 x3 y3 z3 r3 g3 b3 V4 x4 y4 z4 r4 g4 b4 V5 x5 y5 z5 r5 g5 b5 GEOMETRIA + ATTRIBUTI
CONNETTIVITA’
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 6 / 1 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a