From 70ea5c205799bb6f0a292840f7be985735f065b5 Mon Sep 17 00:00:00 2001 From: ganovelli Date: Thu, 18 Dec 2008 18:02:44 +0000 Subject: [PATCH] added support for loading directly polygon meshes. If you are not using polygon mesh this commit does not change anything. --- wrap/io_trimesh/import_obj.h | 85 ++++++++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 9 deletions(-) diff --git a/wrap/io_trimesh/import_obj.h b/wrap/io_trimesh/import_obj.h index c12119e3..e6905780 100644 --- a/wrap/io_trimesh/import_obj.h +++ b/wrap/io_trimesh/import_obj.h @@ -158,12 +158,13 @@ public: //}; struct ObjIndexedFace { - int v[3]; - int n[3]; - int t[3]; - int tInd; - bool edge[3]; - Color4b c; + void set(const int & num){v.resize(num);n.resize(num); t.resize(num);} + std::vector v; + std::vector n; + std::vector t; + int tInd; + bool edge[3];// useless if the face is a polygon, no need to have variable length array + Color4b c; }; struct ObjTexCoord @@ -378,7 +379,69 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi) { if (numTokens < 4) return E_LESS_THAN_3VERTINFACE; int vertexesPerFace = static_cast(tokens.size()-1); + + if( (vertexesPerFace>3) && OpenMeshType::FaceType::HasPolyInfo() ){ + //_BEGIN___ if you are loading a GENERIC POLYGON mesh + + ff.set(vertexesPerFace); + + std::string vertex; + std::string texcoord; + std::string normal; + for(int i=0;i tmp = ff.v; + std::sort(tmp.begin(),tmp.end()); + std::unique(tmp.begin(),tmp.end()); + if(tmp.size() != ff.v.size()) + result = E_VERTICES_WITH_SAME_IDX_IN_FACE; + + for(int i=0;i