Improved comments and interface of perlin noise color
This commit is contained in:
parent
1918c53a09
commit
75122cd193
|
@ -52,13 +52,15 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
MyMesh m;
|
MyMesh m;
|
||||||
|
|
||||||
|
vcg::tri::io::ImporterPLY<MyMesh>::Open(m,"../../meshes/torus_irregular.ply");
|
||||||
|
|
||||||
vcg::tri::UpdateColor<MyMesh>::PerVertexConstant(m, vcg::Color4b::LightGray);
|
vcg::tri::UpdateColor<MyMesh>::PerVertexConstant(m, vcg::Color4b::LightGray);
|
||||||
vcg::tri::UpdateColor<MyMesh>::PerFaceConstant(m, vcg::Color4b::LightGray);
|
vcg::tri::UpdateColor<MyMesh>::PerFaceConstant(m, vcg::Color4b::LightGray);
|
||||||
|
|
||||||
vcg::tri::UpdateColor<MyMesh>::PerVertexPerlinNoise(m, vcg::Color4b::LightGray);
|
vcg::tri::UpdateColor<MyMesh>::PerVertexPerlinNoise(m,vcg::Point3f(0.5,0.75,1.0));
|
||||||
vcg::tri::UpdateColor<MyMesh>::PerFaceFromVertex(m, vcg::Color4b::LightGray);
|
vcg::tri::UpdateColor<MyMesh>::PerFaceFromVertex(m);
|
||||||
|
|
||||||
|
|
||||||
vcg::tri::io::ExporterPLY<MyMesh>::Save(m,argv[2]);
|
vcg::tri::io::ExporterPLY<MyMesh>::Save(m,"out.ply",vcg::tri::io::Mask::IOM_FACECOLOR+vcg::tri::io::Mask::IOM_VERTCOLOR);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -309,18 +309,23 @@ Note: The faux bit is used to color polygonal faces uniformly
|
||||||
/*! \brief Perlin Noise.
|
/*! \brief Perlin Noise.
|
||||||
\return the number of changed vertexes (the selected ones)
|
\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<ScalarType> tr, float freq, Point3i channelOffsets=Point3i(0,0,0))
|
static void PerVertexPerlinNoise(MeshType& m, Point3f period, Point3f offset=Point3f(0,0,0))
|
||||||
{
|
{
|
||||||
Point3<ScalarType> p;
|
Point3<ScalarType> p[3];
|
||||||
for(VertexIterator vi = m.vert.begin(); vi!=m.vert.end(); ++vi)
|
for(VertexIterator vi = m.vert.begin(); vi!=m.vert.end(); ++vi)
|
||||||
{
|
{
|
||||||
if(!(*vi).IsD()){
|
if(!(*vi).IsD()){
|
||||||
p = bbox.GlobalToLocal(tr * (*vi).P()); //actual vertex position scaled to bbox
|
// perlin noise is defined in 022
|
||||||
(*vi).C() = Color4b( int(255*math::Perlin::Noise(channelOffsets[0]+p[0]*freq,channelOffsets[0]+p[1]*freq,channelOffsets[0]+p[2]*freq)),
|
p[0] = (vi->P()/period[0])+offset;
|
||||||
int(255*math::Perlin::Noise(channelOffsets[1]+p[0]*freq,channelOffsets[1]+p[1]*freq,channelOffsets[1]+p[2]*freq)),
|
p[1] = (vi->P()/period[1])+offset;
|
||||||
int(255*math::Perlin::Noise(channelOffsets[2]+p[0]*freq,channelOffsets[2]+p[1]*freq,channelOffsets[2]+p[2]*freq)),
|
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 );
|
255 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue