SkeletalAnimationPlugin.hh 6.77 KB
Newer Older
1 2 3
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
39 40 41 42
*                                                                            *
\*===========================================================================*/


Jan Möbius's avatar
Jan Möbius committed
43

Dirk Wilden's avatar
Dirk Wilden committed
44 45 46 47 48
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
49

50
#include "ObjectTypes/Skeleton/BlendingMethod.hh"
51

Jan Möbius's avatar
Jan Möbius committed
52
class AnimationToolboxWidget;
53
class AnimationHandle;
Jan Möbius's avatar
Jan Möbius committed
54

Dirk Wilden's avatar
Dirk Wilden committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
/**
 * @brief The skeletal animation plugin is used to interact with the skeleton
 *
 * this plugin controls the playback of skeletal animations
 *
 */
class SkeletalAnimationPlugin : public QObject, BaseInterface, ToolboxInterface, LoggingInterface, LoadSaveInterface, RPCInterface
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(ToolboxInterface)
  Q_INTERFACES(LoggingInterface)
  Q_INTERFACES(LoadSaveInterface)
  Q_INTERFACES(RPCInterface)

70 71
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-SkeletalAnimation")

Dirk Wilden's avatar
Dirk Wilden committed
72 73
private:

Jan Möbius's avatar
Jan Möbius committed
74

Dirk Wilden's avatar
Dirk Wilden committed
75 76 77 78 79 80
signals:
  void updateView();

  void log(Logtype _type, QString _message);
  void log(QString _message);
  void addEmptyObject(DataType _type, int& _id);
81
  void updatedObject(int _id, const UpdateType& _type);
Dirk Wilden's avatar
Dirk Wilden committed
82 83 84 85 86
    
  void pluginExists(QString _pluginName, bool &_exists);
  void functionExists(QString _pluginName, QString _functionName, bool &_exists);

  // ToolboxInterface
Dirk Wilden's avatar
Dirk Wilden committed
87
  void addToolbox( QString _name  , QWidget* _widget, QIcon* _icon );   
Dirk Wilden's avatar
Dirk Wilden committed
88 89 90 91

public slots:
  // BaseInterface
  void slotAllCleared();
92
  void slotObjectUpdated( int _id, const UpdateType& _type);
Dirk Wilden's avatar
Dirk Wilden committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106
  void slotObjectSelectionChanged(int _id);
  // LoadSaveInterface
  void fileOpened(int _id);
  void addedEmptyObject(int _id);
  void objectDeleted(int _id);

public slots:
  /**
    * @name Scripting interface
    * Use these methods in the script editor.
    */
  //@{
  int  getNumberOfFrames();
  bool attachSkin(int skeletonId, int skinId);
Dirk Wilden's avatar
Dirk Wilden committed
107 108
  bool detachSkin(int skeletonId, int skinId);
  bool clearSkins(int skeletonId);
Dirk Wilden's avatar
Dirk Wilden committed
109 110 111 112 113 114 115 116 117 118 119

  void setFrame(int _iFrame);
  int  getFrame();
  void changeFPS(int _fps);

  void playAnimation();
  void pauseAnimation();
  void stopAnimation();
  void nextFrame();
  void prevFrame();

Dirk Wilden's avatar
Dirk Wilden committed
120
  void updateSkins();
Dirk Wilden's avatar
Dirk Wilden committed
121 122 123
  //@}

  void UpdateUI();
124
  void setComboBoxPosition(unsigned int _animationIndex);
125
  void checkObjectSelection(const int _objectId);
Dirk Wilden's avatar
Dirk Wilden committed
126

127 128
  void slotAnimationNameChanged();

Dirk Wilden's avatar
Dirk Wilden committed
129 130 131 132 133 134 135 136
private slots:
  void setDescriptions();
  
  void initializePlugin();
  void pluginsInitialized();
  
  void exit();

Dirk Wilden's avatar
Dirk Wilden committed
137 138
  void slotAttachSkin();
  void slotClearSkins();
Dirk Wilden's avatar
Dirk Wilden committed
139 140 141 142
  void slotMethodChanged(int _index);
  void slotAnimationIndexChanged(int /*_index*/);
  void slotFrameChanged(int /*_index*/);
  void slotSkipFramesChanged(int _state);
Dirk Wilden's avatar
Dirk Wilden committed
143
  void slotAddAnimation();
144
  void slotDeleteAnimation();
Dirk Wilden's avatar
Dirk Wilden committed
145 146 147 148

  void animate();

public:
Jan Möbius's avatar
Jan Möbius committed
149
  SkeletalAnimationPlugin();
Dirk Wilden's avatar
Dirk Wilden committed
150 151 152 153 154 155 156
  QString name();
  QString description();

protected:

  AnimationHandle currentAnimationHandle();

Dirk Wilden's avatar
Dirk Wilden committed
157
  void UpdateSkins(BaseObjectData *_pSkeletonObject, AnimationHandle &_hAni);
Dirk Wilden's avatar
Dirk Wilden committed
158 159 160

private:
  /**
Dirk Wilden's avatar
Dirk Wilden committed
161
  * @name Skin management
Dirk Wilden's avatar
Dirk Wilden committed
162 163
  */
  //@{
Dirk Wilden's avatar
Dirk Wilden committed
164 165 166
  void attachSkin(BaseObjectData *pSkin, BaseObjectData *pSkeleton);
  void detachSkin(BaseObjectData *pSkin, BaseObjectData *pSkeleton);
  void clearSkins(BaseObjectData *_pSkeleton);
Dirk Wilden's avatar
Dirk Wilden committed
167 168 169 170
  //@}

protected:
  AnimationToolboxWidget *pToolbox_;         ///< A pointer to the toolbox widget
Dirk Wilden's avatar
Dirk Wilden committed
171
  QIcon* toolIcon_;
Dirk Wilden's avatar
Dirk Wilden committed
172 173

private:
174
  Blending::Method method_; ///< The current blending method for the skin
Dirk Wilden's avatar
Dirk Wilden committed
175 176 177 178 179 180 181 182

  bool bGuiUpdating_;       ///< Used to drop a few messages while the gui is being updated
  QTimer animationTimer_;   ///< Timer used to control animations
  QTime animationTime_;     ///< Time since the animation was started, used to meet the given fps
  int animationOffset_;     ///< This frame was selected as the animation was started
  
  std::vector< int > activeSkeletons_;
};