highlight nearby entities

This commit is contained in:
Dante Ruiz 2018-04-05 15:38:56 -07:00
parent 42149e295d
commit cc341e8ad7
7 changed files with 126 additions and 6 deletions

View file

@ -404,6 +404,7 @@ Script.include("/~/system/libraries/Xform.js");
this.endNearGrabAction(); this.endNearGrabAction();
Selection.removeFromSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity", Selection.removeFromSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity",
this.highlightedEntity); this.highlightedEntity);
this.highlightedEntity = null;
return makeRunningValues(false, [], []); return makeRunningValues(false, [], []);
} }
this.intersectionDistance = controllerData.rayPicks[this.hand].distance; this.intersectionDistance = controllerData.rayPicks[this.hand].distance;
@ -575,6 +576,7 @@ Script.include("/~/system/libraries/Xform.js");
this.endNearGrabAction(); this.endNearGrabAction();
Selection.removeFromSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity", Selection.removeFromSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity",
this.highlightedEntity); this.highlightedEntity);
this.highlightedEntity = null;
return makeRunningValues(false, [], []); return makeRunningValues(false, [], []);
} }
} }

View file

@ -0,0 +1,88 @@
"use strict";
// highlightNearbyEntities.js
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
/* global Script, Controller, RIGHT_HAND, LEFT_HAND, MyAvatar, getGrabPointSphereOffset,
makeRunningValues, Entities, enableDispatcherModule, disableDispatcherModule, makeDispatcherModuleParameters,
PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD,
DEFAULT_SEARCH_SPHERE_DISTANCE, getGrabbableData, makeLaserParams
*/
(function () {
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllers.js");
var dispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js");
function HighlightNearbyEntities(hand) {
this.hand = hand;
this.highlightedEntities = [];
this.parameters = dispatcherUtils.makeDispatcherModuleParameters(
480,
this.hand === dispatcherUtils.RIGHT_HAND ? ["rightHand"] : ["leftHand"],
[],
100);
this.isGrabable = function(controllerData, props) {
if (dispatcherUtils.entityIsGrabbable(props) || dispatcherUtils.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;
}
return true;
}
return false;
};
this.hasHyperLink = function(props) {
return (props.href !== "" && props.href !== undefined);
};
this.highlightEntities = function(controllerData) {
if (this.highlightedEntities.length > 0) {
dispatcherUtils.clearHighlightedEntities();
this.highlightedEntities = [];
}
var nearbyEntitiesProperties = controllerData.nearbyEntityProperties[this.hand];
var sensorScaleFactor = MyAvatar.sensorToWorldScale;
for (var i = 0; i < nearbyEntitiesProperties.length; i++) {
var props = nearbyEntitiesProperties[i];
if (props.distance > dispatcherUtils.NEAR_GRAB_RADIUS * sensorScaleFactor) {
continue;
}
if (this.isGrabable(controllerData, props) || this.hasHyperLink(props)) {
dispatcherUtils.highlightTargetEntity(props.id);
this.highlightedEntities.push(props.id);
}
}
};
this.isReady = function(controllerData) {
this.highlightEntities(controllerData);
return dispatcherUtils.makeRunningValues(false, [], []);
};
this.run = function(controllerData) {
return this.isReady(controllerData);
};
}
var leftHighlightNearbyEntities = new HighlightNearbyEntities(dispatcherUtils.LEFT_HAND);
var rightHighlightNearbyEntities = new HighlightNearbyEntities(dispatcherUtils.RIGHT_HAND);
dispatcherUtils.enableDispatcherModule("LeftHighlightNearbyEntities", leftHighlightNearbyEntities);
dispatcherUtils.enableDispatcherModule("RightHighlightNearbyEntities", rightHighlightNearbyEntities);
function cleanup() {
dispatcherUtils.disableDispatcherModule("LeftHighlightNearbyEntities");
dispatcherUtils.disableDispatcherModule("RightHighlightNearbyEntities");
}
Script.scriptEnding.connect(cleanup);
}());

