port over PR-14429

This commit is contained in:
Seth Alves 2018-12-10 18:36:11 -08:00
parent 9900040ece
commit 1c1e648b8b
2 changed files with 31 additions and 77 deletions

View file

@ -53,7 +53,6 @@ Script.include("/~/system/libraries/controllers.js");
this.potentialEntityWithContextOverlay = false; this.potentialEntityWithContextOverlay = false;
this.entityWithContextOverlay = false; this.entityWithContextOverlay = false;
this.contextOverlayTimer = false; this.contextOverlayTimer = false;
this.highlightedEntity = null;
this.reticleMinX = MARGIN; this.reticleMinX = MARGIN;
this.reticleMaxX = 0; this.reticleMaxX = 0;
this.reticleMinY = MARGIN; this.reticleMinY = MARGIN;
@ -339,8 +338,6 @@ Script.include("/~/system/libraries/controllers.js");
if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE || if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE ||
this.notPointingAtEntity(controllerData) || this.targetIsNull()) { this.notPointingAtEntity(controllerData) || this.targetIsNull()) {
this.endFarGrabEntity(controllerData); this.endFarGrabEntity(controllerData);
Selection.removeFromSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity", 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;
@ -387,8 +384,6 @@ Script.include("/~/system/libraries/controllers.js");
if (rayPickInfo.type === Picks.INTERSECTED_ENTITY) { if (rayPickInfo.type === Picks.INTERSECTED_ENTITY) {
if (controllerData.triggerClicks[this.hand]) { if (controllerData.triggerClicks[this.hand]) {
var entityID = rayPickInfo.objectID; var entityID = rayPickInfo.objectID;
Selection.removeFromSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity", this.highlightedEntity);
this.highlightedEntity = null;
var targetProps = Entities.getEntityProperties(entityID, DISPATCHER_PROPERTIES); var targetProps = Entities.getEntityProperties(entityID, DISPATCHER_PROPERTIES);
if (targetProps.href !== "") { if (targetProps.href !== "") {
AddressManager.handleLookupString(targetProps.href); AddressManager.handleLookupString(targetProps.href);
@ -419,64 +414,42 @@ Script.include("/~/system/libraries/controllers.js");
this.distanceHolding = true; this.distanceHolding = true;
this.startFarGrabEntity(controllerData, targetProps); this.startFarGrabEntity(controllerData, targetProps);
} }
} else { } else if (!this.entityWithContextOverlay) {
var targetEntityID = rayPickInfo.objectID; var _this = this;
if (this.highlightedEntity !== targetEntityID) {
Selection.removeFromSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity", this.highlightedEntity);
var selectionTargetProps = Entities.getEntityProperties(targetEntityID, DISPATCHER_PROPERTIES);
var selectionTargetObject = new TargetObject(targetEntityID, selectionTargetProps); if (_this.potentialEntityWithContextOverlay !== rayPickInfo.objectID) {
selectionTargetObject.parentProps = getEntityParents(selectionTargetProps); if (_this.contextOverlayTimer) {
var selectionTargetEntity = selectionTargetObject.getTargetEntity(); Script.clearTimeout(_this.contextOverlayTimer);
if (entityIsGrabbable(selectionTargetEntity.props) ||
entityIsGrabbable(selectionTargetObject.entityProps)) {
Selection.addToSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity", rayPickInfo.objectID);
} }
this.highlightedEntity = rayPickInfo.objectID; _this.contextOverlayTimer = false;
_this.potentialEntityWithContextOverlay = rayPickInfo.objectID;
} }
if (!this.entityWithContextOverlay) { if (!_this.contextOverlayTimer) {
var _this = this; _this.contextOverlayTimer = Script.setTimeout(function () {
if (!_this.entityWithContextOverlay &&
if (_this.potentialEntityWithContextOverlay !== rayPickInfo.objectID) { _this.contextOverlayTimer &&
if (_this.contextOverlayTimer) { _this.potentialEntityWithContextOverlay === rayPickInfo.objectID) {
Script.clearTimeout(_this.contextOverlayTimer); var cotProps = Entities.getEntityProperties(rayPickInfo.objectID,
DISPATCHER_PROPERTIES);
var pointerEvent = {
type: "Move",
id: _this.hand + 1, // 0 is reserved for hardware mouse
pos2D: projectOntoEntityXYPlane(rayPickInfo.objectID,
rayPickInfo.intersection, cotProps),
pos3D: rayPickInfo.intersection,
normal: rayPickInfo.surfaceNormal,
direction: Vec3.subtract(ZERO_VEC, rayPickInfo.surfaceNormal),
button: "Secondary"
};
if (ContextOverlay.createOrDestroyContextOverlay(rayPickInfo.objectID, pointerEvent)) {
_this.entityWithContextOverlay = rayPickInfo.objectID;
}
} }
_this.contextOverlayTimer = false; _this.contextOverlayTimer = false;
_this.potentialEntityWithContextOverlay = rayPickInfo.objectID; }, 500);
}
if (!_this.contextOverlayTimer) {
_this.contextOverlayTimer = Script.setTimeout(function () {
if (!_this.entityWithContextOverlay &&
_this.contextOverlayTimer &&
_this.potentialEntityWithContextOverlay === rayPickInfo.objectID) {
var cotProps = Entities.getEntityProperties(rayPickInfo.objectID,
DISPATCHER_PROPERTIES);
var pointerEvent = {
type: "Move",
id: _this.hand + 1, // 0 is reserved for hardware mouse
pos2D: projectOntoEntityXYPlane(rayPickInfo.objectID,
rayPickInfo.intersection, cotProps),
pos3D: rayPickInfo.intersection,
normal: rayPickInfo.surfaceNormal,
direction: Vec3.subtract(ZERO_VEC, rayPickInfo.surfaceNormal),
button: "Secondary"
};
if (ContextOverlay.createOrDestroyContextOverlay(rayPickInfo.objectID, pointerEvent)) {
_this.entityWithContextOverlay = rayPickInfo.objectID;
}
}
_this.contextOverlayTimer = false;
}, 500);
}
} }
} }
} else if (this.highlightedEntity) {
Selection.removeFromSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity", this.highlightedEntity);
this.highlightedEntity = null;
} }
} }
return this.exitIfDisabled(controllerData); return this.exitIfDisabled(controllerData);

