mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 04:03:35 +02:00
Merge pull request #13671 from huffman/fix/create-copy-follows-user
Fix duplication not working as expected on grabbed entities
This commit is contained in:
commit
c562a6945d
1 changed files with 84 additions and 21 deletions
|
@ -198,11 +198,40 @@ SelectionManager = (function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Return true if the given entity with `properties` is being grabbed by an avatar.
|
||||||
|
// This is mostly a heuristic - there is no perfect way to know if an entity is being
|
||||||
|
// grabbed.
|
||||||
|
function nonDynamicEntityIsBeingGrabbedByAvatar(properties) {
|
||||||
|
if (properties.dynamic || Uuid.isNull(properties.parentID)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var avatar = AvatarList.getAvatar(properties.parentID);
|
||||||
|
if (Uuid.isNull(avatar.sessionUUID)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var grabJointNames = [
|
||||||
|
'RightHand', 'LeftHand',
|
||||||
|
'_CONTROLLER_RIGHTHAND', '_CONTROLLER_LEFTHAND',
|
||||||
|
'_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND', '_CAMERA_RELATIVE_CONTROLLER_LEFTHAND'];
|
||||||
|
|
||||||
|
for (var i = 0; i < grabJointNames.length; ++i) {
|
||||||
|
if (avatar.getJointIndex(grabJointNames[i]) === properties.parentJointIndex) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
that.duplicateSelection = function() {
|
that.duplicateSelection = function() {
|
||||||
var entitiesToDuplicate = [];
|
var entitiesToDuplicate = [];
|
||||||
var duplicatedEntityIDs = [];
|
var duplicatedEntityIDs = [];
|
||||||
var duplicatedChildrenWithOldParents = [];
|
var duplicatedChildrenWithOldParents = [];
|
||||||
var originalEntityToNewEntityID = [];
|
var originalEntityToNewEntityID = [];
|
||||||
|
|
||||||
|
SelectionManager.saveProperties();
|
||||||
|
|
||||||
// build list of entities to duplicate by including any unselected children of selected parent entities
|
// build list of entities to duplicate by including any unselected children of selected parent entities
|
||||||
Object.keys(that.savedProperties).forEach(function(originalEntityID) {
|
Object.keys(that.savedProperties).forEach(function(originalEntityID) {
|
||||||
|
@ -220,7 +249,30 @@ SelectionManager = (function() {
|
||||||
properties = Entities.getEntityProperties(originalEntityID);
|
properties = Entities.getEntityProperties(originalEntityID);
|
||||||
}
|
}
|
||||||
if (!properties.locked && (!properties.clientOnly || properties.owningAvatarID === MyAvatar.sessionUUID)) {
|
if (!properties.locked && (!properties.clientOnly || properties.owningAvatarID === MyAvatar.sessionUUID)) {
|
||||||
|
if (nonDynamicEntityIsBeingGrabbedByAvatar(properties)) {
|
||||||
|
properties.parentID = null;
|
||||||
|
properties.parentJointIndex = null;
|
||||||
|
properties.localPosition = properties.position;
|
||||||
|
properties.localRotation = properties.rotation;
|
||||||
|
}
|
||||||
|
delete properties.actionData;
|
||||||
var newEntityID = Entities.addEntity(properties);
|
var newEntityID = Entities.addEntity(properties);
|
||||||
|
|
||||||
|
// Re-apply actions from the original entity
|
||||||
|
var actionIDs = Entities.getActionIDs(properties.id);
|
||||||
|
for (var i = 0; i < actionIDs.length; ++i) {
|
||||||
|
var actionID = actionIDs[i];
|
||||||
|
var actionArguments = Entities.getActionArguments(properties.id, actionID);
|
||||||
|
if (actionArguments) {
|
||||||
|
var type = actionArguments.type;
|
||||||
|
if (type == 'hold' || type == 'far-grab') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
delete actionArguments.ttl;
|
||||||
|
Entities.addAction(type, newEntityID, actionArguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
duplicatedEntityIDs.push({
|
duplicatedEntityIDs.push({
|
||||||
entityID: newEntityID,
|
entityID: newEntityID,
|
||||||
properties: properties
|
properties: properties
|
||||||
|
@ -259,7 +311,8 @@ SelectionManager = (function() {
|
||||||
that.worldPosition = null;
|
that.worldPosition = null;
|
||||||
that.worldRotation = null;
|
that.worldRotation = null;
|
||||||
} else if (that.selections.length === 1) {
|
} else if (that.selections.length === 1) {
|
||||||
properties = Entities.getEntityProperties(that.selections[0]);
|
properties = Entities.getEntityProperties(that.selections[0],
|
||||||
|
['dimensions', 'position', 'rotation', 'registrationPoint', 'boundingBox', 'type']);
|
||||||
that.localDimensions = properties.dimensions;
|
that.localDimensions = properties.dimensions;
|
||||||
that.localPosition = properties.position;
|
that.localPosition = properties.position;
|
||||||
that.localRotation = properties.rotation;
|
that.localRotation = properties.rotation;
|
||||||
|
@ -275,7 +328,7 @@ SelectionManager = (function() {
|
||||||
SelectionDisplay.setSpaceMode(SPACE_LOCAL);
|
SelectionDisplay.setSpaceMode(SPACE_LOCAL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
properties = Entities.getEntityProperties(that.selections[0]);
|
properties = Entities.getEntityProperties(that.selections[0], ['type', 'boundingBox']);
|
||||||
|
|
||||||
that.entityType = properties.type;
|
that.entityType = properties.type;
|
||||||
|
|
||||||
|
@ -283,7 +336,7 @@ SelectionManager = (function() {
|
||||||
var tfl = properties.boundingBox.tfl;
|
var tfl = properties.boundingBox.tfl;
|
||||||
|
|
||||||
for (var i = 1; i < that.selections.length; i++) {
|
for (var i = 1; i < that.selections.length; i++) {
|
||||||
properties = Entities.getEntityProperties(that.selections[i]);
|
properties = Entities.getEntityProperties(that.selections[i], 'boundingBox');
|
||||||
var bb = properties.boundingBox;
|
var bb = properties.boundingBox;
|
||||||
brn.x = Math.min(bb.brn.x, brn.x);
|
brn.x = Math.min(bb.brn.x, brn.x);
|
||||||
brn.y = Math.min(bb.brn.y, brn.y);
|
brn.y = Math.min(bb.brn.y, brn.y);
|
||||||
|
@ -1720,6 +1773,20 @@ SelectionDisplay = (function() {
|
||||||
Vec3.print(" pickResult.intersection", pickResult.intersection);
|
Vec3.print(" pickResult.intersection", pickResult.intersection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Duplicate entities if alt is pressed. This will make a
|
||||||
|
// copy of the selected entities and move the _original_ entities, not
|
||||||
|
// the new ones.
|
||||||
|
if (event.isAlt || doClone) {
|
||||||
|
duplicatedEntityIDs = SelectionManager.duplicateSelection();
|
||||||
|
var ids = [];
|
||||||
|
for (var i = 0; i < duplicatedEntityIDs.length; ++i) {
|
||||||
|
ids.push(duplicatedEntityIDs[i].entityID);
|
||||||
|
}
|
||||||
|
SelectionManager.setSelections(ids);
|
||||||
|
} else {
|
||||||
|
duplicatedEntityIDs = null;
|
||||||
|
}
|
||||||
|
|
||||||
SelectionManager.saveProperties();
|
SelectionManager.saveProperties();
|
||||||
that.resetPreviousHandleColor();
|
that.resetPreviousHandleColor();
|
||||||
|
|
||||||
|
@ -1749,15 +1816,6 @@ SelectionDisplay = (function() {
|
||||||
z: 0
|
z: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
// Duplicate entities if alt is pressed. This will make a
|
|
||||||
// copy of the selected entities and move the _original_ entities, not
|
|
||||||
// the new ones.
|
|
||||||
if (event.isAlt || doClone) {
|
|
||||||
duplicatedEntityIDs = SelectionManager.duplicateSelection();
|
|
||||||
} else {
|
|
||||||
duplicatedEntityIDs = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
isConstrained = false;
|
isConstrained = false;
|
||||||
if (wantDebug) {
|
if (wantDebug) {
|
||||||
print("================== TRANSLATE_XZ(End) <- =======================");
|
print("================== TRANSLATE_XZ(End) <- =======================");
|
||||||
|
@ -1933,6 +1991,20 @@ SelectionDisplay = (function() {
|
||||||
addHandleTool(overlay, {
|
addHandleTool(overlay, {
|
||||||
mode: mode,
|
mode: mode,
|
||||||
onBegin: function(event, pickRay, pickResult) {
|
onBegin: function(event, pickRay, pickResult) {
|
||||||
|
// Duplicate entities if alt is pressed. This will make a
|
||||||
|
// copy of the selected entities and move the _original_ entities, not
|
||||||
|
// the new ones.
|
||||||
|
if (event.isAlt) {
|
||||||
|
duplicatedEntityIDs = SelectionManager.duplicateSelection();
|
||||||
|
var ids = [];
|
||||||
|
for (var i = 0; i < duplicatedEntityIDs.length; ++i) {
|
||||||
|
ids.push(duplicatedEntityIDs[i].entityID);
|
||||||
|
}
|
||||||
|
SelectionManager.setSelections(ids);
|
||||||
|
} else {
|
||||||
|
duplicatedEntityIDs = null;
|
||||||
|
}
|
||||||
|
|
||||||
var axisVector;
|
var axisVector;
|
||||||
if (direction === TRANSLATE_DIRECTION.X) {
|
if (direction === TRANSLATE_DIRECTION.X) {
|
||||||
axisVector = { x: 1, y: 0, z: 0 };
|
axisVector = { x: 1, y: 0, z: 0 };
|
||||||
|
@ -1959,15 +2031,6 @@ SelectionDisplay = (function() {
|
||||||
that.setHandleStretchVisible(false);
|
that.setHandleStretchVisible(false);
|
||||||
that.setHandleScaleCubeVisible(false);
|
that.setHandleScaleCubeVisible(false);
|
||||||
that.setHandleClonerVisible(false);
|
that.setHandleClonerVisible(false);
|
||||||
|
|
||||||
// Duplicate entities if alt is pressed. This will make a
|
|
||||||
// copy of the selected entities and move the _original_ entities, not
|
|
||||||
// the new ones.
|
|
||||||
if (event.isAlt) {
|
|
||||||
duplicatedEntityIDs = SelectionManager.duplicateSelection();
|
|
||||||
} else {
|
|
||||||
duplicatedEntityIDs = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
previousPickRay = pickRay;
|
previousPickRay = pickRay;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue