diff --git a/scripts/system/controllers/controllerModules/equipEntity.js b/scripts/system/controllers/controllerModules/equipEntity.js index 09d64b5d05..10bd5d28d3 100644 --- a/scripts/system/controllers/controllerModules/equipEntity.js +++ b/scripts/system/controllers/controllerModules/equipEntity.js @@ -489,7 +489,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa entityID: this.targetEntityID }; - Messages.sendMessage('Hifi-unhighlight-entity', JSON.stringify(message)); + Messages.sendLocalMessage('Hifi-unhighlight-entity', JSON.stringify(message)); var grabbedProperties = Entities.getEntityProperties(this.targetEntityID); // if an object is "equipped" and has a predefined offset, use it. diff --git a/scripts/system/controllers/controllerModules/highlightNearbyEntities.js b/scripts/system/controllers/controllerModules/highlightNearbyEntities.js index a102a5d735..5def5dcd3b 100644 --- a/scripts/system/controllers/controllerModules/highlightNearbyEntities.js +++ b/scripts/system/controllers/controllerModules/highlightNearbyEntities.js @@ -1,7 +1,9 @@ -"use strict"; - +// // highlightNearbyEntities.js // +// Created by Dante Ruiz 2018-4-10 +// Copyright 2017 High Fidelity, Inc. +// // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -12,6 +14,8 @@ DEFAULT_SEARCH_SPHERE_DISTANCE, getGrabbableData, makeLaserParams, entityIsCloneable, Messages, print */ +"use strict"; + (function () { Script.include("/~/system/libraries/controllerDispatcherUtils.js"); Script.include("/~/system/libraries/controllers.js"); @@ -40,15 +44,16 @@ this.isGrabable = function(controllerData, props) { + var entityIsGrabable = false; if (dispatcherUtils.entityIsGrabbable(props) || entityIsCloneable(props)) { // if we've attempted to grab a child, roll up to the root of the tree var groupRootProps = dispatcherUtils.findGroupParent(controllerData, props); - if (dispatcherUtils.entityIsGrabbable(groupRootProps)) { - return true; + entityIsGrabable = true; + if (!dispatcherUtils.entityIsGrabbable(groupRootProps)) { + entityIsGrabable = false; } - return true; } - return false; + return entityIsGrabable; }; this.hasHyperLink = function(props) { diff --git a/scripts/system/controllers/controllerModules/mouseHighlightEntities.js b/scripts/system/controllers/controllerModules/mouseHighlightEntities.js new file mode 100644 index 0000000000..696c819143 --- /dev/null +++ b/scripts/system/controllers/controllerModules/mouseHighlightEntities.js @@ -0,0 +1,77 @@ +// +// mouseHighlightEntities.js +// +// scripts/system/controllers/controllerModules/ +// +// Created by Dante Ruiz 2018-4-11 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +/* jslint bitwise: true */ + +/* global Script, print, Entities, Picks, HMD */ + + +(function() { + var dispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js"); + + function MouseHighlightEntities() { + this.highlightedEntity = null; + + this.parameters = dispatcherUtils.makeDispatcherModuleParameters( + 5, + ["mouse"], + [], + 100); + + this.isReady = function(controllerData) { + if (HMD.active) { + print("????"); + if (this.highlightedEntity) { + // unhighlight entity + } + } else { + var pickResult = controllerData.mouseRayPick; + if (pickResult.type === Picks.INTERSECTED_ENTITY) { + var targetEntityID = pickResult.objectID; + + if (this.highlightedEntity !== targetEntityID) { + var targetProps = Entities.getEntityProperties(targetEntityID, [ + "dynamic", "shapeType", "position", + "rotation", "dimensions", "density", + "userData", "locked", "type", "href" + ]); + + if (this.highlightedEntity) { + dispatcherUtils.unhighlightTargetEntity(this.highlightedEntity); + this.highlightedEntity = null; + } + + if (dispatcherUtils.entityIsGrabbable(targetProps)) { + // highlight entity + dispatcherUtils.highlightTargetEntity(targetEntityID); + this.highlightedEntity = targetEntityID; + } + } + } + } + + return dispatcherUtils.makeRunningValues(false, [], []); + }; + + this.run = function(controllerData) { + return this.isReady(controllerData); + }; + } + + var mouseHighlightEntities = new MouseHighlightEntities(); + dispatcherUtils.enableDispatcherModule("MouseHighlightEntities", mouseHighlightEntities); + + function cleanup() { + dispatcherUtils.disableDispatcherModule("MouseHighlightEntities"); + } + Script.scriptEnding.connect(cleanup); +})(); diff --git a/scripts/system/controllers/controllerModules/nearActionGrabEntity.js b/scripts/system/controllers/controllerModules/nearActionGrabEntity.js index a1e4cff40d..a4e439fe2f 100644 --- a/scripts/system/controllers/controllerModules/nearActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearActionGrabEntity.js @@ -120,7 +120,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); entityID: this.targetEntityID }; - Messages.sendMessage('Hifi-unhighlight-entity', JSON.stringify(message)); + Messages.sendLocalMessage('Hifi-unhighlight-entity', JSON.stringify(message)); }; // this is for when the action is going to time-out diff --git a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js index 55dde21f46..d454d20a02 100644 --- a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js @@ -95,7 +95,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); entityID: this.targetEntityID }; - Messages.sendMessage('Hifi-unhighlight-entity', JSON.stringify(message)); + Messages.sendLocalMessage('Hifi-unhighlight-entity', JSON.stringify(message)); var handJointIndex; // if (this.ignoreIK) { // handJointIndex = this.controllerJointIndex; diff --git a/scripts/system/controllers/controllerScripts.js b/scripts/system/controllers/controllerScripts.js index 058c99349d..50e627fe5d 100644 --- a/scripts/system/controllers/controllerScripts.js +++ b/scripts/system/controllers/controllerScripts.js @@ -33,7 +33,8 @@ var CONTOLLER_SCRIPTS = [ "controllerModules/mouseHMD.js", "controllerModules/scaleEntity.js", "controllerModules/highlightNearbyEntities.js", - "controllerModules/nearGrabHyperLinkEntity.js" + "controllerModules/nearGrabHyperLinkEntity.js", + "controllerModules/mouseHighlightEntities.js" ]; var DEBUG_MENU_ITEM = "Debug defaultScripts.js";