mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 12:49:34 +02:00
Merge pull request #12995 from dback2/RC66.2
RC66.2: Desktop equip/unequip
This commit is contained in:
commit
8b9d2cdcc8
3 changed files with 102 additions and 6 deletions
|
@ -176,7 +176,10 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
||||||
var TRIGGER_OFF_VALUE = 0.1;
|
var TRIGGER_OFF_VALUE = 0.1;
|
||||||
var TRIGGER_ON_VALUE = TRIGGER_OFF_VALUE + 0.05; // Squeezed just enough to activate search or near grab
|
var TRIGGER_ON_VALUE = TRIGGER_OFF_VALUE + 0.05; // Squeezed just enough to activate search or near grab
|
||||||
var BUMPER_ON_VALUE = 0.5;
|
var BUMPER_ON_VALUE = 0.5;
|
||||||
|
|
||||||
|
var EMPTY_PARENT_ID = "{00000000-0000-0000-0000-000000000000}";
|
||||||
|
|
||||||
|
var UNEQUIP_KEY = "u";
|
||||||
|
|
||||||
function getWearableData(props) {
|
function getWearableData(props) {
|
||||||
var wearable = {};
|
var wearable = {};
|
||||||
|
@ -270,6 +273,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
||||||
this.shouldSendStart = false;
|
this.shouldSendStart = false;
|
||||||
this.equipedWithSecondary = false;
|
this.equipedWithSecondary = false;
|
||||||
this.handHasBeenRightsideUp = false;
|
this.handHasBeenRightsideUp = false;
|
||||||
|
this.mouseEquip = false;
|
||||||
|
|
||||||
this.parameters = makeDispatcherModuleParameters(
|
this.parameters = makeDispatcherModuleParameters(
|
||||||
300,
|
300,
|
||||||
|
@ -279,10 +283,11 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
||||||
|
|
||||||
var equipHotspotBuddy = new EquipHotspotBuddy();
|
var equipHotspotBuddy = new EquipHotspotBuddy();
|
||||||
|
|
||||||
this.setMessageGrabData = function(entityProperties) {
|
this.setMessageGrabData = function(entityProperties, mouseEquip) {
|
||||||
if (entityProperties) {
|
if (entityProperties) {
|
||||||
this.messageGrabEntity = true;
|
this.messageGrabEntity = true;
|
||||||
this.grabEntityProps = entityProperties;
|
this.grabEntityProps = entityProperties;
|
||||||
|
this.mouseEquip = mouseEquip;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -574,6 +579,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
||||||
this.targetEntityID = null;
|
this.targetEntityID = null;
|
||||||
this.messageGrabEntity = false;
|
this.messageGrabEntity = false;
|
||||||
this.grabEntityProps = null;
|
this.grabEntityProps = null;
|
||||||
|
this.mouseEquip = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.updateInputs = function (controllerData) {
|
this.updateInputs = function (controllerData) {
|
||||||
|
@ -650,7 +656,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
||||||
var timestamp = Date.now();
|
var timestamp = Date.now();
|
||||||
this.updateInputs(controllerData);
|
this.updateInputs(controllerData);
|
||||||
|
|
||||||
if (!this.isTargetIDValid(controllerData)) {
|
if (!this.mouseEquip && !this.isTargetIDValid(controllerData)) {
|
||||||
this.endEquipEntity();
|
this.endEquipEntity();
|
||||||
return makeRunningValues(false, [], []);
|
return makeRunningValues(false, [], []);
|
||||||
}
|
}
|
||||||
|
@ -751,7 +757,8 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
||||||
var equipModule = (data.hand === "left") ? leftEquipEntity : rightEquipEntity;
|
var equipModule = (data.hand === "left") ? leftEquipEntity : rightEquipEntity;
|
||||||
var entityProperties = Entities.getEntityProperties(data.entityID, DISPATCHER_PROPERTIES);
|
var entityProperties = Entities.getEntityProperties(data.entityID, DISPATCHER_PROPERTIES);
|
||||||
entityProperties.id = data.entityID;
|
entityProperties.id = data.entityID;
|
||||||
equipModule.setMessageGrabData(entityProperties);
|
var mouseEquip = false;
|
||||||
|
equipModule.setMessageGrabData(entityProperties, mouseEquip);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("WARNING: equipEntity.js -- error parsing Hifi-Hand-Grab message: " + message);
|
print("WARNING: equipEntity.js -- error parsing Hifi-Hand-Grab message: " + message);
|
||||||
|
@ -768,10 +775,68 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var clearGrabActions = function(entityID) {
|
||||||
|
var actionIDs = Entities.getActionIDs(entityID);
|
||||||
|
var myGrabTag = "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 === myGrabTag) {
|
||||||
|
Entities.deleteAction(entityID, actionID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var onMousePress = function(event) {
|
||||||
|
if (isInEditMode()) { // don't consider any mouse clicks on the entity while in edit
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||||
|
var intersection = Entities.findRayIntersection(pickRay, true);
|
||||||
|
if (intersection.intersects) {
|
||||||
|
var entityID = intersection.entityID;
|
||||||
|
var entityProperties = Entities.getEntityProperties(entityID, DISPATCHER_PROPERTIES);
|
||||||
|
var hasEquipData = getWearableData(entityProperties).joints || getEquipHotspotsData(entityProperties).length > 0;
|
||||||
|
if (hasEquipData && entityProperties.parentID === EMPTY_PARENT_ID && !entityIsFarGrabbedByOther(entityID)) {
|
||||||
|
entityProperties.id = entityID;
|
||||||
|
var rightHandPosition = MyAvatar.getJointPosition("RightHand");
|
||||||
|
var leftHandPosition = MyAvatar.getJointPosition("LeftHand");
|
||||||
|
var distanceToRightHand = Vec3.distance(entityProperties.position, rightHandPosition);
|
||||||
|
var distanceToLeftHand = Vec3.distance(entityProperties.position, leftHandPosition);
|
||||||
|
var leftHandAvailable = leftEquipEntity.targetEntityID === null;
|
||||||
|
var rightHandAvailable = rightEquipEntity.targetEntityID === null;
|
||||||
|
var mouseEquip = true;
|
||||||
|
if (rightHandAvailable && (distanceToRightHand < distanceToLeftHand || !leftHandAvailable)) {
|
||||||
|
// clear any existing grab actions on the entity now (their later removal could affect bootstrapping flags)
|
||||||
|
clearGrabActions(entityID);
|
||||||
|
rightEquipEntity.setMessageGrabData(entityProperties, mouseEquip);
|
||||||
|
} else if (leftHandAvailable && (distanceToLeftHand < distanceToRightHand || !rightHandAvailable)) {
|
||||||
|
// clear any existing grab actions on the entity now (their later removal could affect bootstrapping flags)
|
||||||
|
clearGrabActions(entityID);
|
||||||
|
leftEquipEntity.setMessageGrabData(entityProperties, mouseEquip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var onKeyPress = function(event) {
|
||||||
|
if (event.text === UNEQUIP_KEY) {
|
||||||
|
if (rightEquipEntity.targetEntityID) {
|
||||||
|
rightEquipEntity.endEquipEntity();
|
||||||
|
}
|
||||||
|
if (leftEquipEntity.targetEntityID) {
|
||||||
|
leftEquipEntity.endEquipEntity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Messages.subscribe('Hifi-Hand-Grab');
|
Messages.subscribe('Hifi-Hand-Grab');
|
||||||
Messages.subscribe('Hifi-Hand-Drop');
|
Messages.subscribe('Hifi-Hand-Drop');
|
||||||
Messages.messageReceived.connect(handleMessage);
|
Messages.messageReceived.connect(handleMessage);
|
||||||
|
Controller.mousePressEvent.connect(onMousePress);
|
||||||
|
Controller.keyPressEvent.connect(onKeyPress);
|
||||||
|
|
||||||
var leftEquipEntity = new EquipEntity(LEFT_HAND);
|
var leftEquipEntity = new EquipEntity(LEFT_HAND);
|
||||||
var rightEquipEntity = new EquipEntity(RIGHT_HAND);
|
var rightEquipEntity = new EquipEntity(RIGHT_HAND);
|
||||||
|
@ -785,6 +850,9 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
||||||
disableDispatcherModule("LeftEquipEntity");
|
disableDispatcherModule("LeftEquipEntity");
|
||||||
disableDispatcherModule("RightEquipEntity");
|
disableDispatcherModule("RightEquipEntity");
|
||||||
clearAttachPoints();
|
clearAttachPoints();
|
||||||
|
Messages.messageReceived.disconnect(handleMessage);
|
||||||
|
Controller.mousePressEvent.disconnect(onMousePress);
|
||||||
|
Controller.keyPressEvent.disconnect(onKeyPress);
|
||||||
}
|
}
|
||||||
Script.scriptEnding.connect(cleanup);
|
Script.scriptEnding.connect(cleanup);
|
||||||
}());
|
}());
|
||||||
|
|
|
@ -567,7 +567,7 @@ Grabber.prototype.moveEventProcess = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.actionID) {
|
if (!this.actionID) {
|
||||||
if (!entityIsGrabbedByOther(this.entityID)) {
|
if (!entityIsGrabbedByOther(this.entityID) && !entityIsEquipped(this.entityID)) {
|
||||||
this.actionID = Entities.addAction("far-grab", this.entityID, actionArgs);
|
this.actionID = Entities.addAction("far-grab", this.entityID, actionArgs);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -384,6 +384,34 @@ distanceBetweenPointAndEntityBoundingBox = function(point, entityProps) {
|
||||||
return Vec3.distance(v, localPoint);
|
return Vec3.distance(v, localPoint);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
entityIsEquipped = function(entityID) {
|
||||||
|
var rightEquipEntity = getEnabledModuleByName("RightEquipEntity");
|
||||||
|
var leftEquipEntity = getEnabledModuleByName("LeftEquipEntity");
|
||||||
|
var equippedInRightHand = rightEquipEntity ? rightEquipEntity.targetEntityID === entityID : false;
|
||||||
|
var equippedInLeftHand = leftEquipEntity ? leftEquipEntity.targetEntityID === entityID : false;
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
if (typeof module !== 'undefined') {
|
if (typeof module !== 'undefined') {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
makeDispatcherModuleParameters: makeDispatcherModuleParameters,
|
makeDispatcherModuleParameters: makeDispatcherModuleParameters,
|
||||||
|
|
Loading…
Reference in a new issue