mirror of
https://github.com/lubosz/overte.git
synced 2025-04-26 22:35:27 +02:00
Merge pull request #9057 from druiz17/childParent
fixed children of parent object not being added back when performing an undo
This commit is contained in:
commit
d2b32c3084
3 changed files with 89 additions and 14 deletions
|
@ -1318,6 +1318,26 @@ QVector<QUuid> EntityScriptingInterface::getChildrenIDs(const QUuid& parentID) {
|
|||
return result;
|
||||
}
|
||||
|
||||
bool EntityScriptingInterface::isChildOfParent(QUuid childID, QUuid parentID) {
|
||||
bool isChild = false;
|
||||
|
||||
if (!_entityTree) {
|
||||
return isChild;
|
||||
}
|
||||
|
||||
_entityTree->withReadLock([&] {
|
||||
EntityItemPointer parent = _entityTree->findEntityByEntityItemID(parentID);
|
||||
parent->forEachDescendant([&](SpatiallyNestablePointer descendant) {
|
||||
if(descendant->getID() == childID) {
|
||||
isChild = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return isChild;
|
||||
}
|
||||
|
||||
QVector<QUuid> EntityScriptingInterface::getChildrenIDsOfJoint(const QUuid& parentID, int jointIndex) {
|
||||
QVector<QUuid> result;
|
||||
if (!_entityTree) {
|
||||
|
|
|
@ -255,6 +255,7 @@ public slots:
|
|||
Q_INVOKABLE QStringList getJointNames(const QUuid& entityID);
|
||||
Q_INVOKABLE QVector<QUuid> getChildrenIDs(const QUuid& parentID);
|
||||
Q_INVOKABLE QVector<QUuid> getChildrenIDsOfJoint(const QUuid& parentID, int jointIndex);
|
||||
Q_INVOKABLE bool isChildOfParent(QUuid childID, QUuid parentID);
|
||||
|
||||
Q_INVOKABLE QUuid getKeyboardFocusEntity() const;
|
||||
Q_INVOKABLE void setKeyboardFocusEntity(QUuid id);
|
||||
|
|
|
@ -1027,19 +1027,70 @@ function selectAllEtitiesInCurrentSelectionBox(keepIfTouching) {
|
|||
}
|
||||
}
|
||||
|
||||
function sortSelectedEntities(selected) {
|
||||
var sortedEntities = selected.slice();
|
||||
var begin = 0;
|
||||
while (begin < sortedEntities.length) {
|
||||
var elementRemoved = false;
|
||||
var next = begin + 1;
|
||||
while (next < sortedEntities.length) {
|
||||
var beginID = sortedEntities[begin];
|
||||
var nextID = sortedEntities[next];
|
||||
|
||||
if (Entities.isChildOfParent(beginID, nextID)) {
|
||||
sortedEntities[begin] = nextID;
|
||||
sortedEntities[next] = beginID;
|
||||
sortedEntities.splice(next, 1);
|
||||
elementRemoved = true;
|
||||
break;
|
||||
} else if (Entities.isChildOfParent(nextID, beginID)) {
|
||||
sortedEntities.splice(next, 1);
|
||||
elementRemoved = true;
|
||||
break;
|
||||
}
|
||||
next++;
|
||||
}
|
||||
if (!elementRemoved) {
|
||||
begin++;
|
||||
}
|
||||
}
|
||||
return sortedEntities;
|
||||
}
|
||||
|
||||
function recursiveDelete(entities, childrenList) {
|
||||
var entitiesLength = entities.length;
|
||||
for (var i = 0; i < entitiesLength; i++) {
|
||||
var entityID = entities[i];
|
||||
var children = Entities.getChildrenIDs(entityID);
|
||||
var grandchildrenList = [];
|
||||
recursiveDelete(children, grandchildrenList);
|
||||
var initialProperties = Entities.getEntityProperties(entityID);
|
||||
childrenList.push({
|
||||
entityID: entityID,
|
||||
properties: initialProperties,
|
||||
children: grandchildrenList
|
||||
});
|
||||
Entities.deleteEntity(entityID);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteSelectedEntities() {
|
||||
if (SelectionManager.hasSelection()) {
|
||||
selectedParticleEntity = 0;
|
||||
particleExplorerTool.destroyWebView();
|
||||
SelectionManager.saveProperties();
|
||||
var savedProperties = [];
|
||||
for (var i = 0; i < selectionManager.selections.length; i++) {
|
||||
var entityID = SelectionManager.selections[i];
|
||||
var newSortedSelection = sortSelectedEntities(selectionManager.selections);
|
||||
for (var i = 0; i < newSortedSelection.length; i++) {
|
||||
var entityID = newSortedSelection[i];
|
||||
var initialProperties = SelectionManager.savedProperties[entityID];
|
||||
SelectionManager.savedProperties[entityID];
|
||||
var children = Entities.getChildrenIDs(entityID);
|
||||
var childList = [];
|
||||
recursiveDelete(children, childList);
|
||||
savedProperties.push({
|
||||
entityID: entityID,
|
||||
properties: initialProperties
|
||||
properties: initialProperties,
|
||||
children: childList
|
||||
});
|
||||
Entities.deleteEntity(entityID);
|
||||
}
|
||||
|
@ -1253,6 +1304,16 @@ Controller.keyReleaseEvent.connect(function (event) {
|
|||
}
|
||||
});
|
||||
|
||||
function recursiveAdd(newParentID, parentData) {
|
||||
var children = parentData.children;
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var childProperties = children[i].properties;
|
||||
childProperties.parentID = newParentID;
|
||||
var newChildID = Entities.addEntity(childProperties);
|
||||
recursiveAdd(newChildID, children[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// When an entity has been deleted we need a way to "undo" this deletion. Because it's not currently
|
||||
// possible to create an entity with a specific id, earlier undo commands to the deleted entity
|
||||
// will fail if there isn't a way to find the new entity id.
|
||||
|
@ -1274,6 +1335,7 @@ function applyEntityProperties(data) {
|
|||
entityID = data.createEntities[i].entityID;
|
||||
var entityProperties = data.createEntities[i].properties;
|
||||
var newEntityID = Entities.addEntity(entityProperties);
|
||||
recursiveAdd(newEntityID, data.createEntities[i]);
|
||||
DELETED_ENTITY_MAP[entityID] = newEntityID;
|
||||
if (data.selectCreated) {
|
||||
selectedEntityIDs.push(newEntityID);
|
||||
|
@ -1314,19 +1376,11 @@ function pushCommandForSelections(createdEntityData, deletedEntityData) {
|
|||
}
|
||||
undoData.setProperties.push({
|
||||
entityID: entityID,
|
||||
properties: {
|
||||
position: initialProperties.position,
|
||||
rotation: initialProperties.rotation,
|
||||
dimensions: initialProperties.dimensions
|
||||
}
|
||||
properties: initialProperties
|
||||
});
|
||||
redoData.setProperties.push({
|
||||
entityID: entityID,
|
||||
properties: {
|
||||
position: currentProperties.position,
|
||||
rotation: currentProperties.rotation,
|
||||
dimensions: currentProperties.dimensions
|
||||
}
|
||||
properties: currentProperties
|
||||
});
|
||||
}
|
||||
UndoStack.pushCommand(applyEntityProperties, undoData, applyEntityProperties, redoData);
|
||||
|
|
Loading…
Reference in a new issue