|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzLib includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheet.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshcell.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/hook.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/dpiscale.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshsimplelevel.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/stage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/hook.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "xshhandlemanager.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Local namespace
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Returns the sum of each pass hook between fid and precFid.
|
|
Toshihiro Shimizu |
890ddd |
TPointD forwardPass(const TFrameId &fid, const TFrameId &precFid,
|
|
Shinya Kitaoka |
120a6e |
TXshSimpleLevel *sl, Hook *hook) {
|
|
Shinya Kitaoka |
120a6e |
TPointD delta;
|
|
Shinya Kitaoka |
120a6e |
std::vector<tframeid> levelFids;</tframeid>
|
|
Shinya Kitaoka |
120a6e |
sl->getFids(levelFids);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int f, fCount = levelFids.size();
|
|
Shinya Kitaoka |
120a6e |
for (f = 0; f != fCount; ++f) {
|
|
Shinya Kitaoka |
120a6e |
const TFrameId &levelFid = levelFids[f];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (levelFid < precFid) continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (levelFid >= fid) break;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (hook->isKeyframe(levelFid))
|
|
Shinya Kitaoka |
120a6e |
delta += hook->getAPos(levelFid) - hook->getBPos(levelFid);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return delta;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
// Returns subtraction of each pass hook between fid and precFid.
|
|
Toshihiro Shimizu |
890ddd |
TPointD backwardPass(const TFrameId &fid, const TFrameId &precFid,
|
|
Shinya Kitaoka |
120a6e |
TXshSimpleLevel *sl, Hook *hook) {
|
|
Shinya Kitaoka |
120a6e |
TPointD delta;
|
|
Shinya Kitaoka |
120a6e |
std::vector<tframeid> levelFids;</tframeid>
|
|
Shinya Kitaoka |
120a6e |
sl->getFids(levelFids);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int f, fCount = levelFids.size();
|
|
Shinya Kitaoka |
120a6e |
for (f = 0; f != fCount; ++f) {
|
|
Shinya Kitaoka |
120a6e |
const TFrameId &levelFid = levelFids[f];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (levelFid < fid) continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (levelFid >= precFid) break;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (hook->isKeyframe(levelFid))
|
|
Shinya Kitaoka |
120a6e |
delta -= hook->getAPos(levelFid) - hook->getBPos(levelFid);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return delta;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
// Compute pass hook between fid and precFid
|
|
Toshihiro Shimizu |
890ddd |
TPointD computePassHook(const TFrameId &fid, const TFrameId &precFid,
|
|
Shinya Kitaoka |
120a6e |
TXshSimpleLevel *sl, Hook *hook) {
|
|
Shinya Kitaoka |
120a6e |
if (fid < precFid && (precFid.getNumber() - fid.getNumber()) <= 2)
|
|
Shinya Kitaoka |
120a6e |
return backwardPass(fid, precFid, sl, hook);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return forwardPass(fid, precFid, sl, hook);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// XshHandleManager implementation
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TPointD XshHandleManager::getHandlePos(const TStageObjectId &id,
|
|
Shinya Kitaoka |
120a6e |
const std::string &handle,
|
|
Shinya Kitaoka |
120a6e |
int row) const {
|
|
Shinya Kitaoka |
120a6e |
static const double unit = 8.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
assert(m_xsh->getScene());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (handle == "")
|
|
Shinya Kitaoka |
120a6e |
return TPointD();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
else if (handle[0] == 'H' && handle.length() > 1) {
|
|
Shinya Kitaoka |
120a6e |
// Hook port case
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!id.isColumn()) return TPointD();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int hookIndex = 0;
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
int h, hLength = handle.length();
|
|
Shinya Kitaoka |
120a6e |
for (h = 1; h != hLength; ++h)
|
|
Shinya Kitaoka |
120a6e |
hookIndex = hookIndex * 10 + (handle[h] - '0');
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TStageObject *obj = m_xsh->getStageObject(id);
|
|
Shinya Kitaoka |
120a6e |
if (const PlasticSkeletonDeformationP &def =
|
|
Shinya Kitaoka |
120a6e |
obj->getPlasticSkeletonDeformation()) {
|
|
Shinya Kitaoka |
120a6e |
int skelId = def->skeletonId(row);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
PlasticSkeleton skel;
|
|
Shinya Kitaoka |
120a6e |
def->storeDeformedSkeleton(skelId, row, skel);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int v = def->vertexIndex(hookIndex, skelId);
|
|
Shinya Kitaoka |
120a6e |
return (v >= 0) ? TScale(1.0 / Stage::inch) * skel.vertex(v).P()
|
|
Shinya Kitaoka |
120a6e |
: TPointD();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
--hookIndex;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int col = id.getIndex();
|
|
Shinya Kitaoka |
120a6e |
TXshCell cell(m_xsh->getCell(row, col));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TXshLevel *xl = cell.m_level.getPointer();
|
|
Shinya Kitaoka |
120a6e |
if (!xl) return TPointD();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TXshSimpleLevel *sl = xl->getSimpleLevel();
|
|
Shinya Kitaoka |
120a6e |
if (!sl) return TPointD();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Hook *hook = sl->getHookSet()->getHook(hookIndex);
|
|
Shinya Kitaoka |
120a6e |
if (!hook) return TPointD();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TFrameId fid(cell.m_frameId);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TPointD pos = hook->getAPos(fid) * (1.0 / Stage::inch);
|
|
Shinya Kitaoka |
120a6e |
TPointD delta;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
for (int r = row - 1; r >= 0; --r) {
|
|
Shinya Kitaoka |
120a6e |
cell = m_xsh->getCell(r, col);
|
|
Shinya Kitaoka |
120a6e |
if (cell.m_level.getPointer() != xl) break;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
const TFrameId &precFid = cell.m_frameId;
|
|
Shinya Kitaoka |
120a6e |
delta += computePassHook(fid, precFid, sl, hook);
|
|
Shinya Kitaoka |
120a6e |
fid = precFid;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
pos += delta * (1.0 / Stage::inch);
|
|
Shinya Kitaoka |
120a6e |
pos = getDpiAffine(sl, cell.m_frameId, true) * pos;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return pos;
|
|
Shinya Kitaoka |
120a6e |
} else if ('A' <= handle[0] && handle[0] <= 'Z')
|
|
Shinya Kitaoka |
120a6e |
return TPointD(unit * (handle[0] - 'B'), 0);
|
|
Shinya Kitaoka |
120a6e |
else if ('a' <= handle[0] && handle[0] <= 'z')
|
|
Shinya Kitaoka |
120a6e |
return TPointD(0.5 * unit * (handle[0] - 'b'), 0);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return TPointD();
|
|
Toshihiro Shimizu |
890ddd |
}
|