equipping mostly works

This commit is contained in:
Seth Alves 2017-08-15 11:45:45 -07:00
parent b2d7eefc97
commit e6ac07d43d
3 changed files with 35 additions and 62 deletions

View file

@ -33,7 +33,8 @@
projectOntoXYPlane, projectOntoXYPlane,
projectOntoEntityXYPlane, projectOntoEntityXYPlane,
projectOntoOverlayXYPlane, projectOntoOverlayXYPlane,
entityHasActions entityHasActions,
ensureDynamic
*/ */
MSECS_PER_SEC = 1000.0; MSECS_PER_SEC = 1000.0;
@ -244,3 +245,16 @@ projectOntoOverlayXYPlane = function projectOntoOverlayXYPlane(overlayID, worldP
entityHasActions = function (entityID) { entityHasActions = function (entityID) {
return Entities.getActionIDs(entityID).length > 0; return Entities.getActionIDs(entityID).length > 0;
}; };
ensureDynamic = function (entityID) {
// if we distance hold something and keep it very still before releasing it, it ends up
// non-dynamic in bullet. If it's too still, give it a little bounce so it will fall.
var props = Entities.getEntityProperties(entityID, ["velocity", "dynamic", "parentID"]);
if (props.dynamic && props.parentID == NULL_UUID) {
var velocity = props.velocity;
if (Vec3.length(velocity) < 0.05) { // see EntityMotionState.cpp DYNAMIC_LINEAR_VELOCITY_THRESHOLD
velocity = { x: 0.0, y: 0.2, z: 0.0 };
Entities.editEntity(entityID, { velocity: velocity });
}
}
};

View file

@ -9,7 +9,7 @@
/* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID, /* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID,
getControllerJointIndex, NULL_UUID, enableDispatcherModule, disableDispatcherModule, getControllerJointIndex, NULL_UUID, enableDispatcherModule, disableDispatcherModule,
Messages, makeDispatcherModuleParameters, makeRunningValues, Settings, entityHasActions, Messages, makeDispatcherModuleParameters, makeRunningValues, Settings, entityHasActions,
Vec3, Overlays, flatten, Xform, getControllerWorldLocation Vec3, Overlays, flatten, Xform, getControllerWorldLocation, ensureDynamic
*/ */
Script.include("/~/system/libraries/Xform.js"); Script.include("/~/system/libraries/Xform.js");
@ -82,10 +82,8 @@ EquipHotspotBuddy.prototype.updateHotspot = function(hotspot, timestamp) {
ignoreRayIntersection: true ignoreRayIntersection: true
})); }));
overlayInfoSet.type = "model"; overlayInfoSet.type = "model";
print("QQQ adding hotspot: " + hotspot.key);
this.map[hotspot.key] = overlayInfoSet; this.map[hotspot.key] = overlayInfoSet;
} else { } else {
print("QQQ updating hopspot: " + hotspot.key);
overlayInfoSet.timestamp = timestamp; overlayInfoSet.timestamp = timestamp;
} }
}; };
@ -114,7 +112,6 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
// start to fade out this hotspot. // start to fade out this hotspot.
if (overlayInfoSet.timestamp != timestamp) { if (overlayInfoSet.timestamp != timestamp) {
print("QQQ fading " + overlayInfoSet.entityID + " " + overlayInfoSet.timestamp + " != " + timestamp);
overlayInfoSet.targetSize = 0; overlayInfoSet.targetSize = 0;
} }
@ -127,16 +124,11 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
overlayInfoSet.currentSize += (overlayInfoSet.targetSize - overlayInfoSet.currentSize) * tau; overlayInfoSet.currentSize += (overlayInfoSet.targetSize - overlayInfoSet.currentSize) * tau;
if (overlayInfoSet.timestamp != timestamp && overlayInfoSet.currentSize <= 0.05) { if (overlayInfoSet.timestamp != timestamp && overlayInfoSet.currentSize <= 0.05) {
print("QQQ deleting " + overlayInfoSet.entityID + " " + overlayInfoSet.timestamp + " != " + timestamp);
// this is an old overlay, that has finished fading out, delete it! // this is an old overlay, that has finished fading out, delete it!
overlayInfoSet.overlays.forEach(Overlays.deleteOverlay); overlayInfoSet.overlays.forEach(Overlays.deleteOverlay);
delete this.map[keys[i]]; delete this.map[keys[i]];
} else { } else {
// update overlay position, rotation to follow the object it's attached to. // update overlay position, rotation to follow the object it's attached to.
print("QQQ grew " + overlayInfoSet.entityID + " " + overlayInfoSet.timestamp + " != " + timestamp);
var props = controllerData.nearbyEntityPropertiesByID[overlayInfoSet.entityID]; var props = controllerData.nearbyEntityPropertiesByID[overlayInfoSet.entityID];
if (props) { if (props) {
var entityXform = new Xform(props.rotation, props.position); var entityXform = new Xform(props.rotation, props.position);
@ -157,7 +149,6 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
}); });
}); });
} else { } else {
print("QQQ but no props for " + overlayInfoSet.entityID);
overlayInfoSet.overlays.forEach(Overlays.deleteOverlay); overlayInfoSet.overlays.forEach(Overlays.deleteOverlay);
delete this.map[keys[i]]; delete this.map[keys[i]];
} }
@ -214,7 +205,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
function getAttachPointSettings() { function getAttachPointSettings() {
try { try {
var str = Settings.getValue(ATTACH_POINT_SETTINGS); var str = Settings.getValue(ATTACH_POINT_SETTINGS);
if (str === "false") { if (str === "false" || str === "") {
return {}; return {};
} else { } else {
return JSON.parse(str); return JSON.parse(str);
@ -257,6 +248,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
this.hand = hand; this.hand = hand;
this.targetEntityID = null; this.targetEntityID = null;
this.prevHandIsUpsideDown = false; this.prevHandIsUpsideDown = false;
this.triggerValue = 0;
this.parameters = makeDispatcherModuleParameters( this.parameters = makeDispatcherModuleParameters(
300, 300,
@ -333,7 +325,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
if (hasParent || entityHasActions(hotspot.entityID)) { if (hasParent || entityHasActions(hotspot.entityID)) {
if (debug) { if (debug) {
print("equip is skipping '" + props.name + "': grabbed by someone else: " + print("equip is skipping '" + props.name + "': grabbed by someone else: " +
hasParent + " : " + entityHasActions(hotspot.entityID)); hasParent + " : " + entityHasActions(hotspot.entityID) + " : " + this.hand);
} }
return false; return false;
} }
@ -345,20 +337,6 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
return (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand; return (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
}; };
this.triggerPress = function(value) {
this.rawTriggerValue = value;
};
this.triggerClick = function(value) {
this.triggerClicked = value;
};
this.secondaryPress = function(value) {
this.rawSecondaryValue = value;
};
this.updateSmoothedTrigger = function(controllerData) { this.updateSmoothedTrigger = function(controllerData) {
var triggerValue = controllerData.triggerValues[this.hand]; var triggerValue = controllerData.triggerValues[this.hand];
// smooth out trigger value // smooth out trigger value
@ -366,10 +344,6 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
(triggerValue * (1.0 - TRIGGER_SMOOTH_RATIO)); (triggerValue * (1.0 - TRIGGER_SMOOTH_RATIO));
}; };
this.triggerSmoothedGrab = function() {
return this.triggerClicked;
};
this.triggerSmoothedSqueezed = function() { this.triggerSmoothedSqueezed = function() {
return this.triggerValue > TRIGGER_ON_VALUE; return this.triggerValue > TRIGGER_ON_VALUE;
}; };
@ -378,16 +352,10 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
return this.triggerValue < TRIGGER_OFF_VALUE; return this.triggerValue < TRIGGER_OFF_VALUE;
}; };
this.secondarySqueezed = function() {
return this.rawSecondaryValue > BUMPER_ON_VALUE;
};
this.secondaryReleased = function() { this.secondaryReleased = function() {
return this.rawSecondaryValue < BUMPER_ON_VALUE; return this.rawSecondaryValue < BUMPER_ON_VALUE;
}; };
this.chooseNearEquipHotspots = function(candidateEntityProps, controllerData) { this.chooseNearEquipHotspots = function(candidateEntityProps, controllerData) {
var _this = this; var _this = this;
var collectedHotspots = flatten(candidateEntityProps.map(function(props) { var collectedHotspots = flatten(candidateEntityProps.map(function(props) {
@ -499,11 +467,11 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
localPosition: this.offsetPosition, localPosition: this.offsetPosition,
localRotation: this.offsetRotation localRotation: this.offsetRotation
}; };
Entities.editEntity(this.grabbedThingID, reparentProps); Entities.editEntity(this.targetEntityID, reparentProps);
Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({ Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({
action: 'equip', action: 'equip',
grabbedEntity: this.grabbedThingID, grabbedEntity: this.targetEntityID,
joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand" joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"
})); }));
}; };
@ -517,6 +485,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID];
Entities.callEntityMethod(this.targetEntityID, "releaseEquip", args); Entities.callEntityMethod(this.targetEntityID, "releaseEquip", args);
ensureDynamic(this.targetEntityID);
this.targetEntityID = null; this.targetEntityID = null;
}; };
@ -537,11 +506,6 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
var controllerLocation = getControllerWorldLocation(this.handToController(), true); var controllerLocation = getControllerWorldLocation(this.handToController(), true);
var worldHandPosition = controllerLocation.position; var worldHandPosition = controllerLocation.position;
// var candidateEntities = controllerData.nearbyEntityProperties[this.hand].map(function (props) {
// return props.id;
// });
var candidateEntityProps = controllerData.nearbyEntityProperties[this.hand]; var candidateEntityProps = controllerData.nearbyEntityProperties[this.hand];
var potentialEquipHotspot = this.chooseBestEquipHotspot(candidateEntityProps, controllerData); var potentialEquipHotspot = this.chooseBestEquipHotspot(candidateEntityProps, controllerData);
@ -558,11 +522,15 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
equipHotspotBuddy.update(deltaTime, timestamp, controllerData); equipHotspotBuddy.update(deltaTime, timestamp, controllerData);
if (potentialEquipHotspot) { if (potentialEquipHotspot) {
if (this.triggerSmoothedSqueezed()) {
this.grabbedHotspot = potentialEquipHotspot;
this.targetEntityID = this.grabbedHotspot.entityID;
this.startEquipEntity(controllerData);
}
return makeRunningValues(true, [potentialEquipHotspot.entityID], []); return makeRunningValues(true, [potentialEquipHotspot.entityID], []);
} else { } else {
return makeRunningValues(false, [], []); return makeRunningValues(false, [], []);
} }
}; };
this.isReady = function (controllerData, deltaTime) { this.isReady = function (controllerData, deltaTime) {
@ -571,7 +539,11 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
this.run = function (controllerData, deltaTime) { this.run = function (controllerData, deltaTime) {
return this.checkNearbyHotspots(controllerData, deltaTime); if (!this.targetEntityID) {
return this.checkNearbyHotspots(controllerData, deltaTime);
}
equipHotspotBuddy.update(deltaTime, timestamp, controllerData);
if (controllerData.secondaryValues[this.hand]) { if (controllerData.secondaryValues[this.hand]) {
// this.secondaryReleased() will always be true when not depressed // this.secondaryReleased() will always be true when not depressed
@ -607,8 +579,8 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
if (dropDetected && !this.waitForTriggerRelease && controllerData.triggerClicks[this.hand]) { if (dropDetected && !this.waitForTriggerRelease && controllerData.triggerClicks[this.hand]) {
// store the offset attach points into preferences. // store the offset attach points into preferences.
if (this.grabbedHotspot && this.grabbedThingID) { if (this.grabbedHotspot && this.targetEntityID) {
var prefprops = Entities.getEntityProperties(this.grabbedThingID, ["localPosition", "localRotation"]); var prefprops = Entities.getEntityProperties(this.targetEntityID, ["localPosition", "localRotation"]);
if (prefprops && prefprops.localPosition && prefprops.localRotation) { if (prefprops && prefprops.localPosition && prefprops.localRotation) {
storeAttachPointForHotspotInSettings(this.grabbedHotspot, this.hand, storeAttachPointForHotspotInSettings(this.grabbedHotspot, this.hand,
prefprops.localPosition, prefprops.localRotation); prefprops.localPosition, prefprops.localRotation);

View file

@ -308,21 +308,8 @@ Script.include("/~/system/libraries/controllers.js");
this.previousRoomControllerPosition = roomControllerPosition; this.previousRoomControllerPosition = roomControllerPosition;
}; };
this.ensureDynamic = function () {
// if we distance hold something and keep it very still before releasing it, it ends up
// non-dynamic in bullet. If it's too still, give it a little bounce so it will fall.
var props = Entities.getEntityProperties(this.grabbedThingID, ["velocity", "dynamic", "parentID"]);
if (props.dynamic && props.parentID == NULL_UUID) {
var velocity = props.velocity;
if (Vec3.length(velocity) < 0.05) { // see EntityMotionState.cpp DYNAMIC_LINEAR_VELOCITY_THRESHOLD
velocity = { x: 0.0, y: 0.2, z: 0.0 };
Entities.editEntity(this.grabbedThingID, { velocity: velocity });
}
}
};
this.endNearGrabAction = function () { this.endNearGrabAction = function () {
this.ensureDynamic(); ensureDynamic(this.grabbedThingID);
this.distanceHolding = false; this.distanceHolding = false;
this.distanceRotating = false; this.distanceRotating = false;
Entities.deleteAction(this.grabbedThingID, this.actionID); Entities.deleteAction(this.grabbedThingID, this.actionID);