finding adjacent vertices

hi all

i just converted a 3ds modell with polytrans programm to opengl c code and included that code in my c++ programm.

polytrans gives me these lines

static GLfloat VertexData[] = {
	-5.38886f, 21.7058f, 5.32406f, -2.77164f, 21.2494f, 8.29626f, -0.782901f, 20.9396f, 8.68122f, .......

static GLfloat NormalData[] = {
	-0.513389f, -0.786477f, 0.343345f, -0.336265f, -0.937733f, 0.0870818f, -0.150752f, -0.988496f, 0.0122153f, .....

static GLint Indices[] = {
	1136, 1123, 1136, 1122, 1128, 1122, 1130, 1120, 1130, 1134, 1135, 1132, 1133, 1064, 1131, 1065, 
	1131, 1059, 1141, 1144, 1141, 1143, 1141, 1142, 1126, 990, 1126, 992, 1126, 1127, 1144, 1163, ....

glNormalPointer(GL_FLOAT, 0, NormalData);
glVertexPointer(3, GL_FLOAT, 0, VertexData);

glColor3f(1.00000f, 0.811881f, 0.707913f);
glDrawElements(GL_TRIANGLE_STRIP, 18, GL_UNSIGNED_INT, &Indices[0]);
glDrawElements(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_INT, &Indices[18]);
glDrawElements(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_INT, &Indices[24]);
glDrawElements(GL_TRIANGLE_STRIP, 8, GL_UNSIGNED_INT, &Indices[30]);
glDrawElements(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_INT, &Indices[38]);
glDrawElements(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_INT, &Indices[44]);
glDrawElements(GL_TRIANGLE_STRIP, 7, GL_UNSIGNED_INT, &Indices[50]);
glDrawElements(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_INT, &Indices[57]);....

to draw the model.

my question:

if i pick one random vertices, how can i get the adjacent vertices to the one i picked?
is that even possible or must the indices_array structured in a diffrent way?

do you know any other good programms which export 3d models in open c code with more options?

many thx for your help :slight_smile:

i’d consider writing my own processing code. that tool gave you the verts and indices, everything you need to do the job.

what kind of connectivity info do you need? or rather, what is it you’re trying to do?

i wanna find out if i choose one point in the mesh, which are the surrounding points, that are connected via lines to the point i choose.
so i can grow a mesh-region starting from one point spreading through the mesh.

i wanna mark all points, that are in a certain distance from the starting point and are reachable walking on the lines of the mesh.

my problem is that the triangle stripes have all a different number of points and i dont know how to get from one indices of a point to the next indices of a point connected to that one.

sounds like you want to construct a directed acyclic graph (DAG). this is a common task in programming. there are many ways to do this, but without getting too fancy, this can be done fairly simply.

firstly, create structures to represent the vertex data in the graph.

struct vert
vec3 pos;
vec3 normal;
… whatever you like

struct edge
int verts[2];
int tris[2];

struct triangle
int edges[3];

now all you need is a function to walk the edge list, and build a path from a starting vertex to some other vertex. the path could simply be an array of edge indices.

int path[???];

to make sure the path is acyclic (no cycles), don’t ever visit a vertex twice, so you need to remember which vertices have been visited.

int visited[???];

so, for each vertex: build a path along each edge connected to that vertex.

now, if all you need is adjacency info, it gets even easier. for each vertex: add each edge’s other vertex to the vertex list. that is, for each vertex, find all edges that have said vertex as an endpoint, then add the other end. if you need this info to persist, then add it to your vertex structure

struct vert
vec3 pos;
vec3 normal;
int adjacentVerts[???];
or int adjacentEdges[???];
or int sharedTriangles[???];
or … get wacky

well, that’s one way to do it anyway. rest assured there are others. you could use hashing to speed up the edge search, and so on… but not important to functionality.

many thx for your help :slight_smile:
and great explained

i will try that solution

thanks dawny, good luck with that.