From 7da7c0128e8cfa946fe78d3da2ccdbd91a99e331 Mon Sep 17 00:00:00 2001 From: cignoni Date: Sun, 29 Jun 2008 07:47:35 +0000 Subject: [PATCH] Added the WedgeTexRemoveNull function. Currently texture coords are kept for ALL the triangles of a mesh. The texture id is stored with each face. if a given face should not have tex coord it has the default -1 value for texture ID. This function will add an new fake texture, add that to the list of textures and change all the -1 id to that value. --- vcg/complex/trimesh/update/texture.h | 32 ++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/vcg/complex/trimesh/update/texture.h b/vcg/complex/trimesh/update/texture.h index 89654bae..b5b1d20f 100644 --- a/vcg/complex/trimesh/update/texture.h +++ b/vcg/complex/trimesh/update/texture.h @@ -29,7 +29,7 @@ $Log: position.h,v $ #ifndef __VCG_TRI_UPDATE_TEXTURE #define __VCG_TRI_UPDATE_TEXTURE -#include +//#include namespace vcg { namespace tri { @@ -56,7 +56,7 @@ typedef typename MeshType::FaceIterator FaceIterator; static void WedgeTexFromPlanar(ComputeMeshType &m, Plane3 &pl) { FaceIterator fi; - for(fi=m.face.begin();vi!=m.face.end();++vi) + for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD()) { @@ -68,6 +68,34 @@ static void WedgeTexFromCamera(ComputeMeshType &m, Plane3 &pl) } + +/// Currently texture coords are kept for ALL the triangles of a mesh. The texture id is stored with each face. +/// if a given face should not have tex coord it has the default -1 value for texture ID. +/// This function will add an new fake texture, add that to the list of textures and change all the -1 id to that value. +static void WedgeTexRemoveNull(ComputeMeshType &m, const std::string &texturename) +{ + bool found=false; + + FaceIterator fi; + // first loop lets check that there are -1 indexed textured face + for(fi=m.face.begin();fi!=m.face.end();++fi) + if(!(*fi).IsD()) if((*fi).WT(0).N()==-1) found = true; + + if(!found) return; + m.textures.push_back(texturename); + + int nullId=m.textures.size()-1; + + for(fi=m.face.begin();fi!=m.face.end();++fi) + if(!(*fi).IsD()) if((*fi).WT(0).N()==-1) + { + (*fi).WT(0).N() = nullId; + (*fi).WT(1).N() = nullId; + (*fi).WT(2).N() = nullId; + } + +} + }; // end class } // End namespace