Shinya Kitaoka 810553
#pragma once
Shinya Kitaoka 810553
Toshihiro Shimizu 890ddd
#ifndef PLASTICSKELETONDEFORMATION_H
Toshihiro Shimizu 890ddd
#define PLASTICSKELETONDEFORMATION_H
Toshihiro Shimizu 890ddd
Shinya Kitaoka 262a92
#include <memory></memory>
Shinya Kitaoka 262a92
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tsmartpointer.h"
Toshihiro Shimizu 890ddd
#include "tdoubleparam.h"
Toshihiro Shimizu 890ddd
#include "tdoublekeyframe.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzExt includes
Toshihiro Shimizu 890ddd
#include "ext/plastichandle.h"
Toshihiro Shimizu 890ddd
#include "ext/plasticskeleton.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// tcg includes
Toshihiro Shimizu 890ddd
#include "tcg/tcg_any_iterator.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qstring></qstring>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TNZEXT_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//====================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//    Forward declarations
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ParamsObserver;
Toshihiro Shimizu 890ddd
class ParamChange;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//====================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**************************************************************************************
Toshihiro Shimizu 890ddd
//    PlasticSkeletonVertexDeformation  declaration
Toshihiro Shimizu 890ddd
//**************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! The deformation of a plastic skeleton vertex.
Shinya Kitaoka d1f6c4
typedef struct DVAPI PlasticSkeletonVertexDeformation final : public TPersist {
Shinya Kitaoka 120a6e
  PERSIST_DECLARATION(PlasticSkeletonVertexDeformation)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  enum Params {
Shinya Kitaoka 120a6e
    ANGLE = 0,  //!< Distance from parent vertex (delta)
Shinya Kitaoka 120a6e
    DISTANCE,   //!< Angle with parent edge (delta)
Shinya Kitaoka 120a6e
    SO,         //!< Vertex's stacking order
Shinya Kitaoka 120a6e
    PARAMS_COUNT
Shinya Kitaoka 120a6e
  };
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  struct Keyframe {
Shinya Kitaoka 120a6e
    TDoubleKeyframe m_keyframes[PARAMS_COUNT];
Shinya Kitaoka 120a6e
  };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TDoubleParamP m_params[PARAMS_COUNT];
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Keyframe getKeyframe(double frame) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setKeyframe(double frame);
Shinya Kitaoka 120a6e
  bool setKeyframe(const Keyframe &values);
Shinya Kitaoka 120a6e
  bool setKeyframe(const Keyframe &values, double frame, double easeIn = -1.0,
Shinya Kitaoka 120a6e
                   double easeOut = -1.0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isKeyframe(double frame) const;
Shinya Kitaoka 120a6e
  bool isFullKeyframe(double frame) const;
Shinya Kitaoka 120a6e
  void deleteKeyframe(double frame);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void saveData(TOStream &os) override;
Shinya Kitaoka 473e70
  void loadData(TIStream &is) override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} SkVD;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**************************************************************************************
Toshihiro Shimizu 890ddd
//    PlasticSkeletonDeformationKeyframe  declaration
Toshihiro Shimizu 890ddd
//**************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! The keyframe of a plastic skeleton vertex deformation.
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
  \note A deformation keyframe stores vertex deformation keyframes by vertex \a
Shinya Kitaoka 120a6e
  names.
Shinya Kitaoka 120a6e
  This is the approach we use to deal with keyframe pasting to different
Shinya Kitaoka 120a6e
  skeletons.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
typedef struct PlasticSkeletonDeformationKeyframe {
Shinya Kitaoka 120a6e
  std::map<qstring, skvd::keyframe=""></qstring,>
Shinya Kitaoka 120a6e
      m_vertexKeyframes;             //!< Keyframes by vertex \a name
Shinya Kitaoka 120a6e
  TDoubleKeyframe m_skelIdKeyframe;  //!< Skeleton id keyframe
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} SkDKey;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**************************************************************************************
Toshihiro Shimizu 890ddd
//    PlasticSkeletonDeformation  declaration
Toshihiro Shimizu 890ddd
//**************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
  PlasticSkeletonDeformation models the deformation of a group of
Shinya Kitaoka 120a6e
PlasticSkeleton instances.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
\par Description
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  A PlasticSkeleton instance is typically used to act as a deformable object -
Shinya Kitaoka 120a6e
in other
Shinya Kitaoka 120a6e
  words, it defines the 'original' form of a hierarchy of vertices that can be
Shinya Kitaoka 120a6e
manipulated
Toshihiro Shimizu 890ddd
  interactively to obtain a 'deformed' configuration.
Toshihiro Shimizu 890ddd
  \n\n
Shinya Kitaoka 120a6e
  PlasticSkeletonDeformation represents a deformation of PlasticSkeleton
Shinya Kitaoka 120a6e
objects,
Toshihiro Shimizu 890ddd
  therefore acting primarily as a collection of PlasticSkeletonVertexDeformation
Shinya Kitaoka 120a6e
  instances - one per skeleton vertex. The collection is an associative
Shinya Kitaoka 120a6e
container mapping a
Shinya Kitaoka 120a6e
   vertex name <\I> to its deformation; using names as keys is a useful
Shinya Kitaoka 120a6e
abstraction
Shinya Kitaoka 120a6e
  that allows vertex deformations data (eg keyframes) to be copied to skeleton
Shinya Kitaoka 120a6e
deformations
Shinya Kitaoka 120a6e
  whose skeletons have a different internal configuration (ie vertex indices and
Shinya Kitaoka 120a6e
such).
Toshihiro Shimizu 890ddd
  \n\n
Shinya Kitaoka 120a6e
  Each vertex deformation also stores a unique  hook number <\I> that can be
Shinya Kitaoka 120a6e
used during
Toshihiro Shimizu 890ddd
  xsheet animation to link stage objects to a skeleton vertex.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
\par The Skeletons group
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  The PlasticSkeletonDeformation implementation has been extended to work on
Shinya Kitaoka 120a6e
multiple
Shinya Kitaoka 120a6e
  skeletons for one class instance. This class stores a map associating skeleton
Shinya Kitaoka 120a6e
indices
Shinya Kitaoka 120a6e
  to the skeleton instances, that can be used to select a skeleton to be
Shinya Kitaoka 120a6e
deformed with
Toshihiro Shimizu 890ddd
  the deformation's data.
Toshihiro Shimizu 890ddd
  \n\n
Shinya Kitaoka 120a6e
  Vertices in different skeleton instances share the same animation if their
Shinya Kitaoka 120a6e
name is the same.
Toshihiro Shimizu 890ddd
  \n\n
Shinya Kitaoka 120a6e
  This class provides an animatable parameter that is intended to choose the \a
Shinya Kitaoka 120a6e
active
Shinya Kitaoka 120a6e
  skeleton along an xsheet timeline. It is retrievable through the
Shinya Kitaoka 120a6e
skeletonIdsParam() method.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
\par Notable implementation details
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  In current implementation, a PlasticSkeletonDeformation keeps shared ownership
Shinya Kitaoka 120a6e
of the
Shinya Kitaoka 120a6e
  skeletons it is attached to. It is therefore intended to be a \a container of
Shinya Kitaoka 120a6e
said skeletons.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka d1f6c4
class DVAPI PlasticSkeletonDeformation final : public TSmartObject,
Shinya Kitaoka d1f6c4
                                               public TPersist {
Shinya Kitaoka 120a6e
  DECLARE_CLASS_CODE
Shinya Kitaoka 120a6e
  PERSIST_DECLARATION(PlasticSkeletonDeformation)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  class Imp;
Shinya Kitaoka 120a6e
  std::unique_ptr<imp> m_imp;</imp>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef tcg::any_it<int, *="" int,="" void="">::bidirectional skelId_iterator;</int,>
Shinya Kitaoka 120a6e
  typedef tcg::any_it<std::pair<const *="" *,="" qstring="" skvd="">,</std::pair<const>
Shinya Kitaoka 120a6e
                      std::pair<const *="" *,="" qstring="" skvd="">, void *>::bidirectional</const>
Shinya Kitaoka 120a6e
      vd_iterator;
Shinya Kitaoka 120a6e
  typedef tcg::any_it<std::pair<int, int="">, std::pair<int, int="">,</int,></std::pair<int,>
Shinya Kitaoka 120a6e
                      void *>::bidirectional vx_iterator;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  PlasticSkeletonDeformation();  //!< Constructs an empty deformation
Shinya Kitaoka 120a6e
  PlasticSkeletonDeformation(
Shinya Kitaoka 120a6e
      const PlasticSkeletonDeformation
Shinya Kitaoka 120a6e
          &other);  //!< Constructs a deformation \a cloning other's skeletons
Shinya Kitaoka 120a6e
  ~PlasticSkeletonDeformation();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  PlasticSkeletonDeformation &operator=(
Shinya Kitaoka 120a6e
      const PlasticSkeletonDeformation &other);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Skeleton-related methods
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool empty() const;
Shinya Kitaoka 120a6e
  int skeletonsCount() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! Acquires  shared ownership <\I> of the specified skeleton, under given
Shinya Kitaoka 120a6e
  //! skeletonId
Shinya Kitaoka 120a6e
  void attach(int skeletonId, PlasticSkeleton *skeleton);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! Releases the skeleton associated to specified skeletonId
Shinya Kitaoka 120a6e
  void detach(int skeletonId);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  PlasticSkeletonP skeleton(int skeletonId) const;
Shinya Kitaoka 120a6e
  int skeletonId(PlasticSkeleton *skeleton) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! Returns the ordered range containing the skeleton ids
Shinya Kitaoka 120a6e
  void skeletonIds(skelId_iterator &begin, skelId_iterator &end) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TDoubleParamP skeletonIdsParam()
Shinya Kitaoka 120a6e
      const;  //!< Returns the skeleton id by frame animatable parameter
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  PlasticSkeletonP skeleton(
Shinya Kitaoka 120a6e
      double frame) const;  //!< Returns the \a active skeleton by xsheet frame
Shinya Kitaoka 120a6e
  int skeletonId(double frame)
Shinya Kitaoka 120a6e
      const;  //!< Returns the \a active skeleton id by xsheet frame
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Vertex deformations-related methods
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int vertexDeformationsCount() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  SkVD *vertexDeformation(const QString &vertexName)
Shinya Kitaoka 120a6e
      const;  //!< Returns the vertex deformation associated to given
Shinya Kitaoka 120a6e
              //!< vertex name. The returned pointer is  owned by
Shinya Kitaoka 120a6e
              //!< the deformation - it must \b not be deleted <\I>
Shinya Kitaoka 120a6e
  SkVD *vertexDeformation(int skelId, int v) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void vertexDeformations(vd_iterator &begin, vd_iterator &end)
Shinya Kitaoka 120a6e
      const;  //!< Returns the ordered range of vertex deformations
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void vdSkeletonVertices(const QString &vertexName, vx_iterator &begin,
Shinya Kitaoka 120a6e
                          vx_iterator &end)
Shinya Kitaoka 120a6e
      const;  //!< Returns the ordered range of skeleton vertices
Shinya Kitaoka 120a6e
              //!< (at max one per skeleton id) associated to a
Shinya Kitaoka 120a6e
              //!< vertex name
Shinya Kitaoka 120a6e
  // Hook number-related methods
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int hookNumber(const QString &name) const;
Shinya Kitaoka 120a6e
  int hookNumber(int skelId, int v) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QString vertexName(int hookNumber) const;
Shinya Kitaoka 120a6e
  int vertexIndex(int hookNumber, int skelId) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Parameters-related methods
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void addObserver(TParamObserver *observer);
Shinya Kitaoka 120a6e
  void removeObserver(TParamObserver *observer);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setGrammar(TSyntax::Grammar *grammar);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Keyframes-related methods
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void getKeyframeAt(double frame, SkDKey &keysMap)
Shinya Kitaoka 120a6e
      const;  //!< \note keysMap returned by argument to avoid map
Shinya Kitaoka 120a6e
              //!< copies in case move semantics is not available
Shinya Kitaoka 120a6e
  void setKeyframe(double frame);
Shinya Kitaoka 120a6e
  bool setKeyframe(const SkDKey &keyframe);
Shinya Kitaoka 120a6e
  bool setKeyframe(const SkDKey &keyframe, double frame, double easeIn = -1.0,
Shinya Kitaoka 120a6e
                   double easeOut = -1.0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isKeyframe(double frame) const;
Shinya Kitaoka 120a6e
  bool isFullKeyframe(double frame) const;
Shinya Kitaoka 120a6e
  void deleteKeyframe(double frame);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Interface methods using a deformed copy of the original skeleton (which is
Shinya Kitaoka 120a6e
  // owned by this class)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void storeDeformedSkeleton(int skeletonId, double frame,
Shinya Kitaoka 120a6e
                             PlasticSkeleton &skeleton) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void updatePosition(const PlasticSkeleton &originalSkeleton,
Shinya Kitaoka 120a6e
                      PlasticSkeleton &deformedSkeleton, double frame, int v,
Shinya Kitaoka 120a6e
                      const TPointD &pos);
Shinya Kitaoka 120a6e
  void updateAngle(const PlasticSkeleton &originalSkeleton,
Shinya Kitaoka 120a6e
                   PlasticSkeleton &deformedSkeleton, double frame, int v,
Shinya Kitaoka 120a6e
                   const TPointD &pos);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 473e70
  void saveData(TOStream &os) override;
Shinya Kitaoka 473e70
  void loadData(TIStream &is) override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  friend class PlasticSkeleton;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void addVertex(
Shinya Kitaoka 120a6e
      PlasticSkeleton *sk,
Shinya Kitaoka 120a6e
      int v);  //!< Deals with vertex deformations when v has been added
Shinya Kitaoka 120a6e
  void insertVertex(PlasticSkeleton *sk, int v);  //!< Deals with vertex
Shinya Kitaoka 38fd86
                                                  //! deformations when v has
Shinya Kitaoka 38fd86
  //! been inserted in an edge
Shinya Kitaoka 120a6e
  void deleteVertex(
Shinya Kitaoka 120a6e
      PlasticSkeleton *sk,
Shinya Kitaoka 120a6e
      int v);  //!< Removes vertex deformation for v, \a before it is deleted
Shinya Kitaoka 120a6e
  void vertexNameChange(
Shinya Kitaoka 120a6e
      PlasticSkeleton *sk, int v,
Shinya Kitaoka 120a6e
      const QString &newName);      //!< Rebinds a vertex deformation name
Shinya Kitaoka 120a6e
  void clear(PlasticSkeleton *sk);  //!< Clears all vertex deformations
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void loadData_prerelease(
Shinya Kitaoka 120a6e
      TIStream &is);  // Toonz 7.0 pre-release loading function. Will be deleted
Shinya Kitaoka 120a6e
                      // in the next minor release.
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef PlasticSkeletonDeformation SkD;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
template class DVAPI TSmartPointerT<plasticskeletondeformation>;</plasticskeletondeformation>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef TSmartPointerT<plasticskeletondeformation> PlasticSkeletonDeformationP;</plasticskeletondeformation>
Toshihiro Shimizu 890ddd
typedef PlasticSkeletonDeformationP SkDP;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // PLASTICSKELETONDEFORMATION_H