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