/* Copyright 2005 Nicholas Bishop * * This file is part of SharpConstruct. * * SharpConstruct is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * SharpConstruct is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with SharpConstruct; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Brush.h" #include "Mesh.h" #include "Optimized.h" #include "SmoothBrush.hh" #include using namespace SharpConstruct; SmoothBrush::SmoothBrush( SculptPhase, Mesh& mesh ) : mesh_( mesh ) { mesh_.ModifiedVertexIndices().clear(); } void SmoothBrush::operator()( SculptPhase, EditData e ) { mesh_.FindActiveVertices( active_data_, e ); // Loop through each active point for( unsigned i = 0; i < active_data_.size(); ++i ) { if( mesh_.CurrentBrush().PositionEdit() ) { Optimized::Point3D average = mesh_.VertexNeighborLocAverage( active_data_[ i ].Index() ); const float strength( active_data_[ i ].Strength() * fabs( mesh_.CurrentBrush().Strength() * 25 ) ); mesh_.VertexLocations()[ active_data_[ i ].Index() ] += ( average - mesh_.VertexLocations()[ active_data_[ i ].Index() ] ) * strength; } if( mesh_.CurrentBrush().ColorEdit() ) { Color average = mesh_.VertexNeighborClrAverage( active_data_[ i ].Index() ); SharpConstruct::Color* v = &mesh_.VertexColors()[ active_data_[ i ].Index() ]; const float intensity( active_data_[ i ].Strength() * mesh_.CurrentBrush().Intensity() ); v->Red = v->Red + ( average.Red - v->Red ) * intensity; v->Green = v->Green + ( average.Green - v->Green ) * intensity; v->Blue = v->Blue + ( average.Blue - v->Blue ) * intensity; } } } void SmoothBrush::Postwork( SculptPhase ) { if( mesh_.CurrentBrush().PositionEdit() ) { mesh_.RecalculateDamaged(); mesh_.RecalculateModifiedNormals(); } }