123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using System;
- using UnityEngine;
- namespace Leap.Unity
- {
- public class DebugHand : IHandModel
- {
- public bool VisualizeBasis
- {
- get
- {
- return this.visualizeBasis;
- }
- set
- {
- this.visualizeBasis = value;
- }
- }
- public override ModelType HandModelType
- {
- get
- {
- return ModelType.Graphics;
- }
- }
- public override Chirality Handedness
- {
- get
- {
- return this.handedness;
- }
- set
- {
- }
- }
- public override Hand GetLeapHand()
- {
- return this.hand_;
- }
- public override void SetLeapHand(Hand hand)
- {
- this.hand_ = hand;
- }
- public override bool SupportsEditorPersistence()
- {
- return true;
- }
- public override void InitHand()
- {
- this.DrawDebugLines();
- }
- public override void UpdateHand()
- {
- this.DrawDebugLines();
- }
- protected void DrawDebugLines()
- {
- Hand leapHand = this.GetLeapHand();
- Debug.DrawLine(leapHand.Arm.ElbowPosition.ToVector3(), leapHand.Arm.WristPosition.ToVector3(), Color.red);
- Debug.DrawLine(leapHand.WristPosition.ToVector3(), leapHand.PalmPosition.ToVector3(), Color.white);
- Debug.DrawLine(leapHand.PalmPosition.ToVector3(), (leapHand.PalmPosition + leapHand.PalmNormal * leapHand.PalmWidth / 2f).ToVector3(), Color.black);
- if (this.VisualizeBasis)
- {
- this.DrawBasis(leapHand.PalmPosition, leapHand.Basis, leapHand.PalmWidth / 4f);
- this.DrawBasis(leapHand.Arm.ElbowPosition, leapHand.Arm.Basis, 0.01f);
- }
- for (int i = 0; i < 5; i++)
- {
- Finger finger = leapHand.Fingers[i];
- for (int j = 0; j < 4; j++)
- {
- Bone bone = finger.Bone((Bone.BoneType)j);
- Debug.DrawLine(bone.PrevJoint.ToVector3(), bone.PrevJoint.ToVector3() + bone.Direction.ToVector3() * bone.Length, this.colors[j]);
- if (this.VisualizeBasis)
- {
- this.DrawBasis(bone.PrevJoint, bone.Basis, 0.01f);
- }
- }
- }
- }
- public void DrawBasis(Vector position, LeapTransform basis, float scale)
- {
- Vector3 vector = position.ToVector3();
- Debug.DrawLine(vector, vector + basis.xBasis.ToVector3() * scale, Color.red);
- Debug.DrawLine(vector, vector + basis.yBasis.ToVector3() * scale, Color.green);
- Debug.DrawLine(vector, vector + basis.zBasis.ToVector3() * scale, Color.blue);
- }
- private Hand hand_;
- [SerializeField]
- private bool visualizeBasis = true;
- protected Color[] colors = new Color[]
- {
- Color.gray,
- Color.yellow,
- Color.cyan,
- Color.magenta
- };
- [SerializeField]
- private Chirality handedness;
- }
- }
|