Add File I/O
This commit is contained in:
parent
48669a758a
commit
b9eebf7d98
|
|
@ -20,15 +20,9 @@
|
||||||
* for more details. *
|
* for more details. *
|
||||||
* *
|
* *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef __VCGLIB_EXPORT_DXF
|
#ifndef __VCGLIB_EXPORT_DXF
|
||||||
#define __VCGLIB_EXPORT_DXF
|
#define __VCGLIB_EXPORT_DXF
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
namespace tri {
|
namespace tri {
|
||||||
namespace io {
|
namespace io {
|
||||||
|
|
@ -43,8 +37,9 @@ public:
|
||||||
*/
|
*/
|
||||||
static int Save(SaveMeshType &m, const char * filename)
|
static int Save(SaveMeshType &m, const char * filename)
|
||||||
{
|
{
|
||||||
|
|
||||||
FILE * o = fopen(filename,"w");
|
FILE * o = fopen(filename,"w");
|
||||||
if(o==NULL) return false;
|
if(o==NULL) return 1;
|
||||||
fprintf(o,"0\n");
|
fprintf(o,"0\n");
|
||||||
fprintf(o,"SECTION\n");
|
fprintf(o,"SECTION\n");
|
||||||
fprintf(o,"2\n");
|
fprintf(o,"2\n");
|
||||||
|
|
@ -83,7 +78,6 @@ public:
|
||||||
fprintf(o,"EOF\n");
|
fprintf(o,"EOF\n");
|
||||||
fclose(o);
|
fclose(o);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *ErrorMsg(int error)
|
static const char *ErrorMsg(int error)
|
||||||
|
|
@ -107,6 +101,4 @@ public:
|
||||||
} // end Namespace io
|
} // end Namespace io
|
||||||
} // end Namespace vcg
|
} // end Namespace vcg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -20,38 +20,78 @@
|
||||||
* for more details. *
|
* for more details. *
|
||||||
* *
|
* *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
/****************************************************************************
|
||||||
|
History
|
||||||
|
$Log: not supported by cvs2svn $
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __VCGLIB_EXPORT_SMF
|
||||||
|
#define __VCGLIB_EXPORT_SMF
|
||||||
|
|
||||||
/** Function to save to Smf format file.
|
#include <stdio.h>
|
||||||
@param filename Name of the new Smf file
|
|
||||||
*/
|
|
||||||
void Save_Smf(const char * filename)
|
|
||||||
{
|
|
||||||
FILE *fp;
|
|
||||||
fp = fopen(filename,"wb");
|
|
||||||
fprintf(fp,"#SMF \n" );
|
|
||||||
|
|
||||||
face_iterator fi;
|
namespace vcg {
|
||||||
vertex_iterator vi;
|
namespace tri {
|
||||||
map<vertex_pointer,int> index;
|
namespace io {
|
||||||
int ind;
|
|
||||||
|
|
||||||
for(ind=1,vi=vert.begin(); vi!=vert.end(); ++vi,++ind)
|
template <class SaveMeshType>
|
||||||
|
class ExporterSMF
|
||||||
{
|
{
|
||||||
fprintf(fp,"v " );
|
public:
|
||||||
fprintf(fp,"%f%s",(*vi).P()[0]," " );
|
typedef typename SaveMeshType::VertexPointer VertexPointer;
|
||||||
fprintf(fp,"%f%s",(*vi).P()[1]," " );
|
typedef typename SaveMeshType::ScalarType ScalarType;
|
||||||
fprintf(fp,"%f%s",(*vi).P()[2],"\n");
|
typedef typename SaveMeshType::VertexType VertexType;
|
||||||
index[&*vi] = ind;
|
typedef typename SaveMeshType::FaceType FaceType;
|
||||||
}
|
typedef typename SaveMeshType::VertexIterator VertexIterator;
|
||||||
|
typedef typename SaveMeshType::FaceIterator FaceIterator;
|
||||||
|
|
||||||
for (fi=face.begin(); fi!=face.end(); ++fi)
|
static int Save(SaveMeshType &m, const char * filename, const int &mask, CallBackPos *cb=0)
|
||||||
{
|
{
|
||||||
fprintf(fp,"%s","f ");
|
VertexIterator vi;
|
||||||
for (int j = 0; j < 3; j++)
|
FaceIterator fi;
|
||||||
fprintf(fp,"%i%s",index[(*fi).V(j)]," ");
|
FILE *fp;
|
||||||
fprintf(fp,"%s","\n");
|
fp = fopen(filename,"wb");
|
||||||
}
|
fprintf(fp,"#SMF \n" );
|
||||||
|
|
||||||
|
std::map<VertexPointer,int> index;
|
||||||
|
int ind;
|
||||||
|
|
||||||
|
for(ind=1,vi=m.vert.begin(); vi!=m.vert.end(); ++vi,++ind)
|
||||||
|
{
|
||||||
|
fprintf(fp,"v " );
|
||||||
|
fprintf(fp,"%f%s",(*vi).P()[0]," " );
|
||||||
|
fprintf(fp,"%f%s",(*vi).P()[1]," " );
|
||||||
|
fprintf(fp,"%f%s",(*vi).P()[2],"\n");
|
||||||
|
|
||||||
|
index[&*vi] = ind;
|
||||||
|
}
|
||||||
|
for (fi=m.face.begin(); fi!=m.face.end(); ++fi)
|
||||||
|
{
|
||||||
|
fprintf(fp,"%s","f ");
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
fprintf(fp,"%i%s",index[(*fi).V(j)]," ");
|
||||||
|
fprintf(fp,"%s","\n");
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static const char *ErrorMsg(int error)
|
||||||
|
{
|
||||||
|
static std::vector<std::string> smf_error_msg;
|
||||||
|
if(smf_error_msg.empty())
|
||||||
|
{
|
||||||
|
smf_error_msg.resize(2 );
|
||||||
|
smf_error_msg[0]="No errors";
|
||||||
|
smf_error_msg[1]="Can't open file";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(error>1 || error<0) return "Unknown error";
|
||||||
|
else return smf_error_msg[error].c_str();
|
||||||
|
}
|
||||||
|
}; // end class
|
||||||
|
} // end Namespace tri
|
||||||
|
} // end Namespace io
|
||||||
|
} // end Namespace vcg
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,305 +1,300 @@
|
||||||
/****************************************************************************
|
#ifndef __VCGLIB_EXPORT_WRL
|
||||||
* VCGLib o o *
|
#define __VCGLIB_EXPORT_WRL
|
||||||
* Visual and Computer Graphics Library o o *
|
|
||||||
* _ O _ *
|
|
||||||
* Copyright(C) 2004 \/)\/ *
|
|
||||||
* Visual Computing Lab /\/| *
|
|
||||||
* ISTI - Italian National Research Council | *
|
|
||||||
* \ *
|
|
||||||
* All rights reserved. *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
|
||||||
* for more details. *
|
|
||||||
* *
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <wrap/io_trimesh/io_mask.h>
|
||||||
|
|
||||||
|
#include "io_material.h"
|
||||||
|
|
||||||
/** Function to save in Inventor format file.
|
namespace vcg {
|
||||||
@param filename Name of the new inventor file
|
namespace tri {
|
||||||
*/
|
namespace io {
|
||||||
bool Save_VRML2(const char * filename, int savemask = SM_ALL )
|
|
||||||
{
|
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
fp = fopen(filename,"wb");
|
template <class SaveMeshType>
|
||||||
if(fp==0)
|
class ExporterWRL
|
||||||
return false;
|
|
||||||
|
|
||||||
// Header
|
|
||||||
fprintf(fp,
|
|
||||||
"#VRML V2.0 utf8\n"
|
|
||||||
"\n"
|
|
||||||
"# Generated by VCGLIB, (C)Copyright 1999-2001 VCG, IEI-CNR\n"
|
|
||||||
"\n"
|
|
||||||
"NavigationInfo {\n"
|
|
||||||
" type [ \"EXAMINE\", \"ANY\" ]\n"
|
|
||||||
"}\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Trans principale
|
|
||||||
double ss = 8.0/bbox.Diag();
|
|
||||||
|
|
||||||
fprintf(fp,
|
|
||||||
"Transform {\n"
|
|
||||||
" scale %g %g %g\n"
|
|
||||||
" translation %g %g %g\n"
|
|
||||||
" children\n"
|
|
||||||
" [\n"
|
|
||||||
,ss
|
|
||||||
,ss
|
|
||||||
,ss
|
|
||||||
, -bbox.Center()[0]*ss
|
|
||||||
, -bbox.Center()[1]*ss
|
|
||||||
,-3-bbox.Center()[2]*ss
|
|
||||||
);
|
|
||||||
|
|
||||||
// Start Shape
|
|
||||||
fprintf(fp,
|
|
||||||
" Shape\n"
|
|
||||||
" {\n"
|
|
||||||
" geometry IndexedFaceSet\n"
|
|
||||||
" {\n"
|
|
||||||
" creaseAngle .5\n"
|
|
||||||
" solid FALSE\n"
|
|
||||||
" coord Coordinate\n"
|
|
||||||
" {\n"
|
|
||||||
" point\n"
|
|
||||||
" ["
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
face_iterator fi;
|
|
||||||
vertex_iterator vi;
|
|
||||||
map<vertex_pointer,int> index;
|
|
||||||
int ind;
|
|
||||||
// Vertici
|
|
||||||
for(ind=0,vi=vert.begin(); vi!=vert.end(); ++vi,++ind)
|
|
||||||
{
|
|
||||||
if(ind%4==0)
|
|
||||||
fprintf(fp,"\n ");
|
|
||||||
|
|
||||||
fprintf(fp,"%g %g %g, "
|
|
||||||
,(*vi).P()[0]
|
|
||||||
,(*vi).P()[1]
|
|
||||||
,(*vi).P()[2]
|
|
||||||
);
|
|
||||||
index[&*vi] = ind;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(fp,
|
|
||||||
"\n"
|
|
||||||
" ]\n"
|
|
||||||
" }\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
if( ( savemask & SM_VERTCOLOR ) && (vertex_type::OBJ_TYPE & vertex_type::OBJ_TYPE_C) )
|
|
||||||
{
|
|
||||||
fprintf(fp,
|
|
||||||
" color Color\n"
|
|
||||||
" {\n"
|
|
||||||
" color\n"
|
|
||||||
" ["
|
|
||||||
);
|
|
||||||
|
|
||||||
for(ind=0,vi=vert.begin();vi!=vert.end();++vi,++ind)
|
|
||||||
{
|
|
||||||
|
|
||||||
float r = float(vi->C()[0])/255;
|
|
||||||
float g = float(vi->C()[1])/255;
|
|
||||||
float b = float(vi->C()[2])/255;
|
|
||||||
|
|
||||||
if(ind%4==0)
|
|
||||||
fprintf(fp,"\n ");
|
|
||||||
|
|
||||||
fprintf(fp,
|
|
||||||
"%g %g %g,"
|
|
||||||
,r,g,b
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(fp,
|
|
||||||
"\n"
|
|
||||||
" ]\n"
|
|
||||||
" }\n"
|
|
||||||
" colorIndex\n"
|
|
||||||
" ["
|
|
||||||
);
|
|
||||||
|
|
||||||
for(ind=0,fi=face.begin(); fi!=face.end(); ++fi,++ind)
|
|
||||||
{
|
|
||||||
if(ind%4==0)
|
|
||||||
fprintf(fp,"\n ");
|
|
||||||
for (int j = 0; j < 3; j++)
|
|
||||||
fprintf(fp,"%i,",index[(*fi).V(j)]);
|
|
||||||
fprintf(fp,"-1,");
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(fp,
|
|
||||||
"\n"
|
|
||||||
" ]\n"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else if( ( savemask & SM_WEDGCOLOR ) && (face_type::OBJ_TYPE & face_type::OBJ_TYPE_WC) )
|
|
||||||
{
|
|
||||||
fprintf(fp,
|
|
||||||
" color Color\n"
|
|
||||||
" {\n"
|
|
||||||
" color\n"
|
|
||||||
" ["
|
|
||||||
);
|
|
||||||
|
|
||||||
for(ind=0,fi=face.begin();fi!=face.end();++fi,++ind)
|
|
||||||
{
|
|
||||||
for(int z=0;z<3;++z)
|
|
||||||
{
|
{
|
||||||
float r = float(fi->WC(z)[0])/255;
|
public:
|
||||||
float g = float(fi->WC(z)[1])/255;
|
typedef typename SaveMeshType::VertexPointer VertexPointer;
|
||||||
float b = float(fi->WC(z)[2])/255;
|
typedef typename SaveMeshType::ScalarType ScalarType;
|
||||||
|
typedef typename SaveMeshType::VertexType VertexType;
|
||||||
|
typedef typename SaveMeshType::FaceType FaceType;
|
||||||
|
typedef typename SaveMeshType::VertexIterator VertexIterator;
|
||||||
|
typedef typename SaveMeshType::FaceIterator FaceIterator;
|
||||||
|
|
||||||
if(ind%4==0)
|
static int Save(SaveMeshType &m, const char * filename, const int &mask, CallBackPos *cb=0)
|
||||||
fprintf(fp,"\n ");
|
{
|
||||||
|
FILE *fp;
|
||||||
|
fp = fopen(filename,"wb");
|
||||||
|
if(fp==NULL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
fprintf(fp,
|
// Header
|
||||||
"%g %g %g,"
|
fprintf(fp,
|
||||||
,r,g,b
|
"#VRML V2.0 utf8\n"
|
||||||
);
|
"\n"
|
||||||
}
|
"# Generated by VCGLIB, (C)Copyright 1999-2001 VCG, IEI-CNR\n"
|
||||||
}
|
"\n"
|
||||||
|
"NavigationInfo {\n"
|
||||||
|
" type [ \"EXAMINE\", \"ANY\" ]\n"
|
||||||
|
"}\n"
|
||||||
|
);
|
||||||
|
|
||||||
fprintf(fp,
|
// Tranche principale
|
||||||
"\n"
|
double ss = 8.0/m.bbox.Diag();
|
||||||
" ]\n"
|
m.bbox.Diag();
|
||||||
" }\n"
|
|
||||||
" colorIndex\n"
|
|
||||||
" ["
|
|
||||||
);
|
|
||||||
|
|
||||||
int nn = 0;
|
fprintf(fp,
|
||||||
for(ind=0,fi=face.begin(); fi!=face.end(); ++fi,++ind)
|
"Transform {\n"
|
||||||
{
|
" scale %g %g %g\n"
|
||||||
if(ind%4==0)
|
" translation %g %g %g\n"
|
||||||
fprintf(fp,"\n ");
|
" children\n"
|
||||||
for (int j = 0; j < 3; j++)
|
" [\n"
|
||||||
{
|
,ss
|
||||||
fprintf(fp,"%i,",nn);
|
,ss
|
||||||
++nn;
|
,ss
|
||||||
}
|
, -m.bbox.Center()[0]*ss
|
||||||
fprintf(fp,"-1,");
|
, -m.bbox.Center()[1]*ss
|
||||||
}
|
,-3-m.bbox.Center()[2]*ss
|
||||||
|
);
|
||||||
|
|
||||||
fprintf(fp,
|
// Start Shape
|
||||||
"\n"
|
fprintf(fp,
|
||||||
" ]\n"
|
" Shape\n"
|
||||||
);
|
" {\n"
|
||||||
|
" geometry IndexedFaceSet\n"
|
||||||
|
" {\n"
|
||||||
|
" creaseAngle .5\n"
|
||||||
|
" solid FALSE\n"
|
||||||
|
" coord Coordinate\n"
|
||||||
|
" {\n"
|
||||||
|
" point\n"
|
||||||
|
" ["
|
||||||
|
);
|
||||||
|
FaceIterator fi;
|
||||||
|
VertexIterator vi;
|
||||||
|
std::map<VertexPointer,int> index;
|
||||||
|
int ind;
|
||||||
|
|
||||||
|
// Vertici
|
||||||
|
for(ind=0,vi=m.vert.begin(); vi!=m.vert.end(); ++vi, ++ind)
|
||||||
|
{
|
||||||
|
if(ind%4==0)
|
||||||
|
fprintf(fp,
|
||||||
|
"\n "
|
||||||
|
);
|
||||||
|
fprintf(fp,
|
||||||
|
"%g %g %g, "
|
||||||
|
,(*vi).P()[0]
|
||||||
|
,(*vi).P()[1]
|
||||||
|
,(*vi).P()[2]
|
||||||
|
);
|
||||||
|
index[&*vi] = ind;
|
||||||
|
|
||||||
|
}
|
||||||
|
fprintf(fp,"\n"
|
||||||
|
" ]\n"
|
||||||
|
" }\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if( m.HasPerVertexColor() && (mask & vcg::tri::io::Mask::IOM_VERTCOLOR))
|
||||||
|
{
|
||||||
|
fprintf(fp,
|
||||||
|
" color Color\n"
|
||||||
|
" {\n"
|
||||||
|
" color\n"
|
||||||
|
" ["
|
||||||
|
);
|
||||||
|
for(ind=0,vi=m.vert.begin();vi!=m.vert.end();++vi,++ind)
|
||||||
|
{
|
||||||
|
float r = float(vi->C()[0])/255;
|
||||||
|
float g = float(vi->C()[1])/255;
|
||||||
|
float b = float(vi->C()[2])/255;
|
||||||
|
|
||||||
|
if(ind%4==0)
|
||||||
|
fprintf(fp,"\n ");
|
||||||
|
fprintf(fp,"%g %g %g,",r,g,b);
|
||||||
|
}
|
||||||
|
fprintf(fp,
|
||||||
|
"\n"
|
||||||
|
" ]\n"
|
||||||
|
" }\n"
|
||||||
|
" colorIndex\n"
|
||||||
|
" ["
|
||||||
|
);
|
||||||
|
|
||||||
|
for(ind=0,fi=m.face.begin(); fi!=m.face.end(); ++fi,++ind)
|
||||||
|
{
|
||||||
|
if(ind%4==0)
|
||||||
|
fprintf(fp,"\n ");
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
fprintf(fp,"%i,",index[(*fi).V(j)]);
|
||||||
|
fprintf(fp,"-1,");
|
||||||
|
}
|
||||||
|
fprintf(fp,
|
||||||
|
"\n"
|
||||||
|
" ]\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if( m.HasPerWedgeColor() && (mask & vcg::tri::io::Mask::IOM_WEDGCOLOR ))
|
||||||
|
{
|
||||||
|
fprintf(fp,
|
||||||
|
" color Color\n"
|
||||||
|
" {\n"
|
||||||
|
" color\n"
|
||||||
|
" [" );
|
||||||
|
for(ind=0,fi=m.face.begin();fi!=m.face.end();++fi,++ind)
|
||||||
|
{
|
||||||
|
for(int z=0;z<3;++z)
|
||||||
|
{
|
||||||
|
float r = float(fi->WC(z)[0])/255;
|
||||||
|
float g = float(fi->WC(z)[1])/255;
|
||||||
|
float b = float(fi->WC(z)[2])/255;
|
||||||
|
if(ind%4==0)
|
||||||
|
fprintf(fp,"\n ");
|
||||||
|
fprintf(fp,"%g %g %g,",r,g,b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf(fp,
|
||||||
|
"\n"
|
||||||
|
" ]\n"
|
||||||
|
" }\n"
|
||||||
|
" colorIndex\n"
|
||||||
|
" [" );
|
||||||
|
int nn = 0;
|
||||||
|
for(ind=0,fi=m.face.begin(); fi!=m.face.end(); ++fi,++ind)
|
||||||
|
{
|
||||||
|
if(ind%4==0)
|
||||||
|
fprintf(fp,"\n ");
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
fprintf(fp,"%i,",nn);
|
||||||
|
++nn;
|
||||||
|
}
|
||||||
|
fprintf(fp,"-1,");
|
||||||
|
}
|
||||||
|
fprintf(fp,
|
||||||
|
"\n"
|
||||||
|
" ]\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if (HasPerWedgeTexture(m) &&(mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD))
|
||||||
|
{
|
||||||
|
fprintf(fp,
|
||||||
|
"\n"
|
||||||
|
" texCoord TextureCoordinate\n"
|
||||||
|
" {\n"
|
||||||
|
" point\n"
|
||||||
|
" [\n"
|
||||||
|
);
|
||||||
|
for(ind=0,fi=m.face.begin(); fi!=m.face.end(); ++fi,++ind)
|
||||||
|
{
|
||||||
|
if(ind%4==0)
|
||||||
|
fprintf(fp,"\n ");
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
fprintf(fp,"%g %g, ",fi->WT(j).u(),fi->WT(j).v());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf(fp,
|
||||||
|
"\n"
|
||||||
|
" ]\n"
|
||||||
|
" }\n"
|
||||||
|
" texCoordIndex\n"
|
||||||
|
" [\n"
|
||||||
|
);
|
||||||
|
int nn = 0;
|
||||||
|
for(ind=0,fi=m.face.begin(); fi!=m.face.end(); ++fi,++ind)
|
||||||
|
{
|
||||||
|
if(ind%4==0)
|
||||||
|
fprintf(fp,"\n ");
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
fprintf(fp,"%d,",nn);
|
||||||
|
++nn;
|
||||||
|
}
|
||||||
|
fprintf(fp,"-1,");
|
||||||
|
}
|
||||||
|
fprintf(fp,
|
||||||
|
"\n"
|
||||||
|
" ]\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
fprintf(fp,
|
||||||
|
" coordIndex\n"
|
||||||
|
" ["
|
||||||
|
);
|
||||||
|
// Facce
|
||||||
|
for(ind=0,fi=m.face.begin(); fi!=m.face.end(); ++fi,++ind)
|
||||||
|
{
|
||||||
|
if(ind%6==0)
|
||||||
|
{
|
||||||
|
fprintf(fp,"\n ");
|
||||||
|
}
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
fprintf(fp,"%i,",index[(*fi).V(j)]);
|
||||||
|
fprintf(fp,"-1,");
|
||||||
|
}
|
||||||
|
fprintf(fp,
|
||||||
|
"\n"
|
||||||
|
" ]\n"
|
||||||
|
" }\n"
|
||||||
|
" appearance Appearance\n"
|
||||||
|
" {\n"
|
||||||
|
" material Material\n"
|
||||||
|
" {\n"
|
||||||
|
" ambientIntensity 0.2\n"
|
||||||
|
" diffuseColor 0.9 0.9 0.9\n"
|
||||||
|
" specularColor .1 .1 .1\n"
|
||||||
|
" shininess .5\n"
|
||||||
|
" }\n"
|
||||||
|
);
|
||||||
|
if(m.textures.size())
|
||||||
|
{
|
||||||
|
fprintf(fp,
|
||||||
|
" texture ImageTexture { url \" %s \" }\n"
|
||||||
|
,m.textures[0].c_str()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
fprintf(fp,
|
||||||
|
" }\n"
|
||||||
|
" }\n"
|
||||||
|
" ]\n"
|
||||||
|
"}\n"
|
||||||
|
);
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
else if( ( savemask & SM_WEDGTEXCOORD ) && (face_type::OBJ_TYPE & face_type::OBJ_TYPE_WT) )
|
static int GetExportMaskCapability()
|
||||||
{
|
{
|
||||||
fprintf(fp,
|
int capability = 0;
|
||||||
"\n"
|
|
||||||
" texCoord TextureCoordinate\n"
|
|
||||||
" {\n"
|
|
||||||
" point\n"
|
|
||||||
" [\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
for(ind=0,fi=face.begin(); fi!=face.end(); ++fi,++ind)
|
//vert
|
||||||
{
|
capability |= MeshModel::IOM_VERTCOLOR;
|
||||||
if(ind%4==0)
|
|
||||||
fprintf(fp,"\n ");
|
|
||||||
for (int j = 0; j < 3; j++)
|
|
||||||
{
|
|
||||||
fprintf(fp,"%g %g, "
|
|
||||||
,fi->WT(j).u()
|
|
||||||
,fi->WT(j).v()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(fp,
|
//wedg
|
||||||
"\n"
|
capability |= MeshModel::IOM_WEDGTEXCOORD;
|
||||||
" ]\n"
|
capability |= MeshModel::IOM_WEDGCOLOR;
|
||||||
" }\n"
|
|
||||||
" texCoordIndex\n"
|
|
||||||
" [\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
int nn = 0;
|
return capability;
|
||||||
for(ind=0,fi=face.begin(); fi!=face.end(); ++fi,++ind)
|
|
||||||
{
|
|
||||||
if(ind%4==0)
|
|
||||||
fprintf(fp,"\n ");
|
|
||||||
for (int j = 0; j < 3; j++)
|
|
||||||
{
|
|
||||||
fprintf(fp,"%d,",nn);
|
|
||||||
++nn;
|
|
||||||
}
|
|
||||||
fprintf(fp,"-1,");
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(fp,
|
|
||||||
"\n"
|
|
||||||
" ]\n"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *ErrorMsg(int error)
|
||||||
fprintf(fp,
|
|
||||||
" coordIndex\n"
|
|
||||||
" ["
|
|
||||||
);
|
|
||||||
// Facce
|
|
||||||
for(ind=0,fi=face.begin(); fi!=face.end(); ++fi,++ind)
|
|
||||||
{
|
{
|
||||||
if(ind%6==0)
|
static std::vector<std::string> wrl_error_msg;
|
||||||
|
if(wrl_error_msg.empty())
|
||||||
{
|
{
|
||||||
fprintf(fp,"\n ");
|
wrl_error_msg.resize(2 );
|
||||||
|
wrl_error_msg[0]="No errors";
|
||||||
|
wrl_error_msg[1]="Can't open file";
|
||||||
|
}
|
||||||
|
if(error>1 || error<0) return "Unknown error";
|
||||||
|
else return wrl_error_msg[error].c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < 3; j++)
|
}; // end class
|
||||||
fprintf(fp,"%i,",index[(*fi).V(j)]);
|
} // end Namespace io
|
||||||
fprintf(fp,"-1,");
|
} // end Namespace tri
|
||||||
}
|
} // end Namespace vcg
|
||||||
|
|
||||||
fprintf(fp,
|
#endif
|
||||||
"\n"
|
|
||||||
" ]\n"
|
|
||||||
" }\n"
|
|
||||||
" appearance Appearance\n"
|
|
||||||
" {\n"
|
|
||||||
" material Material\n"
|
|
||||||
" {\n"
|
|
||||||
" ambientIntensity 0.2\n"
|
|
||||||
" diffuseColor 0.9 0.9 0.9\n"
|
|
||||||
" specularColor .1 .1 .1\n"
|
|
||||||
" shininess .5\n"
|
|
||||||
" }\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
if(textures.size())
|
|
||||||
{
|
|
||||||
fprintf(fp,
|
|
||||||
" texture ImageTexture { url \"%s\" }\n"
|
|
||||||
,textures[0]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(fp,
|
|
||||||
" }\n"
|
|
||||||
" }\n"
|
|
||||||
" ]\n"
|
|
||||||
"}\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,24 +1,129 @@
|
||||||
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
|
/****************************************************************************
|
||||||
* Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
* VCGLib o o *
|
||||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
|
* Visual and Computer Graphics Library o o *
|
||||||
|
* _ O _ *
|
||||||
|
* Copyright(C) 2004 \/)\/ *
|
||||||
|
* Visual Computing Lab /\/| *
|
||||||
|
* ISTI - Italian National Research Council | *
|
||||||
|
* \ *
|
||||||
|
* All rights reserved. *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||||
|
* for more details. *
|
||||||
|
* *
|
||||||
|
****************************************************************************/
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
|
||||||
****************************************************************************/
#ifndef __VCGLIB_IMPORTERSMF
|
****************************************************************************/
|
||||||
#define __VCGLIB_IMPORTERSMF
#include <map>
|
|
||||||
|
#ifndef __VCGLIB_IMPORTER_SMF
|
||||||
|
#define __VCGLIB_IMPORTER_SMF
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <vcg/space/point3.h>
|
||||||
|
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
namespace tri {
|
namespace tri {
|
||||||
namespace io {
|
namespace io {
|
||||||
|
template<class OpenMeshType>
|
||||||
|
class ImporterSMF
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename OpenMeshType::VertexPointer VertexPointer;
|
||||||
|
typedef typename OpenMeshType::ScalarType ScalarType;
|
||||||
|
typedef typename OpenMeshType::VertexType VertexType;
|
||||||
|
typedef typename OpenMeshType::FaceType FaceType;
|
||||||
|
typedef typename OpenMeshType::VertexIterator VertexIterator;
|
||||||
|
typedef typename OpenMeshType::FaceIterator FaceIterator;
|
||||||
|
|
||||||
|
// if it is binary there are 80 char of comment, the number fn of faces and then exactly fn*4*3 bytes.
|
||||||
|
enum {SMF_LABEL_SIZE=80};
|
||||||
|
|
||||||
|
class SMFFacet
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
vcg::Point3f n;
|
||||||
|
vcg::Point3f v[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
enum SMFError {
|
||||||
|
E_NOERROR, // 0
|
||||||
|
// Errori di open
|
||||||
|
E_CANTOPEN, // 1
|
||||||
|
E_UNESPECTEDEOF // 2
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *ErrorMsg(int error)
|
||||||
|
{
|
||||||
|
static const char * smf_error_msg[] =
|
||||||
|
{
|
||||||
|
"No errors",
|
||||||
|
"Can't open file",
|
||||||
|
"Premature End of file",
|
||||||
|
};
|
||||||
|
if(error>2 || error<0) return "Unknown error";
|
||||||
|
else return smf_error_msg[error];
|
||||||
|
};
|
||||||
|
static int Open(OpenMeshType &m, const char * filename )
|
||||||
|
{
|
||||||
|
VertexType v;
|
||||||
|
FaceType f;
|
||||||
|
FILE *fp;
|
||||||
|
float x,y,z;
|
||||||
|
bool one = true;
|
||||||
|
std::map<int,VertexPointer> mv;
|
||||||
|
fp = fopen(filename,"r");
|
||||||
|
if(!fp) return -1;
|
||||||
|
char buf[1024];
|
||||||
|
while( fgets(buf,1024,fp) )
|
||||||
|
{
|
||||||
|
char *vf, *comm_pt;
|
||||||
|
if((comm_pt = strstr(buf,"#")) != NULL)
|
||||||
|
*comm_pt = '\0';
|
||||||
|
if( (vf = strstr(buf,"v")) != NULL )
|
||||||
|
{
|
||||||
|
sscanf(vf+1,"%f %f %f", &x, &y, &z);
|
||||||
|
v.P()[0] = x;
|
||||||
|
v.P()[1] = y;
|
||||||
|
v.P()[2] = z;
|
||||||
|
m.vert.push_back(v);
|
||||||
|
}
|
||||||
|
else if( (vf = strstr(buf,"f")) != NULL)
|
||||||
|
{
|
||||||
|
if(one)
|
||||||
|
{
|
||||||
|
VertexIterator vi;
|
||||||
|
int ind;
|
||||||
|
for(ind=1,vi=m.vert.begin(); vi!=m.vert.end(); ++vi,++ind)
|
||||||
|
mv[ind]=&*vi;
|
||||||
|
one = false;
|
||||||
|
}
|
||||||
|
int v1,v2,v3;
|
||||||
|
sscanf(vf+1,"%d %d %d", &v1, &v2, &v3);
|
||||||
|
f.V(0) = mv[v1];
|
||||||
|
f.V(1) = mv[v2];
|
||||||
|
f.V(2) = mv[v3];
|
||||||
|
m.face.push_back(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.vn = m.vert.size();
|
||||||
|
m.fn = m.face.size();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}// end of io
|
||||||
|
}// end of tri
|
||||||
|
}// end of vcg
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
template <class MESHTYPE>
|
|
||||||
int Load_Smf( MESHTYPE & m, const char * filename )
{
typedef typename MESHTYPE::VertexPointer VertexPointer;
|
|
||||||
typedef typename MESHTYPE::VertexType VertexType;
|
|
||||||
typedef typename MESHTYPE::FaceType FaceType;
|
|
||||||
typedef typename MESHTYPE::VertexIterator VertexIterator;
|
|
||||||
typedef typename MESHTYPE::FaceIterator FaceIterator;
|
|
||||||
char buf[1024];
|
|
||||||
FILE *fp;
float x,y,z;
bool one = true;
std::map<int,VertexPointer> mv;
fp = fopen(filename,"r");
if(!fp) return -1;
VertexType v;
v.Supervisor_Flags() = 0;
FaceType f;
f.Supervisor_Flags() = 0;
|
|
||||||
while( fgets(buf,1024,fp) )
{
char *vf, *comm_pt;
if((comm_pt = strstr(buf,"#")) != NULL)
*comm_pt = '\0';
if( (vf = strstr(buf,"v")) != NULL )
{
sscanf(vf+1,"%f %f %f", &x, &y, &z);
v.P()[0] = x;
v.P()[1] = y;
v.P()[2] = z;
m.vert.push_back(v);
}
else if( (vf = strstr(buf,"f")) != NULL)
{
if(one)
{
VertexIterator vi;
int ind;
for(ind=1,vi=m.vert.begin(); vi!=m.vert.end(); ++vi,++ind)
mv[ind]=&*vi;
one = false;
}
int v1,v2,v3;
sscanf(vf+1,"%d %d %d", &v1, &v2, &v3);
f.V(0) = mv[v1];
f.V(1) = mv[v2];
f.V(2) = mv[v3];
m.face.push_back(f);
}
}
m.vn = m.vert.size();
m.fn = m.face.size();
return 0;
}
};// end of io
};// end of tri
};// end of vcg
#endif
|
|
||||||
Loading…
Reference in New Issue