/* 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 "DisplaceBrush.hh" #include "Mesh.h" #include "Optimized.h" #include using namespace SharpConstruct; DisplaceBrush::DisplaceBrush( SculptPhase, Mesh& mesh ) : mesh_( mesh ) { mesh_.ClearModifiedVertexIndices(); } void DisplaceBrush::operator()( SculptPhase, EditData e ) { mesh_.FindActiveVertices( active_data_, e ); if( mesh_.CurrentBrush().PositionEdit() ) { Optimized::Point3D area_normal = mesh_.CalculateAreaNormal( active_data_ ); displace_location_ dl( mesh_, e, area_normal ); std::for_each( active_data_.begin(), active_data_.end(), dl ); } if( mesh_.CurrentBrush().ColorEdit() ) { displace_color_ dc( mesh_, e ); std::for_each( active_data_.begin(), active_data_.end(), dc ); } } void DisplaceBrush::Postwork( SculptPhase ) { if( mesh_.CurrentBrush().PositionEdit() ) { mesh_.RecalculateDamaged(); mesh_.RecalculateModifiedNormals(); } } void DisplaceBrush::displace_location_::operator()( const ActiveData& a ) { Optimized::Point3D& loc( mesh_.VertexLocations()[ a.Index() ] ); loc += normal_ * ( a.Strength() * mesh_.CurrentBrush().Strength() ); } void DisplaceBrush::displace_color_::operator()( const ActiveData& a ) { float intensity; SharpConstruct::Color& v( mesh_.VertexColors()[ a.Index() ] ); intensity = a.Strength() * mesh_.CurrentBrush().Intensity(); v += ( mesh_.CurrentBrush().CurrentColor() - v ) * intensity; }