start to clean up grab generated signals

This commit is contained in:
Seth Alves 2016-02-10 16:40:50 -08:00
parent b1c6d1d256
commit 8e16bda7bb
2 changed files with 48 additions and 99 deletions

View file

@ -333,13 +333,10 @@ function MyController(hand) {
} }
}; };
this.callEntityMethodOnGrabbed = function(entityMethodName, args) { this.callEntityMethodOnGrabbed = function(entityMethodName) {
// print("Entity Method: " + entityMethodName + ", hand: " + this.hand); // print("Entity Method: " + entityMethodName + ", hand: " + this.hand);
if (args.length > 0) { Entities.callEntityMethod(this.grabbedEntity, entityMethodName, [JSON.stringify(this.hand),
Entities.callEntityMethod(this.grabbedEntity, entityMethodName, args); JSON.stringify(MyAvatar.SessionUUID)]);
} else {
Entities.callEntityMethod(this.grabbedEntity, entityMethodName);
}
} }
this.setState = function(newState) { this.setState = function(newState) {
@ -1080,7 +1077,7 @@ function MyController(hand) {
if (this.actionID !== null) { if (this.actionID !== null) {
this.setState(STATE_CONTINUE_DISTANCE_HOLDING); this.setState(STATE_CONTINUE_DISTANCE_HOLDING);
this.activateEntity(this.grabbedEntity, grabbedProperties, false); this.activateEntity(this.grabbedEntity, grabbedProperties, false);
this.callSetupEntityMethods("startDistanceGrab"); this.callEntityMethodOnGrabbed("startDistanceGrab");
} }
this.currentAvatarPosition = MyAvatar.position; this.currentAvatarPosition = MyAvatar.position;
@ -1093,7 +1090,7 @@ function MyController(hand) {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
if (this.isInitialGrab) { if (this.isInitialGrab) {
this.callEntityMethodOnGrabbed("releaseGrab", []); this.callEntityMethodOnGrabbed("releaseGrab");
} }
return; return;
} }
@ -1176,7 +1173,7 @@ function MyController(hand) {
this.handPreviousRotation = handRotation; this.handPreviousRotation = handRotation;
this.currentObjectRotation = Quat.multiply(handChange, this.currentObjectRotation); this.currentObjectRotation = Quat.multiply(handChange, this.currentObjectRotation);
this.callEntityMethodOnGrabbed("continueDistantGrab", []); this.callEntityMethodOnGrabbed("continueDistantGrab");
var defaultMoveWithHeadData = { var defaultMoveWithHeadData = {
disableMoveWithHead: false disableMoveWithHead: false
@ -1292,18 +1289,6 @@ function MyController(hand) {
return projection return projection
}; };
this.callSetupEntityMethods = function(entityMethodName) {
if (this.isInitialGrab) {
if (this.hand === RIGHT_HAND) {
this.callEntityMethodOnGrabbed("setRightHand", []);
} else {
this.callEntityMethodOnGrabbed("setLeftHand", []);
}
this.callEntityMethodOnGrabbed("setHand", [this.hand]);
this.callEntityMethodOnGrabbed(entityMethodName, [JSON.stringify(this.hand)]);
}
}
this.hasPresetOffsets = function() { this.hasPresetOffsets = function() {
var wearableData = getEntityCustomData('wearable', this.grabbedEntity, {joints: {}}); var wearableData = getEntityCustomData('wearable', this.grabbedEntity, {joints: {}});
if ("joints" in wearableData) { if ("joints" in wearableData) {
@ -1341,7 +1326,7 @@ function MyController(hand) {
if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) { if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
if (this.isInitialGrab) { if (this.isInitialGrab) {
this.callEntityMethodOnGrabbed("releaseGrab", []); this.callEntityMethodOnGrabbed("releaseGrab");
} }
return; return;
} }
@ -1410,7 +1395,7 @@ function MyController(hand) {
})); }));
} }
this.callSetupEntityMethods(this.state == STATE_NEAR_GRABBING ? "startNearGrab" : "startEquip"); this.callEntityMethodOnGrabbed(this.state == STATE_NEAR_GRABBING ? "startNearGrab" : "startEquip");
if (this.state == STATE_NEAR_GRABBING) { if (this.state == STATE_NEAR_GRABBING) {
// near grabbing // near grabbing
@ -1429,7 +1414,7 @@ function MyController(hand) {
if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased()) { if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
if (this.isInitialGrab) { if (this.isInitialGrab) {
this.callEntityMethodOnGrabbed("releaseGrab", []); this.callEntityMethodOnGrabbed("releaseGrab");
} }
return; return;
} }
@ -1439,15 +1424,15 @@ function MyController(hand) {
} }
if (this.state == STATE_CONTINUE_EQUIP && this.bumperSqueezed()) { if (this.state == STATE_CONTINUE_EQUIP && this.bumperSqueezed()) {
this.setState(STATE_WAITING_FOR_BUMPER_RELEASE); this.setState(STATE_WAITING_FOR_BUMPER_RELEASE);
this.callEntityMethodOnGrabbed("releaseEquip", [JSON.stringify(this.hand)]); this.callEntityMethodOnGrabbed("releaseEquip");
return; return;
} }
if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.bumperSqueezed()) { if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.bumperSqueezed()) {
this.setState(STATE_CONTINUE_EQUIP_BD); this.setState(STATE_CONTINUE_EQUIP_BD);
if (this.isInitialGrab) { if (this.isInitialGrab) {
this.callEntityMethodOnGrabbed("releaseGrab", [JSON.stringify(this.hand)]); this.callEntityMethodOnGrabbed("releaseGrab");
this.callEntityMethodOnGrabbed("startEquip", [JSON.stringify(this.hand)]);
} }
this.callEntityMethodOnGrabbed("startEquip");
return; return;
} }
@ -1458,8 +1443,7 @@ function MyController(hand) {
print("handControllerGrab -- autoreleasing held or equipped item because it is far from hand." + print("handControllerGrab -- autoreleasing held or equipped item because it is far from hand." +
props.parentID + " " + vec3toStr(props.position)); props.parentID + " " + vec3toStr(props.position));
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed(this.state == STATE_NEAR_GRABBING ? "releaseGrab" : "releaseEquip", this.callEntityMethodOnGrabbed(this.state == STATE_NEAR_GRABBING ? "releaseGrab" : "releaseEquip");
[JSON.stringify(this.hand)]);
return; return;
} }
@ -1480,14 +1464,12 @@ function MyController(hand) {
this.currentObjectTime = now; this.currentObjectTime = now;
var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, {}); var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, {});
if (this.state === STATE_CONTINUE_EQUIP) {
this.callEntityMethodOnGrabbed("continueEquip");
}
if (this.isInitialGrab) { if (this.isInitialGrab) {
if (this.state === STATE_CONTINUE_EQUIP) {
// this.callEntityMethodOnGrabbed("continueEquip", []);
Entities.callEntityMethod(this.grabbedEntity, "continueEquip");
}
if (this.state == STATE_CONTINUE_NEAR_GRABBING) { if (this.state == STATE_CONTINUE_NEAR_GRABBING) {
// this.callEntityMethodOnGrabbed("continueNearGrab", []); this.callEntityMethodOnGrabbed("continueNearGrab");
Entities.callEntityMethod(this.grabbedEntity, "continueNearGrab");
} }
} }
@ -1516,48 +1498,42 @@ function MyController(hand) {
this.waitingForBumperRelease = function() { this.waitingForBumperRelease = function() {
if (this.bumperReleased()) { if (this.bumperReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, {});
if (this.isInitialGrab) {
// TODO -- only one of these should be sent
this.callEntityMethodOnGrabbed("releaseGrab", []);
this.callEntityMethodOnGrabbed("unequip", []);
}
} }
}; };
this.nearTrigger = function() { this.nearTrigger = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("stopNearTrigger", []); this.callEntityMethodOnGrabbed("stopNearTrigger");
return; return;
} }
this.callSetupEntityMethods("startNearTrigger"); this.callEntityMethodOnGrabbed("startNearTrigger");
this.setState(STATE_CONTINUE_NEAR_TRIGGER); this.setState(STATE_CONTINUE_NEAR_TRIGGER);
}; };
this.farTrigger = function() { this.farTrigger = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("stopFarTrigger", []); this.callEntityMethodOnGrabbed("stopFarTrigger");
return; return;
} }
this.callSetupEntityMethods("startFarTrigger"); this.callEntityMethodOnGrabbed("startFarTrigger");
this.setState(STATE_CONTINUE_FAR_TRIGGER); this.setState(STATE_CONTINUE_FAR_TRIGGER);
}; };
this.continueNearTrigger = function() { this.continueNearTrigger = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("stopNearTrigger", []); this.callEntityMethodOnGrabbed("stopNearTrigger");
return; return;
} }
this.callEntityMethodOnGrabbed("continueNearTrigger", []); this.callEntityMethodOnGrabbed("continueNearTrigger");
}; };
this.continueFarTrigger = function() { this.continueFarTrigger = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("stopFarTrigger", []); this.callEntityMethodOnGrabbed("stopFarTrigger");
return; return;
} }
@ -1573,7 +1549,7 @@ function MyController(hand) {
this.lastPickTime = now; this.lastPickTime = now;
if (intersection.entityID != this.grabbedEntity) { if (intersection.entityID != this.grabbedEntity) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("stopFarTrigger", []); this.callEntityMethodOnGrabbed("stopFarTrigger");
return; return;
} }
} }
@ -1581,7 +1557,7 @@ function MyController(hand) {
if (USE_ENTITY_LINES_FOR_MOVING === true) { if (USE_ENTITY_LINES_FOR_MOVING === true) {
this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR); this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR);
} }
this.callEntityMethodOnGrabbed("continueFarTrigger", []); this.callEntityMethodOnGrabbed("continueFarTrigger");
}; };
_this.allTouchedIDs = {}; _this.allTouchedIDs = {};
@ -1641,16 +1617,15 @@ function MyController(hand) {
}; };
this.startTouch = function(entityID) { this.startTouch = function(entityID) {
this.callEntityMethodOnGrabbed("startTouch", []); this.callEntityMethodOnGrabbed("startTouch");
}; };
this.continueTouch = function(entityID) { this.continueTouch = function(entityID) {
// this.callEntityMethodOnGrabbed("continueTouch", []); this.callEntityMethodOnGrabbed("continueTouch");
Entities.callEntityMethod(this.grabbedEntity, "continueTouch");
}; };
this.stopTouch = function(entityID) { this.stopTouch = function(entityID) {
this.callEntityMethodOnGrabbed("stopTouch", []); this.callEntityMethodOnGrabbed("stopTouch");
}; };
this.release = function() { this.release = function() {
@ -1819,7 +1794,7 @@ function MyController(hand) {
this.grabbedEntity = loadedEntityID; this.grabbedEntity = loadedEntityID;
this.activateEntity(this.grabbedEntity, loadedProps, true); this.activateEntity(this.grabbedEntity, loadedProps, true);
this.isInitialGrab = true; this.isInitialGrab = true;
this.callSetupEntityMethods("startEquip"); this.callEntityMethodOnGrabbed("startEquip");
this.setState(STATE_CONTINUE_EQUIP); this.setState(STATE_CONTINUE_EQUIP);
} }
} }

