struct pos {
float x, y, z;
bool operator==( pos const & other ) const {
return x == other.x && y == other.y && z == other.z;
}
};
struct uv {
float u, v;
bool operator==( uv const & other ) const {
return u == other.u && v == other.v;
}
};
struct vert {
pos p;
uv t;
bool operator==( vert const & other ) const {
return p == other.p && t == other.t;
}
};
struct two_indices {
int p;
int t;
};// assuming you pass "enough" space in
// vertOut and ixOut
int
normalize_arrays(
pos const * posIn,
uv const * uvIn,
two_indices const * ixIn,
int ixInCount,
vert * vertOut,
int * ixOut )
{
int oCount = 0;
int oUsed = 0;
for( int ix = 0; ix < ixInCount; ++ix ) {
vert v;
v.p = posIn[ ixIn[ ix ].p ];
v.t = uvIn[ ixIn[ ix ].t ];
for( int f = 0; f < ix; ++f ) {
if( v == vertOut[ f ] ) {
ixOut[ oCount ] = f;
goto next_vert;
}
}
vertOut[ oUsed ] = v;
ixOut[ oCount ] = oUsed;
++oUsed;
next_vert:
++oCount;
}
assert( oCount == ixInCount );
return oUsed;
}