brush.h

Go to the documentation of this file.
00001 
00002 //**************************************************************************/
00003 // Copyright (c) 2008 Autodesk, Inc.
00004 // All rights reserved.
00005 //
00006 // Use of this software is subject to the terms of the Autodesk license
00007 // agreement provided at the time of installation or download, or which
00008 // otherwise accompanies this software in either electronic or hard copy form.
00009 //
00010 //**************************************************************************/
00011 // DESCRIPTION:
00012 // CREATED: August 2009
00013 //**************************************************************************/
00014 
00015 #ifndef __MUDBOXSDK_BRUSH_H__
00016 #define __MUDBOXSDK_BRUSH_H__
00017 
00018 #include <QtCore/QHash>
00019 #include <QtCore/QSharedPointer>
00020 #include <QtCore/QCoreApplication>
00021 
00022 namespace mudbox {
00023 
00025 class MBDLL_DECL BrushConfiguration
00026 {
00027 public:
00028     typedef enum
00029     {
00030         PaintTools,
00031         SculptTools,
00032         PoseTools,
00033         SelectTools
00034     } PredefinedCategory;
00035 
00036 public:
00038     BrushConfiguration( );
00039     BrushConfiguration( const ClassDesc *pClass, unsigned int iID, const QString& sStringID, const QString& sDisplayName, const QString& sCategory, const QString& sCategoryTr, const QString& sToolTip );
00040     BrushConfiguration( const ClassDesc *pClass, unsigned int iID, const QString& sStringID, const QString& sDisplayName, PredefinedCategory nCategory, const QString& sToolTip );
00041     ~BrushConfiguration( );
00043     unsigned int ID( void ) const;
00046     virtual QString Name( void ) const;
00048     virtual QString StringID( void ) const;
00050     virtual QString DisplayName( void ) const;
00052     virtual void SetDisplayName( const QString & sDisplayName );
00054     virtual QString ToolTip( void ) const;
00056     virtual const ClassDesc *OperationClass( void ) const;
00058     virtual QString Category() const;
00060     virtual QString DisplayCategory() const;
00062     virtual void Serialize( Stream& s );
00063 
00064 private:
00065     const ClassDesc *m_pClass;
00066     unsigned int m_iID;
00067     QString m_sStringID, m_sToolTip, m_sCategory;
00068     QString m_sDisplayName, m_sCategoryTr;
00069     Action* m_pAction;
00070 };
00071 
00073 enum MirrorMode
00074 {
00076     eMirrorNone,
00078     eMirrorX,
00080     eMirrorY,
00082     eMirrorZ,
00084     eMirrorLocalX,
00086     eMirrorLocalY,
00088     eMirrorLocalZ,
00090     eMirrorTangent
00091 };
00092 
00094 struct MBDLL_DECL MirrorConfiguration
00095 {
00097     MirrorConfiguration( void );
00098     MirrorConfiguration( const MirrorConfiguration &v );
00100     enum MirrorMode MirrorMode( void ) const;
00102     void SetMirrorMode( enum MirrorMode mode );
00104     const Store<mudbox::Vector> &MirrorPlaneNormals( void ) const { return m_aMirrorPlaneNormals; };
00106     const Store<mudbox::Vector> &MirrorPlanePositions( void ) const { return m_aMirrorPlanePositions; };
00108     bool IsMirrorLocal( void ) const { return m_bMirrorLocal; };
00110     int MirrorPlanes( void ) const { return m_iMirrorPlanes; };
00114     Matrix TransformationMatrix( 
00115             const SurfacePoint *pSourceLocation,    
00116 
00117 
00118              bool bNormalizeLocalFrame = false  
00119         ) const;
00122     Vector Transform( 
00123         const Vector &cSource, 
00124         float fW, 
00125         const SurfacePoint *pSourceLocation 
00126 
00127 
00128         ) const;
00129 
00130     inline bool operator ==( const MirrorConfiguration & ) const throw() { return false; };
00131     inline bool operator !=( const MirrorConfiguration &v ) const throw() { return !operator ==( v ); };
00132 
00134     virtual void Serialize( Stream& s );
00135 
00136 private:
00138     Matrix AxisTransformationMatrix( 
00139             const SurfacePoint *pSourceLocation 
00140 
00141 
00142         ) const;
00146     Matrix TangentTransformationMatrix( 
00147             const SurfacePoint *pSourceLocation,    
00148 
00149 
00150              bool bNormalizeLocalFrame = false           
00151         ) const;
00152 
00153     bool m_bMirrorLocal;
00154     int m_iMirrorPlanes;
00155     Store<mudbox::Vector> m_aMirrorPlaneNormals;
00156     Store<mudbox::Vector> m_aMirrorPlanePositions;
00157 
00158     friend class BrushOperation;
00159 };
00160 
00161 typedef AttributeInstance<MirrorConfiguration> amirrorcfg;
00162 
00163 MBDLL_DECL AttributeWidget *CreateNewMirrorConfigurationWidget( QWidget *pParent, int iWidth, amirrorcfg *pAttribute );
00164 
00165 template <> inline
00166 AttributeWidget *amirrorcfg::CreateEditorWidget( QWidget *pParent, int iWidth ) { return CreateNewMirrorConfigurationWidget( pParent, iWidth, this ); };
00167 
00168 template <> inline
00169 Attribute::AttributeType amirrorcfg::Type( void ) const { return typeUnknown; };
00170 
00171 template <> inline
00172 QString amirrorcfg::AsString( bool /*bLocalized*/ ) const { return   QString::number(m_cValue.MirrorMode()); };
00173 
00174 template <> inline
00175 void amirrorcfg::SetFromString( const QString &mode, bool /*bInternal*/, bool /*bLocalized*/ ) { m_cValue.SetMirrorMode(MirrorMode(mode.toInt()));  };
00176 
00177 
00179 struct MBDLL_DECL StampConfiguration
00180 {
00181     StampConfiguration( void )
00182     {
00183         m_bActive = false;
00184         m_bOrientToStroke = true;
00185         m_bStretch = false;
00186         m_bFlipX = m_bFlipY = m_bRandomize = m_bRandomizeFlipX = m_bRandomizeFlipY = false;
00187         m_fRotation = m_fRandomizeScale = m_fRandomizeStrength = 0.0f;
00188         m_fRandomizeRotation = 0.35f;
00189         m_fRandomizePositionX = m_fRandomizePositionY = 0.4f;
00190     }
00191 
00192     void Serialize( Stream &s );
00193 
00194     inline bool operator ==( const StampConfiguration & ) const throw() { return false; };
00195     inline bool operator !=( const StampConfiguration &v ) const throw() { return !operator ==( v ); };
00196 
00197     QString m_sFileName;
00198     bool m_bActive;
00199     bool m_bOrientToStroke, m_bStretch;
00200     bool m_bFlipX, m_bFlipY;
00201     float m_fRotation;
00202     bool m_bRandomize, m_bRandomizeFlipX, m_bRandomizeFlipY;
00203     float m_fRandomizeScale, m_fRandomizeRotation, m_fRandomizePositionX, m_fRandomizePositionY, m_fRandomizeStrength;
00204 };
00205 
00206 typedef AttributeInstance<StampConfiguration> astampcfg;
00207 
00208 MBDLL_DECL AttributeWidget *CreateNewStampConfigurationWidget( QWidget *pParent, int iWidth, astampcfg *pAttribute );
00209 
00210 template <> inline
00211 AttributeWidget *astampcfg::CreateEditorWidget( QWidget *pParent, int iWidth ) { return CreateNewStampConfigurationWidget( pParent, iWidth, this ); };
00212 
00213 template <> inline
00214 Attribute::AttributeType astampcfg::Type( void ) const { return typeUnknown; };
00215      
00216 template<> inline
00217 QString astampcfg::AsString( bool /*bLocalized*/ ) const
00218 {
00219     return QString("%0 %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13")
00220         .arg(m_cValue.m_bActive)
00221         .arg(m_cValue.m_bOrientToStroke)
00222         .arg(m_cValue.m_bStretch)
00223         .arg(m_cValue.m_bFlipX)
00224         .arg(m_cValue.m_bFlipY)
00225         .arg(m_cValue.m_fRotation)
00226         .arg(m_cValue.m_bRandomize)
00227         .arg(m_cValue.m_bRandomizeFlipX)
00228         .arg(m_cValue.m_bRandomizeFlipY)
00229         .arg(m_cValue.m_fRandomizeScale)
00230         .arg(m_cValue.m_fRandomizeRotation)
00231         .arg(m_cValue.m_fRandomizePositionX)
00232         .arg(m_cValue.m_fRandomizePositionY)
00233         .arg(m_cValue.m_fRandomizeStrength);
00234 };
00235 
00236 template<> inline
00237 void astampcfg::SetFromString( const QString &s , bool /*bInternal*/, bool /*bLocalized*/ )
00238 {
00239     m_cValue.m_bActive = s.section( ' ', 0,0 ) == "1" ? true : false;
00240     m_cValue.m_bOrientToStroke = s.section( ' ', 1,1 ) == "1" ? true : false;
00241     m_cValue.m_bStretch = s.section( ' ', 2,2) == "1" ? true : false;
00242     m_cValue.m_bFlipX = s.section( ' ', 3,3 ) == "1" ? true : false;
00243     m_cValue.m_bFlipY = s.section( ' ', 4,4 ) == "1" ? true : false;
00244     m_cValue.m_fRotation = s.section( ' ', 5,5 ).toFloat();
00245     m_cValue.m_bRandomize = s.section( ' ', 6,6 ) == "1" ? true : false;
00246     m_cValue.m_bRandomizeFlipX  = s.section( ' ', 7,7 ) == "1" ? true : false;
00247     m_cValue.m_bRandomizeFlipY = s.section( ' ', 8,8 ) == "1" ? true : false;
00248     m_cValue.m_fRandomizeScale = s.section( ' ', 9,9 ).toFloat();
00249     m_cValue.m_fRandomizeRotation = s.section( ' ', 10,10 ).toFloat();
00250     m_cValue.m_fRandomizePositionX = s.section( ' ', 11,11 ).toFloat();
00251     m_cValue.m_fRandomizePositionY = s.section( ' ', 12,12 ).toFloat();
00252     m_cValue.m_fRandomizeStrength =s.section( ' ', 13,13 ).toFloat(); 
00253 };
00254     
00261 class MBDLL_DECL BrushOperation : public Operation
00262 {
00263     Q_DECLARE_TR_FUNCTIONS(mudbox::BrushOperation)
00264     DECLARE_CLASS;
00265 public:
00267     enum Direction
00268     {
00269         eDirNormal,
00270         eDirAveragedNormal,
00271         eDirVertexNormal,
00272         eDirForward,
00273         eDirRight,
00274         eDirX,
00275         eDirY,
00276         eDirZ,
00277         eDirCamera,
00278         eDirScreen,
00279         eDirXY,
00280         eDirXZ,
00281         eDirYZ
00282     };
00283 
00285     enum Modifier
00286     {
00287         eModNormal,
00288         eModAdditive,
00289         eModInverted,
00290         eModNoEffect
00291     };
00292 
00294     enum TriggerType
00295     {
00296         eTriggerPrimary,    // primary button was used (by default left mouse button)
00297         eTriggerSecondary,  // secondary button was used (by default middle mouse button)
00298         eTriggerTertiary    // tertiary button was used (by default left+middle mouse button)
00299     };
00300 
00302     enum MaskType
00303     {
00304         eMaskAny = -1,
00305         eMaskStamp,
00306         eMaskStencil,
00307         eMaskTypeCount
00308     };
00309 
00312     enum StampSizingMode
00313     {
00315         eStampSizingNone,
00317         eStampSizingRadius,
00319         eStampSizingDiameter
00320     };
00321 
00323     struct BrushBehavior
00324     {
00325         enum BehaviorType
00326         {
00327             eBehaviorNone,
00328             eBehaviorBrush,
00329             eBehaviorAttribute
00330         };
00331 
00332         BrushBehavior( void ) { m_eType = eBehaviorNone; m_sTarget = ""; m_iHotkey = 0; };
00333         BrushBehavior( BehaviorType type, QString target, int iHotkey ) : m_eType( type ), m_sTarget( target ), m_iHotkey( iHotkey ) {};
00334 
00335         BehaviorType m_eType;
00336         QString m_sTarget;
00337         int m_iHotkey;
00338     };
00339 
00341     BrushOperation( void );
00342 
00344     virtual QString StringID( const ClassDesc *pClass = 0 ) const;
00346     virtual QString DisplayName( void ) const;
00347 
00349     virtual void OnNodeEvent( const Attribute &cAttribute, NodeEventType eType );
00350 
00352     virtual bool IsScreenSpace( void ) const;
00354     virtual float BrushSize( void ) const;
00356     virtual float BrushStrength( void ) const;
00358     virtual void SetBrushSize( float fSize );
00360     virtual void SetBrushStrength( float fStrength );
00362     virtual float EffectiveBrushSize( void ) const;
00364     virtual float EffectiveBrushStrength( void ) const;
00366     virtual float BrushSizeBias( void ) const;
00368     virtual float BrushStrengthBias( void ) const;
00370     virtual float MaxBrushSize( void ) const;
00372     virtual float MaxBrushStrength( void ) const;
00373 
00375     virtual bool UsesStrokeSmoothing( void ) const;
00377     virtual float StrokeSmoothingDistance( void ) const;
00379     virtual void SetStrokeSmoothing( bool bEnable, float fDistance );
00381     virtual bool HasCustomCursor( void );
00382 
00384     virtual bool UsesSteadyStroke( void ) const;
00386     virtual float SteadyStrokeDistance( void ) const;
00388     virtual void SetSteadyStroke( bool bEnable, float fDistance );
00389 
00391     virtual enum StampSizingMode StampSizingMode( void ) const;
00393     virtual void SetStampSizingMode( enum StampSizingMode eMode );
00394 
00396     virtual const NURBSCurve *Falloff( void ) const;
00398     virtual void SetFalloff( NURBSCurve *pCurve );
00400     virtual const Store<float> &FalloffData( void ) const;
00402     inline float FalloffValue( float fValue ) const
00403     {
00404         return FalloffData()[int(fValue*(FalloffData().ItemCount()-1))];
00405     };
00407     virtual bool UsesFalloffBasedOnFacingAngle( void ) const;
00409     virtual void SetFalloffBasedOnFacingAngle( bool bEnable );
00410 
00412     virtual bool UsesStampRandomize( void ) const;
00414     virtual void SetStampRandomize( bool bEnable );
00415 
00417     virtual bool IsMaskEnabled( MaskType type = eMaskAny ) const;
00419     virtual const Image *MaskImage( MaskType type = eMaskAny ) const;
00421     virtual Matrix MaskMatrix( MaskType type = eMaskAny ) const;
00423     virtual bool IsMaskInverted( MaskType type = eMaskAny ) const;
00425     virtual float MaskFactor( MaskType type = eMaskAny ) const;
00427     virtual bool IsMaskTiled( MaskType type = eMaskAny ) const;
00429     virtual QString MaskName( MaskType type = eMaskAny ) const;
00431     virtual bool MaskBuildUp( MaskType type = eMaskAny ) const;
00433     virtual const Image *MaskOpacityImage( MaskType type = eMaskAny ) const;
00435     virtual float MaskOffset( MaskType type = eMaskAny ) const;
00437     virtual void OnMaskChanged( MaskType type = eMaskAny );
00438 
00440     virtual float BuildUpRate( void ) const;
00442     virtual bool PatchesAtRelease( void ) const;
00444     virtual bool PressureControlsBrushSize( void ) const;
00446     virtual bool PressureControlsBrushStrength( void ) const;
00448     virtual bool IsInverted( void ) const;
00450     virtual bool IsOrientedToSurface( void ) const;
00451 
00453     Direction Direction( void ) const;
00455     Vector DirectionVector( unsigned int iVertexIndex ) const;
00457     virtual void SetDirectionVector( const Vector &vDirection ) const;
00459     Vector PreviousPatchPosition( void ) const;
00460 
00462     virtual void BeginStroke( Mesh *pMesh, Modifier eModifier, TriggerType eTriggerType );
00464     virtual void EndStroke( void );
00466     virtual void MouseMove( float fXPosition, float fYPosition, float fXDelta, float fYDelta, AxisAlignedBoundingBox &cDirtyWorldArea, float fSize, float fPressure, float fStrength );
00468     virtual void AddPatch( const SurfacePoint *pPoint, const Vector &vPatchCenter, float fSize, float fPressure, float fStrength, AxisAlignedBoundingBox &cDirtyWorldArea );
00470     virtual void Flood( Mesh *pTarget, float fStrength = 1.0f, bool bFromCamera = false );
00471 
00473     virtual void SetInactive();
00475     virtual void SetActiveConfiguration( BrushConfiguration *config );
00477     virtual void SetActiveConfiguration( const QString &sName );
00479     virtual BrushConfiguration *ActiveConfiguration( void ) const;
00480 
00482     static void AddConfiguration( BrushConfiguration *config );
00484     static unsigned int ConfigurationCount( void );
00486     static BrushConfiguration *Configuration( unsigned int iIndex );
00487 
00489     const StampConfiguration &StampConfig( void ) const;
00491     void SetStampConfig( StampConfiguration &newConfig );
00493     void SetStamp( bool bEnable, const QString &sFileName = "" );
00494 
00496     void SetBrushSizeScale( float fScale );
00498     void SetBrushStrengthScale( float fScale );
00499 
00501     bool UsesGlobalBrushSize( void ) const;
00502 
00505     Modifier CurrentModifier( void ) const;
00506 
00508     const MirrorConfiguration &MirrorConfig( void ) const;
00510     virtual void SetMirrorConfig( MirrorConfiguration newConfig );
00511 
00516     virtual bool IsConfigurationInited( BrushConfiguration *config ) const;
00519     virtual void StoreConfiguration( BrushConfiguration *config );
00523     virtual void RestoreConfiguration( BrushConfiguration *config );
00525     static void SerializeConfigurationStates( Stream &s );
00526 
00528     virtual QString OverlayIcon( void );
00530     virtual QPointF OverlayOffset( void );
00531 
00533     virtual bool ExecuteAndInvert( void );
00535     virtual void Serialize( Stream &s );
00537     virtual BrushOperation &operator =( const BrushOperation &op );
00538 
00541     virtual bool CanLockLayer( void ) const;
00542 
00545     virtual bool CustomPicker( void );
00546 
00549     virtual Node *AttributeHolderNode( void );
00550 
00552     virtual void SetFalloffIndex( int iIndex );
00553 
00555     virtual int FalloffIndex( void ) const;
00556 
00558     virtual unsigned int AlternateBehaviorCount( void ) const;
00559 
00561     virtual const BrushBehavior &AlternateBehavior( unsigned int iIndex ) const;
00562 
00564     virtual bool IsSnapToCurve( void ) const;
00565     
00567     virtual float SnapDistance( void ) const;
00568 
00569 protected:
00571     abool m_bScreenSpace;
00572     abool m_bInverted;
00573     abool m_bOrientToSurface;
00574     afloatr m_fNormalBrushSize, m_fNormalBrushStrength;
00575     afloatr m_fScreenBrushSize, m_fScreenBrushStrength;
00576     afloatr m_fMaxBrushSize, m_fMaxBrushStrength;
00577     afloatr m_fBrushSizeBias, m_fBrushStrengthBias;
00578     acheckablefloat m_fStrokeSmoothing;
00579     acheckablefloat m_fSteadyStroke;
00580     abool m_bRememberSize;
00581     aenum m_iDirection;
00582     astampcfg m_cStampCfg;
00583     amirrorcfg m_cMirrorCfg;
00584     aevent m_cFlood;
00585     aevent m_cFloodFromCamera;
00586     avoid m_vPressure;
00587     acurveptr m_cFalloff;
00588     aint m_iFalloffIndex;
00589     aptr<NURBSCurve> m_pFalloffCurve;
00590     AttributeCheckableFloatArray m_aFalloffBasedonFacingAngle;
00591     aevent m_cReset;
00592 
00593     Modifier m_eModifier;
00594     TriggerType m_eTriggerType;
00595     float m_fBrushSizeScale;
00596     float m_fBrushStrengthScale;
00597     BrushConfiguration *m_pActiveConfiguration;
00598 
00599     BrushBehavior m_cAlternateBehavior1, m_cAlternateBehavior2;
00600 
00601     acheckablefloat m_fSnapToCurve;
00602 
00603 private:
00604     static QHash< BrushConfiguration *, QSharedPointer<mudbox::BrushOperation> > s_aConfigurationStates;
00605     static Store<BrushConfiguration *> s_aConfigurations;
00606 };
00607 
00608 #define MB_ADD_CONFIG( classname, id, name, nametr, category, tooltip ) \
00609     mudbox::BrushOperation::AddConfiguration( new BrushConfiguration( classname::StaticClass(), id, name, nametr, category, tooltip ) );
00610 
00611 #define MB_ADD_CONFIG2( classname, id, name, nametr, category, categoryTr, tooltip ) \
00612     mudbox::BrushOperation::AddConfiguration( new BrushConfiguration( classname::StaticClass(), id, name, nametr, category, categoryTr, tooltip ) );
00613 
00614 }; // end of namespace mudbox
00615 
00616 #endif