diff --git a/vcg/complex/trimesh/update/normal.h b/vcg/complex/trimesh/update/normal.h index a85d0245..745abd72 100644 --- a/vcg/complex/trimesh/update/normal.h +++ b/vcg/complex/trimesh/update/normal.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.14 2007/07/12 23:11:35 cignoni +added the missing PerVertexNormalizedPerFaceNormalized + Revision 1.13 2007/01/10 17:25:14 matteodelle *** empty log message *** @@ -230,6 +233,48 @@ static void PerVertexNormalized(ComputeMeshType &m) (*vi).N().Normalize(); } +/// multiply the vertex normals by the matrix passed. By default, the scale component is removed +static void PerVertexMatrix(ComputeMeshType &m, const Matrix44 &mat, bool remove_scaling= true){ + float pos_33; + float scale; + + Matrix33 mat33(mat,3); + + if( !m.HasPerVertexNormal()) return; + + if(remove_scaling){ + scale = pow(mat33.Determinant(),1/(float)3.0); + mat33[0][0]/=scale; + mat33[1][1]/=scale; + mat33[2][2]/=scale; + } + + for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) + if( !(*vi).IsD() && (*vi).IsRW() ) + (*vi).N() = mat33*(*vi).N(); +} + +/// multiply the face normals by the matrix passed. By default, the scale component is removed +static void PerFaceMatrix(ComputeMeshType &m, const Matrix44 &mat, bool remove_scaling= true){ + float pos_33; + float scale; + + Matrix33 mat33(mat,3); + + if( !m.HasPerFaceNormal()) return; + + if(remove_scaling){ + scale = pow(mat33.Determinant(),1/(float)3.0); + mat33[0][0]/=scale; + mat33[1][1]/=scale; + mat33[2][2]/=scale; + } + + for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) + if( !(*fi).IsD() && (*fi).IsRW() ) + (*fi).N() = mat33* (*fi).N(); +} + }; // end class } // End namespace diff --git a/vcg/complex/trimesh/update/position.h b/vcg/complex/trimesh/update/position.h index 2c863d7d..aa4d6bb7 100644 --- a/vcg/complex/trimesh/update/position.h +++ b/vcg/complex/trimesh/update/position.h @@ -24,11 +24,16 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2005/07/06 08:02:27 cignoni +Initial commit + ****************************************************************************/ #ifndef __VCG_TRI_UPDATE_POSITION #define __VCG_TRI_UPDATE_POSITION +#include "normal.h" + namespace vcg { namespace tri { @@ -51,11 +56,20 @@ typedef typename MeshType::FacePointer FacePointer; typedef typename MeshType::FaceIterator FaceIterator; /// Multiply -static void Matrix(ComputeMeshType &m, const Matrix44 &M) +static void Matrix(ComputeMeshType &m, const Matrix44 &M, bool update_also_normals = true) { VertexIterator vi; for(vi=m.vert.begin();vi!=m.vert.end();++vi) if(!(*vi).IsD()) (*vi).P()=M*(*vi).cP(); + + if(update_also_normals){ + if(m.HasPerVertexNormal()){ + UpdateNormals::PerVertexMatrix(m,M); + } + if(m.HasPerFaceNormal()){ + UpdateNormals::PerFaceMatrix(m,M); + } + } }