This commit is contained in:
howard-stearns 2016-03-29 16:17:19 -07:00
parent bcb729eac2
commit 4ebf816166
3 changed files with 21 additions and 52 deletions

View file

@ -2791,19 +2791,7 @@ void Application::calibrateEyeTracker5Points() {
} }
#endif #endif
bool Application::exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs) { bool Application::exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs, const glm::vec3* givenOffset) {
/* class EntityDatum { // For parent-first sorting and mapping.
public:
EntityItemPointer item;
EntityItemProperties properties;
EntityItemID originalParentID;
EntityItemID mappedID;
EntityDatum() {};
EntityDatum(EntityItemPointer itemArg, EntityItemProperties propertiesArg, EntityItemID parentID) :
item(itemArg), properties(propertiesArg), originalParentID(parentID) {
};
};
QHash<EntityItemID, EntityDatum> entities;*/
QHash<EntityItemID, EntityItemPointer> entities; QHash<EntityItemID, EntityItemPointer> entities;
auto entityTree = getEntities()->getTree(); auto entityTree = getEntities()->getTree();
@ -2818,6 +2806,7 @@ bool Application::exportEntities(const QString& filename, const QVector<EntityIt
continue; continue;
} }
if (!givenOffset) {
EntityItemID parentID = entityItem->getParentID(); EntityItemID parentID = entityItem->getParentID();
if (parentID.isInvalidID() || !entityIDs.contains(parentID) || !entityTree->findEntityByEntityItemID(parentID)) { if (parentID.isInvalidID() || !entityIDs.contains(parentID) || !entityTree->findEntityByEntityItemID(parentID)) {
auto position = entityItem->getPosition(); // If parent wasn't selected, we want absolute position, which isn't in properties. auto position = entityItem->getPosition(); // If parent wasn't selected, we want absolute position, which isn't in properties.
@ -2825,14 +2814,17 @@ bool Application::exportEntities(const QString& filename, const QVector<EntityIt
root.y = glm::min(root.y, position.y); root.y = glm::min(root.y, position.y);
root.z = glm::min(root.z, position.z); root.z = glm::min(root.z, position.z);
} }
entities[entityID] = entityItem; // EntityDatum(entityItem, entityItem->getProperties(), parentID); }
entities[entityID] = entityItem;
} }
if (entities.size() == 0) { if (entities.size() == 0) {
return false; return false;
} }
//for (EntityDatum& entityDatum : entities) { if (givenOffset) {
root = *givenOffset;
}
for (EntityItemPointer& entityDatum : entities) { for (EntityItemPointer& entityDatum : entities) {
auto properties = entityDatum->getProperties(); auto properties = entityDatum->getProperties();
EntityItemID parentID = properties.getParentID(); EntityItemID parentID = properties.getParentID();
@ -2852,33 +2844,14 @@ bool Application::exportEntities(const QString& filename, const QVector<EntityIt
} }
bool Application::exportEntities(const QString& filename, float x, float y, float z, float scale) { bool Application::exportEntities(const QString& filename, float x, float y, float z, float scale) {
glm::vec3 offset(x, y, z);
QVector<EntityItemPointer> entities; QVector<EntityItemPointer> entities;
getEntities()->getTree()->findEntities(AACube(glm::vec3(x, y, z), scale), entities); QVector<EntityItemID> ids;
getEntities()->getTree()->findEntities(AACube(offset, scale), entities);
if (entities.size() > 0) { foreach(EntityItemPointer entity, entities) {
glm::vec3 root(x, y, z); ids << entity->getEntityItemID();
auto exportTree = std::make_shared<EntityTree>();
exportTree->createRootElement();
for (int i = 0; i < entities.size(); i++) {
EntityItemProperties properties = entities.at(i)->getProperties();
EntityItemID id = entities.at(i)->getEntityItemID();
properties.setPosition(properties.getPosition() - root);
exportTree->addEntity(id, properties);
} }
return exportEntities(filename, ids, &offset);
// remap IDs on export so that we aren't publishing the IDs of entities in our domain
exportTree->remapIDs();
exportTree->writeToSVOFile(filename.toLocal8Bit().constData());
} else {
qCDebug(interfaceapp) << "No models were selected";
return false;
}
// restore the main window's active state
_window->activateWindow();
return true;
} }
void Application::loadSettings() { void Application::loadSettings() {
@ -2911,7 +2884,6 @@ bool Application::importEntities(const QString& urlOrFilename) {
bool success = _entityClipboard->readFromURL(urlOrFilename); bool success = _entityClipboard->readFromURL(urlOrFilename);
if (success) { if (success) {
// FIXME _entityClipboard->remapIDs();
_entityClipboard->reaverageOctreeElements(); _entityClipboard->reaverageOctreeElements();
} }
return success; return success;

View file

@ -233,7 +233,7 @@ signals:
public slots: public slots:
QVector<EntityItemID> pasteEntities(float x, float y, float z); QVector<EntityItemID> pasteEntities(float x, float y, float z);
bool exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs); bool exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs, const glm::vec3* givenOffset = nullptr);
bool exportEntities(const QString& filename, float x, float y, float z, float scale); bool exportEntities(const QString& filename, float x, float y, float z, float scale);
bool importEntities(const QString& url); bool importEntities(const QString& url);

View file

@ -1009,7 +1009,6 @@ void EntityTree::entityChanged(EntityItemPointer entity) {
void EntityTree::fixupMissingParents() { void EntityTree::fixupMissingParents() {
MovingEntitiesOperator moveOperator(getThisPointer()); MovingEntitiesOperator moveOperator(getThisPointer());
if (!_missingParent.empty()) qCDebug(entities) << "HRS fixme fixupMissingParents" << _missingParent.count() << "entities";
QMutableVectorIterator<EntityItemWeakPointer> iter(_missingParent); QMutableVectorIterator<EntityItemWeakPointer> iter(_missingParent);
while (iter.hasNext()) { while (iter.hasNext()) {
EntityItemWeakPointer entityWP = iter.next(); EntityItemWeakPointer entityWP = iter.next();
@ -1028,7 +1027,6 @@ void EntityTree::fixupMissingParents() {
bool doMove = false; bool doMove = false;
if (entity->isParentIDValid()) { if (entity->isParentIDValid()) {
qCDebug(entities) << "HRS fixme valid parent" << entity->getEntityItemID() << queryAACubeSuccess;
// this entity's parent was previously not known, and now is. Update its location in the EntityTree... // this entity's parent was previously not known, and now is. Update its location in the EntityTree...
doMove = true; doMove = true;
} else if (getIsServer() && _avatarIDs.contains(entity->getParentID())) { } else if (getIsServer() && _avatarIDs.contains(entity->getParentID())) {
@ -1040,7 +1038,6 @@ void EntityTree::fixupMissingParents() {
_childrenOfAvatars[entity->getParentID()] += entity->getEntityItemID(); _childrenOfAvatars[entity->getParentID()] += entity->getEntityItemID();
doMove = true; doMove = true;
} }
else qCDebug(entities) << "HRS fixme failed parent" << entity->getEntityItemID() << queryAACubeSuccess << "parent:" << entity->getParentID() << !!findEntityByID(entity->getParentID());
if (queryAACubeSuccess && doMove) { if (queryAACubeSuccess && doMove) {
moveOperator.addEntityToMoveList(entity, newCube); moveOperator.addEntityToMoveList(entity, newCube);
@ -1342,7 +1339,6 @@ bool EntityTree::sendEntitiesOperation(OctreeElementPointer element, void* extra
return args->map->value(oldID); return args->map->value(oldID);
} }
EntityItemID newID = QUuid::createUuid(); EntityItemID newID = QUuid::createUuid();
args->map->insert(oldID, newID);
EntityItemProperties properties = item->getProperties(); EntityItemProperties properties = item->getProperties();
EntityItemID oldParentID = properties.getParentID(); EntityItemID oldParentID = properties.getParentID();
if (oldParentID.isInvalidID()) { // no parent if (oldParentID.isInvalidID()) { // no parent
@ -1368,6 +1364,7 @@ bool EntityTree::sendEntitiesOperation(OctreeElementPointer element, void* extra
args->otherTree->addEntity(newID, properties); args->otherTree->addEntity(newID, properties);
}); });
} }
args->map->insert(oldID, newID);
return newID; return newID;
}; };