diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 51814ad5d7..cc486802ff 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -333,13 +333,10 @@ function MyController(hand) { } }; - this.callEntityMethodOnGrabbed = function(entityMethodName, args) { + this.callEntityMethodOnGrabbed = function(entityMethodName) { // print("Entity Method: " + entityMethodName + ", hand: " + this.hand); - if (args.length > 0) { - Entities.callEntityMethod(this.grabbedEntity, entityMethodName, args); - } else { - Entities.callEntityMethod(this.grabbedEntity, entityMethodName); - } + Entities.callEntityMethod(this.grabbedEntity, entityMethodName, [JSON.stringify(this.hand), + JSON.stringify(MyAvatar.SessionUUID)]); } this.setState = function(newState) { @@ -1080,7 +1077,7 @@ function MyController(hand) { if (this.actionID !== null) { this.setState(STATE_CONTINUE_DISTANCE_HOLDING); this.activateEntity(this.grabbedEntity, grabbedProperties, false); - this.callSetupEntityMethods("startDistanceGrab"); + this.callEntityMethodOnGrabbed("startDistanceGrab"); } this.currentAvatarPosition = MyAvatar.position; @@ -1093,7 +1090,7 @@ function MyController(hand) { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab", []); + this.callEntityMethodOnGrabbed("releaseGrab"); } return; } @@ -1176,7 +1173,7 @@ function MyController(hand) { this.handPreviousRotation = handRotation; this.currentObjectRotation = Quat.multiply(handChange, this.currentObjectRotation); - this.callEntityMethodOnGrabbed("continueDistantGrab", []); + this.callEntityMethodOnGrabbed("continueDistantGrab"); var defaultMoveWithHeadData = { disableMoveWithHead: false @@ -1292,18 +1289,6 @@ function MyController(hand) { 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() { var wearableData = getEntityCustomData('wearable', this.grabbedEntity, {joints: {}}); if ("joints" in wearableData) { @@ -1341,7 +1326,7 @@ function MyController(hand) { if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab", []); + this.callEntityMethodOnGrabbed("releaseGrab"); } 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) { // near grabbing @@ -1429,7 +1414,7 @@ function MyController(hand) { if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab", []); + this.callEntityMethodOnGrabbed("releaseGrab"); } return; } @@ -1439,15 +1424,15 @@ function MyController(hand) { } if (this.state == STATE_CONTINUE_EQUIP && this.bumperSqueezed()) { this.setState(STATE_WAITING_FOR_BUMPER_RELEASE); - this.callEntityMethodOnGrabbed("releaseEquip", [JSON.stringify(this.hand)]); + this.callEntityMethodOnGrabbed("releaseEquip"); return; } if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.bumperSqueezed()) { this.setState(STATE_CONTINUE_EQUIP_BD); if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab", [JSON.stringify(this.hand)]); - this.callEntityMethodOnGrabbed("startEquip", [JSON.stringify(this.hand)]); + this.callEntityMethodOnGrabbed("releaseGrab"); } + this.callEntityMethodOnGrabbed("startEquip"); return; } @@ -1458,8 +1443,7 @@ function MyController(hand) { print("handControllerGrab -- autoreleasing held or equipped item because it is far from hand." + props.parentID + " " + vec3toStr(props.position)); this.setState(STATE_RELEASE); - this.callEntityMethodOnGrabbed(this.state == STATE_NEAR_GRABBING ? "releaseGrab" : "releaseEquip", - [JSON.stringify(this.hand)]); + this.callEntityMethodOnGrabbed(this.state == STATE_NEAR_GRABBING ? "releaseGrab" : "releaseEquip"); return; } @@ -1480,14 +1464,12 @@ function MyController(hand) { this.currentObjectTime = now; var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, {}); + if (this.state === STATE_CONTINUE_EQUIP) { + this.callEntityMethodOnGrabbed("continueEquip"); + } if (this.isInitialGrab) { - if (this.state === STATE_CONTINUE_EQUIP) { - // this.callEntityMethodOnGrabbed("continueEquip", []); - Entities.callEntityMethod(this.grabbedEntity, "continueEquip"); - } if (this.state == STATE_CONTINUE_NEAR_GRABBING) { - // this.callEntityMethodOnGrabbed("continueNearGrab", []); - Entities.callEntityMethod(this.grabbedEntity, "continueNearGrab"); + this.callEntityMethodOnGrabbed("continueNearGrab"); } } @@ -1516,48 +1498,42 @@ function MyController(hand) { this.waitingForBumperRelease = function() { if (this.bumperReleased()) { 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() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - this.callEntityMethodOnGrabbed("stopNearTrigger", []); + this.callEntityMethodOnGrabbed("stopNearTrigger"); return; } - this.callSetupEntityMethods("startNearTrigger"); + this.callEntityMethodOnGrabbed("startNearTrigger"); this.setState(STATE_CONTINUE_NEAR_TRIGGER); }; this.farTrigger = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - this.callEntityMethodOnGrabbed("stopFarTrigger", []); + this.callEntityMethodOnGrabbed("stopFarTrigger"); return; } - this.callSetupEntityMethods("startFarTrigger"); + this.callEntityMethodOnGrabbed("startFarTrigger"); this.setState(STATE_CONTINUE_FAR_TRIGGER); }; this.continueNearTrigger = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - this.callEntityMethodOnGrabbed("stopNearTrigger", []); + this.callEntityMethodOnGrabbed("stopNearTrigger"); return; } - this.callEntityMethodOnGrabbed("continueNearTrigger", []); + this.callEntityMethodOnGrabbed("continueNearTrigger"); }; this.continueFarTrigger = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - this.callEntityMethodOnGrabbed("stopFarTrigger", []); + this.callEntityMethodOnGrabbed("stopFarTrigger"); return; } @@ -1573,7 +1549,7 @@ function MyController(hand) { this.lastPickTime = now; if (intersection.entityID != this.grabbedEntity) { this.setState(STATE_RELEASE); - this.callEntityMethodOnGrabbed("stopFarTrigger", []); + this.callEntityMethodOnGrabbed("stopFarTrigger"); return; } } @@ -1581,7 +1557,7 @@ function MyController(hand) { if (USE_ENTITY_LINES_FOR_MOVING === true) { this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR); } - this.callEntityMethodOnGrabbed("continueFarTrigger", []); + this.callEntityMethodOnGrabbed("continueFarTrigger"); }; _this.allTouchedIDs = {}; @@ -1641,16 +1617,15 @@ function MyController(hand) { }; this.startTouch = function(entityID) { - this.callEntityMethodOnGrabbed("startTouch", []); + this.callEntityMethodOnGrabbed("startTouch"); }; this.continueTouch = function(entityID) { - // this.callEntityMethodOnGrabbed("continueTouch", []); - Entities.callEntityMethod(this.grabbedEntity, "continueTouch"); + this.callEntityMethodOnGrabbed("continueTouch"); }; this.stopTouch = function(entityID) { - this.callEntityMethodOnGrabbed("stopTouch", []); + this.callEntityMethodOnGrabbed("stopTouch"); }; this.release = function() { @@ -1819,7 +1794,7 @@ function MyController(hand) { this.grabbedEntity = loadedEntityID; this.activateEntity(this.grabbedEntity, loadedProps, true); this.isInitialGrab = true; - this.callSetupEntityMethods("startEquip"); + this.callEntityMethodOnGrabbed("startEquip"); this.setState(STATE_CONTINUE_EQUIP); } } diff --git a/examples/toybox/bow/bow.js b/examples/toybox/bow/bow.js index 489cc6341e..cd52a8ed5b 100644 --- a/examples/toybox/bow/bow.js +++ b/examples/toybox/bow/bow.js @@ -33,7 +33,8 @@ }; 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 = { x: 0.02, @@ -94,7 +95,6 @@ } Bow.prototype = { - isGrabbed: false, stringDrawn: false, aiming: false, arrowTipPosition: null, @@ -125,33 +125,13 @@ Entities.deleteEntity(this.arrow); }, - setLeftHand: function() { - if (this.isGrabbed === true) { - return false; - } - this.hand = 'left'; - }, - - setRightHand: function() { - if (this.isGrabbed === true) { - return false; - } - this.hand = 'right'; - }, - - startEquip: function() { + startEquip: function(hand, avatarID) { + this.hand = hand; 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 - var handToDisable = this.initialHand === 'right' ? 'left' : 'right'; + var handToDisable = this.hand === 'right' ? 'left' : 'right'; Messages.sendMessage('Hifi-Hand-Disabler', handToDisable); var data = getEntityCustomData('grabbableKey', this.entityID, {}); @@ -159,7 +139,7 @@ setEntityCustomData('grabbableKey', this.entityID, data); }, - continueEquip: function() { + continueEquip: function(hand, avatarID) { this.deltaTime = checkInterval(); //debounce during debugging -- maybe we're updating too fast? @@ -188,25 +168,19 @@ this.checkStringHand(); }, - - releaseGrab: function() { + releaseEquip: function(hand, avatarID) { // 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; - this.stringDrawn = false; - this.deleteStrings(); - - var data = getEntityCustomData('grabbableKey', this.entityID, {}); - data.grabbable = true; - setEntityCustomData('grabbableKey', this.entityID, data); - Entities.deleteEntity(this.arrow); - this.aiming = false; - this.hasArrowNotched = false; - - } + var data = getEntityCustomData('grabbableKey', this.entityID, {}); + data.grabbable = true; + setEntityCustomData('grabbableKey', this.entityID, data); + Entities.deleteEntity(this.arrow); + this.aiming = false; + this.hasArrowNotched = false; }, createArrow: function() { @@ -367,10 +341,10 @@ 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 var triggerLookup; - if (this.initialHand === 'left') { + if (this.hand === 'left') { triggerLookup = 1; this.getStringHandPosition = MyAvatar.getRightPalmPosition; - } else if (this.initialHand === 'right') { + } else if (this.hand === 'right') { this.getStringHandPosition = MyAvatar.getLeftPalmPosition; triggerLookup = 0; }