The Puzzling Case of the Magic Hand Controller function calls


#1

While reverse engineering the Flashlight to get a proper Torch to work, I have dug deep with the intricacies of scripting in HiFi, I’ve bumped into undocumented code and inconsistancy with the handControllerGrab.js script.

All these methods are defined within the handController script, as it is the one which calls these events.

Digging through other “Grabbables” like those defined in pistol.js, magic wand, etc, I made a “GenericGrabbableObject” to handle objects for community use so that it can generically be extended upon to make handController/Controller Interactable objects have more commonalities.

Here is what I have (collection of methods only, not functionality, yet) so far:


function GenericGrabbableObject(){return;}
GenericGrabbableObject.prototype = {
    hand: null,
    whichHand:  null,
    entityId: null,
    // Called when object is first loaded
    preload: function(entityId){
      this.entityId = entityId;
    },
    unload: function(){},
    setHand: function(hand){
       this.hand = hand;
    },
    setRightHand: function() {
       setHand('RIGHT');
    },
    setLeftHand: function() {
       setHand('LEFT');
    },
    // Stumps
    startTouch: function(){},
    continueTouch: function(){},
    stopTouch: function(){},
    
    startNearGrab: function(entityId) {},
    releaseGrab: function() {},
    continueNearGrab: function() {},

    startEquip: function(id, params) {}, 
        releaseEquip: function() {}, 
        continueEquip: function(){},
    //  unequip: function(){}, // seems DEPRECATED:  use   releaseEquip instead
        stopNearTrigger: function(){}, // This occurs when a trigger is "released"
        stopFarTrigger: function(){},
        continueNearTrigger: function(){},

        setWhichHand: function() {
            this.whichHand = this.hand;
        }
}

which is then plan to included in a main script by extending it with the new object. (via prototype, such as in)


function Torch(){ return; };
Torch.prototype = GenericGrabbableObject.prototype;
Torch.prototype.constructor = Torch;

Or through a library such as underscore extend to allow for recursive modifying of object to another object to have new items. This is just to make sure all objects have same functionality for controllers:


So about the inconsistancies I found:

  • is unequip a depricated method? It is only used in “pistol.js”. Line 1422 of handControllerGrab still calls it, but it is not used elsewhere.
  • “equip” and “grab” seems very interchangeable… Is this on purpose, or was one deprecated over the other?. This is especially noticable in state update within the handControllerGrab.js (lines 282+). Flashlight seems to use to always use grab events, regardless if equip is called.
  • Why have setLeftHand / setRightHand when you have setHand?
  • What are NearTrigger / FarTrigger. Are these interaction events when the object is far / near?
  • What is Touch vs Grab vs Equip in general terms?

#2

I think these are the triggers on the end of the hydras r1 r2 l1 l2. They are badly labelled on the physical controller so my guess is the devs are using near for the button nearest to u


#3

The Xbox controller naming sounds more sense in this case then: Bumper (near) and Trigger (far).
But would like an official word on it as its currently very vague.


#4

Hi @MenithalI , Your script would be very useful for users, you could also add in the user_data information that could be passed.

  • is unequip a depricated method? It is only used in “pistol.js”. Line 1422 of handControllerGrab still calls it, but it is not used elsewhere.
    (It is still a valid call, however may not that useful)

  • “equip” and “grab” seems very interchangeable… Is this on purpose, or was one deprecated over the other?. This is especially noticable in state update within the handControllerGrab.js (lines 282+).
    (That was true, but shouldn’t be true now or at least very shortly )

  • Why have setLeftHand / setRightHand when you have setHand?
    (I do not really have a good explanation)

  • What are NearTrigger / FarTrigger. Are these interaction events when the object is far / near?
    (Yes! Near trigger is when you trigger an object that is close by, and far trigger far. Trigger refers to selecting objects that are not physical. )

  • What is Touch vs Grab vs Equip in general terms?
    (Touch is for things that get triggered but don’t move. grab is for temporary moving, equip is for longer term moving)