Skip to content

Commit

Permalink
Merge pull request #1213 from AleziaKurdis/CreateApp-CopyPasteLocatio…
Browse files Browse the repository at this point in the history
…nRotation

Create app: Copy-Paste Position and Rotation
  • Loading branch information
daleglass authored May 15, 2021
2 parents 1ed0b2c + a4483e6 commit 97352b8
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 1 deletion.
43 changes: 43 additions & 0 deletions scripts/system/create/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ var hmdMultiSelectMode = false;
var expectingRotateAsClickedSurface = false;
var keepSelectedOnNextClick = false;

var copiedPosition;
var copiedRotation;

var cameraManager = new CameraManager();

var grid = new Grid();
Expand Down Expand Up @@ -2613,6 +2616,46 @@ var PropertiesTool = function (opts) {
Entities.reloadServerScripts(selectionManager.selections[i]);
}
}
} else if (data.action === "copyPosition") {
if (selectionManager.selections.length === 1) {
selectionManager.saveProperties();
properties = selectionManager.savedProperties[selectionManager.selections[0]];
copiedPosition = properties.position;
Window.copyToClipboard(JSON.stringify(copiedPosition));
}
} else if (data.action === "copyRotation") {
if (selectionManager.selections.length === 1) {
selectionManager.saveProperties();
properties = selectionManager.savedProperties[selectionManager.selections[0]];
copiedRotation = properties.rotation;
Window.copyToClipboard(JSON.stringify(copiedRotation));
}
} else if (data.action === "pastePosition") {
if (copiedPosition !== undefined && selectionManager.selections.length > 0 && SelectionManager.hasUnlockedSelection()) {
selectionManager.saveProperties();
for (i = 0; i < selectionManager.selections.length; i++) {
Entities.editEntity(selectionManager.selections[i], {
position: copiedPosition
});
}
pushCommandForSelections();
selectionManager._update(false, this);
} else {
audioFeedback.rejection();
}
} else if (data.action === "pasteRotation") {
if (copiedRotation !== undefined && selectionManager.selections.length > 0 && SelectionManager.hasUnlockedSelection()) {
selectionManager.saveProperties();
for (i = 0; i < selectionManager.selections.length; i++) {
Entities.editEntity(selectionManager.selections[i], {
rotation: copiedRotation
});
}
pushCommandForSelections();
selectionManager._update(false, this);
} else {
audioFeedback.rejection();
}
}
} else if (data.type === "propertiesPageReady") {
updateSelections(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,12 @@ const GROUPS = [
propertyID: "localPosition",
spaceMode: PROPERTY_SPACE_MODE.LOCAL,
},
{
type: "buttons",
buttons: [ { id: "copyPosition", label: "Copy Position", className: "secondary", onClick: copyPositionProperty },
{ id: "pastePosition", label: "Paste Position", className: "secondary", onClick: pastePositionProperty } ],
propertyID: "copyPastePosition"
},
{
label: "Rotation",
type: "vec3",
Expand All @@ -1375,6 +1381,12 @@ const GROUPS = [
propertyID: "localRotation",
spaceMode: PROPERTY_SPACE_MODE.LOCAL,
},
{
type: "buttons",
buttons: [ { id: "copyRotation", label: "Copy Rotation", className: "secondary", onClick: copyRotationProperty },
{ id: "pasteRotation", label: "Paste Rotation", className: "secondary", onClick: pasteRotationProperty } ],
propertyID: "copyPasteRotation"
},
{
label: "Dimensions",
type: "vec3",
Expand Down Expand Up @@ -1852,6 +1864,24 @@ function setPropertyVisibility(property, visible) {
property.elContainer.style.display = visible ? null : "none";
}

function setCopyPastePositionAndRotationAvailability (selectionLength, islocked) {
if (selectionLength === 1) {
$('#property-copyPastePosition-button-copyPosition').attr('disabled', false);
$('#property-copyPasteRotation-button-copyRotation').attr('disabled', false);
} else {
$('#property-copyPastePosition-button-copyPosition').attr('disabled', true);
$('#property-copyPasteRotation-button-copyRotation').attr('disabled', true);
}

if (selectionLength > 0 && !islocked) {
$('#property-copyPastePosition-button-pastePosition').attr('disabled', false);
$('#property-copyPasteRotation-button-pasteRotation').attr('disabled', false);
} else {
$('#property-copyPastePosition-button-pastePosition').attr('disabled', true);
$('#property-copyPasteRotation-button-pasteRotation').attr('disabled', true);
}
}

function resetProperties() {
for (let propertyID in properties) {
let property = properties[propertyID];
Expand Down Expand Up @@ -3217,6 +3247,33 @@ function copySkyboxURLToAmbientURL() {
updateProperty("ambientLight.ambientURL", skyboxURL, false);
}

function copyPositionProperty() {
EventBridge.emitWebEvent(JSON.stringify({
type: "action",
action: "copyPosition"
}));
}

function pastePositionProperty() {
EventBridge.emitWebEvent(JSON.stringify({
type: "action",
action: "pastePosition"
}));
}

function copyRotationProperty() {
EventBridge.emitWebEvent(JSON.stringify({
type: "action",
action: "copyRotation"
}));
}

function pasteRotationProperty() {
EventBridge.emitWebEvent(JSON.stringify({
type: "action",
action: "pasteRotation"
}));
}

/**
* USER DATA FUNCTIONS
Expand Down Expand Up @@ -3952,7 +4009,7 @@ function handleEntitySelectionUpdate(selections, isPropertiesToolUpdate) {
selectedEntityIDs = new Set(selections.map(selection => selection.id));
const multipleSelections = currentSelections.length > 1;
const hasSelectedEntityChanged = !areSetsEqual(selectedEntityIDs, previouslySelectedEntityIDs);

requestZoneList();

if (selections.length === 0) {
Expand All @@ -3976,6 +4033,8 @@ function handleEntitySelectionUpdate(selections, isPropertiesToolUpdate) {
showSaveMaterialDataButton();
showNewJSONMaterialEditorButton();

setCopyPastePositionAndRotationAvailability (selections.length, true);

disableProperties();
} else {
if (!isPropertiesToolUpdate && !hasSelectedEntityChanged && document.hasFocus()) {
Expand Down Expand Up @@ -4006,10 +4065,12 @@ function handleEntitySelectionUpdate(selections, isPropertiesToolUpdate) {
if (lockedMultiValue.isMultiDiffValue || lockedMultiValue.value) {
disableProperties();
getPropertyInputElement('locked').removeAttribute('disabled');
setCopyPastePositionAndRotationAvailability (selections.length, true);
} else {
enableProperties();
disableSaveUserDataButton();
disableSaveMaterialDataButton();
setCopyPastePositionAndRotationAvailability (selections.length, false);
}

const certificateIDMultiValue = getMultiplePropertyValue('certificateID');
Expand Down
16 changes: 16 additions & 0 deletions scripts/system/html/css/edit-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,22 @@ input[type=button].white, button.hifi-edit-button.white {
background-color: #afafaf;
background: linear-gradient(#fff 20%, #afafaf 100%);
}
input[type=button].secondary, button.hifi-edit-button.secondary {
font-family: Raleway-Bold;
font-size: 10px;
text-transform: uppercase;
vertical-align: top;
height: 18px;
min-width: 60px;
padding: 0 14px;
margin-right: 6px;
border-radius: 4px;
border: none;
color: #fff;
background-color: #000;
background: linear-gradient(#343434 20%, #000 100%);
cursor: pointer;
}

input[type=button]:enabled:hover, button.hifi-edit-button:enabled:hover {
background: linear-gradient(#000, #000);
Expand Down

0 comments on commit 97352b8

Please sign in to comment.