update blobs

This commit is contained in:
2026-05-19 04:02:46 +02:00
parent c060be79e8
commit 3d2fc0a3b1
3 changed files with 35 additions and 36 deletions
+2
View File
@@ -85,6 +85,8 @@ void BlobGroup::markShapeDirty(BlobShape* source) {
const QRectF otherRect(static_cast<double>(shape->m_cachedPaddedX), static_cast<double>(shape->m_cachedPaddedY),
static_cast<double>(shape->m_cachedPaddedW), static_cast<double>(shape->m_cachedPaddedH));
if (srcRect.intersects(otherRect)) {
shape->setExpandedRect(srcRect);
shape->m_hasExpandedRect = true;
shape->polish();
shape->update();
}
+5 -21
View File
@@ -69,26 +69,6 @@ void BlobShape::geometryChange(const QRectF& newGeometry, const QRectF& oldGeome
QQuickItem::geometryChange(newGeometry, oldGeometry);
updateCenteredDeformMatrix();
if (m_group) {
// Update cached values so markShapeDirty uses current geometry
const QPointF scenePos = mapToScene(QPointF(0, 0));
if (isInvertedRect()) {
m_cachedPaddedX = static_cast<float>(scenePos.x());
m_cachedPaddedY = static_cast<float>(scenePos.y());
m_cachedPaddedW = static_cast<float>(width());
m_cachedPaddedH = static_cast<float>(height());
m_localPaddedRect = QRectF(0, 0, width(), height());
} else {
const float hw = static_cast<float>(width()) * 0.5f;
const float hh = static_cast<float>(height()) * 0.5f;
const float totalPad = static_cast<float>(m_group->smoothing()) + deformPadding(m_deformMatrix, hw, hh);
m_cachedPaddedX = static_cast<float>(scenePos.x()) - totalPad;
m_cachedPaddedY = static_cast<float>(scenePos.y()) - totalPad;
m_cachedPaddedW = static_cast<float>(width()) + 2.0f * totalPad;
m_cachedPaddedH = static_cast<float>(height()) + 2.0f * totalPad;
m_localPaddedRect = QRectF(static_cast<double>(-totalPad), static_cast<double>(-totalPad),
width() + 2.0 * static_cast<double>(totalPad), height() + 2.0 * static_cast<double>(totalPad));
}
// Accumulate sub-pixel drift so slow movements don't desync the shader
m_pendingDx += static_cast<float>(newGeometry.x() - oldGeometry.x());
m_pendingDy += static_cast<float>(newGeometry.y() - oldGeometry.y());
@@ -138,6 +118,8 @@ void BlobShape::updatePolish() {
if (!m_group)
return;
m_hasExpandedRect = false;
// Ensure all shapes have up-to-date physics (only once per frame)
m_group->ensurePhysicsUpdated();
@@ -186,9 +168,11 @@ void BlobShape::updatePolish() {
const QPointF otherScene = other->mapToScene(QPointF(0, 0));
bool include = false;
bool include = false;
if (isInvertedRect()) {
include = true;
} else if (m_hasExpandedRect) {
include = m_expandedRect.intersects(otherPadded);
} else {
const float otherHW = static_cast<float>(other->width()) * 0.5f;
const float otherHH = static_cast<float>(other->height()) * 0.5f;
+17 -4
View File
@@ -67,10 +67,20 @@ virtual void updatePhysics() {
}
virtual void registerWithGroup();
virtual void unregisterFromGroup();
void updateCenteredDeformMatrix();
virtual void unregisterFromGroup();
void updateCenteredDeformMatrix();
BlobGroup* m_group = nullptr;
void setExpandedRect(const QRectF& rect) {
m_expandedRect = rect;
}
const QRectF& expandedRect() const {
return m_expandedRect;
}
bool hasExpandedRect() const {
return m_hasExpandedRect;
}
BlobGroup* m_group = nullptr;
qreal m_radius = 0;
QMatrix4x4 m_deformMatrix; // identity by default
QMatrix4x4 m_centeredDeformMatrix;
@@ -88,5 +98,8 @@ float m_pendingDy = 0;
bool m_cachedHasInverted = false;
float m_cachedInvertedRadius = 0;
float m_cachedInvertedOuter[4] = {};
float m_cachedInvertedInner[4] = {};
float m_cachedInvertedInner[4] = {};
QRectF m_expandedRect;
bool m_hasExpandedRect = false;
};