/* Copyright 2004, 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 */ #ifndef BRUSH_H #define BRUSH_H #include "Color.h" #include "Mesh.h" #include "Optimized.h" #include "Sculpt.hh" #include namespace SharpConstruct { namespace Math { class PolarPoint; } class DisplaceBrush; class GrabBrush; class LayerBrush; class PinchBrush; class SmoothBrush; class SymmetryData { public: SymmetryData(); SymmetryData( bool x, bool y, bool z ); bool X() const; void SetX( const bool x ); bool Y() const; void SetY( const bool y ); bool Z() const; void SetZ( const bool z ); private: bool x_, y_, z_; }; class EditData { public: unsigned SIndex; // Symmetry index, 0 to 7 Optimized::Normal3D Up, Left, Z; Optimized::Point3D Center; }; class Brush { public: enum PositionMode{ OFF = 0, ADD, SUB }; enum BrushMode{ DISPLACE, GRAB, SMOOTH, PINCH }; Brush(); static void StartSculpt( Mesh& mesh ); static void ContinueSculpt( Mesh& mesh ); BrushMode Mode() const; void SetMode( const BrushMode& ); PositionMode PositionEdit() const; void SetPositionEdit( PositionMode ); bool ColorEdit() const; void SetColorEdit( bool ); bool Flip() const; void SetFlip( bool ); unsigned Radius() const; unsigned RadiusBase() const; void SetRadius( float ); float Strength() const; void SetStrength( float ); float Intensity() const; void SetIntensity( float ); float Pressure() const; void SetPressure( const float ); void SetRadiusPressure( const bool ); void SetStrengthPressure( const bool ); void SetIntensityPressure( const bool ); const Color& CurrentColor() const; void SetColor( const Color& c ); const SymmetryData& Symmetry() const; void SetSymmetry( const SymmetryData& s ); bool Once() const; void SetOnce( bool o ); bool Dot() const; void SetDot( bool d ); void SetShape( Glib::RefPtr< Gdk::Pixbuf > ); float AlphaStrength( Math::PolarPoint ); float AlphaStrength( const float, const float ); float BackLimit() const; void SetBackLimit( const float ); float FrontLimit() const; void SetFrontLimit( const float ); float CursorZ() const; void SetCursorZ( const float ); private: template< typename Phase > void _sculpt( Mesh& mesh ) { if( Mode() == DISPLACE ) { if( Once() || Dot() ) _sculpt_symmetrical< Phase, LayerBrush >( mesh ); else _sculpt_symmetrical< Phase, DisplaceBrush >( mesh ); } else if( Mode() == GRAB ) _sculpt_symmetrical< Phase, GrabBrush >( mesh ); else if( Mode() == PINCH ) _sculpt_symmetrical< Phase, PinchBrush >( mesh ); else if( Mode() == SMOOTH ) _sculpt_symmetrical< Phase, SmoothBrush >( mesh ); } template< typename Phase, typename Action > void _sculpt_symmetrical( Mesh& mesh ) { // Prepare phase and action Phase phase; Action action( phase, mesh ); // Do action action( phase, mesh.GetMirror( false, false, false ) ); if( Symmetry().X() ) action( phase, mesh.GetMirror( true, false, false ) ); if( Symmetry().Y() ) action( phase, mesh.GetMirror( false, true, false ) ); if( Symmetry().Z() ) action( phase, mesh.GetMirror( false, false, true ) ); if( Symmetry().X() && Symmetry().Y() ) action( phase, mesh.GetMirror( true, true, false ) ); if( Symmetry().Y() && Symmetry().Z() ) action( phase, mesh.GetMirror( false, true, true ) ); if( Symmetry().X() && Symmetry().Z() ) action( phase, mesh.GetMirror( true, false, true ) ); if( Symmetry().X() && Symmetry().Y() && Symmetry().Z() ) action( phase, mesh.GetMirror( true, true, true ) ); // Clean up action.Postwork( phase ); } BrushMode mode_; PositionMode position_edit_; bool color_edit_; bool flip_; unsigned radius_; float strength_, intensity_; float pressure_; bool radius_pressure_; bool strength_pressure_; bool intensity_pressure_; Color color_; SymmetryData symmetry_; bool once_, dot_; Glib::RefPtr< Gdk::Pixbuf > shape_; // Data for the current sculpt action float back_limit_, front_limit_; float cursor_z_; }; } #endif // BRUSH_H