mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 19:04:27 +02:00
Merge pull request #11554 from sethalves/import-av-entities
Import av entities
This commit is contained in:
commit
1bba5ff812
9 changed files with 69 additions and 18 deletions
|
@ -3963,9 +3963,14 @@ void Application::calibrateEyeTracker5Points() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool Application::exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs, const glm::vec3* givenOffset) {
|
bool Application::exportEntities(const QString& filename,
|
||||||
|
const QVector<EntityItemID>& entityIDs,
|
||||||
|
const glm::vec3* givenOffset) {
|
||||||
QHash<EntityItemID, EntityItemPointer> entities;
|
QHash<EntityItemID, EntityItemPointer> entities;
|
||||||
|
|
||||||
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
|
const QUuid myAvatarID = nodeList->getSessionUUID();
|
||||||
|
|
||||||
auto entityTree = getEntities()->getTree();
|
auto entityTree = getEntities()->getTree();
|
||||||
auto exportTree = std::make_shared<EntityTree>();
|
auto exportTree = std::make_shared<EntityTree>();
|
||||||
exportTree->createRootElement();
|
exportTree->createRootElement();
|
||||||
|
@ -3981,8 +3986,12 @@ bool Application::exportEntities(const QString& filename, const QVector<EntityIt
|
||||||
|
|
||||||
if (!givenOffset) {
|
if (!givenOffset) {
|
||||||
EntityItemID parentID = entityItem->getParentID();
|
EntityItemID parentID = entityItem->getParentID();
|
||||||
if (parentID.isInvalidID() || !entityIDs.contains(parentID) || !entityTree->findEntityByEntityItemID(parentID)) {
|
bool parentIsAvatar = (parentID == AVATAR_SELF_ID || parentID == myAvatarID);
|
||||||
auto position = entityItem->getPosition(); // If parent wasn't selected, we want absolute position, which isn't in properties.
|
if (!parentIsAvatar && (parentID.isInvalidID() ||
|
||||||
|
!entityIDs.contains(parentID) ||
|
||||||
|
!entityTree->findEntityByEntityItemID(parentID))) {
|
||||||
|
// If parent wasn't selected, we want absolute position, which isn't in properties.
|
||||||
|
auto position = entityItem->getPosition();
|
||||||
root.x = glm::min(root.x, position.x);
|
root.x = glm::min(root.x, position.x);
|
||||||
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);
|
||||||
|
@ -4002,12 +4011,16 @@ bool Application::exportEntities(const QString& filename, const QVector<EntityIt
|
||||||
for (EntityItemPointer& entityDatum : entities) {
|
for (EntityItemPointer& entityDatum : entities) {
|
||||||
auto properties = entityDatum->getProperties();
|
auto properties = entityDatum->getProperties();
|
||||||
EntityItemID parentID = properties.getParentID();
|
EntityItemID parentID = properties.getParentID();
|
||||||
|
bool parentIsAvatar = (parentID == AVATAR_SELF_ID || parentID == myAvatarID);
|
||||||
|
if (parentIsAvatar) {
|
||||||
|
properties.setParentID(AVATAR_SELF_ID);
|
||||||
|
} else {
|
||||||
if (parentID.isInvalidID()) {
|
if (parentID.isInvalidID()) {
|
||||||
properties.setPosition(properties.getPosition() - root);
|
properties.setPosition(properties.getPosition() - root);
|
||||||
}
|
} else if (!entities.contains(parentID)) {
|
||||||
else if (!entities.contains(parentID)) {
|
|
||||||
entityDatum->globalizeProperties(properties, "Parent %3 of %2 %1 is not selected for export.", -root);
|
entityDatum->globalizeProperties(properties, "Parent %3 of %2 %1 is not selected for export.", -root);
|
||||||
} // else valid parent -- don't offset
|
} // else valid parent -- don't offset
|
||||||
|
}
|
||||||
exportTree->addEntity(entityDatum->getEntityItemID(), properties);
|
exportTree->addEntity(entityDatum->getEntityItemID(), properties);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3238,3 +3238,9 @@ void MyAvatar::setModelScale(float scale) {
|
||||||
emit sensorToWorldScaleChanged(sensorToWorldScale);
|
emit sensorToWorldScaleChanged(sensorToWorldScale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SpatialParentTree* MyAvatar::getParentTree() const {
|
||||||
|
auto entityTreeRenderer = qApp->getEntities();
|
||||||
|
EntityTreePointer entityTree = entityTreeRenderer ? entityTreeRenderer->getTree() : nullptr;
|
||||||
|
return entityTree.get();
|
||||||
|
}
|
||||||
|
|
|
@ -544,6 +544,8 @@ public:
|
||||||
float getUserHeight() const;
|
float getUserHeight() const;
|
||||||
float getUserEyeHeight() const;
|
float getUserEyeHeight() const;
|
||||||
|
|
||||||
|
virtual SpatialParentTree* getParentTree() const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void increaseSize();
|
void increaseSize();
|
||||||
void decreaseSize();
|
void decreaseSize();
|
||||||
|
|
|
@ -305,3 +305,9 @@ Transform Base3DOverlay::evalRenderTransform() {
|
||||||
void Base3DOverlay::setRenderTransform(const Transform& transform) {
|
void Base3DOverlay::setRenderTransform(const Transform& transform) {
|
||||||
_renderTransform = transform;
|
_renderTransform = transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SpatialParentTree* Base3DOverlay::getParentTree() const {
|
||||||
|
auto entityTreeRenderer = qApp->getEntities();
|
||||||
|
EntityTreePointer entityTree = entityTreeRenderer ? entityTreeRenderer->getTree() : nullptr;
|
||||||
|
return entityTree.get();
|
||||||
|
}
|
||||||
|
|
|
@ -69,6 +69,8 @@ public:
|
||||||
return findRayIntersection(origin, direction, distance, face, surfaceNormal);
|
return findRayIntersection(origin, direction, distance, face, surfaceNormal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual SpatialParentTree* getParentTree() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void locationChanged(bool tellPhysics = true) override;
|
virtual void locationChanged(bool tellPhysics = true) override;
|
||||||
virtual void parentDeleted() override;
|
virtual void parentDeleted() override;
|
||||||
|
|
|
@ -45,7 +45,7 @@ void EntityEditPacketSender::queueEditAvatarEntityMessage(PacketType type,
|
||||||
}
|
}
|
||||||
EntityItemPointer entity = entityTree->findEntityByEntityItemID(entityItemID);
|
EntityItemPointer entity = entityTree->findEntityByEntityItemID(entityItemID);
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
qCDebug(entities) << "EntityEditPacketSender::queueEditEntityMessage can't find entity.";
|
qCDebug(entities) << "EntityEditPacketSender::queueEditAvatarEntityMessage can't find entity: " << entityItemID;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1848,7 +1848,13 @@ bool EntityTree::sendEntitiesOperation(const OctreeElementPointer& element, void
|
||||||
|
|
||||||
QHash<EntityItemID, EntityItemID>::iterator iter = args->map->find(oldID);
|
QHash<EntityItemID, EntityItemID>::iterator iter = args->map->find(oldID);
|
||||||
if (iter == args->map->end()) {
|
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);
|
args->map->insert(oldID, newID);
|
||||||
return newID;
|
return newID;
|
||||||
}
|
}
|
||||||
|
@ -1865,8 +1871,8 @@ bool EntityTree::sendEntitiesOperation(const OctreeElementPointer& element, void
|
||||||
properties.setPosition(properties.getPosition() + args->root);
|
properties.setPosition(properties.getPosition() + args->root);
|
||||||
} else {
|
} else {
|
||||||
EntityItemPointer parentEntity = args->ourTree->findEntityByEntityItemID(oldParentID);
|
EntityItemPointer parentEntity = args->ourTree->findEntityByEntityItemID(oldParentID);
|
||||||
if (parentEntity) { // map the parent
|
if (parentEntity || oldParentID == AVATAR_SELF_ID) { // map the parent
|
||||||
properties.setParentID(getMapped(parentEntity->getID()));
|
properties.setParentID(getMapped(oldParentID));
|
||||||
// But do not add root offset in this case.
|
// But do not add root offset in this case.
|
||||||
} else { // Should not happen, but let's try to be helpful...
|
} else { // Should not happen, but let's try to be helpful...
|
||||||
item->globalizeProperties(properties, "Cannot find %3 parent of %2 %1", args->root);
|
item->globalizeProperties(properties, "Cannot find %3 parent of %2 %1", args->root);
|
||||||
|
@ -1941,6 +1947,12 @@ bool EntityTree::readFromMap(QVariantMap& map) {
|
||||||
entityItemID = EntityItemID(QUuid::createUuid());
|
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);
|
EntityItemPointer entity = addEntity(entityItemID, properties);
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
qCDebug(entities) << "adding Entity failed:" << entityItemID << properties.getType();
|
qCDebug(entities) << "adding Entity failed:" << entityItemID << properties.getType();
|
||||||
|
|
|
@ -102,9 +102,12 @@ SpatiallyNestablePointer SpatiallyNestable::getParentPointer(bool& success) cons
|
||||||
if (parent && parent->getID() == parentID) {
|
if (parent && parent->getID() == parentID) {
|
||||||
// parent pointer is up-to-date
|
// parent pointer is up-to-date
|
||||||
if (!_parentKnowsMe) {
|
if (!_parentKnowsMe) {
|
||||||
|
SpatialParentTree* parentTree = parent->getParentTree();
|
||||||
|
if (!parentTree || parentTree == getParentTree()) {
|
||||||
parent->beParentOfChild(getThisPointer());
|
parent->beParentOfChild(getThisPointer());
|
||||||
_parentKnowsMe = true;
|
_parentKnowsMe = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
success = true;
|
success = true;
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
@ -129,9 +132,16 @@ SpatiallyNestablePointer SpatiallyNestable::getParentPointer(bool& success) cons
|
||||||
|
|
||||||
parent = _parent.lock();
|
parent = _parent.lock();
|
||||||
if (parent) {
|
if (parent) {
|
||||||
|
|
||||||
|
// 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());
|
parent->beParentOfChild(getThisPointer());
|
||||||
_parentKnowsMe = true;
|
_parentKnowsMe = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
success = (parent || parentID.isNull());
|
success = (parent || parentID.isNull());
|
||||||
return parent;
|
return parent;
|
||||||
|
|
|
@ -222,7 +222,7 @@ getControllerJointIndex = function (hand) {
|
||||||
return controllerJointIndex;
|
return controllerJointIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
return MyAvatar.getJointIndex("Head");
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
propsArePhysical = function (props) {
|
propsArePhysical = function (props) {
|
||||||
|
|
Loading…
Reference in a new issue