diff --git a/apps/sample/trimesh_color/trimesh_color.cpp b/apps/sample/trimesh_color/trimesh_color.cpp index 621b8bcd..4f741bfc 100644 --- a/apps/sample/trimesh_color/trimesh_color.cpp +++ b/apps/sample/trimesh_color/trimesh_color.cpp @@ -52,13 +52,15 @@ int main(int argc, char **argv) { MyMesh m; + vcg::tri::io::ImporterPLY::Open(m,"../../meshes/torus_irregular.ply"); + vcg::tri::UpdateColor::PerVertexConstant(m, vcg::Color4b::LightGray); vcg::tri::UpdateColor::PerFaceConstant(m, vcg::Color4b::LightGray); - vcg::tri::UpdateColor::PerVertexPerlinNoise(m, vcg::Color4b::LightGray); - vcg::tri::UpdateColor::PerFaceFromVertex(m, vcg::Color4b::LightGray); + vcg::tri::UpdateColor::PerVertexPerlinNoise(m,vcg::Point3f(0.5,0.75,1.0)); + vcg::tri::UpdateColor::PerFaceFromVertex(m); - vcg::tri::io::ExporterPLY::Save(m,argv[2]); + vcg::tri::io::ExporterPLY::Save(m,"out.ply",vcg::tri::io::Mask::IOM_FACECOLOR+vcg::tri::io::Mask::IOM_VERTCOLOR); return 0; } diff --git a/vcg/complex/algorithms/update/color.h b/vcg/complex/algorithms/update/color.h index 54f3c7e3..e7b24b20 100644 --- a/vcg/complex/algorithms/update/color.h +++ b/vcg/complex/algorithms/update/color.h @@ -309,18 +309,23 @@ Note: The faux bit is used to color polygonal faces uniformly /*! \brief Perlin Noise. \return the number of changed vertexes (the selected ones) - Simple Perlin noise. To make things weirder each color band can be offset. + Simple Perlin noise. To make things weirder each color band can have its own offset and frequency. + Period is expressed in absolute terms. + So as period it is meaningful could be to use something in the range of 1/10 of the bbox diag. */ - static void PerVertexPerlinNoise(MeshType& m, Box3f bbox, Matrix44 tr, float freq, Point3i channelOffsets=Point3i(0,0,0)) + static void PerVertexPerlinNoise(MeshType& m, Point3f period, Point3f offset=Point3f(0,0,0)) { - Point3 p; + Point3 p[3]; for(VertexIterator vi = m.vert.begin(); vi!=m.vert.end(); ++vi) { if(!(*vi).IsD()){ - p = bbox.GlobalToLocal(tr * (*vi).P()); //actual vertex position scaled to bbox - (*vi).C() = Color4b( int(255*math::Perlin::Noise(channelOffsets[0]+p[0]*freq,channelOffsets[0]+p[1]*freq,channelOffsets[0]+p[2]*freq)), - int(255*math::Perlin::Noise(channelOffsets[1]+p[0]*freq,channelOffsets[1]+p[1]*freq,channelOffsets[1]+p[2]*freq)), - int(255*math::Perlin::Noise(channelOffsets[2]+p[0]*freq,channelOffsets[2]+p[1]*freq,channelOffsets[2]+p[2]*freq)), + // perlin noise is defined in 022 + p[0] = (vi->P()/period[0])+offset; + p[1] = (vi->P()/period[1])+offset; + p[2] = (vi->P()/period[2])+offset; + (*vi).C() = Color4b( int(127+128.0*math::Perlin::Noise(p[0][0],p[0][1],p[0][2])), + int(127+128.0*math::Perlin::Noise(p[1][0],p[1][1],p[1][2])), + int(127+128.0*math::Perlin::Noise(p[2][0],p[2][1],p[2][2])), 255 ); } }