Cleaned up a bit the indentation and added support for saving line mesh in OBJ
This commit is contained in:
parent
c5549f607a
commit
636f818107
|
@ -37,11 +37,12 @@ namespace vcg {
|
|||
namespace tri {
|
||||
namespace io {
|
||||
|
||||
template <class SaveMeshType>
|
||||
class ExporterOBJ
|
||||
{
|
||||
public:
|
||||
template <class SaveMeshType>
|
||||
class ExporterOBJ
|
||||
{
|
||||
public:
|
||||
typedef typename SaveMeshType::FaceIterator FaceIterator;
|
||||
typedef typename SaveMeshType::EdgeIterator EdgeIterator;
|
||||
typedef typename SaveMeshType::VertexIterator VertexIterator;
|
||||
typedef typename SaveMeshType::VertexType VertexType;
|
||||
typedef typename SaveMeshType::ScalarType ScalarType;
|
||||
|
@ -97,6 +98,7 @@ namespace io {
|
|||
//face
|
||||
capability |= vcg::tri::io::Mask::IOM_FACECOLOR;
|
||||
|
||||
capability |= vcg::tri::io::Mask::IOM_EDGEINDEX;
|
||||
//wedg
|
||||
capability |= vcg::tri::io::Mask::IOM_WEDGTEXCOORD;
|
||||
capability |= vcg::tri::io::Mask::IOM_WEDGNORMAL;
|
||||
|
@ -193,12 +195,11 @@ namespace io {
|
|||
fprintf(fp,"# %d vertices, %d vertices normals\n\n",m.vn,int(NormalVertex.size()));
|
||||
|
||||
//faces + texture coords
|
||||
FaceIterator fi;
|
||||
std::map<vcg::TexCoord2<ScalarType>,int> CoordIndexTexture;
|
||||
unsigned int material_num = 0;
|
||||
int mem_index = 0; //var temporany
|
||||
int curTexCoordIndex = 1;
|
||||
for(fi=m.face.begin(); fi!=m.face.end(); ++fi) if( !(*fi).IsD() )
|
||||
for(FaceIterator fi=m.face.begin(); fi!=m.face.end(); ++fi) if( !(*fi).IsD() )
|
||||
{
|
||||
if((mask & Mask::IOM_FACECOLOR) || (mask & Mask::IOM_WEDGTEXCOORD) )
|
||||
{
|
||||
|
@ -223,7 +224,6 @@ namespace io {
|
|||
//saves texture coord x wedge
|
||||
if(HasPerWedgeTexCoord(m) && (mask & Mask::IOM_WEDGTEXCOORD))
|
||||
for(int k=0;k<(*fi).VN();k++)
|
||||
{
|
||||
{
|
||||
if(AddNewTextureCoord(CoordIndexTexture,(*fi).WT(k),curTexCoordIndex))
|
||||
{
|
||||
|
@ -231,7 +231,6 @@ namespace io {
|
|||
curTexCoordIndex++; //ncreases the value number to be associated to the Texture
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fprintf(fp,"f ");
|
||||
|
@ -240,7 +239,7 @@ namespace io {
|
|||
if(k!=0) fprintf(fp," ");
|
||||
int vInd = -1;
|
||||
// +1 because Obj file format begins from index = 1 but not from index = 0.
|
||||
vInd = VertexId[GetIndexVertex(m, (*fi).V(k))] + 1;//index of vertex per face
|
||||
vInd = VertexId[tri::Index(m, (*fi).V(k))] + 1;//index of vertex per face
|
||||
|
||||
int vt = -1;
|
||||
if(mask & Mask::IOM_WEDGTEXCOORD)
|
||||
|
@ -258,34 +257,35 @@ namespace io {
|
|||
WriteFacesElement(fp,vInd,vt,vn);
|
||||
}
|
||||
fprintf(fp,"\n");
|
||||
|
||||
if (cb !=NULL) {
|
||||
if(!(*cb)((100*++current)/totalPrimitives, "writing vertices "))
|
||||
{ fclose(fp); return E_ABORTED;}
|
||||
}
|
||||
|
||||
}//for
|
||||
}//for faces
|
||||
|
||||
for(EdgeIterator ei=m.edge.begin(); ei!=m.edge.end(); ++ei) if( !(*ei).IsD() )
|
||||
{
|
||||
fprintf(fp,"l %i %i\n",
|
||||
VertexId[tri::Index(m, (*ei).V(0))] + 1,
|
||||
VertexId[tri::Index(m, (*ei).V(1))] + 1);
|
||||
}
|
||||
|
||||
fprintf(fp,"# %d faces, %d coords texture\n\n",m.fn,int(CoordIndexTexture.size()));
|
||||
|
||||
fprintf(fp,"# End of File\n");
|
||||
fclose(fp);
|
||||
|
||||
int r = 0;
|
||||
int errCode = E_NOERROR;
|
||||
if((mask & Mask::IOM_WEDGTEXCOORD) || (mask & Mask::IOM_FACECOLOR) )
|
||||
r = WriteMaterials(materialVec, filename,cb);//write material
|
||||
errCode = WriteMaterials(materialVec, filename,cb);//write material
|
||||
|
||||
if(r!= E_NOERROR)
|
||||
return r;
|
||||
if(errCode!= E_NOERROR)
|
||||
return errCode;
|
||||
return E_NOERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
returns index of the vertex
|
||||
*/
|
||||
inline static int GetIndexVertex(SaveMeshType &m, VertexType *p)
|
||||
{
|
||||
return p-&*(m.vert.begin());
|
||||
}
|
||||
|
||||
/*
|
||||
returns index of the texture coord
|
||||
*/
|
||||
|
@ -307,9 +307,6 @@ namespace io {
|
|||
typename std::map<CoordType,int>::iterator iter= mapNormToInt.find(norm);
|
||||
if(iter != mapNormToInt.end()) return (*iter).second;
|
||||
else return -1;
|
||||
// Old wrong version.
|
||||
// int index = mapNormToInt[m.vert[iv].N()];
|
||||
// if(index!=0){return index;}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -399,7 +396,7 @@ namespace io {
|
|||
return E_NOERROR;
|
||||
}
|
||||
|
||||
}; // end class
|
||||
}; // end class
|
||||
} // end Namespace tri
|
||||
} // end Namespace io
|
||||
} // end Namespace vcg
|
||||
|
|
Loading…
Reference in New Issue