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 );
00099     enum MirrorMode MirrorMode( void ) const;
00101     void SetMirrorMode( enum MirrorMode mode );
00103     const Store<mudbox::Vector> &MirrorPlaneNormals( void ) const { return m_aMirrorPlaneNormals; };
00105     const Store<mudbox::Vector> &MirrorPlanePositions( void ) const { return m_aMirrorPlanePositions; };
00107     bool IsMirrorLocal( void ) const { return m_bMirrorLocal; };
00109     int MirrorPlanes( void ) const { return m_iMirrorPlanes; };
00113     Matrix TransformationMatrix( 
00114             const SurfacePoint *pSourceLocation,    
00115 
00116 
00117              bool bNormalizeLocalFrame = false  
00118         ) const;
00121     Vector Transform( 
00122         const Vector &cSource, 
00123         float fW, 
00124         const SurfacePoint *pSourceLocation 
00125 
00126 
00127         ) const;
00128 
00129     inline bool operator ==( const MirrorConfiguration & ) const throw() { return false; };
00130     inline bool operator !=( const MirrorConfiguration &v ) const throw() { return !operator ==( v ); };
00131 
00132 private:
00134     Matrix AxisTransformationMatrix( 
00135             const SurfacePoint *pSourceLocation 
00136 
00137 
00138         ) const;
00142     Matrix TangentTransformationMatrix( 
00143             const SurfacePoint *pSourceLocation,    
00144 
00145 
00146              bool bNormalizeLocalFrame = false           
00147         ) const;
00148 
00149     bool m_bMirrorLocal;
00150     int m_iMirrorPlanes;
00151     Store<mudbox::Vector> m_aMirrorPlaneNormals;
00152     Store<mudbox::Vector> m_aMirrorPlanePositions;
00153 
00154     friend class BrushOperation;
00155 };
00156 
00157 typedef AttributeInstance<MirrorConfiguration> amirrorcfg;
00158 
00159 MBDLL_DECL AttributeWidget *CreateNewMirrorConfigurationWidget( QWidget *pParent, int iWidth, amirrorcfg *pAttribute );
00160 
00161 template <> inline
00162 AttributeWidget *amirrorcfg::CreateEditorWidget( QWidget *pParent, int iWidth ) { return CreateNewMirrorConfigurationWidget( pParent, iWidth, this ); };
00163 
00164 template <> inline
00165 Attribute::AttributeType amirrorcfg::Type( void ) const { return typeUnknown; };
00166 
00167 template <> inline
00168 QString amirrorcfg::AsString( unsigned int /*options*/ ) const { return   QString::number(m_cValue.MirrorMode()); };
00169 
00170 template <> inline
00171 void amirrorcfg::SetFromString( const QString &mode, unsigned int /*options*/) { m_cValue.SetMirrorMode(MirrorMode(mode.toInt()));  };
00172 
00173 
00175 struct MBDLL_DECL StampConfiguration
00176 {
00177     StampConfiguration( void )
00178     {
00179         m_bActive = false;
00180         m_bOrientToStroke = true;
00181         m_bStretch = false;
00182         m_bFlipX = m_bFlipY = m_bRandomize = m_bRandomizeFlipX = m_bRandomizeFlipY = false;
00183         m_fRotation = m_fRandomizeScale = m_fRandomizeStrength = 0.0f;
00184         m_fRandomizeRotation = 0.35f;
00185         m_fRandomizePositionX = m_fRandomizePositionY = 0.4f;
00186     }
00187 
00188     void Serialize( Stream &s );
00189 
00190     inline bool operator ==( const StampConfiguration & ) const throw() { return false; };
00191     inline bool operator !=( const StampConfiguration &v ) const throw() { return !operator ==( v ); };
00192 
00193     QString m_sFileName;
00194     bool m_bActive;
00195     bool m_bOrientToStroke, m_bStretch;
00196     bool m_bFlipX, m_bFlipY;
00197     float m_fRotation;
00198     bool m_bRandomize, m_bRandomizeFlipX, m_bRandomizeFlipY;
00199     float m_fRandomizeScale, m_fRandomizeRotation, m_fRandomizePositionX, m_fRandomizePositionY, m_fRandomizeStrength;
00200 };
00201 
00202 typedef AttributeInstance<StampConfiguration> astampcfg;
00203 
00204 MBDLL_DECL AttributeWidget *CreateNewStampConfigurationWidget( QWidget *pParent, int iWidth, astampcfg *pAttribute );
00205 
00206 template <> inline
00207 AttributeWidget *astampcfg::CreateEditorWidget( QWidget *pParent, int iWidth ) { return CreateNewStampConfigurationWidget( pParent, iWidth, this ); };
00208 
00209 template <> inline
00210 Attribute::AttributeType astampcfg::Type( void ) const { return typeUnknown; };
00211      
00212 template<> inline
00213 QString astampcfg::AsString( unsigned int /*options*/ ) const
00214 {
00215     return QString("%0 %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13")
00216         .arg(m_cValue.m_bActive)
00217         .arg(m_cValue.m_bOrientToStroke)
00218         .arg(m_cValue.m_bStretch)
00219         .arg(m_cValue.m_bFlipX)
00220         .arg(m_cValue.m_bFlipY)
00221         .arg(m_cValue.m_fRotation)
00222         .arg(m_cValue.m_bRandomize)
00223         .arg(m_cValue.m_bRandomizeFlipX)
00224         .arg(m_cValue.m_bRandomizeFlipY)
00225         .arg(m_cValue.m_fRandomizeScale)
00226         .arg(m_cValue.m_fRandomizeRotation)
00227         .arg(m_cValue.m_fRandomizePositionX)
00228         .arg(m_cValue.m_fRandomizePositionY)
00229         .arg(m_cValue.m_fRandomizeStrength);
00230 };
00231 
00232 template<> inline
00233 void astampcfg::SetFromString( const QString &s , unsigned int /*options*/)
00234 {
00235     m_cValue.m_bActive = s.section( ' ', 0,0 ) == "1" ? true : false;
00236     m_cValue.m_bOrientToStroke = s.section( ' ', 1,1 ) == "1" ? true : false;
00237     m_cValue.m_bStretch = s.section( ' ', 2,2) == "1" ? true : false;
00238     m_cValue.m_bFlipX = s.section( ' ', 3,3 ) == "1" ? true : false;
00239     m_cValue.m_bFlipY = s.section( ' ', 4,4 ) == "1" ? true : false;
00240     m_cValue.m_fRotation = s.section( ' ', 5,5 ).toFloat();
00241     m_cValue.m_bRandomize = s.section( ' ', 6,6 ) == "1" ? true : false;
00242     m_cValue.m_bRandomizeFlipX  = s.section( ' ', 7,7 ) == "1" ? true : false;
00243     m_cValue.m_bRandomizeFlipY = s.section( ' ', 8,8 ) == "1" ? true : false;
00244     m_cValue.m_fRandomizeScale = s.section( ' ', 9,9 ).toFloat();
00245     m_cValue.m_fRandomizeRotation = s.section( ' ', 10,10 ).toFloat();
00246     m_cValue.m_fRandomizePositionX = s.section( ' ', 11,11 ).toFloat();
00247     m_cValue.m_fRandomizePositionY = s.section( ' ', 12,12 ).toFloat();
00248     m_cValue.m_fRandomizeStrength =s.section( ' ', 13,13 ).toFloat(); 
00249 };
00250     
00257 class MBDLL_DECL BrushOperation : public Operation
00258 {
00259     Q_DECLARE_TR_FUNCTIONS(mudbox::BrushOperation)
00260     DECLARE_CLASS;
00261 
00263     enum Direction
00264     {
00265         eDirNormal,
00266         eDirAveragedNormal,
00267         eDirVertexNormal,
00268         eDirForward,
00269         eDirRight,
00270         eDirX,
00271         eDirY,
00272         eDirZ,
00273         eDirCamera,
00274         eDirScreen,
00275         eDirXY,
00276         eDirXZ,
00277         eDirYZ
00278     };
00279 
00281     enum Modifier
00282     {
00283         eModNormal,
00284         eModAdditive,
00285         eModInverted,
00286         eModSmooth,
00287         eModNoEffect
00288     };
00289 
00291     enum TriggerType
00292     {
00293         eTriggerPrimary,    // primary button was used (by default left mouse button)
00294         eTriggerSecondary,  // secondary button was used (by default middle mouse button)
00295         eTriggerTertiary    // tertiary button was used (by default left+middle mouse button)
00296     };
00297 
00299     enum MaskType
00300     {
00301         eMaskAny = -1,
00302         eMaskStamp,
00303         eMaskStencil,
00304         eMaskTypeCount
00305     };
00306 
00309     enum StampSizingMode
00310     {
00312         eStampSizingNone,
00314         eStampSizingRadius,
00316         eStampSizingDiameter
00317     };
00318 
00320     BrushOperation( void );
00321 
00323     virtual QString StringID( const ClassDesc *pClass = 0 ) const;
00325     virtual QString DisplayName( void ) const;
00326 
00328     virtual void OnNodeEvent( const Attribute &cAttribute, NodeEventType eType );
00329 
00331     virtual bool IsScreenSpace( void ) const;
00333     virtual float BrushSize( void ) const;
00335     virtual float BrushStrength( void ) const;
00337     virtual void SetBrushSize( float fSize );
00339     virtual void SetBrushStrength( float fStrength );
00341     virtual float EffectiveBrushSize( void ) const;
00343     virtual float EffectiveBrushStrength( void ) const;
00345     virtual float BrushSizeBias( void ) const;
00347     virtual float BrushStrengthBias( void ) const;
00349     virtual float MaxBrushSize( void ) const;
00351     virtual float MaxBrushStrength( void ) const;
00352 
00354     virtual bool UsesStrokeSmoothing( void ) const;
00356     virtual float StrokeSmoothingDistance( void ) const;
00358     virtual void SetStrokeSmoothing( bool bEnable, float fDistance );
00360     virtual bool HasCustomCursor( void );
00361 
00363     virtual bool UsesSteadyStroke( void ) const;
00365     virtual float SteadyStrokeDistance( void ) const;
00367     virtual void SetSteadyStroke( bool bEnable, float fDistance );
00368 
00370     virtual enum StampSizingMode StampSizingMode( void ) const;
00372     virtual void SetStampSizingMode( enum StampSizingMode eMode );
00373 
00375     virtual const NURBSCurve *Falloff( void ) const;
00377     virtual void SetFalloff( NURBSCurve *pCurve );
00379     virtual const Store<float> &FalloffData( void ) const;
00381     inline float FalloffValue( float fValue ) const
00382     {
00383         return FalloffData()[int(fValue*(FalloffData().ItemCount()-1))];
00384     };
00386     virtual bool UsesFalloffBasedOnFacingAngle( void ) const;
00388     virtual void SetFalloffBasedOnFacingAngle( bool bEnable );
00389 
00391     virtual bool UsesStampRandomize( void ) const;
00393     virtual void SetStampRandomize( bool bEnable );
00394 
00396     virtual bool IsMaskEnabled( MaskType type = eMaskAny ) const;
00398     virtual const Image *MaskImage( MaskType type = eMaskAny ) const;
00400     virtual Matrix MaskMatrix( MaskType type = eMaskAny ) const;
00402     virtual bool IsMaskInverted( MaskType type = eMaskAny ) const;
00404     virtual float MaskFactor( MaskType type = eMaskAny ) const;
00406     virtual bool IsMaskTiled( MaskType type = eMaskAny ) const;
00408     virtual QString MaskName( MaskType type = eMaskAny ) const;
00410     virtual bool MaskBuildUp( MaskType type = eMaskAny ) const;
00412     virtual const Image *MaskOpacityImage( MaskType type = eMaskAny ) const;
00414     virtual void OnMaskChanged( MaskType type = eMaskAny );
00415 
00417     virtual float BuildUpRate( void ) const;
00419     virtual bool PatchesAtRelease( void ) const;
00421     virtual bool PressureControlsBrushSize( void ) const;
00423     virtual bool PressureControlsBrushStrength( void ) const;
00425     virtual bool IsInverted( void ) const;
00427     virtual bool IsOrientedToSurface( void ) const;
00428 
00430     Direction Direction( void ) const;
00432     Vector DirectionVector( unsigned int iVertexIndex ) const;
00434     virtual void SetDirectionVector( const Vector &vDirection ) const;
00436     Vector PreviousPatchPosition( void ) const;
00437 
00439     virtual void BeginStroke( Mesh *pMesh, Modifier eModifier, TriggerType eTriggerType );
00441     virtual void EndStroke( void );
00443     virtual void MouseMove( float fXPosition, float fYPosition, float fXDelta, float fYDelta, AxisAlignedBoundingBox &cDirtyWorldArea );
00445     virtual void AddPatch( const SurfacePoint *pPoint, const Vector &vPatchCenter, float fSize, float fPressure, float fStrength, AxisAlignedBoundingBox &cDirtyWorldArea );
00447     virtual void Flood( Mesh *pTarget, float fStrength = 1.0f, bool bFromCamera = false );
00448 
00450     virtual void SetActiveConfiguration( BrushConfiguration *config );
00452     virtual void SetActiveConfiguration( const QString &sName );
00454     virtual BrushConfiguration *ActiveConfiguration( void ) const;
00455 
00457     static void AddConfiguration( BrushConfiguration *config );
00459     static unsigned int ConfigurationCount( void );
00461     static BrushConfiguration *Configuration( unsigned int iIndex );
00462 
00464     const StampConfiguration &StampConfig( void ) const;
00466     void SetStampConfig( StampConfiguration &newConfig );
00468     void SetStamp( bool bEnable, const QString &sFileName = "" );
00469 
00471     void SetBrushSizeScale( float fScale );
00473     void SetBrushStrengthScale( float fScale );
00474 
00476     bool UsesGlobalBrushSize( void ) const;
00477 
00480     Modifier CurrentModifier( void ) const;
00481 
00483     const MirrorConfiguration &MirrorConfig( void ) const;
00485     virtual void SetMirrorConfig( MirrorConfiguration newConfig );
00486 
00491     virtual bool IsConfigurationInited( BrushConfiguration *config ) const;
00494     virtual void StoreConfiguration( BrushConfiguration *config );
00498     virtual void RestoreConfiguration( BrushConfiguration *config );
00500     static void SerializeConfigurationStates( Stream &s );
00501 
00503     virtual QString OverlayIcon( void );
00505     virtual QPointF OverlayOffset( void );
00506 
00508     virtual bool ExecuteAndInvert( void );
00510     virtual void Serialize( Stream &s );
00512     virtual BrushOperation &operator =( const BrushOperation &op );
00513 
00516     virtual bool CanLockLayer( void ) const;
00517 
00520     virtual bool CustomPicker( void );
00521 
00524     virtual Node *AttributeHolderNode( void );
00525 
00527     virtual void SetFalloffIndex( int iIndex );
00528 
00530     virtual int FalloffIndex( void ) const;
00531 
00532 protected:
00534     abool m_bScreenSpace;
00535     abool m_bInverted;
00536     abool m_bOrientToSurface;
00537     afloatr m_fNormalBrushSize, m_fNormalBrushStrength;
00538     afloatr m_fScreenBrushSize, m_fScreenBrushStrength;
00539     afloatr m_fMaxBrushSize, m_fMaxBrushStrength;
00540     afloatr m_fBrushSizeBias, m_fBrushStrengthBias;
00541     acheckablefloat m_fStrokeSmoothing;
00542     acheckablefloat m_fSteadyStroke;
00543     abool m_bRememberSize;
00544     aenum m_iDirection;
00545     astampcfg m_cStampCfg;
00546     amirrorcfg m_cMirrorCfg;
00547     aevent m_cFlood;
00548     avoid m_vPressure;
00549     acurveptr m_cFalloff;
00550     aint m_iFalloffIndex;
00551     aptr<NURBSCurve> m_pFalloffCurve;
00552     AttributeCheckableFloatArray m_aFalloffBasedonFacingAngle;
00553 
00554     Modifier m_eModifier;
00555     TriggerType m_eTriggerType;
00556     float m_fBrushSizeScale;
00557     float m_fBrushStrengthScale;
00558     BrushConfiguration *m_pActiveConfiguration;
00559 
00560 private:
00561     static QHash< BrushConfiguration *, QSharedPointer<mudbox::BrushOperation> > s_aConfigurationStates;
00562     static Store<BrushConfiguration *> s_aConfigurations;
00563 };
00564 
00565 #define MB_ADD_CONFIG( classname, id, name, nametr, category, tooltip ) \
00566     mudbox::BrushOperation::AddConfiguration( new BrushConfiguration( classname::StaticClass(), id, name, nametr, category, tooltip ) );
00567 
00568 #define MB_ADD_CONFIG2( classname, id, name, nametr, category, categoryTr, tooltip ) \
00569     mudbox::BrushOperation::AddConfiguration( new BrushConfiguration( classname::StaticClass(), id, name, nametr, category, categoryTr, tooltip ) );
00570 
00571 }; // end of namespace mudbox
00572 
00573 #endif