From bf2c2e9bb2dd0b13cb2cb6728de0c2421fbafbb7 Mon Sep 17 00:00:00 2001 From: Jim Albamont Date: Wed, 13 Mar 2019 13:23:21 -0500 Subject: Fix Entity parenting hierarchy When the initial Entity backend node hierarchy is created it skips over any non-entity nodes to ensure that Entities are only parented to other Entities. Calling QNode::setParent breaks this when reparenting Entities to non-entity nodes. Fix by sending a new "parentEntityUpdated" property update that backend Entity nodes listen for. They keep the id of their new parent and flag the need to rebuild the entity hierarchy. This triggers a new job to clear the children and parents of every backend Entity, then rebuilds the hierarchy using the stored parent ID in each Entity. This is much more forgiving of creation/parenting ordering issues and shouldn't be less performant because any Entity reparent was previously marking everything dirty anyway. Add a new test from QTBUG-73905 that creates 4 cylinders and manipulates the parents in different ways. Add a new test to tst_nodes to reparent a QEntity to a QNode and ensure the entity finds it's correct QEntity parent. Add a new test to tst_entity to ensure backend nodes correctly handle the new parenting events. Task-number: QTBUG-73905 Change-Id: Iab0203947d89bbed2868b3629fbde879675fe568 Reviewed-by: Paul Lemire --- src/render/backend/entity_p.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/render/backend/entity_p.h') diff --git a/src/render/backend/entity_p.h b/src/render/backend/entity_p.h index 075871d85..afa7dbf23 100644 --- a/src/render/backend/entity_p.h +++ b/src/render/backend/entity_p.h @@ -97,6 +97,10 @@ public: HEntity handle() const { return m_handle; } Entity *parent() const; HEntity parentHandle() const { return m_parentHandle; } + Qt3DCore::QNodeId parentEntityId() const { return m_parentEntityId; } + + void clearEntityHierarchy(); + void rebuildEntityHierarchy(); void appendChildHandle(HEntity childHandle); void removeChildHandle(HEntity childHandle) { m_childrenHandles.removeOne(childHandle); } @@ -181,6 +185,8 @@ private: HEntity m_parentHandle; QVector m_childrenHandles; + Qt3DCore::QNodeId m_parentEntityId; + HMatrix m_worldTransform; QSharedPointer m_localBoundingVolume; QSharedPointer m_worldBoundingVolume; -- cgit v1.2.3