mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 07:57:30 +02:00
working on fixing action/constraint export/import
This commit is contained in:
parent
cfe118e2c6
commit
fd238f5438
6 changed files with 104 additions and 52 deletions
|
@ -24,7 +24,7 @@ public:
|
||||||
AssignmentDynamic(EntityDynamicType type, const QUuid& id, EntityItemPointer ownerEntity);
|
AssignmentDynamic(EntityDynamicType type, const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~AssignmentDynamic();
|
virtual ~AssignmentDynamic();
|
||||||
|
|
||||||
virtual void remapIDs(QHash<EntityItemID, EntityItemID>* map) override {};
|
virtual void remapIDs(QHash<EntityItemID, EntityItemID>& map) override {};
|
||||||
|
|
||||||
virtual void removeFromSimulation(EntitySimulationPointer simulation) const override;
|
virtual void removeFromSimulation(EntitySimulationPointer simulation) const override;
|
||||||
virtual EntityItemWeakPointer getOwnerEntity() const override { return _ownerEntity; }
|
virtual EntityItemWeakPointer getOwnerEntity() const override { return _ownerEntity; }
|
||||||
|
|
|
@ -47,7 +47,7 @@ public:
|
||||||
const QUuid& getID() const { return _id; }
|
const QUuid& getID() const { return _id; }
|
||||||
EntityDynamicType getType() const { return _type; }
|
EntityDynamicType getType() const { return _type; }
|
||||||
|
|
||||||
virtual void remapIDs(QHash<EntityItemID, EntityItemID>* map) = 0;
|
virtual void remapIDs(QHash<EntityItemID, EntityItemID>& map) = 0;
|
||||||
|
|
||||||
virtual bool isAction() const { return false; }
|
virtual bool isAction() const { return false; }
|
||||||
virtual bool isConstraint() const { return false; }
|
virtual bool isConstraint() const { return false; }
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include "RecurseOctreeToMapOperator.h"
|
#include "RecurseOctreeToMapOperator.h"
|
||||||
#include "LogHandler.h"
|
#include "LogHandler.h"
|
||||||
#include "EntityEditFilters.h"
|
#include "EntityEditFilters.h"
|
||||||
|
#include "EntityDynamicFactoryInterface.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;
|
||||||
const float EntityTree::DEFAULT_MAX_TMP_ENTITY_LIFETIME = 60 * 60; // 1 hour
|
const float EntityTree::DEFAULT_MAX_TMP_ENTITY_LIFETIME = 60 * 60; // 1 hour
|
||||||
|
@ -1549,13 +1551,23 @@ QVector<EntityItemID> EntityTree::sendEntities(EntityEditPacketSender* packetSen
|
||||||
bool EntityTree::sendEntitiesOperation(OctreeElementPointer element, void* extraData) {
|
bool EntityTree::sendEntitiesOperation(OctreeElementPointer element, void* extraData) {
|
||||||
SendEntitiesOperationArgs* args = static_cast<SendEntitiesOperationArgs*>(extraData);
|
SendEntitiesOperationArgs* args = static_cast<SendEntitiesOperationArgs*>(extraData);
|
||||||
EntityTreeElementPointer entityTreeElement = std::static_pointer_cast<EntityTreeElement>(element);
|
EntityTreeElementPointer entityTreeElement = std::static_pointer_cast<EntityTreeElement>(element);
|
||||||
std::function<const EntityItemID(EntityItemPointer&)> getMapped = [&](EntityItemPointer& item) -> const EntityItemID {
|
|
||||||
EntityItemID oldID = item->getEntityItemID();
|
auto getMapped = [&](EntityItemID oldID) {
|
||||||
if (args->map->contains(oldID)) { // Already been handled (e.g., as a parent of somebody that we've processed).
|
if (oldID.isNull()) {
|
||||||
return args->map->value(oldID);
|
return EntityItemID();
|
||||||
}
|
}
|
||||||
|
if (args->map->contains(oldID)) {
|
||||||
|
return args->map->value(oldID);
|
||||||
|
} else {
|
||||||
EntityItemID newID = QUuid::createUuid();
|
EntityItemID newID = QUuid::createUuid();
|
||||||
args->map->insert(oldID, newID);
|
args->map->insert(oldID, newID);
|
||||||
|
return newID;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
entityTreeElement->forEachEntity([&](EntityItemPointer item) {
|
||||||
|
EntityItemID oldID = item->getEntityItemID();
|
||||||
|
EntityItemID newID = getMapped(oldID);
|
||||||
|
|
||||||
EntityItemProperties properties = item->getProperties();
|
EntityItemProperties properties = item->getProperties();
|
||||||
EntityItemID oldParentID = properties.getParentID();
|
EntityItemID oldParentID = properties.getParentID();
|
||||||
|
@ -1564,8 +1576,7 @@ bool EntityTree::sendEntitiesOperation(OctreeElementPointer element, void* extra
|
||||||
} else {
|
} else {
|
||||||
EntityItemPointer parentEntity = args->ourTree->findEntityByEntityItemID(oldParentID);
|
EntityItemPointer parentEntity = args->ourTree->findEntityByEntityItemID(oldParentID);
|
||||||
if (parentEntity) { // map the parent
|
if (parentEntity) { // map the parent
|
||||||
// Warning: (non-tail) recursion of getMapped could blow the call stack if the parent hierarchy is VERY deep.
|
properties.setParentID(getMapped(parentEntity->getID()));
|
||||||
properties.setParentID(getMapped(parentEntity));
|
|
||||||
// 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);
|
||||||
|
@ -1573,40 +1584,63 @@ bool EntityTree::sendEntitiesOperation(OctreeElementPointer element, void* extra
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!properties.getXNNeighborID().isInvalidID()) {
|
if (!properties.getXNNeighborID().isInvalidID()) {
|
||||||
auto neighborEntity = args->ourTree->findEntityByEntityItemID(properties.getXNNeighborID());
|
properties.setXNNeighborID(getMapped(properties.getXNNeighborID()));
|
||||||
if (neighborEntity) {
|
|
||||||
properties.setXNNeighborID(getMapped(neighborEntity));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!properties.getXPNeighborID().isInvalidID()) {
|
if (!properties.getXPNeighborID().isInvalidID()) {
|
||||||
auto neighborEntity = args->ourTree->findEntityByEntityItemID(properties.getXPNeighborID());
|
properties.setXPNeighborID(getMapped(properties.getXPNeighborID()));
|
||||||
if (neighborEntity) {
|
|
||||||
properties.setXPNeighborID(getMapped(neighborEntity));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!properties.getYNNeighborID().isInvalidID()) {
|
if (!properties.getYNNeighborID().isInvalidID()) {
|
||||||
auto neighborEntity = args->ourTree->findEntityByEntityItemID(properties.getYNNeighborID());
|
properties.setYNNeighborID(getMapped(properties.getYNNeighborID()));
|
||||||
if (neighborEntity) {
|
|
||||||
properties.setYNNeighborID(getMapped(neighborEntity));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!properties.getYPNeighborID().isInvalidID()) {
|
if (!properties.getYPNeighborID().isInvalidID()) {
|
||||||
auto neighborEntity = args->ourTree->findEntityByEntityItemID(properties.getYPNeighborID());
|
properties.setYPNeighborID(getMapped(properties.getYPNeighborID()));
|
||||||
if (neighborEntity) {
|
|
||||||
properties.setYPNeighborID(getMapped(neighborEntity));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!properties.getZNNeighborID().isInvalidID()) {
|
if (!properties.getZNNeighborID().isInvalidID()) {
|
||||||
auto neighborEntity = args->ourTree->findEntityByEntityItemID(properties.getZNNeighborID());
|
properties.setZNNeighborID(getMapped(properties.getZNNeighborID()));
|
||||||
if (neighborEntity) {
|
|
||||||
properties.setZNNeighborID(getMapped(neighborEntity));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!properties.getZPNeighborID().isInvalidID()) {
|
if (!properties.getZPNeighborID().isInvalidID()) {
|
||||||
auto neighborEntity = args->ourTree->findEntityByEntityItemID(properties.getZPNeighborID());
|
properties.setZPNeighborID(getMapped(properties.getZPNeighborID()));
|
||||||
if (neighborEntity) {
|
|
||||||
properties.setZPNeighborID(getMapped(neighborEntity));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray actionData = properties.getActionData();
|
||||||
|
if (!actionData.isEmpty()) {
|
||||||
|
QDataStream serializedActionsStream(actionData);
|
||||||
|
QVector<QByteArray> serializedActions;
|
||||||
|
serializedActionsStream >> serializedActions;
|
||||||
|
|
||||||
|
auto actionFactory = DependencyManager::get<EntityDynamicFactoryInterface>();
|
||||||
|
|
||||||
|
QHash<QUuid, EntityDynamicPointer> remappedActions;
|
||||||
|
foreach(QByteArray serializedAction, serializedActions) {
|
||||||
|
QDataStream serializedActionStream(serializedAction);
|
||||||
|
EntityDynamicType actionType;
|
||||||
|
QUuid oldActionID;
|
||||||
|
serializedActionStream >> actionType;
|
||||||
|
serializedActionStream >> oldActionID;
|
||||||
|
QUuid actionID = QUuid::createUuid(); // give the action a new ID
|
||||||
|
(*args->map)[oldActionID] = actionID;
|
||||||
|
EntityDynamicPointer action = actionFactory->factoryBA(nullptr, serializedAction);
|
||||||
|
if (action) {
|
||||||
|
action->remapIDs(*args->map);
|
||||||
|
remappedActions[actionID] = action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<QByteArray> remappedSerializedActions;
|
||||||
|
|
||||||
|
QHash<QUuid, EntityDynamicPointer>::const_iterator i = remappedActions.begin();
|
||||||
|
while (i != remappedActions.end()) {
|
||||||
|
const QUuid id = i.key();
|
||||||
|
EntityDynamicPointer action = remappedActions[id];
|
||||||
|
QByteArray bytesForAction = action->serialize();
|
||||||
|
remappedSerializedActions << bytesForAction;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray result;
|
||||||
|
QDataStream remappedSerializedActionsStream(&result, QIODevice::WriteOnly);
|
||||||
|
remappedSerializedActionsStream << remappedSerializedActions;
|
||||||
|
properties.setActionData(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set creation time to "now" for imported entities
|
// set creation time to "now" for imported entities
|
||||||
|
@ -1623,13 +1657,26 @@ bool EntityTree::sendEntitiesOperation(OctreeElementPointer element, void* extra
|
||||||
// also update the local tree instantly (note: this is not our tree, but an alternate tree)
|
// also update the local tree instantly (note: this is not our tree, but an alternate tree)
|
||||||
if (args->otherTree) {
|
if (args->otherTree) {
|
||||||
args->otherTree->withWriteLock([&] {
|
args->otherTree->withWriteLock([&] {
|
||||||
args->otherTree->addEntity(newID, properties);
|
EntityItemPointer entity = args->otherTree->addEntity(newID, properties);
|
||||||
|
entity->deserializeActions();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return newID;
|
return newID;
|
||||||
};
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
QHash<EntityItemID, EntityItemID>::iterator i = (*args->map).begin();
|
||||||
|
while (i != (*args->map).end()) {
|
||||||
|
EntityItemID newID = i.value();
|
||||||
|
if (args->otherTree->findEntityByEntityItemID(newID)) {
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
EntityItemID oldID = i.key();
|
||||||
|
i = (*args->map).erase(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
entityTreeElement->forEachEntity(getMapped);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -275,7 +275,6 @@ bool ObjectConstraintHinge::updateArguments(QVariantMap arguments) {
|
||||||
QVariantMap ObjectConstraintHinge::getArguments() {
|
QVariantMap ObjectConstraintHinge::getArguments() {
|
||||||
QVariantMap arguments = ObjectDynamic::getArguments();
|
QVariantMap arguments = ObjectDynamic::getArguments();
|
||||||
withReadLock([&] {
|
withReadLock([&] {
|
||||||
if (_constraint) {
|
|
||||||
arguments["pivot"] = glmToQMap(_pivotInA);
|
arguments["pivot"] = glmToQMap(_pivotInA);
|
||||||
arguments["axis"] = glmToQMap(_axisInA);
|
arguments["axis"] = glmToQMap(_axisInA);
|
||||||
arguments["otherEntityID"] = _otherEntityID;
|
arguments["otherEntityID"] = _otherEntityID;
|
||||||
|
@ -286,7 +285,10 @@ QVariantMap ObjectConstraintHinge::getArguments() {
|
||||||
arguments["softness"] = _softness;
|
arguments["softness"] = _softness;
|
||||||
arguments["biasFactor"] = _biasFactor;
|
arguments["biasFactor"] = _biasFactor;
|
||||||
arguments["relaxationFactor"] = _relaxationFactor;
|
arguments["relaxationFactor"] = _relaxationFactor;
|
||||||
|
if (_constraint) {
|
||||||
arguments["angle"] = static_cast<btHingeConstraint*>(_constraint)->getHingeAngle(); // [-PI,PI]
|
arguments["angle"] = static_cast<btHingeConstraint*>(_constraint)->getHingeAngle(); // [-PI,PI]
|
||||||
|
} else {
|
||||||
|
arguments["angle"] = 0.0f;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return arguments;
|
return arguments;
|
||||||
|
|
|
@ -24,14 +24,17 @@ ObjectDynamic::ObjectDynamic(EntityDynamicType type, const QUuid& id, EntityItem
|
||||||
ObjectDynamic::~ObjectDynamic() {
|
ObjectDynamic::~ObjectDynamic() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectDynamic::remapIDs(QHash<EntityItemID, EntityItemID>* map) {
|
void ObjectDynamic::remapIDs(QHash<EntityItemID, EntityItemID>& map) {
|
||||||
withWriteLock([&]{
|
withWriteLock([&]{
|
||||||
if (map->contains(_id)) {
|
if (!map.contains(_id)) {
|
||||||
_id = (*map)[_id];
|
map[_id] = QUuid::createUuid();
|
||||||
}
|
}
|
||||||
if (map->contains(_otherID)) {
|
_id = map[_id];
|
||||||
_otherID = (*map)[_otherID];
|
|
||||||
|
if (!map.contains(_otherID)) {
|
||||||
|
map[_otherID] = QUuid::createUuid();
|
||||||
}
|
}
|
||||||
|
_otherID = map[_otherID];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ public:
|
||||||
ObjectDynamic(EntityDynamicType type, const QUuid& id, EntityItemPointer ownerEntity);
|
ObjectDynamic(EntityDynamicType type, const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~ObjectDynamic();
|
virtual ~ObjectDynamic();
|
||||||
|
|
||||||
virtual void remapIDs(QHash<EntityItemID, EntityItemID>* map) override;
|
virtual void remapIDs(QHash<EntityItemID, EntityItemID>& map) override;
|
||||||
|
|
||||||
virtual void removeFromSimulation(EntitySimulationPointer simulation) const override;
|
virtual void removeFromSimulation(EntitySimulationPointer simulation) const override;
|
||||||
virtual EntityItemWeakPointer getOwnerEntity() const override { return _ownerEntity; }
|
virtual EntityItemWeakPointer getOwnerEntity() const override { return _ownerEntity; }
|
||||||
|
|
Loading…
Reference in a new issue