Skip to content

Commit

Permalink
add debug mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
tommego committed Sep 29, 2020
1 parent beff7f4 commit b628734
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
37 changes: 34 additions & 3 deletions spineplugin/spineitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 255,8 @@ QRectF SpineItem::computeBoundingRect()
{
if(!isSkeletonReady())
return QRectF();
float minX = FLT_MAX, minY = FLT_MAX, maxX = FLT_MIN, maxY = FLT_MIN;
float vminX = FLT_MAX, vminY = FLT_MAX, vmaxX = FLT_MIN, vmaxY = FLT_MIN;
float minX = FLT_MAX, minY = FLT_MAX, maxX = -FLT_MAX, maxY = -FLT_MAX;
float vminX = FLT_MAX, vminY = FLT_MAX, vmaxX = -FLT_MAX, vmaxY = -FLT_MAX;
for(int i = 0; i < m_skeleton->getSlots().size(); i ) {
auto slot = m_skeleton->getSlots()[i];
if(!slot->getAttachment())
Expand Down Expand Up @@ -523,7 523,7 @@ void SpineItem::batchRenderCmd()
m_clipper->clipEnd();

// debug drawing
if(m_debugBones || m_debugSlots) {
if(m_debugBones || m_debugSlots || m_debugMesh) {
m_renderCache->bindShader(RenderCmdsCache::ShaderColor);
m_renderCache->blendFunc(GL_ONE, GL_ZERO);

Expand All @@ -545,6 545,26 @@ void SpineItem::batchRenderCmd()
}
}

if(m_debugMesh) {
spine::Vector<Point> points;
m_renderCache->drawColor(40, 150, 200, 255);
for (size_t i = 0, n = m_skeleton->getSlots().size(); i < n; i ) {
auto slot = m_skeleton->getSlots()[i];
if(!slot->getAttachment() || !slot->getAttachment()->getRTTI().isExactly(spine::MeshAttachment::rtti))
continue;
auto* mesh = (spine::MeshAttachment*)slot->getAttachment();
size_t numVertices = mesh->getWorldVerticesLength() / 2;
points.setSize(numVertices, Point());
mesh->computeWorldVertices(*slot,
0,
mesh->getWorldVerticesLength(),
(float*)points.buffer(),
0,
sizeof (Point) / sizeof (float));
m_renderCache->drawPoly(points.buffer(), points.size());
}
}

if(m_debugBones) {
m_renderCache->drawColor(200, 150, 40, 255);
m_renderCache->lineWidth(2);
Expand Down Expand Up @@ -574,6 863,17 @@ void SpineItem::renderToCache(QQuickFramebufferObject::Renderer *renderer)
Q_UNUSED(renderer)
}

bool SpineItem::debugMesh() const
{
return m_debugMesh;
}

void SpineItem::setDebugMesh(bool debugMesh)
{
m_debugMesh = debugMesh;
emit debugMeshChanged(m_debugMesh);
}

int SpineItem::blendColorChannel() const
{
return m_blendColorChannel;
Expand Down
6 changes: 6 additions & 0 deletions spineplugin/spineitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 48,7 @@ class SpineItem : public QQuickFramebufferObject
Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
Q_PROPERTY(bool debugBones READ debugBones WRITE setDebugBones NOTIFY debugBonesChanged)
Q_PROPERTY(bool debugSlots READ debugSlots WRITE setDebugSlots NOTIFY debugSlotsChanged)
Q_PROPERTY(bool debugMesh READ debugMesh WRITE setDebugMesh NOTIFY debugMeshChanged)
Q_PROPERTY(QStringList animations READ animations NOTIFY animationsChanged)
Q_PROPERTY(QStringList skins READ skins NOTIFY skinsChanged)
Q_PROPERTY(qreal skeletonScale READ skeletonScale WRITE setSkeletonScale NOTIFY skeletonScaleChanged)
Expand Down Expand Up @@ -180,6 181,9 @@ class SpineItem : public QQuickFramebufferObject
int blendColorChannel() const;
void setBlendColorChannel(int blendColorChannel);

bool debugMesh() const;
void setDebugMesh(bool debugMesh);

signals:

// property signals
Expand All @@ -191,6 195,7 @@ class SpineItem : public QQuickFramebufferObject
void premultipliedAlphaChanged(const bool& ret);
void debugBonesChanged(const bool& ret);
void debugSlotsChanged(const bool& ret);
void debugMeshChanged(const bool& ret);
void animationsChanged(const QStringList& animations);
void skinsChanged(const QStringList& skins);
void skeletonScaleChanged(const qreal& scale);
Expand Down Expand Up @@ -238,6 243,7 @@ private slots:
bool m_loaded = false;
bool m_debugBones = false;
bool m_debugSlots = false;
bool m_debugMesh = false;
bool m_isLoading = false;
bool m_hasViewPort = false;
qreal m_scaleX = 1.0;
Expand Down

0 comments on commit b628734

Please sign in to comment.