tahoma2d/toonz/sources/toonzlib/plasticdeformerfx.cpp

524 lines
16 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "toonz/plasticdeformerfx.h"
// TnzLib includes
#include "toonz/txsheet.h"
#include "toonz/txshleveltypes.h"
#include "toonz/txshcell.h"
#include "toonz/tcolumnfx.h"
#include "toonz/txshlevelcolumn.h"
#include "toonz/dpiscale.h"
#include "toonz/stage.h"
#include "toonz/preferences.h"
2016-03-19 06:57:51 +13:00
// TnzExt includes
#include "ext/plasticskeleton.h"
#include "ext/plasticdeformerstorage.h"
#include "ext/ttexturesstorage.h"
#include "ext/plasticvisualsettings.h"
#include "ext/meshutils.h"
// TnzBase includes
#include "trenderer.h"
// TnzCore includes
#include "tgl.h"
#include "tofflinegl.h"
#include "tgldisplaylistsmanager.h"
#include "tconvert.h"
#include "trop.h"
2018-01-23 19:08:50 +13:00
#include <QOpenGLFramebufferObject>
2018-01-12 20:00:36 +13:00
#include <QOffscreenSurface>
#include <QSurfaceFormat>
#include <QOpenGLContext>
#include <QImage>
2016-03-19 06:57:51 +13:00
FX_IDENTIFIER_IS_HIDDEN(PlasticDeformerFx, "plasticDeformerFx")
//***************************************************************************************************
// Local namespace
//***************************************************************************************************
2016-06-15 18:43:10 +12:00
namespace {
std::string toString(const TAffine &aff) {
return
// Observe that toString distinguishes + and - 0. That is a problem
// when comparing aliases - so near 0 values are explicitly rounded to 0.
(areAlmostEqual(aff.a11, 0.0) ? "0" : ::to_string(aff.a11, 5)) + "," +
(areAlmostEqual(aff.a12, 0.0) ? "0" : ::to_string(aff.a12, 5)) + "," +
(areAlmostEqual(aff.a13, 0.0) ? "0" : ::to_string(aff.a13, 5)) + "," +
(areAlmostEqual(aff.a21, 0.0) ? "0" : ::to_string(aff.a21, 5)) + "," +
(areAlmostEqual(aff.a22, 0.0) ? "0" : ::to_string(aff.a22, 5)) + "," +
(areAlmostEqual(aff.a23, 0.0) ? "0" : ::to_string(aff.a23, 5));
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
std::string toString(SkVD *vd, double sdFrame) {
std::string result;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
for (int p = 0; p < SkVD::PARAMS_COUNT; ++p)
result += ::to_string(vd->m_params[p]->getValue(sdFrame), 5) + " ";
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return result;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
std::string toString(const PlasticSkeleton::vertex_type &vx) {
// TODO: Add z and rigidity
return ::to_string(vx.P().x, 5) + " " + ::to_string(vx.P().y, 5);
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
std::string toString(const PlasticSkeletonDeformationP &sd, double sdFrame) {
std::string result;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const PlasticSkeletonP &skeleton = sd->skeleton(sdFrame);
if (!skeleton || skeleton->empty()) return result;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const tcg::list<PlasticSkeleton::vertex_type> &vertices =
skeleton->vertices();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
tcg::list<PlasticSkeleton::vertex_type>::const_iterator vt,
vEnd(vertices.end());
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
result = toString(*vertices.begin());
for (vt = vertices.begin(); vt != vEnd; ++vt) {
result += "; " + toString(*vt);
result += " " + toString(sd->vertexDeformation(vt->name()), sdFrame);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return result;
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
} // namespace
2016-03-19 06:57:51 +13:00
//***************************************************************************************************
// PlasticDeformerFx implementation
//***************************************************************************************************
2016-06-15 18:43:10 +12:00
PlasticDeformerFx::PlasticDeformerFx() : TRasterFx() {
addInputPort("source", m_port);
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TFx *PlasticDeformerFx::clone(bool recursive) const {
PlasticDeformerFx *fx =
dynamic_cast<PlasticDeformerFx *>(TFx::clone(recursive));
assert(fx);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
fx->m_xsh = m_xsh;
fx->m_col = m_col;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return fx;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
bool PlasticDeformerFx::canHandle(const TRenderSettings &info, double frame) {
// Yep. Affines are handled. Well - it's easy, since OpenGL lets you do that
// directly
// with a glPushMatrix...
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return true;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
std::string PlasticDeformerFx::getAlias(double frame,
const TRenderSettings &info) const {
std::string alias(getFxType());
alias += "[";
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (m_port.isConnected()) {
TRasterFxP ifx = m_port.getFx();
assert(ifx);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
alias += ifx->getAlias(frame, info);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TStageObject *meshColumnObj =
m_xsh->getStageObject(TStageObjectId::ColumnId(m_col));
const PlasticSkeletonDeformationP &sd =
meshColumnObj->getPlasticSkeletonDeformation();
if (sd) alias += ", " + toString(sd, meshColumnObj->paramsTime(frame));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
alias + "]";
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return alias;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
bool PlasticDeformerFx::doGetBBox(double frame, TRectD &bbox,
const TRenderSettings &info) {
if (!m_port.isConnected()) return false;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// It's hard work to calculate the bounding box of a plastic deformation.
// Decline.
bbox = TConsts::infiniteRectD;
return true;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void PlasticDeformerFx::buildRenderSettings(double frame,
TRenderSettings &info) {
// As previously pointed out, this fx is able to handle affines. We can,
// actually, *decide*
// the input reference to work with.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// So, the best choice is to let the *input fx* decide the appropriate
// reference, by invoking
// its handledAffine() method.
2020-10-08 17:26:39 +13:00
m_was64bit = false;
if (info.m_bpp == 64) {
m_was64bit = true;
info.m_bpp = 32; // We need to fix the input to 32-bpp
}
2016-06-15 18:43:10 +12:00
info.m_affine = m_port->handledAffine(info, frame);
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
bool PlasticDeformerFx::buildTextureDataSl(double frame, TRenderSettings &info,
TAffine &worldLevelToLevelAff) {
int row = (int)frame;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Initialize level vars
TLevelColumnFx *lcfx = (TLevelColumnFx *)m_port.getFx();
TXshLevelColumn *texColumn = lcfx->getColumn();
2016-03-19 06:57:51 +13:00
TXshCell texCell = texColumn->getCell(row);
if (texCell.isEmpty() && Preferences::instance()->isImplicitHoldEnabled()) {
int r0, r1;
texColumn->getRange(r0, r1);
for (int r = std::min(r1, (int)frame); r >= r0; r--) {
texCell = texColumn->getCell(r);
if (texCell.isEmpty()) continue;
break;
}
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TXshSimpleLevel *texSl = texCell.getSimpleLevel();
const TFrameId &texFid = texCell.getFrameId();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (!texSl || texSl->getType() == MESH_XSHLEVEL) return false;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Build dpi data
TPointD texDpi(texSl->getDpi(texFid, 0));
if (texDpi.x == 0.0 || texDpi.y == 0.0 || texSl->getType() == PLI_XSHLEVEL)
texDpi.x = texDpi.y = Stage::inch;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Build reference transforms data
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// NOTE: TAffine() corresponds to IMAGE coordinates here, not WORLD
// coordinates. This is achieved
// by removing the level's dpi affine during render-tree build-up (see
// scenefx.cpp).
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
worldLevelToLevelAff = TScale(texDpi.x / Stage::inch, texDpi.y / Stage::inch);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Initialize input render settings
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// In the case of vector images, in order to retain the image quality required
// by info.m_affine,
// the scale component is allowed too.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// In the raster image case, we'll use the original image reference IF the
// affine is a magnification
// (ie the scale is > 1.0) - OTHERWISE, the OpenGL minification filter is too
// crude since it renders
// a fragment using its 4 adjacent pixels ONLY; in this case, we'll pass the
// affine below.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const TAffine &handledAff = TRasterFx::handledAffine(info, frame);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (texSl->getType() == PLI_XSHLEVEL) {
info.m_affine = handledAff;
buildRenderSettings(frame, info);
} else {
info.m_affine = TAffine();
buildRenderSettings(frame, info);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// NOTE: scale = handledAff.a11 / worldLevelToLevelAff.a11
if (handledAff.a11 < worldLevelToLevelAff.a11)
info.m_affine =
TScale(handledAff.a11 / worldLevelToLevelAff.a11) * info.m_affine;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return true;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
bool PlasticDeformerFx::buildTextureData(double frame, TRenderSettings &info,
TAffine &worldLevelToLevelAff) {
// Common case (typically happen with sub-xsheets)
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
buildRenderSettings(frame, info); // Adjust the info
worldLevelToLevelAff = TAffine(); // Reference match
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return true;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void PlasticDeformerFx::doCompute(TTile &tile, double frame,
const TRenderSettings &info) {
if (!m_port.isConnected()) {
tile.getRaster()->clear();
return;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int row = (int)frame;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Build texture data
TRenderSettings texInfo(info);
TAffine worldTexLevelToTexLevelAff;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (dynamic_cast<TLevelColumnFx *>(m_port.getFx())) {
if (!buildTextureDataSl(frame, texInfo, worldTexLevelToTexLevelAff)) return;
} else
buildTextureData(frame, texInfo, worldTexLevelToTexLevelAff);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Initialize mesh level vars
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const TXshCell &meshCell = m_xsh->getCell(row, m_col);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TXshSimpleLevel *meshSl = meshCell.getSimpleLevel();
const TFrameId &meshFid = meshCell.getFrameId();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (!meshSl || meshSl->getType() != MESH_XSHLEVEL) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Retrieve mesh image and deformation
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TStageObject *meshColumnObj =
m_xsh->getStageObject(TStageObjectId::ColumnId(m_col));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TMeshImageP mi(meshSl->getFrame(meshFid, false));
if (!mi) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Retrieve deformation data
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const PlasticSkeletonDeformationP &sd =
meshColumnObj->getPlasticSkeletonDeformation();
assert(sd);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
double sdFrame = meshColumnObj->paramsTime(frame);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Build dpi data
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPointD meshDpi(meshSl->getDpi(meshFid, 0));
assert(meshDpi.x != 0.0 && meshDpi.y != 0.0);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Build reference transforms data
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Build affines
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const TAffine &imageToTextureAff = texInfo.m_affine;
const TAffine &worldTexLevelToWorldMeshAff = m_texPlacement;
const TAffine &meshToWorldMeshAff =
TScale(Stage::inch / meshDpi.x, Stage::inch / meshDpi.y);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const TAffine &meshToTexLevelAff = worldTexLevelToTexLevelAff *
worldTexLevelToWorldMeshAff.inv() *
meshToWorldMeshAff;
const TAffine &meshToTextureAff = imageToTextureAff * meshToTexLevelAff;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Retrieve deformer data
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TScale worldMeshToMeshAff(meshDpi.x / Stage::inch, meshDpi.y / Stage::inch);
2016-03-19 06:57:51 +13:00
std::unique_ptr<const PlasticDeformerDataGroup> dataGroup(
2016-06-15 18:43:10 +12:00
PlasticDeformerStorage::instance()->processOnce(
sdFrame, mi.getPointer(), sd.getPointer(), sd->skeletonId(sdFrame),
worldMeshToMeshAff));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Build texture
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Build the mesh's bounding box and map it to input reference
TRectD meshBBox(meshToTextureAff * mi->getBBox());
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Now, build the tile's geometry
TRectD texBBox;
m_port->getBBox(frame, texBBox, texInfo);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRectD bbox = texBBox * meshBBox;
if (bbox.getLx() <= 0.0 || bbox.getLy() <= 0.0) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bbox.x0 = tfloor(bbox.x0);
bbox.y0 = tfloor(bbox.y0);
bbox.x1 = tceil(bbox.x1);
bbox.y1 = tceil(bbox.y1);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TDimension tileSize(tround(bbox.getLx()), tround(bbox.getLy()));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Then, compute the input image
TTile inTile;
m_port->allocateAndCompute(inTile, bbox.getP00(), tileSize, TRasterP(), frame,
texInfo);
2018-01-12 20:00:36 +13:00
QOpenGLContext *context;
2016-06-15 18:43:10 +12:00
// Draw the textured mesh
{
// Prepare texture
TRaster32P tex(inTile.getRaster());
TRop::depremultiply(tex); // Textures must be stored depremultiplied.
// See docs about the tglDraw() below.
static TAtomicVar var;
const std::string &texId = "render_tex " + std::to_string(++var);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Prepare an OpenGL context
2018-01-12 20:00:36 +13:00
context = new QOpenGLContext();
2018-03-06 16:52:40 +13:00
if (QOpenGLContext::currentContext())
context->setShareContext(QOpenGLContext::currentContext());
2018-01-12 20:00:36 +13:00
context->setFormat(QSurfaceFormat::defaultFormat());
context->create();
context->makeCurrent(info.m_offScreenSurface.get());
TDimension d = tile.getRaster()->getSize();
QOpenGLFramebufferObject fb(d.lx, d.ly);
fb.bind();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Load texture into the context
TTexturesStorage *ts = TTexturesStorage::instance();
const DrawableTextureDataP &texData = ts->loadTexture(texId, tex, bbox);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Draw
2018-01-12 20:00:36 +13:00
glViewport(0, 0, d.lx, d.ly);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, d.lx, 0, d.ly);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
2016-06-15 18:43:10 +12:00
tglMultMatrix(TTranslation(-tile.m_pos) * info.m_affine *
meshToWorldMeshAff);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
tglDraw(*mi, *texData, meshToTextureAff, *dataGroup);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Retrieve drawing and copy to output tile
2016-03-19 06:57:51 +13:00
2018-01-12 20:00:36 +13:00
QImage img = fb.toImage().scaled(QSize(d.lx, d.ly), Qt::IgnoreAspectRatio,
Qt::SmoothTransformation);
int wrap = tile.getRaster()->getLx() * sizeof(TPixel32);
2020-10-08 17:26:39 +13:00
if (!m_was64bit) {
uchar *srcPix = img.bits();
uchar *dstPix = tile.getRaster()->getRawData() + wrap * (d.ly - 1);
for (int y = 0; y < d.ly; y++) {
memcpy(dstPix, srcPix, wrap);
dstPix -= wrap;
srcPix += wrap;
}
}
else if (m_was64bit) {
TRaster64P newRaster(tile.getRaster()->getSize());
TRaster32P tempRaster(tile.getRaster()->getSize());
uchar *srcPix = img.bits();
uchar *dstPix = tempRaster.getPointer()->getRawData() + wrap * (d.ly - 1);
for (int y = 0; y < d.ly; y++) {
memcpy(dstPix, srcPix, wrap);
dstPix -= wrap;
srcPix += wrap;
}
TRop::convert(newRaster, tempRaster);
int size = tile.getRaster()->getLx() * tile.getRaster()->getLy() * sizeof(TPixel64);
srcPix = newRaster.getPointer()->getRawData();
dstPix = tile.getRaster()->getRawData();
memcpy(dstPix, srcPix, size);
texInfo.m_bpp = 64;
2018-01-12 20:00:36 +13:00
}
2020-10-08 17:26:39 +13:00
2018-01-12 20:00:36 +13:00
fb.release();
// context->getRaster(tile.getRaster());
glFlush();
glFinish();
2016-06-15 18:43:10 +12:00
// Cleanup
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// No need to disable stuff - the context dies here
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// ts->unloadTexture(texId); // Auto-released
// due to display list destruction
2018-01-12 20:00:36 +13:00
context->deleteLater();
// context->doneCurrent();
2016-06-15 18:43:10 +12:00
}
2018-01-12 20:00:36 +13:00
assert(glGetError() == GL_NO_ERROR);
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void PlasticDeformerFx::doDryCompute(TRectD &rect, double frame,
const TRenderSettings &info) {
if (!m_port.isConnected()) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int row = (int)frame;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRenderSettings texInfo(info);
TAffine worldTexLevelToTexLevelAff;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (dynamic_cast<TLevelColumnFx *>(m_port.getFx())) {
if (!buildTextureDataSl(frame, texInfo, worldTexLevelToTexLevelAff)) return;
} else
buildTextureData(frame, texInfo, worldTexLevelToTexLevelAff);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const TXshCell &meshCell = m_xsh->getCell(row, m_col);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TXshSimpleLevel *meshSl = meshCell.getSimpleLevel();
const TFrameId &meshFid = meshCell.getFrameId();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (!meshSl || meshSl->getType() == MESH_XSHLEVEL) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TStageObject *meshColumnObj =
m_xsh->getStageObject(TStageObjectId::ColumnId(m_col));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TMeshImageP mi(meshSl->getFrame(meshFid, false));
if (!mi) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const PlasticSkeletonDeformationP &sd =
meshColumnObj->getPlasticSkeletonDeformation();
assert(sd);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPointD meshDpi(meshSl->getDpi(meshFid, 0));
assert(meshDpi.x != 0.0 && meshDpi.y != 0.0);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const TAffine &textureToImageAff = texInfo.m_affine;
const TAffine &worldImageToWorldMeshAff = m_texPlacement;
const TAffine &meshToWorldMeshAff =
TScale(Stage::inch / meshDpi.x, Stage::inch / meshDpi.y);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const TAffine &meshToTextureAff =
textureToImageAff.inv() * worldTexLevelToTexLevelAff *
worldImageToWorldMeshAff.inv() * meshToWorldMeshAff;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Build the mesh's bounding box and map it to input reference
TRectD meshBBox(meshToTextureAff * mi->getBBox());
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Now, build the tile's geometry
TRectD texBBox;
m_port->getBBox(frame, texBBox, texInfo);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRectD bbox = texBBox * meshBBox;
if (bbox.getLx() <= 0.0 || bbox.getLy() <= 0.0) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bbox.x0 = tfloor(bbox.x0);
bbox.y0 = tfloor(bbox.y0);
bbox.x1 = tceil(bbox.x1);
bbox.y1 = tceil(bbox.y1);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_port->dryCompute(bbox, frame, texInfo);
2016-03-19 06:57:51 +13:00
}