From f44a3cfa7855f653ae763c2f65351ec9302ccd2f Mon Sep 17 00:00:00 2001 From: cignoni Date: Sun, 23 Aug 2009 07:16:49 +0000 Subject: [PATCH] Added support to additional per-face data in stl files. Code patch initially contributed by Tommy Odom (thanks!) --- wrap/io_trimesh/export_stl.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wrap/io_trimesh/export_stl.h b/wrap/io_trimesh/export_stl.h index 58381bb9..63084528 100644 --- a/wrap/io_trimesh/export_stl.h +++ b/wrap/io_trimesh/export_stl.h @@ -71,13 +71,16 @@ The stl format is quite simple and rather un-flexible. It just stores, in ascii template 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 *) { 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; FILE *fp; @@ -108,6 +111,9 @@ static int Save(SaveMeshType &m, const char * filename , bool binary =true, cons p.Import((*fi).V(k)->P()); fwrite(p.V(),3,sizeof(float),fp); } + if (faceAttributeCallback != NULL) { + attributes = (*faceAttributeCallback)(m, *fi); + } fwrite(&attributes,1,sizeof(short),fp); } }