Tanoda
MinimalHand.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10using System.Collections;
11using System;
12using Leap;
13
14namespace Leap.Unity {
15 public class MinimalHand : HandModelBase {
16 public override bool SupportsEditorPersistence() {
17 return true;
18 }
19
20 #pragma warning disable 0649
21 [SerializeField]
22 private Chirality _handedness;
23
24 [SerializeField]
25 private Mesh _palmMesh;
26
27 [SerializeField]
28 private float _palmScale = 0.02f;
29
30 [SerializeField]
31 private Material _palmMat;
32
33 [SerializeField]
34 private Mesh _jointMesh;
35
36 [SerializeField]
37 private float _jointScale = 0.01f;
38
39 [SerializeField]
40 private Material _jointMat;
41 #pragma warning restore 0649
42
43 private Hand _hand;
44 private Transform _palm;
45 private Transform[] _joints;
46
47 public override Chirality Handedness {
48 get {
49 return _handedness;
50 }
51 set {
52 _handedness = value;
53 }
54 }
55
56 public override ModelType HandModelType {
57 get {
58 return ModelType.Graphics;
59 }
60 }
61
62 public override void SetLeapHand(Hand hand) {
63 _hand = hand;
64 }
65
66 public override Hand GetLeapHand() {
67 return _hand;
68 }
69
70 public override void InitHand() {
71 _joints = new Transform[5 * 4];
72 for (int i = 0; i < 20; i++) {
73 _joints[i] = createRenderer("Joint", _jointMesh, _jointScale, _jointMat);
74 }
75
76 _palm = createRenderer("Palm", _palmMesh, _palmScale, _palmMat);
77 }
78
79 public override void UpdateHand() {
80 var list = _hand.Fingers;
81 int index = 0;
82 for (int i = 0; i < 5; i++) {
83 Finger finger = list[i];
84 for (int j = 0; j < 4; j++) {
85 _joints[index++].position = finger.Bone((Bone.BoneType)j).NextJoint.ToVector3();
86 }
87 }
88
89 _palm.position = _hand.PalmPosition.ToVector3();
90 }
91
92 private Transform createRenderer(string name, Mesh mesh, float scale, Material mat) {
93 GameObject obj = new GameObject(name);
94 obj.AddComponent<MeshFilter>().mesh = mesh;
95 obj.AddComponent<MeshRenderer>().sharedMaterial = mat;
96 obj.transform.parent = transform;
97 obj.transform.localScale = Vector3.one * scale;
98 return obj.transform;
99 }
100 }
101}
The Bone class represents a tracked bone.
Definition: Bone.cs:26
BoneType
Enumerates the type of bones.
Definition: Bone.cs:168
Vector NextJoint
The end of the bone, closest to the finger tip. In anatomical terms, this is the distal end of the bo...
Definition: Bone.cs:90
The Finger class represents a tracked finger.
Definition: Finger.cs:20
Bone Bone(Bone.BoneType boneIx)
The bone at a given bone index on this finger.
Definition: Finger.cs:79
The Hand class reports the physical characteristics of a detected hand.
Definition: Hand.cs:26
Vector PalmPosition
The center position of the palm.
Definition: Hand.cs:165
List< Finger > Fingers
The list of Finger objects detected in this frame that are attached to this hand, given in order from...
Definition: Hand.cs:159
override Hand GetLeapHand()
Definition: MinimalHand.cs:66
override void InitHand()
Definition: MinimalHand.cs:70
override ModelType HandModelType
Definition: MinimalHand.cs:56
override bool SupportsEditorPersistence()
Returns whether or not this hand model supports editor persistence. This is false by default and must...
Definition: MinimalHand.cs:16
override void SetLeapHand(Hand hand)
Definition: MinimalHand.cs:62
override Chirality Handedness
Definition: MinimalHand.cs:47
override void UpdateHand()
Definition: MinimalHand.cs:79