View file

@ -10,7 +10,7 @@
propsArePhysical, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, entityIsGrabbable, propsArePhysical, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, entityIsGrabbable,
Quat, Vec3, MSECS_PER_SEC, getControllerWorldLocation, makeDispatcherModuleParameters, makeRunningValues, Quat, Vec3, MSECS_PER_SEC, getControllerWorldLocation, makeDispatcherModuleParameters, makeRunningValues,
TRIGGER_OFF_VALUE, NEAR_GRAB_RADIUS, findGroupParent, entityIsCloneable, propsAreCloneDynamic, cloneEntity, TRIGGER_OFF_VALUE, NEAR_GRAB_RADIUS, findGroupParent, entityIsCloneable, propsAreCloneDynamic, cloneEntity,
HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, BUMPER_ON_VALUE HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, BUMPER_ON_VALUE, unhighlightTargetEntity
*/ */
Script.include("/~/system/libraries/controllerDispatcherUtils.js"); Script.include("/~/system/libraries/controllerDispatcherUtils.js");
@ -114,6 +114,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js");
var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID];
Entities.callEntityMethod(this.targetEntityID, "startNearGrab", args); Entities.callEntityMethod(this.targetEntityID, "startNearGrab", args);
unhighlightTargetEntity(this.targetEntityID);
}; };
// this is for when the action is going to time-out // this is for when the action is going to time-out

View file

