mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 02:27:48 +02:00
remap IDs when importing entities
This commit is contained in:
parent
f0fb9966ad
commit
3cc423ca03
5 changed files with 72 additions and 0 deletions
|
@ -2480,6 +2480,7 @@ bool Application::importEntities(const QString& urlOrFilename) {
|
||||||
|
|
||||||
bool success = _entityClipboard->readFromURL(url.toString());
|
bool success = _entityClipboard->readFromURL(url.toString());
|
||||||
if (success) {
|
if (success) {
|
||||||
|
_entityClipboard->remapIDs();
|
||||||
_entityClipboard->reaverageOctreeElements();
|
_entityClipboard->reaverageOctreeElements();
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "EntitiesLogging.h"
|
#include "EntitiesLogging.h"
|
||||||
#include "RecurseOctreeToMapOperator.h"
|
#include "RecurseOctreeToMapOperator.h"
|
||||||
#include "LogHandler.h"
|
#include "LogHandler.h"
|
||||||
|
#include "RemapIDOperator.h"
|
||||||
|
|
||||||
static const quint64 DELETED_ENTITIES_EXTRA_USECS_TO_CONSIDER = USECS_PER_MSEC * 50;
|
static const quint64 DELETED_ENTITIES_EXTRA_USECS_TO_CONSIDER = USECS_PER_MSEC * 50;
|
||||||
|
|
||||||
|
@ -1194,6 +1195,11 @@ bool EntityTree::sendEntitiesOperation(OctreeElementPointer element, void* extra
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityTree::remapIDs() {
|
||||||
|
RemapIDOperator theOperator;
|
||||||
|
recurseTreeWithOperator(&theOperator);
|
||||||
|
}
|
||||||
|
|
||||||
bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElementPointer element, bool skipDefaultValues) {
|
bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElementPointer element, bool skipDefaultValues) {
|
||||||
if (! entityDescription.contains("Entities")) {
|
if (! entityDescription.contains("Entities")) {
|
||||||
entityDescription["Entities"] = QVariantList();
|
entityDescription["Entities"] = QVariantList();
|
||||||
|
|
|
@ -196,6 +196,8 @@ public:
|
||||||
bool wantTerseEditLogging() const { return _wantTerseEditLogging; }
|
bool wantTerseEditLogging() const { return _wantTerseEditLogging; }
|
||||||
void setWantTerseEditLogging(bool value) { _wantTerseEditLogging = value; }
|
void setWantTerseEditLogging(bool value) { _wantTerseEditLogging = value; }
|
||||||
|
|
||||||
|
void remapIDs();
|
||||||
|
|
||||||
bool writeToMap(QVariantMap& entityDescription, OctreeElementPointer element, bool skipDefaultValues);
|
bool writeToMap(QVariantMap& entityDescription, OctreeElementPointer element, bool skipDefaultValues);
|
||||||
bool readFromMap(QVariantMap& entityDescription);
|
bool readFromMap(QVariantMap& entityDescription);
|
||||||
|
|
||||||
|
|
33
libraries/entities/src/RemapIDOperator.cpp
Normal file
33
libraries/entities/src/RemapIDOperator.cpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
//
|
||||||
|
// RemapIDOperator.cpp
|
||||||
|
// libraries/entities/src
|
||||||
|
//
|
||||||
|
// Created by Seth Alves on 2015-12-6.
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#include "EntityTree.h"
|
||||||
|
#include "RemapIDOperator.h"
|
||||||
|
|
||||||
|
QUuid RemapIDOperator::remap(const QUuid& oldID) {
|
||||||
|
if (oldID.isNull()) {
|
||||||
|
return oldID;
|
||||||
|
}
|
||||||
|
if (!_oldToNew.contains(oldID)) {
|
||||||
|
_oldToNew[oldID] = QUuid::createUuid();
|
||||||
|
}
|
||||||
|
return _oldToNew[oldID];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RemapIDOperator::postRecursion(OctreeElementPointer element) {
|
||||||
|
EntityTreeElementPointer entityTreeElement = std::static_pointer_cast<EntityTreeElement>(element);
|
||||||
|
entityTreeElement->forEachEntity([&](EntityItemPointer entityItem) {
|
||||||
|
entityItem->setID(remap(entityItem->getID()));
|
||||||
|
entityItem->setParentID(remap(entityItem->getParentID()));
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
30
libraries/entities/src/RemapIDOperator.h
Normal file
30
libraries/entities/src/RemapIDOperator.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
//
|
||||||
|
// RemapIDOperator.h
|
||||||
|
// libraries/entities/src
|
||||||
|
//
|
||||||
|
// Created by Seth Alves on 2015-12-6.
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_RemapIDOperator_h
|
||||||
|
#define hifi_RemapIDOperator_h
|
||||||
|
|
||||||
|
#include "Octree.h"
|
||||||
|
|
||||||
|
// this will change all the IDs in an EntityTree. Parent/Child relationships are maintained.
|
||||||
|
|
||||||
|
class RemapIDOperator : public RecurseOctreeOperator {
|
||||||
|
public:
|
||||||
|
RemapIDOperator() : RecurseOctreeOperator() {}
|
||||||
|
~RemapIDOperator() {}
|
||||||
|
virtual bool preRecursion(OctreeElementPointer element) { return true; }
|
||||||
|
virtual bool postRecursion(OctreeElementPointer element);
|
||||||
|
private:
|
||||||
|
QUuid remap(const QUuid& oldID);
|
||||||
|
QHash<QUuid, QUuid> _oldToNew;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_RemapIDOperator_h
|
Loading…
Reference in a new issue