From 554a144b0efc43ed435fae9c2011502dddc4cfc4 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Wed, 20 Mar 2019 21:55:36 -0700 Subject: [PATCH] adding tool to change avatar inputs properties --- .../qml/hifi/EditAvatarInputsBar.qml | 38 +++- scripts/system/createAvatarInputsBarEntity.js | 175 ++++++++++-------- 2 files changed, 138 insertions(+), 75 deletions(-) diff --git a/interface/resources/qml/hifi/EditAvatarInputsBar.qml b/interface/resources/qml/hifi/EditAvatarInputsBar.qml index d34537bb0e..bbf3652a92 100644 --- a/interface/resources/qml/hifi/EditAvatarInputsBar.qml +++ b/interface/resources/qml/hifi/EditAvatarInputsBar.qml @@ -55,6 +55,7 @@ Rectangle { top: title.bottom topMargin: 50 left: parent.left + leftMargin: 20 } label: "X OFFSET" maximumValue: 1.0 @@ -76,6 +77,7 @@ Rectangle { top: xSlider.bottom topMargin: 50 left: parent.left + leftMargin: 20 } label: "Y OFFSET" maximumValue: 1.0 @@ -92,12 +94,14 @@ Rectangle { } HifiControlsUit.Slider { + id: zSlider anchors { top: ySlider.bottom topMargin: 50 left: parent.left + leftMargin: 20 } - label: "Y OFFSET" + label: "Z OFFSET" maximumValue: 0.0 minimumValue: -1.0 stepSize: 0.05 @@ -112,9 +116,39 @@ Rectangle { } HifiControlsUit.Button { - id: setVisibleButton + id: setVisibleButton; + text: setVisible ? "SET INVISIBLE" : "SET VISIBLE"; + width: 300; + property bool setVisible: true; + anchors { + top: zSlider.bottom + topMargin: 50 + left: parent.left + leftMargin: 20 + } + onClicked: { + setVisible = !setVisible; + emitSendToScript({ + "method": "setVisible", + "visible": setVisible + }); + } } HifiControlsUit.Button { + id: printButton; + text: "PRINT POSITIONS"; + width: 300; + anchors { + top: setVisibleButton.bottom + topMargin: 50 + left: parent.left + leftMargin: 20 + } + onClicked: { + emitSendToScript({ + "method": "print", + }); + } } } diff --git a/scripts/system/createAvatarInputsBarEntity.js b/scripts/system/createAvatarInputsBarEntity.js index 5ffba2c029..35c50416ed 100644 --- a/scripts/system/createAvatarInputsBarEntity.js +++ b/scripts/system/createAvatarInputsBarEntity.js @@ -5,98 +5,127 @@ var ui; - var button; - var buttonName = "AVBAR"; var onCreateAvatarInputsBarEntity = false; var micBarEntity, bubbleIconEntity; var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var AVATAR_INPUTS_EDIT_QML_SOURCE = "hifi/EditAvatarInputsBar.qml"; - function fromQml(message) { - print("message from QML: " + JSON.stringify(message)); - }; + // QML NATURAL DIMENSIONS + var MIC_BAR_DIMENSIONS = {x: 0.036, y: 0.048, z: 0.3}; + var BUBBLE_ICON_DIMENSIONS = {x: 0.036, y: 0.036, z: 0.3}; + // CONSTANTS + var LOCAL_POSITION_X_OFFSET = -0.2; + var LOCAL_POSITION_Y_OFFSET = -0.125; + var LOCAL_POSITION_Z_OFFSET = -0.5; - function onClicked(){ - onCreateAvatarInputsBarEntity = !onCreateAvatarInputsBarEntity; - button.editProperties({isActive: onCreateAvatarInputsBarEntity}); - // QML NATURAL DIMENSIONS - var MIC_BAR_DIMENSIONS = {x: 0.036, y: 0.048, z: 0.3}; - var BUBBLE_ICON_DIMENSIONS = {x: 0.036, y: 0.036, z: 0.3}; - // CONSTANTS - var LOCAL_POSITION_X_OFFSET = -0.2; - var LOCAL_POSITION_Y_OFFSET = -0.125; - var LOCAL_POSITION_Z_OFFSET = -0.5; - // POSITIONS - var micBarLocalPosition = {x: (-(MIC_BAR_DIMENSIONS.x / 2)) + LOCAL_POSITION_X_OFFSET, y: LOCAL_POSITION_Y_OFFSET, z: LOCAL_POSITION_Z_OFFSET}; - var bubbleIconLocalPosition = {x: (MIC_BAR_DIMENSIONS.x * 1.2 / 2) + LOCAL_POSITION_X_OFFSET, y: ((MIC_BAR_DIMENSIONS.y - BUBBLE_ICON_DIMENSIONS.y) / 2 + LOCAL_POSITION_Y_OFFSET), z: LOCAL_POSITION_Z_OFFSET}; - if (onCreateAvatarInputsBarEntity) { - var props = { - type: "Web", - name: "AvatarInputsMicBarEntity", - parentID: MyAvatar.SELF_ID, - parentJointIndex: MyAvatar.getJointIndex("_CAMERA_MATRIX"), - localPosition: micBarLocalPosition, - localRotation: Quat.cancelOutRollAndPitch(Quat.lookAtSimple(Camera.orientation, micBarLocalPosition)), - sourceUrl: Script.resourcesPath() + "qml/hifi/audio/MicBarApplication.qml", - // cutoff alpha for detecting transparency - alpha: 0.98, - dimensions: MIC_BAR_DIMENSIONS, - drawInFront: true, - userData: { - grabbable: false - }, + function fromQml(message) { + if (message.method === "reposition") { + var micBarLocalPosition = Entities.getEntityProperties(micBarEntity).localPosition; + var bubbleIconLocalPosition = Entities.getEntityProperties(bubbleIconEntity).localPosition; + var newMicBarLocalPosition, newBubbleIconLocalPosition; + if (message.x !== undefined) { + newMicBarLocalPosition = { x: -((MIC_BAR_DIMENSIONS.x) / 2) - message.x, y: micBarLocalPosition.y, z: micBarLocalPosition.z }; + newBubbleIconLocalPosition = { x: ((MIC_BAR_DIMENSIONS.x) * 1.2 / 2) - message.x, y: bubbleIconLocalPosition.y, z: bubbleIconLocalPosition.z }; + } else if (message.y !== undefined) { + newMicBarLocalPosition = { x: micBarLocalPosition.x, y: message.y, z: micBarLocalPosition.z }; + newBubbleIconLocalPosition = { x: bubbleIconLocalPosition.x, y: ((MIC_BAR_DIMENSIONS.y - BUBBLE_ICON_DIMENSIONS.y) / 2 + message.y), z: bubbleIconLocalPosition.z }; + } else if (message.z !== undefined) { + newMicBarLocalPosition = { x: micBarLocalPosition.x, y: micBarLocalPosition.y, z: message.z }; + newBubbleIconLocalPosition = { x: bubbleIconLocalPosition.x, y: bubbleIconLocalPosition.y, z: message.z }; + } + var micBarProps = { + localPosition: newMicBarLocalPosition }; - micBarEntity = Entities.addEntity(props, "local"); - var props = { - type: "Web", - name: "AvatarInputsBubbleIconEntity", - parentID: MyAvatar.SELF_ID, - parentJointIndex: MyAvatar.getJointIndex("_CAMERA_MATRIX"), - localPosition: bubbleIconLocalPosition, - localRotation: Quat.cancelOutRollAndPitch(Quat.lookAtSimple(Camera.orientation, bubbleIconLocalPosition)), - sourceUrl: Script.resourcesPath() + "qml/BubbleIcon.qml", - // cutoff alpha for detecting transparency - alpha: 0.98, - dimensions: BUBBLE_ICON_DIMENSIONS, - drawInFront: true, - userData: { - grabbable: false - }, + var bubbleIconProps = { + localPosition: newBubbleIconLocalPosition }; - bubbleIconEntity = Entities.addEntity(props, "local"); - tablet.loadQMLSource(AVATAR_INPUTS_EDIT_QML_SOURCE); - } else { + + Entities.editEntity(micBarEntity, micBarProps); + Entities.editEntity(bubbleIconEntity, bubbleIconProps); + } else if (message.method === "setVisible") { + if (message.visible !== undefined) { + var props = { + visible: message.visible + }; + Entities.editEntity(micBarEntity, props); + Entities.editEntity(bubbleIconEntity, props); + } + } else if (message.method === "print") { + // prints the local position into the hifi log. + var micBarLocalPosition = Entities.getEntityProperties(micBarEntity).localPosition; + var bubbleIconLocalPosition = Entities.getEntityProperties(bubbleIconEntity).localPosition; + console.log("mic bar local position is at " + JSON.stringify(micBarLocalPosition)); + console.log("bubble icon local position is at " + JSON.stringify(bubbleIconLocalPosition)); + } else if (message.method === "destroy") { + console.log("destroying"); Entities.deleteEntity(micBarEntity); Entities.deleteEntity(bubbleIconEntity); } }; - function setup() { - // button = tablet.addButton({ - // icon: "icons/tablet-icons/edit-i.svg", - // activeIcon: "icons/tablet-icons/edit-a.svg", - // text: buttonName - // }); - ui = new AppUi({ - buttonName: "AVBAR", - home: Script.resourcesPath() + "qml/hifi/EditAvatarInputsBar.qml", - onMessage: fromQml, - // normalButton: "icons/tablet-icons/avatar-i.svg", - // activeButton: "icons/tablet-icons/avatar-a.svg", - }); - button.clicked.connect(onClicked); + function createEntities(){ + // POSITIONS + var micBarLocalPosition = {x: (-(MIC_BAR_DIMENSIONS.x / 2)) + LOCAL_POSITION_X_OFFSET, y: LOCAL_POSITION_Y_OFFSET, z: LOCAL_POSITION_Z_OFFSET}; + var bubbleIconLocalPosition = {x: (MIC_BAR_DIMENSIONS.x * 1.2 / 2) + LOCAL_POSITION_X_OFFSET, y: ((MIC_BAR_DIMENSIONS.y - BUBBLE_ICON_DIMENSIONS.y) / 2 + LOCAL_POSITION_Y_OFFSET), z: LOCAL_POSITION_Z_OFFSET}; + var props = { + type: "Web", + name: "AvatarInputsMicBarEntity", + parentID: MyAvatar.SELF_ID, + parentJointIndex: MyAvatar.getJointIndex("_CAMERA_MATRIX"), + localPosition: micBarLocalPosition, + localRotation: Quat.cancelOutRollAndPitch(Quat.lookAtSimple(Camera.orientation, micBarLocalPosition)), + sourceUrl: Script.resourcesPath() + "qml/hifi/audio/MicBarApplication.qml", + // cutoff alpha for detecting transparency + alpha: 0.98, + dimensions: MIC_BAR_DIMENSIONS, + drawInFront: true, + userData: { + grabbable: false + }, + }; + micBarEntity = Entities.addEntity(props, "local"); + var props = { + type: "Web", + name: "AvatarInputsBubbleIconEntity", + parentID: MyAvatar.SELF_ID, + parentJointIndex: MyAvatar.getJointIndex("_CAMERA_MATRIX"), + localPosition: bubbleIconLocalPosition, + localRotation: Quat.cancelOutRollAndPitch(Quat.lookAtSimple(Camera.orientation, bubbleIconLocalPosition)), + sourceUrl: Script.resourcesPath() + "qml/BubbleIcon.qml", + // cutoff alpha for detecting transparency + alpha: 0.98, + dimensions: BUBBLE_ICON_DIMENSIONS, + drawInFront: true, + userData: { + grabbable: false + }, + }; + bubbleIconEntity = Entities.addEntity(props, "local"); + tablet.loadQMLSource(AVATAR_INPUTS_EDIT_QML_SOURCE); }; - - setup(); - - Script.scriptEnding.connect(function() { + function cleanup() { if (micBarEntity) { Entities.deleteEntity(micBarEntity); } if (bubbleIconEntity) { Entities.deleteEntity(bubbleIconEntity); } - tablet.removeButton(button); - }); + }; + + function setup() { + ui = new AppUi({ + buttonName: "AVBAR", + home: Script.resourcesPath() + "qml/hifi/EditAvatarInputsBar.qml", + onMessage: fromQml, + onOpened: createEntities, + onClosed: cleanup, + // normalButton: "icons/tablet-icons/avatar-i.svg", + // activeButton: "icons/tablet-icons/avatar-a.svg", + }); + }; + + setup(); + + Script.scriptEnding.connect(cleanup); }());