added "only on selection" to PerVertexAddNoise and PerVertexPerlinNoise functions

This commit is contained in:
Marco Callieri 2015-10-29 14:26:16 +00:00
parent 667d3034dd
commit 497a42dffe
1 changed files with 45 additions and 42 deletions

View File

@ -324,53 +324,56 @@ 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 have its own offset and frequency. Simple Perlin noise. To make things weirder each color band can have its own offset and frequency.
Period is expressed in absolute terms. 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. 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, CoordType period, CoordType offset=CoordType(0,0,0)) static void PerVertexPerlinNoise(MeshType& m, CoordType period, CoordType offset = CoordType(0, 0, 0), bool onSelected = false)
{ {
RequirePerVertexColor(m); RequirePerVertexColor(m);
CoordType p[3]; CoordType 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())
// perlin noise is defined in 022 if ((!onSelected) || ((*vi).IsS()))
p[0] = (vi->P()/period[0])+offset; {
p[1] = (vi->P()/period[1])+offset; // perlin noise is defined in 022
p[2] = (vi->P()/period[2])+offset; p[0] = (vi->P()/period[0])+offset;
(*vi).C() = Color4b( int(127+128.0*math::Perlin::Noise(p[0][0],p[0][1],p[0][2])), p[1] = (vi->P()/period[1])+offset;
int(127+128.0*math::Perlin::Noise(p[1][0],p[1][1],p[1][2])), p[2] = (vi->P()/period[2])+offset;
int(127+128.0*math::Perlin::Noise(p[2][0],p[2][1],p[2][2])), (*vi).C() = Color4b( int(127+128.0*math::Perlin::Noise(p[0][0],p[0][1],p[0][2])),
255 ); 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 );
} }
/*! \brief Simple Noise adding function. }
It simply add signed noise to the color of the mesh. The noise has uniform distribution and the amplitude is +/-2^(noisebits-1).
*/
static void PerVertexAddNoise(MeshType& m, int noiseBits)
{
RequirePerVertexColor(m);
if(noiseBits>8) noiseBits = 8; /*! \brief Simple Noise adding function.
if(noiseBits<1) return; It simply add signed noise to the color of the mesh. The noise has uniform distribution and the amplitude is +/-2^(noisebits-1).
*/
static void PerVertexAddNoise(MeshType& m, int noiseBits, bool onSelected=false)
{
RequirePerVertexColor(m);
math::SubtractiveRingRNG randomGen = math::SubtractiveRingRNG(time(NULL)); if(noiseBits>8) noiseBits = 8;
for(VertexIterator vi = m.vert.begin(); vi!=m.vert.end(); ++vi) if(noiseBits<1) return;
{
if(!(*vi).IsD()){ math::SubtractiveRingRNG randomGen = math::SubtractiveRingRNG(time(NULL));
(*vi).C()[0] = math::Clamp<int>((*vi).C()[0] + randomGen.generate(int(2*pow(2.0f,noiseBits))) - int(pow(2.0f,noiseBits)),0,255); for(VertexIterator vi = m.vert.begin(); vi!=m.vert.end(); ++vi)
(*vi).C()[1] = math::Clamp<int>((*vi).C()[1] + randomGen.generate(int(2*pow(2.0f,noiseBits))) - int(pow(2.0f,noiseBits)),0,255); if(!(*vi).IsD())
(*vi).C()[2] = math::Clamp<int>((*vi).C()[2] + randomGen.generate(int(2*pow(2.0f,noiseBits))) - int(pow(2.0f,noiseBits)),0,255); if ((!onSelected) || ((*vi).IsS()))
} {
} (*vi).C()[0] = math::Clamp<int>((*vi).C()[0] + randomGen.generate(int(2*pow(2.0f,noiseBits))) - int(pow(2.0f,noiseBits)),0,255);
} (*vi).C()[1] = math::Clamp<int>((*vi).C()[1] + randomGen.generate(int(2*pow(2.0f,noiseBits))) - int(pow(2.0f,noiseBits)),0,255);
(*vi).C()[2] = math::Clamp<int>((*vi).C()[2] + randomGen.generate(int(2*pow(2.0f,noiseBits))) - int(pow(2.0f,noiseBits)),0,255);
}
}
/*! \brief Reduces vertex color the mesh to two colors according to a threshold. /*! \brief Reduces vertex color the mesh to two colors according to a threshold.