Added support to additional per-face data in stl files. Code patch initially contributed by Tommy Odom (thanks!)

This commit is contained in:
Paolo Cignoni 2009-08-23 07:16:49 +00:00
parent ecd1de4d94
commit f44a3cfa78
1 changed files with 8 additions and 2 deletions

View File

@ -71,13 +71,16 @@ The stl format is quite simple and rather un-flexible. It just stores, in ascii
template <class SaveMeshType> template <class SaveMeshType>
class ExporterSTL class ExporterSTL
{ {
public: public:
typedef typename SaveMeshType::FaceType FaceType;
typedef unsigned short CallBackSTLFaceAttribute(const SaveMeshType &m, const FaceType &f);
static int Save(SaveMeshType &m, const char * filename, const int &/*mask*/, CallBackPos *) static int Save(SaveMeshType &m, const char * filename, const int &/*mask*/, CallBackPos *)
{ {
return Save(m,filename,true); return Save(m,filename,true);
} }
static int Save(SaveMeshType &m, const char * filename , bool binary =true, const char *objectname=0) static int Save(SaveMeshType &m, const char * filename , bool binary =true, const char *objectname=0, CallBackSTLFaceAttribute *faceAttributeCallback = NULL)
{ {
typedef typename SaveMeshType::FaceIterator FaceIterator; typedef typename SaveMeshType::FaceIterator FaceIterator;
FILE *fp; FILE *fp;
@ -108,6 +111,9 @@ static int Save(SaveMeshType &m, const char * filename , bool binary =true, cons
p.Import((*fi).V(k)->P()); p.Import((*fi).V(k)->P());
fwrite(p.V(),3,sizeof(float),fp); fwrite(p.V(),3,sizeof(float),fp);
} }
if (faceAttributeCallback != NULL) {
attributes = (*faceAttributeCallback)(m, *fi);
}
fwrite(&attributes,1,sizeof(short),fp); fwrite(&attributes,1,sizeof(short),fp);
} }
} }