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
+16 -32
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,18 +168,20 @@ void BlobShape::updatePolish() {
const QPointF otherScene = other->mapToScene(QPointF(0, 0));
bool include = false;
if (isInvertedRect()) {
include = true;
} else {
const float otherHW = static_cast<float>(other->width()) * 0.5f;
const float otherHH = static_cast<float>(other->height()) * 0.5f;
const float otherPad = pad + deformPadding(other->m_deformMatrix, otherHW, otherHH);
const QRectF otherPadded(otherScene.x() - static_cast<double>(otherPad),
otherScene.y() - static_cast<double>(otherPad), other->width() + 2.0 * static_cast<double>(otherPad),
other->height() + 2.0 * static_cast<double>(otherPad));
include = myPadded.intersects(otherPadded);
}
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;
const float otherPad = pad + deformPadding(other->m_deformMatrix, otherHW, otherHH);
const QRectF otherPadded(otherScene.x() - static_cast<double>(otherPad),
otherScene.y() - static_cast<double>(otherPad), other->width() + 2.0 * static_cast<double>(otherPad),
other->height() + 2.0 * static_cast<double>(otherPad));
include = myPadded.intersects(otherPadded);
}
if (include) {
if (other == this)