Merge pull request #11532 from sethalves/import-av-entities

fix importing of avatar entities
This commit is contained in:
Brad Hefta-Gaub 2017-10-06 17:59:54 -07:00 committed by GitHub
commit 62fc193bff
6 changed files with 39 additions and 9 deletions

View file

@ -3238,3 +3238,9 @@ void MyAvatar::setModelScale(float scale) {
emit sensorToWorldScaleChanged(sensorToWorldScale);
}
}
SpatialParentTree* MyAvatar::getParentTree() const {
auto entityTreeRenderer = qApp->getEntities();
EntityTreePointer entityTree = entityTreeRenderer ? entityTreeRenderer->getTree() : nullptr;
return entityTree.get();
}

View file

@ -544,6 +544,8 @@ public:
float getUserHeight() const;
float getUserEyeHeight() const;
virtual SpatialParentTree* getParentTree() const override;
public slots:
void increaseSize();
void decreaseSize();

View file

@ -45,7 +45,7 @@ void EntityEditPacketSender::queueEditAvatarEntityMessage(PacketType type,
}
EntityItemPointer entity = entityTree->findEntityByEntityItemID(entityItemID);
if (!entity) {
qCDebug(entities) << "EntityEditPacketSender::queueEditEntityMessage can't find entity.";
qCDebug(entities) << "EntityEditPacketSender::queueEditAvatarEntityMessage can't find entity: " << entityItemID;
return;
}

View file

@ -1842,7 +1842,13 @@ bool EntityTree::sendEntitiesOperation(const OctreeElementPointer& element, void
QHash<EntityItemID, EntityItemID>::iterator iter = args->map->find(oldID);
if (iter == args->map->end()) {
EntityItemID newID = QUuid::createUuid();
EntityItemID newID;
if (oldID == AVATAR_SELF_ID) {
auto nodeList = DependencyManager::get<NodeList>();
newID = EntityItemID(nodeList->getSessionUUID());
} else {
newID = QUuid::createUuid();
}
args->map->insert(oldID, newID);
return newID;
}
@ -1859,8 +1865,8 @@ bool EntityTree::sendEntitiesOperation(const OctreeElementPointer& element, void
properties.setPosition(properties.getPosition() + args->root);
} else {
EntityItemPointer parentEntity = args->ourTree->findEntityByEntityItemID(oldParentID);
if (parentEntity) { // map the parent
properties.setParentID(getMapped(parentEntity->getID()));
if (parentEntity || oldParentID == AVATAR_SELF_ID) { // map the parent
properties.setParentID(getMapped(oldParentID));
// But do not add root offset in this case.
} else { // Should not happen, but let's try to be helpful...
item->globalizeProperties(properties, "Cannot find %3 parent of %2 %1", args->root);
@ -1935,6 +1941,12 @@ bool EntityTree::readFromMap(QVariantMap& map) {
entityItemID = EntityItemID(QUuid::createUuid());
}
if (properties.getClientOnly()) {
auto nodeList = DependencyManager::get<NodeList>();
const QUuid myNodeID = nodeList->getSessionUUID();
properties.setOwningAvatarID(myNodeID);
}
EntityItemPointer entity = addEntity(entityItemID, properties);
if (!entity) {
qCDebug(entities) << "adding Entity failed:" << entityItemID << properties.getType();

View file

@ -102,8 +102,11 @@ SpatiallyNestablePointer SpatiallyNestable::getParentPointer(bool& success) cons
if (parent && parent->getID() == parentID) {
// parent pointer is up-to-date
if (!_parentKnowsMe) {
parent->beParentOfChild(getThisPointer());
_parentKnowsMe = true;
SpatialParentTree* parentTree = parent->getParentTree();
if (!parentTree || parentTree == getParentTree()) {
parent->beParentOfChild(getThisPointer());
_parentKnowsMe = true;
}
}
success = true;
return parent;
@ -129,8 +132,15 @@ SpatiallyNestablePointer SpatiallyNestable::getParentPointer(bool& success) cons
parent = _parent.lock();
if (parent) {
parent->beParentOfChild(getThisPointer());
_parentKnowsMe = true;
// it's possible for an entity with a parent of AVATAR_SELF_ID can be imported into a side-tree
// such as the clipboard's. if this is the case, we don't want the parent to consider this a
// child.
SpatialParentTree* parentTree = parent->getParentTree();
if (!parentTree || parentTree == getParentTree()) {
parent->beParentOfChild(getThisPointer());
_parentKnowsMe = true;
}
}
success = (parent || parentID.isNull());

View file

@ -222,7 +222,7 @@ getControllerJointIndex = function (hand) {
return controllerJointIndex;
}
return MyAvatar.getJointIndex("Head");
return -1;
};
propsArePhysical = function (props) {