From 732fe3b8dbc1e4f23cede8a319c2360f2b4d6151 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Fri, 20 Oct 2017 11:32:43 +0200 Subject: [PATCH] Improved outline debugging script for easier test plan --- .../scripting/SelectionScriptingInterface.cpp | 6 ++ .../scripting/SelectionScriptingInterface.h | 1 + .../utilities/render/debugOutline.js | 85 +++++++++++++------ .../developer/utilities/render/outline.qml | 31 +++++-- 4 files changed, 90 insertions(+), 33 deletions(-) diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp index 808396c901..1adf5650dd 100644 --- a/interface/src/scripting/SelectionScriptingInterface.cpp +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -71,6 +71,12 @@ bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& lis return false; } +bool SelectionScriptingInterface::clearSelectedItemsList(const QString& listName) { + _selectedItemsListMap.insert(listName, GameplayObjects()); + emit selectedItemsListChanged(listName); + return true; +} + template bool SelectionScriptingInterface::addToGameplayObjects(const QString& listName, T idToAdd) { GameplayObjects currentList = _selectedItemsListMap.value(listName); currentList.addToGameplayObjects(idToAdd); diff --git a/interface/src/scripting/SelectionScriptingInterface.h b/interface/src/scripting/SelectionScriptingInterface.h index d1a372c5c4..28c1713050 100644 --- a/interface/src/scripting/SelectionScriptingInterface.h +++ b/interface/src/scripting/SelectionScriptingInterface.h @@ -61,6 +61,7 @@ public: Q_INVOKABLE bool addToSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id); Q_INVOKABLE bool removeFromSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id); + Q_INVOKABLE bool clearSelectedItemsList(const QString& listName); signals: void selectedItemsListChanged(const QString& listName); diff --git a/scripts/developer/utilities/render/debugOutline.js b/scripts/developer/utilities/render/debugOutline.js index 5ac7bcd6aa..c01fbd3c76 100644 --- a/scripts/developer/utilities/render/debugOutline.js +++ b/scripts/developer/utilities/render/debugOutline.js @@ -55,14 +55,7 @@ var end2 = { } var outlineGroupIndex = 0 - -function setOutlineGroupIndex(index) { - print("Switching to outline group "+index) - outlineGroupIndex = index -} - -window.fromQml.connect(setOutlineGroupIndex); - +var isSelectionAddEnabled = false var renderStates = [{name: "test", end: end}]; var defaultRenderStates = [{name: "test", distance: 20.0, end: end2}]; @@ -71,33 +64,64 @@ var ray = LaserPointers.createLaserPointer({ filter: RayPick.PICK_ENTITIES | RayPick.PICK_OVERLAYS | RayPick.PICK_AVATARS | RayPick.PICK_INVISIBLE | RayPick.PICK_NONCOLLIDABLE, renderStates: renderStates, defaultRenderStates: defaultRenderStates, - enabled: true + enabled: false }); +function getSelectionName() { + var selectionName = "contextOverlayHighlightList" + + if (outlineGroupIndex>0) { + selectionName += outlineGroupIndex + } + return selectionName +} + +function fromQml(message) { + tokens = message.split(' ') + print("Received '"+message+"' from outline.qml") + if (tokens[0]=="outline") { + outlineGroupIndex = parseInt(tokens[1]) + print("Switching to outline group "+outlineGroupIndex) + } else if (tokens[0]=="pick") { + var isPickingEnabled = tokens[1]=='true' + print("Ray picking set to "+isPickingEnabled.toString()) + if (isPickingEnabled) { + LaserPointers.enableLaserPointer(ray) + } else { + LaserPointers.disableLaserPointer(ray) + } + } else if (tokens[0]=="add") { + isSelectionAddEnabled = tokens[1]=='true' + print("Add to selection set to "+isSelectionAddEnabled.toString()) + if (!isSelectionAddEnabled) { + Selection.clearSelectedItemsList(getSelectionName()) + } + } +} + +window.fromQml.connect(fromQml); + function cleanup() { LaserPointers.removeLaserPointer(ray); } Script.scriptEnding.connect(cleanup); -var prevID = 0; -var prevType = ""; -function update() { +var prevID = 0 +var prevType = "" +var selectedID = 0 +var selectedType = "" +var time = 0 +function update(deltaTime) { + // you have to do this repeatedly because there's a bug but I'll fix it LaserPointers.setRenderState(ray, "test"); var result = LaserPointers.getPrevRayPickResult(ray); - var selectionName = "contextOverlayHighlightList" - - if (outlineGroupIndex>0) { - selectionName += outlineGroupIndex - } + var selectionName = getSelectionName() if (result.type != RayPick.INTERSECTED_NONE) { + time += deltaTime if (result.objectID != prevID) { - if (prevID != 0) { - Selection.removeFromSelectedItemsList(selectionName, prevType, prevID) - } - var typeName = "" if (result.type == RayPick.INTERSECTED_ENTITY) { typeName = "entity" @@ -107,19 +131,28 @@ function update() { typeName = "avatar" } - Selection.addToSelectedItemsList(selectionName, typeName, result.objectID) - //print("OUTLINE " + outlineGroupIndex + " picked type: " + result.type + ", id: " + result.objectID); - prevID = result.objectID; prevType = typeName; + time = 0 + } else if (time>1.0 && prevID!=selectedID) { + if (prevID != 0 && !isSelectionAddEnabled) { + Selection.removeFromSelectedItemsList(selectionName, selectedType, selectedID) + } + selectedID = prevID + selectedType = prevType + Selection.addToSelectedItemsList(selectionName, selectedType, selectedID) + //print("OUTLINE " + outlineGroupIndex + " picked type: " + result.type + ", id: " + result.objectID); } } else { - if (prevID != 0) { + if (prevID != 0 && !isSelectionAddEnabled) { Selection.removeFromSelectedItemsList(selectionName, prevType, prevID) } - prevID = 0; + prevID = 0 + selectedID = 0 + time = 0 } } + Script.update.connect(update); }()); // END LOCAL_SCOPE \ No newline at end of file diff --git a/scripts/developer/utilities/render/outline.qml b/scripts/developer/utilities/render/outline.qml index 578f0857dc..39acd854ac 100644 --- a/scripts/developer/utilities/render/outline.qml +++ b/scripts/developer/utilities/render/outline.qml @@ -21,12 +21,29 @@ Item { spacing: 8 anchors.fill: parent - CheckBox { - id: debug - text: "View Mask" - checked: root.debugConfig["viewMask"] - onCheckedChanged: { - root.debugConfig["viewMask"] = checked; + Row { + spacing: 8 + CheckBox { + id: debug + text: "View Mask" + checked: root.debugConfig["viewMask"] + onCheckedChanged: { + root.debugConfig["viewMask"] = checked; + } + } + CheckBox { + text: "Hover select" + checked: false + onCheckedChanged: { + sendToScript("pick "+checked.toString()) + } + } + CheckBox { + text: "Add to selection" + checked: false + onCheckedChanged: { + sendToScript("add "+checked.toString()) + } } } @@ -36,7 +53,7 @@ Item { height: 400 onCurrentIndexChanged: { - sendToScript(currentIndex) + sendToScript("outline "+currentIndex) } Tab {