@ -11,7 +11,8 @@
TRIGGER_OFF_VALUE, makeDispatcherModuleParameters, entityIsGrabbable, makeRunningValues, NEAR_GRAB_RADIUS, TRIGGER_OFF_VALUE, makeDispatcherModuleParameters, entityIsGrabbable, makeRunningValues, NEAR_GRAB_RADIUS,
findGroupParent, Vec3, cloneEntity, entityIsCloneable, propsAreCloneDynamic, HAPTIC_PULSE_STRENGTH, findGroupParent, Vec3, cloneEntity, entityIsCloneable, propsAreCloneDynamic, HAPTIC_PULSE_STRENGTH,
HAPTIC_PULSE_DURATION, BUMPER_ON_VALUE, findHandChildEntities, TEAR_AWAY_DISTANCE, MSECS_PER_SEC, TEAR_AWAY_CHECK_TIME, HAPTIC_PULSE_DURATION, BUMPER_ON_VALUE, findHandChildEntities, TEAR_AWAY_DISTANCE, MSECS_PER_SEC, TEAR_AWAY_CHECK_TIME,
TEAR_AWAY_COUNT, distanceBetweenPointAndEntityBoundingBox TEAR_AWAY_COUNT, distanceBetweenPointAndEntityBoundingBox, print, Selection, DISPATCHER_HOVERING_LIST, Uuid,
highlightTargetEntity, unhighlightTargetEntity
*/ */
Script.include("/~/system/libraries/controllerDispatcherUtils.js"); Script.include("/~/system/libraries/controllerDispatcherUtils.js");
@ -34,6 +35,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js");
this.autoUnequipCounter = 0; this.autoUnequipCounter = 0;
this.lastUnexpectedChildrenCheckTime = 0; this.lastUnexpectedChildrenCheckTime = 0;
this.robbed = false; this.robbed = false;
this.highlightedEntity = null;
this.parameters = makeDispatcherModuleParameters( this.parameters = makeDispatcherModuleParameters(
500, 500,
@ -87,7 +89,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js");
this.startNearParentingGrabEntity = function (controllerData, targetProps) { this.startNearParentingGrabEntity = function (controllerData, targetProps) {
Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand);
unhighlightTargetEntity(this.targetEntityID);
var handJointIndex; var handJointIndex;
// if (this.ignoreIK) { // if (this.ignoreIK) {
// handJointIndex = this.controllerJointIndex; // handJointIndex = this.controllerJointIndex;
@ -158,6 +160,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js");
grabbedEntity: this.targetEntityID, grabbedEntity: this.targetEntityID,
joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand" joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"
})); }));
unhighlightTargetEntity(this.targetEntityID);
this.grabbing = false; this.grabbing = false;
this.targetEntityID = null; this.targetEntityID = null;
this.robbed = false; this.robbed = false;
@ -280,6 +283,8 @@ Script.include("/~/system/libraries/cloneEntityUtils.js");
return makeRunningValues(false, [], []); // let nearActionGrabEntity handle it return makeRunningValues(false, [], []); // let nearActionGrabEntity handle it
} else { } else {
this.targetEntityID = targetProps.id; this.targetEntityID = targetProps.id;
this.highlightedEntity = this.targetEntityID;
highlightTargetEntity(this.targetEntityID);
return makeRunningValues(true, [this.targetEntityID], []); return makeRunningValues(true, [this.targetEntityID], []);
} }
} else { } else {
@ -300,6 +305,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js");
var props = controllerData.nearbyEntityPropertiesByID[this.targetEntityID]; var props = controllerData.nearbyEntityPropertiesByID[this.targetEntityID];
if (!props) { if (!props) {
// entity was deleted // entity was deleted
unhighlightTargetEntity(this.targetEntityID);
this.grabbing = false; this.grabbing = false;
this.targetEntityID = null; this.targetEntityID = null;
this.hapticTargetID = null; this.hapticTargetID = null;
@ -321,6 +327,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js");
var readiness = this.isReady(controllerData); var readiness = this.isReady(controllerData);
if (!readiness.active) { if (!readiness.active) {
this.robbed = false; this.robbed = false;
unhighlightTargetEntity(this.highlightedEntity);
return readiness; return readiness;
} }
if (controllerData.triggerClicks[this.hand] || controllerData.secondaryValues[this.hand] > BUMPER_ON_VALUE) { if (controllerData.triggerClicks[this.hand] || controllerData.secondaryValues[this.hand] > BUMPER_ON_VALUE) {

View file

@ -7,7 +7,7 @@
/* global Script, Entities, MyAvatar, RIGHT_HAND, LEFT_HAND, enableDispatcherModule, disableDispatcherModule, getGrabbableData, /* global Script, Entities, MyAvatar, RIGHT_HAND, LEFT_HAND, enableDispatcherModule, disableDispatcherModule, getGrabbableData,
Vec3, TRIGGER_OFF_VALUE, makeDispatcherModuleParameters, makeRunningValues, NEAR_GRAB_RADIUS Vec3, TRIGGER_OFF_VALUE, makeDispatcherModuleParameters, makeRunningValues, NEAR_GRAB_RADIUS, unhighlightTargetEntity
*/ */
Script.include("/~/system/libraries/controllerDispatcherUtils.js"); Script.include("/~/system/libraries/controllerDispatcherUtils.js");
@ -55,6 +55,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
this.startNearTrigger = function (controllerData) { this.startNearTrigger = function (controllerData) {
var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID];
Entities.callEntityMethod(this.targetEntityID, "startNearTrigger", args); Entities.callEntityMethod(this.targetEntityID, "startNearTrigger", args);
unhighlightTargetEntity(this.targetEntityID);
}; };
this.continueNearTrigger = function (controllerData) { this.continueNearTrigger = function (controllerData) {

View file

@ -32,6 +32,7 @@ var CONTOLLER_SCRIPTS = [
"controllerModules/hudOverlayPointer.js", "controllerModules/hudOverlayPointer.js",
"controllerModules/mouseHMD.js", "controllerModules/mouseHMD.js",
"controllerModules/scaleEntity.js", "controllerModules/scaleEntity.js",
"controllerModules/highlightNearbyEntities.js",
"controllerModules/nearGrabHyperLinkEntity.js" "controllerModules/nearGrabHyperLinkEntity.js"
]; ];

View file

@ -7,6 +7,7 @@
/* global module, Camera, HMD, MyAvatar, controllerDispatcherPlugins:true, Quat, Vec3, Overlays, Xform, /* global module, Camera, HMD, MyAvatar, controllerDispatcherPlugins:true, Quat, Vec3, Overlays, Xform,
Selection,
MSECS_PER_SEC:true , LEFT_HAND:true, RIGHT_HAND:true, FORBIDDEN_GRAB_TYPES:true, MSECS_PER_SEC:true , LEFT_HAND:true, RIGHT_HAND:true, FORBIDDEN_GRAB_TYPES:true,
HAPTIC_PULSE_STRENGTH:true, HAPTIC_PULSE_DURATION:true, ZERO_VEC:true, ONE_VEC:true, HAPTIC_PULSE_STRENGTH:true, HAPTIC_PULSE_DURATION:true, ZERO_VEC:true, ONE_VEC:true,
DEFAULT_REGISTRATION_POINT:true, INCHES_TO_METERS:true, DEFAULT_REGISTRATION_POINT:true, INCHES_TO_METERS:true,
@ -51,7 +52,10 @@
TEAR_AWAY_DISTANCE:true, TEAR_AWAY_DISTANCE:true,
TEAR_AWAY_COUNT:true, TEAR_AWAY_COUNT:true,
TEAR_AWAY_CHECK_TIME:true, TEAR_AWAY_CHECK_TIME:true,
distanceBetweenPointAndEntityBoundingBox:true distanceBetweenPointAndEntityBoundingBox:true,
highlightTargetEntity:true,
clearHighlightedEntities:true,
unhighlightTargetEntity:true
*/ */
MSECS_PER_SEC = 1000.0; MSECS_PER_SEC = 1000.0;
@ -95,7 +99,7 @@ DISPATCHER_HOVERING_STYLE = {
isOutlineSmooth: true, isOutlineSmooth: true,
outlineWidth: 0, outlineWidth: 0,
outlineUnoccludedColor: {red: 255, green: 128, blue: 128}, outlineUnoccludedColor: {red: 255, green: 128, blue: 128},
outlineUnoccludedAlpha: 0, outlineUnoccludedAlpha: 0.0,
outlineOccludedColor: {red: 255, green: 128, blue: 128}, outlineOccludedColor: {red: 255, green: 128, blue: 128},
outlineOccludedAlpha:0.0, outlineOccludedAlpha:0.0,
fillUnoccludedColor: {red: 255, green: 255, blue: 255}, fillUnoccludedColor: {red: 255, green: 255, blue: 255},
@ -235,6 +239,18 @@ entityIsGrabbable = function (props) {
return true; return true;
}; };
clearHighlightedEntities = function() {
Selection.clearSelectedItemsList(DISPATCHER_HOVERING_LIST);
};
highlightTargetEntity = function(entityID) {
Selection.addToSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity", entityID);
};
unhighlightTargetEntity = function(entityID) {
Selection.removeFromSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity", entityID);
};
entityIsDistanceGrabbable = function(props) { entityIsDistanceGrabbable = function(props) {
if (!entityIsGrabbable(props)) { if (!entityIsGrabbable(props)) {
return false; return false;
@ -404,7 +420,11 @@ if (typeof module !== 'undefined') {
makeDispatcherModuleParameters: makeDispatcherModuleParameters, makeDispatcherModuleParameters: makeDispatcherModuleParameters,
enableDispatcherModule: enableDispatcherModule, enableDispatcherModule: enableDispatcherModule,
disableDispatcherModule: disableDispatcherModule, disableDispatcherModule: disableDispatcherModule,
highlightTargetEntity: highlightTargetEntity,
unhighlightTargetEntity: unhighlightTargetEntity,
clearHighlightedEntities: clearHighlightedEntities,
makeRunningValues: makeRunningValues, makeRunningValues: makeRunningValues,
findGroupParent: findGroupParent,
LEFT_HAND: LEFT_HAND, LEFT_HAND: LEFT_HAND,
RIGHT_HAND: RIGHT_HAND, RIGHT_HAND: RIGHT_HAND,
BUMPER_ON_VALUE: BUMPER_ON_VALUE, BUMPER_ON_VALUE: BUMPER_ON_VALUE,