PDA

View Full Version : Texture Indices



FlavorICE
03-28-2002, 05:52 AM
How would you go about syncing a pair of
verts/indices and uvcoords/indices for use
with vertex arrays? I understand that there
is some vertex duplication involved. I'm
just lost on how you know what vertex to
duplicate. Is there some sort of implicit
link between them?

8 verts
12 indices

36 uvcoords
12 indices

Above data belongs to a simple cube I
exported with max. The texture indices
are different from the vertex indices.
What am I missing here?

jwatte
03-28-2002, 08:13 AM
Do a search on the forum. Basically, you have to expand all unique combinations of px,py,pz,nx,ny,nz,tu,tv into individual GL verts. The idea of "texture verts" vs "position verts" doesn't exist in GL (or most other hardware APIs); it's a software-only kind of thing.




struct maxpvert {
float px, py, pz;
};
struct maxtvert {
float tu, tv;
};
struct glvert {
maxpvert p;
maxtvert t;
};
#define TOLERANCE 0.00001
class vertconverter {
public:
vector<glvert> glverts;
vector<int> glindices;
void addvert( maxpvert const & p, maxtvert const & t ) {
int s = (int)glverts.size();
for( int i = 0; i < s; ++i ) {
glvert const & c = glverts[i];
if( close(p,c.p) &amp;&amp; close(t,c.t) ) {
glindices.push_back( i );
}
}
glvert g; g.p = p; g.t = t;
glverts.push_back( g );
glindices.push_back( s );
}
bool close( maxpvert const & p1, maxpvert const & p2 ) {
return (fabs(p1.px-p2.px)<TOLERANCE)&amp;&amp;
(fabs(p1.py-p2.py)<TOLERANCE)&amp;&amp;
(fabs(p1.pz-p2.pz)<TOLERANCE);
}
bool close( maxtvert const & t1, maxtvert const & t2 ) {
return (fabs(t1.tu-t2.tu)<TOLERANCE)&amp;&amp;
(fabs(t1.tv-t2.tv)<TOLERANCE);
}
};


Good luck.