💻Examples

You can do some complex stuff with very little code. Here's how 👨‍💻

Avatar

How to access the left hand of the first registered avatar?

HandView hand = HPTK.core.avatars[0].body.leftHand;

How to access the Transform of the master representation of the tip of the pinky finger?

Transform tip = hand.pinky.tip.reprs[AvatarModel.key].transformRef;

or

Transform tip = hand.pinky.tip.master.transformRef;

How to get the avatar from a hand?

AvatarView a = hand.body.avatar;

How to get the root bone of the parent part of the hand (upper arm bone)?

BoneView b = hand.parent.root;

Input

How to listen to tracking lost/recovery events?

InputView input = hand.GetRegisteredView<InputView>();
if (input != null)
{
	input.onHandTrackingLost.AddListener(myMethodA);
	input.onHandTrackingRecovered.AddListener(myMethodB);
}

Contact detection

How to get the list of objects that are at least being hovered?

ContactDetectionView detector = hand.GetRegisteredView<ContactDetectionView>();
if (detector != null)
{
	List<ContactableView> contactables = detector.contacts.FindAll(c => c.type >= ContactType.Entered).ConvertAll(c => c.contactable);
}

Gesture detection

How to do something only when the user is performing a gesture (index pinch) but not another one (pose match)?

GestureDetectionView detector = hand.GetRegisteredView<GestureDetectionView>();
if (detector != null)
{
	Gesture poseMatch = detector.extra.Find(g => g is HandPoseMatch);
	Gesture indexPinch = detector.index.pinch;

	// .lerp values goes from 0.0 to 1.0
	if (indexPinch.lerp > 0.8f && poseMatch.lerp < 0.2f)
	{
		// ...
	}
}

Puppet

How to make slave hand to fall dramatically after 10 seconds?

AsyncHelpers.DoAfterTime(this, 10.0f, () =>
{
	if (hand.wrist.reprs.ContainsKey(PuppetModel.key) && hand.wrist.reprs[PuppetModel.key] is PuppetReprView)
	{
		PuppetReprView puppetRepr = hand.wrist.reprs[PuppetModel.key] as PuppetReprView;
		
		puppetRepr.pheasy.rb.useGravity = true;
		
		ConfigurableJoint wristJoint = puppetRepr.constraint.joint;
		
		wristJoint.xDrive = new JointDrive();
		wristJoint.yDrive = new JointDrive();
		wristJoint.zDrive = new JointDrive();
		wristJoint.slerpDrive = new JointDrive();
	}
});

How to get the maximum stregth for the rotation drive of the physical constraint that drives the index root?

BoneView indexRoot = hand.index.root;
if (indexRoot.point.reprs.ContainsKey("slave") && indexRoot.point.reprs["slave"] is PuppetReprView)
{
	PuppetReprView puppetRepr = indexRoot.point.reprs["slave"] as PuppetReprView;
	float strength = puppetRepr.constraint.settings.angularDrive.maxForce;
}

or without hard-coded representation keys (recommended)

BoneView indexRoot = hand.index.root;
if (indexRoot.point.reprs.ContainsKey(PuppetModel.key) && indexRoot.point.reprs[PuppetModel.key] is PuppetReprView)
{
	PuppetReprView puppetRepr = indexRoot.point.reprs[PuppetModel.key] as PuppetReprView;
	float strength = puppetRepr.constraint.settings.angularDrive.maxForce;
}

Last updated