summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Render/Q3DSTranslators.cpp
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2019-03-08 16:15:29 +0200
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2019-03-20 08:48:32 +0000
commit961f7e783670be0627ddb21c1379ebfec0c3c944 (patch)
tree1e0f2ea839868d7333fdd1ddcd0b3e0141948875 /src/Authoring/Studio/Render/Q3DSTranslators.cpp
parentae044e6ee37b228e109b19c7c13be5c260c0bb64 (diff)
Improve scene translation push efficiencywip/runtime2
There is no need to remove all scene content and recreate the layers every time anything changes in the scene. Change-Id: I16d9401f1977d5bcc4ac27d864800eb1db1d972e Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Antti Määttä <antti.maatta@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'src/Authoring/Studio/Render/Q3DSTranslators.cpp')
-rw-r--r--src/Authoring/Studio/Render/Q3DSTranslators.cpp67
1 files changed, 60 insertions, 7 deletions
diff --git a/src/Authoring/Studio/Render/Q3DSTranslators.cpp b/src/Authoring/Studio/Render/Q3DSTranslators.cpp
index 752caffb..2db4a74a 100644
--- a/src/Authoring/Studio/Render/Q3DSTranslators.cpp
+++ b/src/Authoring/Studio/Render/Q3DSTranslators.cpp
@@ -815,16 +815,69 @@ void Q3DSSceneTranslator::pushTranslation(Q3DSTranslation &inContext)
Q3DSTranslatorDataModelParser theParser(inContext, instanceHandle());
Q3DSPropertyChangeList list;
ITERATE_Q3DS_SCENE_PROPERTIES
- theItem.removeAllChildNodes();
- int childCount = inContext.assetGraph().GetChildCount(instanceHandle());
+
+ // Check if there are any changes to layer children
+ // First collect a set of existing child objects of the scene, excluding helper layers
+ int oldChildCount = theItem.childCount();
+ QVector<Q3DSGraphObject *> oldChildren;
+ oldChildren.reserve(oldChildCount);
+ for (int i = 0; i < oldChildCount; ++i) {
+ Q3DSGraphObject *obj = theItem.childAtIndex(i);
+ if (!inContext.isHelperLayer(obj))
+ oldChildren << obj;
+ }
+ oldChildCount = oldChildren.size();
+
+ // Collect current children in asset graph
+ int newChildCount = inContext.assetGraph().GetChildCount(instanceHandle());
QVector<Q3DSGraphObjectTranslator *> translators;
- for (long idx = 0; idx < childCount; ++idx) {
- qt3dsdm::Qt3DSDMInstanceHandle child =
- inContext.assetGraph().GetChild(instanceHandle(), idx);
+ translators.reserve(newChildCount);
+ QVector<Q3DSGraphObject *> newChildren;
+ newChildren.reserve(newChildCount);
+ for (long i = 0; i < newChildCount; ++i) {
+ qt3dsdm::Qt3DSDMInstanceHandle child
+ = inContext.assetGraph().GetChild(instanceHandle(), i);
Q3DSGraphObjectTranslator *translator = inContext.getOrCreateTranslator(child);
- theItem.appendChildNode(&translator->graphObject());
- translators << translator;
+ if (translator) { // Script items do not get translators
+ translators << translator;
+ newChildren << &translator->graphObject();
+ }
+ }
+
+ // Remove nodes that have been reordered
+ newChildCount = newChildren.size();
+ for (int newIdx = 0, oldIdx = 0; newIdx < newChildCount && oldIdx < oldChildCount;) {
+ auto newChild = newChildren[newIdx];
+ auto oldChild = oldChildren[oldIdx];
+ if (!oldChildren.contains(newChild)) {
+ ++newIdx;
+ } else {
+ if (oldChild != newChild) {
+ theItem.removeChildNode(oldChild);
+ ++oldIdx;
+ } else {
+ ++oldIdx;
+ ++newIdx;
+ }
+ }
}
+
+ // Now insert new and moved nodes back to correct positions
+ Q3DSGraphObject *nextChild = theItem.firstChild();
+ while (nextChild && inContext.isHelperLayer(nextChild))
+ nextChild = nextChild->nextSibling();
+ for (int newIdx = 0; newIdx < newChildCount; ++newIdx) {
+ auto child = newChildren[newIdx];
+ if (nextChild != child) {
+ if (!nextChild)
+ theItem.appendChildNode(child);
+ else
+ theItem.insertChildNodeBefore(child, nextChild);
+ } else if (nextChild) {
+ nextChild = nextChild->nextSibling();
+ }
+ }
+
theItem.resolveReferences(*inContext.presentation());
for (auto t : qAsConst(translators))
t->pushTranslationIfDirty(inContext);