#include "TbirdUvSynth.h" using namespace CCS; const int TbirdUvSynth::NUM_TBIRD_UVS = 4; bool TbirdUvSynth::addVisitedFace(Face* f) { pair::iterator, bool> stat = visitedFaces.insert(f); bool wasntAlreadyThere = stat.second; return wasntAlreadyThere; } /* * Returns the tbird UV number that the neighbor (an edge nbor) * should start with if the current face starts at vertStart * at the shared edge. */ int TbirdUvSynth::getStartUvForNbor(int vertStart) { switch(vertStart) { case 0: return 0; case 1: return 3; case 2: return 2; case 3: return 1; default: __ERROR__("bad vertstart for tbird UV: " << vertStart); exit(1); return -1; } } /* * The main recursive func */ void TbirdUvSynth::synthUVs(Face* f, Vertex* startVert, int startUvNum) { if(addVisitedFace(f)) { // This hasn't been synth'd yet - do it! if(f->edgeUses.size() != NUM_TBIRD_UVS) { __ERROR__("tried to syth tbird UVs over a face that has " << f->edgeUses.size() << " verts! It should only have " << NUM_TBIRD_UVS << " verts.."); exit(1); } f->txtr = this->tbirdTxtr; // first, obtain the UVs iterator that corresponds // to the given startVert list::iterator uv_iter; list::iterator eu_iter; f->getItersForVert(startVert, eu_iter, uv_iter); __STAT__("starting face at vert " << startVert->p << " with UV num " << startUvNum); int uvNum = startUvNum; for(int count = 0; count < NUM_TBIRD_UVS; ++count) { // set the UV! *uv_iter = this->tbirdUVs[uvNum]; // recursively do the current nbor Face *nbor = (*eu_iter).getSharingFace(); Vertex *nborStart = (*eu_iter).getUseStart(); if(nbor != NULL) { synthUVs(nbor, nborStart, getStartUvForNbor(uvNum)); } else { __WARN__("non-closed mesh given!"); } // advance uv iter and uvNum, cyclically uvNum = (uvNum + 1) % NUM_TBIRD_UVS; ++uv_iter; ++eu_iter; if(uv_iter == f->uvs.end()) { // wrap! uv_iter = f->uvs.begin(); eu_iter = f->edgeUses.begin(); } } } else { // don't do jack } } TbirdUvSynth::TbirdUvSynth() { // set UVs this->tbirdUVs.clear(); this->tbirdUVs.resize(NUM_TBIRD_UVS); this->tbirdUVs[0] = UVs(0,0); this->tbirdUVs[1] = UVs(1,0); this->tbirdUVs[2] = UVs(1,1); this->tbirdUVs[3] = UVs(0,1); tbirdTxtr = NULL; visitedFaces.clear(); } void TbirdUvSynth::synth(Mesh *mesh, TiffImage *txtr) { tbirdTxtr = txtr; visitedFaces.clear(); Face *firstFace = mesh->faces.front(); Vertex *firstVert = firstFace->edgeUses.front().getUseStart(); synthUVs(firstFace, firstVert, 0); }