View file

@ -10,7 +10,7 @@
disableDispatcherModule, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, TRIGGER_OFF_VALUE, TRIGGER_ON_VALUE, disableDispatcherModule, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, TRIGGER_OFF_VALUE, TRIGGER_ON_VALUE,
makeDispatcherModuleParameters, entityIsGrabbable, makeRunningValues, NEAR_GRAB_RADIUS, findGroupParent, Vec3, makeDispatcherModuleParameters, entityIsGrabbable, makeRunningValues, NEAR_GRAB_RADIUS, findGroupParent, Vec3,
cloneEntity, entityIsCloneable, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, BUMPER_ON_VALUE, cloneEntity, entityIsCloneable, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, BUMPER_ON_VALUE,
distanceBetweenPointAndEntityBoundingBox, highlightTargetEntity, unhighlightTargetEntity, getGrabbableData, distanceBetweenPointAndEntityBoundingBox, getGrabbableData,
DISPATCHER_PROPERTIES, HMD, NEAR_GRAB_DISTANCE DISPATCHER_PROPERTIES, HMD, NEAR_GRAB_DISTANCE
*/ */
@ -24,7 +24,6 @@ Script.include("/~/system/libraries/controllers.js");
this.hand = hand; this.hand = hand;
this.targetEntityID = null; this.targetEntityID = null;
this.grabbing = false; this.grabbing = false;
this.highlightedEntity = null;
this.cloneAllowed = true; this.cloneAllowed = true;
this.grabID = null; this.grabID = null;
@ -37,14 +36,7 @@ Script.include("/~/system/libraries/controllers.js");
this.startNearGrabEntity = function (controllerData, targetProps) { this.startNearGrabEntity = function (controllerData, targetProps) {
var grabData = getGrabbableData(targetProps); var grabData = getGrabbableData(targetProps);
Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand);
unhighlightTargetEntity(this.targetEntityID);
this.highlightedEntity = null;
var message = {
hand: this.hand,
entityID: this.targetEntityID
};
Messages.sendLocalMessage('Hifi-unhighlight-entity', JSON.stringify(message));
var handJointIndex; var handJointIndex;
if (HMD.mounted && HMD.isHandControllerAvailable() && grabData.grabFollowsController) { if (HMD.mounted && HMD.isHandControllerAvailable() && grabData.grabFollowsController) {
handJointIndex = getControllerJointIndex(this.hand); handJointIndex = getControllerJointIndex(this.hand);
@ -87,8 +79,7 @@ Script.include("/~/system/libraries/controllers.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.highlightedEntity = null;
this.grabbing = false; this.grabbing = false;
this.targetEntityID = null; this.targetEntityID = null;
}; };
@ -135,14 +126,8 @@ Script.include("/~/system/libraries/controllers.js");
var targetProps = this.getTargetProps(controllerData); var targetProps = this.getTargetProps(controllerData);
if (targetProps) { if (targetProps) {
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 {
if (this.highlightedEntity) {
unhighlightTargetEntity(this.highlightedEntity);
this.highlightedEntity = null;
}
return makeRunningValues(false, [], []); return makeRunningValues(false, [], []);
} }
}; };
@ -167,8 +152,6 @@ Script.include("/~/system/libraries/controllers.js");
props = Entities.getEntityProperties(this.targetEntityID, DISPATCHER_PROPERTIES); props = Entities.getEntityProperties(this.targetEntityID, DISPATCHER_PROPERTIES);
if (!props) { if (!props) {
// entity was deleted // entity was deleted
unhighlightTargetEntity(this.targetEntityID);
this.highlightedEntity = null;
this.grabbing = false; this.grabbing = false;
this.targetEntityID = null; this.targetEntityID = null;
return makeRunningValues(false, [], []); return makeRunningValues(false, [], []);
@ -178,11 +161,9 @@ Script.include("/~/system/libraries/controllers.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, "continueNearGrab", args); Entities.callEntityMethod(this.targetEntityID, "continueNearGrab", args);
} else { } else {
// still searching / highlighting // still searching
var readiness = this.isReady(controllerData); var readiness = this.isReady(controllerData);
if (!readiness.active) { if (!readiness.active) {
unhighlightTargetEntity(this.highlightedEntity);
this.highlightedEntity = null;
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) {