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,21 +324,23 @@ Note: The faux bit is used to color polygonal faces uniformly
}
}
/*! \brief Perlin Noise.
\return the number of changed vertexes (the selected ones)
/*! \brief Perlin Noise.
\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.
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, CoordType period, CoordType offset=CoordType(0,0,0))
{
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, CoordType period, CoordType offset = CoordType(0, 0, 0), bool onSelected = false)
{
RequirePerVertexColor(m);
CoordType p[3];
for(VertexIterator vi = m.vert.begin(); vi!=m.vert.end(); ++vi)
if(!(*vi).IsD())
if ((!onSelected) || ((*vi).IsS()))
{
if(!(*vi).IsD()){
// perlin noise is defined in 022
p[0] = (vi->P()/period[0])+offset;
p[1] = (vi->P()/period[1])+offset;
@ -348,14 +350,14 @@ Note: The faux bit is used to color polygonal faces uniformly
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)
{
}
/*! \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, bool onSelected=false)
{
RequirePerVertexColor(m);
if(noiseBits>8) noiseBits = 8;
@ -363,14 +365,15 @@ Note: The faux bit is used to color polygonal faces uniformly
math::SubtractiveRingRNG randomGen = math::SubtractiveRingRNG(time(NULL));
for(VertexIterator vi = m.vert.begin(); vi!=m.vert.end(); ++vi)
if(!(*vi).IsD())
if ((!onSelected) || ((*vi).IsS()))
{
if(!(*vi).IsD()){
(*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.