From 7ef26b5a25930b70b2499d60a458b90066bc5f1d Mon Sep 17 00:00:00 2001 From: cignoni Date: Tue, 27 Oct 2009 23:55:44 +0000 Subject: [PATCH] Improved support for loading meshes with per vertex texture coords (as saved by blender) --- wrap/io_trimesh/import_ply.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/wrap/io_trimesh/import_ply.h b/wrap/io_trimesh/import_ply.h index 395f0842..8103d14f 100644 --- a/wrap/io_trimesh/import_ply.h +++ b/wrap/io_trimesh/import_ply.h @@ -276,7 +276,7 @@ struct LoadPly_Camera float k4; }; -#define _VERTDESC_LAST_ 20 +#define _VERTDESC_LAST_ 22 static const PropDescriptor &VertDesc(int i) { static const PropDescriptor pv[_VERTDESC_LAST_]={ @@ -300,6 +300,8 @@ static const PropDescriptor &VertDesc(int i) /*17*/ {"vertex", "texture_v", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_VertAux,v),0,0,0,0,0 ,0}, /*18*/ {"vertex", "texture_w", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_VertAux,w),0,0,0,0,0 ,0}, /*19*/ {"vertex", "intensity", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_VertAux,intensity),0,0,0,0,0 ,0}, +/*20*/ {"vertex", "s", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_VertAux,u),0,0,0,0,0 ,0}, +/*21*/ {"vertex", "t", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_VertAux,v),0,0,0,0,0 ,0}, }; return pv[i]; @@ -573,7 +575,17 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi ) } } - + if( tri::HasPerVertexTexCoord(m) ) + { + if(( pf.AddToRead(VertDesc(20))!=-1 )&& (pf.AddToRead(VertDesc(21))!=-1)) + { + pi.mask |= Mask::IOM_VERTTEXCOORD; + } + if(( pf.AddToRead(VertDesc(16))!=-1 )&& (pf.AddToRead(VertDesc(17))!=-1)) + { + pi.mask |= Mask::IOM_VERTTEXCOORD; + } + } if(tri::HasPerVertexRadius(m)) { if( pf.AddToRead(VertDesc(15))!=-1 ) @@ -878,7 +890,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi ) int curpos=int(fi-m.face.begin()); Allocator::AddFaces(m,fa.size-3); fi=m.face.begin()+curpos; - + pi.mask |= Mask::IOM_BITPOLYGONAL; } for(int qq=0;qq