grab.js will now ignore click-to-equip entities

This commit is contained in:
Seth Alves 2019-01-15 14:17:51 -08:00
parent e8676f63c6
commit b5326936d8
3 changed files with 21 additions and 37 deletions

View file

@ -6,11 +6,11 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
/* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, Camera, print,
getControllerJointIndex, enableDispatcherModule, disableDispatcherModule, entityIsFarGrabbedByOther,
Messages, makeDispatcherModuleParameters, makeRunningValues, Settings, entityHasActions,
Vec3, Overlays, flatten, Xform, getControllerWorldLocation, ensureDynamic, entityIsCloneable,
cloneEntity, DISPATCHER_PROPERTIES, Uuid, unhighlightTargetEntity, isInEditMode, getGrabbableData
/* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, Camera, print, getControllerJointIndex,
enableDispatcherModule, disableDispatcherModule, entityIsFarGrabbedByOther, Messages, makeDispatcherModuleParameters,
makeRunningValues, Settings, entityHasActions, Vec3, Overlays, flatten, Xform, getControllerWorldLocation, ensureDynamic,
entityIsCloneable, cloneEntity, DISPATCHER_PROPERTIES, Uuid, unhighlightTargetEntity, isInEditMode, getGrabbableData,
entityIsEquippable
*/
Script.include("/~/system/libraries/Xform.js");
@ -767,7 +767,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
var entityProperties = Entities.getEntityProperties(entityID, DISPATCHER_PROPERTIES);
entityProperties.id = entityID;
var hasEquipData = getWearableData(entityProperties);
if (hasEquipData && entityProperties.parentID === EMPTY_PARENT_ID && !entityIsFarGrabbedByOther(entityID)) {
if (hasEquipData && entityIsEquippable(entityProperties)) {
entityProperties.id = entityID;
var rightHandPosition = MyAvatar.getJointPosition("RightHand");
var leftHandPosition = MyAvatar.getJointPosition("LeftHand");

View file

@ -257,15 +257,12 @@ Grabber.prototype.pressEvent = function(event) {
if (isInEditMode() || HMD.active) {
return;
}
if (event.button !== "LEFT") {
return;
}
if (event.isAlt || event.isMeta) {
return;
}
if (Overlays.getOverlayAtPoint(Reticle.position) > 0) {
// the mouse is pointing at an overlay; don't look for entities underneath the overlay.
return;
@ -287,6 +284,10 @@ Grabber.prototype.pressEvent = function(event) {
// only grab grabbable objects
return;
}
if (props.grab.equippable) {
// don't mouse-grab click-to-equip entities (let equipEntity.js handle these)
return;
}
Pointers.setRenderState(this.mouseRayEntities, "grabbed");
Pointers.setLockEndUUID(this.mouseRayEntities, pickResults.objectID, false);

View file

@ -58,7 +58,6 @@
NEAR_GRAB_DISTANCE: true,
distanceBetweenPointAndEntityBoundingBox:true,
entityIsEquipped:true,
entityIsFarGrabbedByOther:true,
highlightTargetEntity:true,
clearHighlightedEntities:true,
unhighlightTargetEntity:true,
@ -323,16 +322,20 @@ isAnothersChildEntity = function (iaceProps) {
return false;
};
entityIsGrabbable = function (eigProps) {
var grabbable = getGrabbableData(eigProps).grabbable;
entityIsEquippable = function (eieProps) {
var grabbable = getGrabbableData(eieProps).grabbable;
if (!grabbable ||
eigProps.locked ||
isAnothersAvatarEntity(eigProps) ||
isAnothersChildEntity(eigProps) ||
FORBIDDEN_GRAB_TYPES.indexOf(eigProps.type) >= 0) {
isAnothersAvatarEntity(eieProps) ||
isAnothersChildEntity(eieProps) ||
FORBIDDEN_GRAB_TYPES.indexOf(eieProps.type) >= 0) {
return false;
}
return true;
}
entityIsGrabbable = function (eigProps) {
return entityIsEquippable(eigProps) && !eigProps.locked;
};
clearHighlightedEntities = function() {
@ -561,27 +564,6 @@ entityIsEquipped = function(entityID) {
return equippedInRightHand || equippedInLeftHand;
};
entityIsFarGrabbedByOther = function(entityID) {
// by convention, a far grab sets the tag of its action to be far-grab-*owner-session-id*.
var actionIDs = Entities.getActionIDs(entityID);
var myFarGrabTag = "far-grab-" + MyAvatar.sessionUUID;
for (var actionIndex = 0; actionIndex < actionIDs.length; actionIndex++) {
var actionID = actionIDs[actionIndex];
var actionArguments = Entities.getActionArguments(entityID, actionID);
var tag = actionArguments.tag;
if (tag == myFarGrabTag) {
// we see a far-grab-*uuid* shaped tag, but it's our tag, so that's okay.
continue;
}
if (tag.slice(0, 9) == "far-grab-") {
// we see a far-grab-*uuid* shaped tag and it's not ours, so someone else is grabbing it.
return true;
}
}
return false;
};
worldPositionToRegistrationFrameMatrix = function(wptrProps, pos) {
// get world matrix for intersection point
var intersectionMat = new Xform({ x: 0, y: 0, z:0, w: 1 }, pos);
@ -620,6 +602,7 @@ if (typeof module !== 'undefined') {
BUMPER_ON_VALUE: BUMPER_ON_VALUE,
TEAR_AWAY_DISTANCE: TEAR_AWAY_DISTANCE,
propsArePhysical: propsArePhysical,
entityIsEquippable: entityIsEquippable,
entityIsGrabbable: entityIsGrabbable,
NEAR_GRAB_RADIUS: NEAR_GRAB_RADIUS,
projectOntoOverlayXYPlane: projectOntoOverlayXYPlane,