View file

@ -33,7 +33,8 @@
}; };
var ARROW_MODEL_URL = "http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/newarrow_textured.fbx"; var ARROW_MODEL_URL = "http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/newarrow_textured.fbx";
var ARROW_COLLISION_HULL_URL = "http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/newarrow_collision_hull.obj"; var ARROW_COLLISION_HULL_URL =
"http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/newarrow_collision_hull.obj";
var ARROW_DIMENSIONS = { var ARROW_DIMENSIONS = {
x: 0.02, x: 0.02,
@ -94,7 +95,6 @@
} }
Bow.prototype = { Bow.prototype = {
isGrabbed: false,
stringDrawn: false, stringDrawn: false,
aiming: false, aiming: false,
arrowTipPosition: null, arrowTipPosition: null,
@ -125,33 +125,13 @@
Entities.deleteEntity(this.arrow); Entities.deleteEntity(this.arrow);
}, },
setLeftHand: function() { startEquip: function(hand, avatarID) {
if (this.isGrabbed === true) { this.hand = hand;
return false;
}
this.hand = 'left';
},
setRightHand: function() {
if (this.isGrabbed === true) {
return false;
}
this.hand = 'right';
},
startEquip: function() {
print('START BOW GRAB') print('START BOW GRAB')
if (this.isGrabbed === true) {
return false;
}
this.isGrabbed = true;
this.initialHand = this.hand;
//disable the opposite hand in handControllerGrab.js by message //disable the opposite hand in handControllerGrab.js by message
var handToDisable = this.initialHand === 'right' ? 'left' : 'right'; var handToDisable = this.hand === 'right' ? 'left' : 'right';
Messages.sendMessage('Hifi-Hand-Disabler', handToDisable); Messages.sendMessage('Hifi-Hand-Disabler', handToDisable);
var data = getEntityCustomData('grabbableKey', this.entityID, {}); var data = getEntityCustomData('grabbableKey', this.entityID, {});
@ -159,7 +139,7 @@
setEntityCustomData('grabbableKey', this.entityID, data); setEntityCustomData('grabbableKey', this.entityID, data);
}, },
continueEquip: function() { continueEquip: function(hand, avatarID) {
this.deltaTime = checkInterval(); this.deltaTime = checkInterval();
//debounce during debugging -- maybe we're updating too fast? //debounce during debugging -- maybe we're updating too fast?
@ -188,25 +168,19 @@
this.checkStringHand(); this.checkStringHand();
}, },
releaseEquip: function(hand, avatarID) {
releaseGrab: function() {
// print('RELEASE GRAB EVENT') // print('RELEASE GRAB EVENT')
if (this.isGrabbed === true && this.hand === this.initialHand) { Messages.sendMessage('Hifi-Hand-Disabler', "none")
Messages.sendMessage('Hifi-Hand-Disabler', "none") this.stringDrawn = false;
this.deleteStrings();
this.isGrabbed = false; var data = getEntityCustomData('grabbableKey', this.entityID, {});
this.stringDrawn = false; data.grabbable = true;
this.deleteStrings(); setEntityCustomData('grabbableKey', this.entityID, data);
Entities.deleteEntity(this.arrow);
var data = getEntityCustomData('grabbableKey', this.entityID, {}); this.aiming = false;
data.grabbable = true; this.hasArrowNotched = false;
setEntityCustomData('grabbableKey', this.entityID, data);
Entities.deleteEntity(this.arrow);
this.aiming = false;
this.hasArrowNotched = false;
}
}, },
createArrow: function() { createArrow: function() {
@ -367,10 +341,10 @@
checkStringHand: function() { checkStringHand: function() {
//invert the hands because our string will be held with the opposite hand of the first one we pick up the bow with //invert the hands because our string will be held with the opposite hand of the first one we pick up the bow with
var triggerLookup; var triggerLookup;
if (this.initialHand === 'left') { if (this.hand === 'left') {
triggerLookup = 1; triggerLookup = 1;
this.getStringHandPosition = MyAvatar.getRightPalmPosition; this.getStringHandPosition = MyAvatar.getRightPalmPosition;
} else if (this.initialHand === 'right') { } else if (this.hand === 'right') {
this.getStringHandPosition = MyAvatar.getLeftPalmPosition; this.getStringHandPosition = MyAvatar.getLeftPalmPosition;
triggerLookup = 0; triggerLookup = 0;
} }