diff --git a/opensubdiv/far/meshFactory.h b/opensubdiv/far/meshFactory.h index 95c6c950..bed4a953 100644 --- a/opensubdiv/far/meshFactory.h +++ b/opensubdiv/far/meshFactory.h @@ -675,91 +675,6 @@ getNumPtexFaces(HbrMesh const * hmesh) { return result; } -// Computes per-face or per-patch local ptex texture coordinates. -template FarPatchParam * -computePatchParam(HbrFace const *f, FarPatchParam *coord) { - - short u,v; - unsigned short ofs = 1; - unsigned char depth; - bool nonquad = false; - - if (coord == NULL) return NULL; - - // save the rotation state of the coarse face - unsigned char rots = f->_adaptiveFlags.rots; - - // track upwards towards coarse parent face, accumulating u,v indices - HbrFace const * p = f->GetParent(); - for ( u=v=depth=0; p!=NULL; depth++ ) { - - int nverts = p->GetNumVertices(); - if ( nverts != 4 ) { // non-quad coarse face : stop accumulating offsets - nonquad = true; // set non-quad bit - break; - } - - for (unsigned char i=0; iGetChild( i )==f ) { - switch ( i ) { - case 0 : break; - case 1 : { u+=ofs; } break; - case 2 : { u+=ofs; v+=ofs; } break; - case 3 : { v+=ofs; } break; - } - break; - } - } - ofs = ofs << 1; - f = p; - p = f->GetParent(); - } - - coord->Set( f->GetPtexIndex(), u, v, rots, depth, nonquad ); - - return ++coord; -} - -template float * -computeFVarData(HbrFace const *f, const int width, float *coord, bool isAdaptive) { - - if (coord == NULL) return NULL; - - if (isAdaptive) { - - int rots = f->_adaptiveFlags.rots; - int nverts = f->GetNumVertices(); - assert(nverts==4); - - for ( int j=0; j < nverts; ++j ) { - - HbrVertex *v = f->GetVertex((j+rots)%4); - float *fvdata = v->GetFVarData(f).GetData(0); - - for ( int k=0; kGetNumVertices(); - for ( int j=0; j < nverts; ++j ) { - - HbrVertex *v = f->GetVertex(j); - float *fvdata = v->GetFVarData(f).GetData(0); - - for ( int k=0; k FarMesh * FarMeshFactory::Create( bool requireFVarData ) { diff --git a/opensubdiv/far/patchTablesFactory.h b/opensubdiv/far/patchTablesFactory.h index 699e0d75..746d2739 100644 --- a/opensubdiv/far/patchTablesFactory.h +++ b/opensubdiv/far/patchTablesFactory.h @@ -105,12 +105,20 @@ private: // Returns the rotation for a corner patch static unsigned char computeCornerPatchRotation( HbrFace * f ); + + // Populates the face-varying data buffer 'coord' for the given face and + // returns a pointer to the next entry in the table + static float * computeFVarData(HbrFace const *f, const int width, float *coord, bool isAdaptive); + + // Populates the patch parametrization descriptor 'coord' for the given face + // returns a pointer to the next descriptor + static FarPatchParam * computePatchParam(HbrFace const *f, FarPatchParam *coord); // Populates an array of indices with the "one-ring" vertices for the given face - void getOneRing( HbrFace * f, int ringsize, unsigned int const * remap, unsigned int * result ); + void getOneRing(HbrFace const * f, int ringsize, unsigned int const * remap, unsigned int * result) const; // Populates the Gregory patch quad offsets table - static void getQuadOffsets( HbrFace * f, unsigned int * result ); + static void getQuadOffsets(HbrFace const * f, unsigned int * result); // Iterates through the faces of an HbrMesh and tags the _adaptiveFlags on faces and vertices void tagAdaptivePatches( HbrMesh const * mesh, int nfaces ); @@ -901,15 +909,18 @@ FarPatchTablesFactory::Create( int maxlevel, int maxvalence, bool requireFVar // The One Ring vertices to rule them all ! template void -FarPatchTablesFactory::getOneRing( HbrFace * f, int ringsize, unsigned int const * remap, unsigned int * result) { +FarPatchTablesFactory::getOneRing(HbrFace const * f, + int ringsize, unsigned int const * remap, unsigned int * result) const { assert( f and f->GetNumVertices()==4 and ringsize >=4 ); int idx=0; - for (unsigned char i=0; i<4; ++i) - result[remap[idx++ % ringsize]] = _remapTable[f->GetVertex( (i+f->_adaptiveFlags.rots)%4 )->GetID()]; - + for (unsigned char i=0; i<4; ++i) { + result[remap[idx++ % ringsize]] = + _remapTable[f->GetVertex( (i+f->_adaptiveFlags.rots)%4 )->GetID()]; + } + if (ringsize==16) { // Regular case @@ -1017,7 +1028,7 @@ FarPatchTablesFactory::getOneRing( HbrFace * f, int ringsize, unsigned int // Populate the quad-offsets table used by Gregory patches template void -FarPatchTablesFactory::getQuadOffsets( HbrFace * f, unsigned int * result ) { +FarPatchTablesFactory::getQuadOffsets(HbrFace const * f, unsigned int * result) { assert( f and f->GetNumVertices()==4 ); @@ -1090,6 +1101,95 @@ FarPatchTablesFactory::getQuadOffsets( HbrFace * f, unsigned int * result } } +// Computes per-face or per-patch local ptex texture coordinates. +template FarPatchParam * +FarPatchTablesFactory::computePatchParam(HbrFace const * f, FarPatchParam *coord) { + + short u,v; + unsigned short ofs = 1; + unsigned char depth; + bool nonquad = false; + + if (coord == NULL) return NULL; + + // save the rotation state of the coarse face + unsigned char rots = f->_adaptiveFlags.rots; + + // track upwards towards coarse parent face, accumulating u,v indices + HbrFace const * p = f->GetParent(); + for ( u=v=depth=0; p!=NULL; depth++ ) { + + int nverts = p->GetNumVertices(); + if ( nverts != 4 ) { // non-quad coarse face : stop accumulating offsets + nonquad = true; // set non-quad bit + break; + } + + for (unsigned char i=0; iGetChild( i )==f ) { + switch ( i ) { + case 0 : break; + case 1 : { u+=ofs; } break; + case 2 : { u+=ofs; v+=ofs; } break; + case 3 : { v+=ofs; } break; + } + break; + } + } + ofs = ofs << 1; + f = p; + p = f->GetParent(); + } + + coord->Set( f->GetPtexIndex(), u, v, rots, depth, nonquad ); + + return ++coord; +} + +// Populates the face-varying data buffer 'coord' for the given face +template float * +FarPatchTablesFactory::computeFVarData( + HbrFace const *f, const int width, float *coord, bool isAdaptive) { + + if (coord == NULL) return NULL; + + if (isAdaptive) { + + int rots = f->_adaptiveFlags.rots; + int nverts = f->GetNumVertices(); + assert(nverts==4); + + for ( int j=0; j < nverts; ++j ) { + + HbrVertex *v = f->GetVertex((j+rots)%4); + float *fvdata = v->GetFVarData(f).GetData(0); + + for ( int k=0; kGetNumVertices(); + for ( int j=0; j < nverts; ++j ) { + + HbrVertex *v = f->GetVertex(j); + float *fvdata = v->GetFVarData(f).GetData(0); + + for ( int k=0; k