Exemplo n.º 1
0
        private void setBehaviourForPoint(AttachmentPointFlags singlePoint, AttachmentPointBehaviour behaviour)
        {
            switch (singlePoint)
            {
            case AttachmentPointFlags.None: break;

            case AttachmentPointFlags.Wrist:                wrist = behaviour; break;

            case AttachmentPointFlags.Palm:                 palm = behaviour; break;

            case AttachmentPointFlags.ThumbProximalJoint:   thumbProximalJoint = behaviour; break;

            case AttachmentPointFlags.ThumbDistalJoint:     thumbDistalJoint = behaviour; break;

            case AttachmentPointFlags.ThumbTip:             thumbTip = behaviour; break;

            case AttachmentPointFlags.IndexKnuckle:         indexKnuckle = behaviour; break;

            case AttachmentPointFlags.IndexMiddleJoint:     indexMiddleJoint = behaviour; break;

            case AttachmentPointFlags.IndexDistalJoint:     indexDistalJoint = behaviour; break;

            case AttachmentPointFlags.IndexTip:             indexTip = behaviour; break;

            case AttachmentPointFlags.MiddleKnuckle:        middleKnuckle = behaviour; break;

            case AttachmentPointFlags.MiddleMiddleJoint:    middleMiddleJoint = behaviour; break;

            case AttachmentPointFlags.MiddleDistalJoint:    middleDistalJoint = behaviour; break;

            case AttachmentPointFlags.MiddleTip:            middleTip = behaviour; break;

            case AttachmentPointFlags.RingKnuckle:          ringKnuckle = behaviour; break;

            case AttachmentPointFlags.RingMiddleJoint:      ringMiddleJoint = behaviour; break;

            case AttachmentPointFlags.RingDistalJoint:      ringDistalJoint = behaviour; break;

            case AttachmentPointFlags.RingTip:              ringTip = behaviour; break;

            case AttachmentPointFlags.PinkyKnuckle:         pinkyKnuckle = behaviour; break;

            case AttachmentPointFlags.PinkyMiddleJoint:     pinkyMiddleJoint = behaviour; break;

            case AttachmentPointFlags.PinkyDistalJoint:     pinkyDistalJoint = behaviour; break;

            case AttachmentPointFlags.PinkyTip:             pinkyTip = behaviour; break;
            }

      #if UNITY_EDITOR
            EditorUtility.SetDirty(this);
      #endif
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the AttachmentPointBehaviour child object of this AttachmentHand given a
        /// reference to a single AttachmentPointFlags flag, or null if there is no such child object.
        /// </summary>
        public AttachmentPointBehaviour GetBehaviourForPoint(AttachmentPointFlags singlePoint)
        {
            AttachmentPointBehaviour behaviour = null;

            switch (singlePoint)
            {
            case AttachmentPointFlags.None: break;

            case AttachmentPointFlags.Wrist:                behaviour = wrist; break;

            case AttachmentPointFlags.Palm:                 behaviour = palm; break;

            case AttachmentPointFlags.ThumbProximalJoint:   behaviour = thumbProximalJoint; break;

            case AttachmentPointFlags.ThumbDistalJoint:     behaviour = thumbDistalJoint; break;

            case AttachmentPointFlags.ThumbTip:             behaviour = thumbTip; break;

            case AttachmentPointFlags.IndexKnuckle:         behaviour = indexKnuckle; break;

            case AttachmentPointFlags.IndexMiddleJoint:     behaviour = indexMiddleJoint; break;

            case AttachmentPointFlags.IndexDistalJoint:     behaviour = indexDistalJoint; break;

            case AttachmentPointFlags.IndexTip:             behaviour = indexTip; break;

            case AttachmentPointFlags.MiddleKnuckle:        behaviour = middleKnuckle; break;

            case AttachmentPointFlags.MiddleMiddleJoint:    behaviour = middleMiddleJoint; break;

            case AttachmentPointFlags.MiddleDistalJoint:    behaviour = middleDistalJoint; break;

            case AttachmentPointFlags.MiddleTip:            behaviour = middleTip; break;

            case AttachmentPointFlags.RingKnuckle:          behaviour = ringKnuckle; break;

            case AttachmentPointFlags.RingMiddleJoint:      behaviour = ringMiddleJoint; break;

            case AttachmentPointFlags.RingDistalJoint:      behaviour = ringDistalJoint; break;

            case AttachmentPointFlags.RingTip:              behaviour = ringTip; break;

            case AttachmentPointFlags.PinkyKnuckle:         behaviour = pinkyKnuckle; break;

            case AttachmentPointFlags.PinkyMiddleJoint:     behaviour = pinkyMiddleJoint; break;

            case AttachmentPointFlags.PinkyDistalJoint:     behaviour = pinkyDistalJoint; break;

            case AttachmentPointFlags.PinkyTip:             behaviour = pinkyTip; break;
            }

            return(behaviour);
        }
Exemplo n.º 3
0
        private void ensureTransformExists(AttachmentPointFlags singlePoint)
        {
            if (!singlePoint.IsSinglePoint())
            {
                Debug.LogError("Tried to ensure transform exists for singlePoint, but it contains more than one set flag.");
                return;
            }

            AttachmentPointBehaviour pointBehaviour = GetBehaviourForPoint(singlePoint);

            if (pointBehaviour == null)
            {
                // First, see if there's already one in the hierarchy! Might exist due to, e.g. an Undo operation
                var existingPointBehaviour = this.gameObject.GetComponentsInChildren <AttachmentPointBehaviour>()
                                             .Query()
                                             .FirstOrDefault(p => p.attachmentPoint == singlePoint);

                // Only make a new object if the transform really doesn't exist.
                if (existingPointBehaviour == AttachmentPointFlags.None)
                {
                    GameObject obj = new GameObject(Enum.GetName(typeof(AttachmentPointFlags), singlePoint));
          #if UNITY_EDITOR
                    Undo.RegisterCreatedObjectUndo(obj, "Created Object");
                    pointBehaviour = Undo.AddComponent <AttachmentPointBehaviour>(obj);
          #else
                    pointBehaviour = obj.AddComponent <AttachmentPointBehaviour>();
          #endif
                }
                else
                {
                    pointBehaviour = existingPointBehaviour;
                }

        #if UNITY_EDITOR
                Undo.RecordObject(pointBehaviour, "Set Attachment Point");
        #endif
                pointBehaviour.attachmentPoint = singlePoint;
                pointBehaviour.attachmentHand  = this;
                setBehaviourForPoint(singlePoint, pointBehaviour);

                SetTransformParent(pointBehaviour.transform, this.transform);

                _attachmentPointsDirty = true;

        #if UNITY_EDITOR
                EditorUtility.SetDirty(this);
        #endif
            }
        }
Exemplo n.º 4
0
        public void notifyPointBehaviourDeleted(AttachmentPointBehaviour point)
        {
      #if UNITY_EDITOR
            // Only valid if the AttachmentHand itself is also not being destroyed.
            if (_isBeingDestroyed)
            {
                return;
            }

            // Refresh this hand's attachment transforms on a slight delay.
            // Only AttachmentHands can _truly_ remove attachment points!
            AttachmentHands attachHands = GetComponentInParent <AttachmentHands>();
            if (attachHands != null)
            {
                EditorApplication.delayCall += () => { refreshAttachmentTransforms(attachHands.attachmentPoints); };
            }
      #endif
        }
Exemplo n.º 5
0
        private void onUpdateFrame(Frame frame)
        {
            if (frame == null)
            {
                Debug.Log("Frame null");
            }

            var hand = frame.Hands.Query()
                       .FirstOrDefault(h => h.IsLeft == (whichHand == Chirality.Left));

            bool shouldStream = false;
            Ray  streamRay    = default(Ray);

            if (hand != null)
            {
                _isHandTracked = true;

                if (enabled && gameObject.activeInHierarchy)
                {
                    Vector3 pointPosition; Quaternion pointRotation;
                    AttachmentPointBehaviour.GetLeapHandPointData(hand, attachmentPoint,
                                                                  out pointPosition,
                                                                  out pointRotation);

                    // Replace wrist rotation data with that from the palm for now.
                    if (attachmentPoint == AttachmentPointFlags.Wrist)
                    {
                        Vector3 unusedPos;
                        AttachmentPointBehaviour.GetLeapHandPointData(hand, AttachmentPointFlags.Palm,
                                                                      out unusedPos,
                                                                      out pointRotation);
                    }

                    this.transform.position = pointPosition;
                    this.transform.rotation = pointRotation;

                    var origin = projectionOrigin;
                    streamRay = new Ray(origin,
                                        pointPosition - origin);
                    _lastRay     = streamRay;
                    shouldStream = true;
                }
            }
            else
            {
                _isHandTracked = false;
            }

            // Ray Stream data.
            shouldStream &= Application.isPlaying;
            shouldStream &= this.enabled && gameObject.activeInHierarchy;
            if (!shouldStream && _isStreamOpen)
            {
                OnClose();
                _isStreamOpen = false;
            }
            if (shouldStream && !_isStreamOpen)
            {
                OnOpen();
                _isStreamOpen = true;
            }
            if (shouldStream)
            {
                OnSend(streamRay);
            }
        }
Exemplo n.º 6
0
        private void onUpdateFrame(Frame frame)
        {
            if (frame == null)
            {
                Debug.Log("Frame null");
            }

            var hand = frame.Hands.Query()
                       .FirstOrDefault(h => h.IsLeft == (whichHand == Chirality.Left));

            bool shouldStream = false;
            Pose streamPose   = Pose.identity;

            if (hand != null)
            {
                _isHandTracked = true;

                if (enabled && gameObject.activeInHierarchy)
                {
                    Vector3 pointPosition; Quaternion pointRotation;
                    AttachmentPointBehaviour.GetLeapHandPointData(hand, attachmentPoint,
                                                                  out pointPosition,
                                                                  out pointRotation);

                    // Replace wrist rotation data with that from the palm for now.
                    if (attachmentPoint == AttachmentPointFlags.Wrist)
                    {
                        Vector3 unusedPos;
                        AttachmentPointBehaviour.GetLeapHandPointData(hand, AttachmentPointFlags.Palm,
                                                                      out unusedPos,
                                                                      out pointRotation);
                    }

                    this.transform.position = pointPosition;
                    this.transform.rotation = pointRotation;

                    streamPose = new Pose(pointPosition, pointRotation);
                    var streamOffset = Pose.identity;
                    if (usePoseStreamOffset && poseStreamOffsetSource != null)
                    {
                        streamOffset = poseStreamOffsetSource.transform.ToWorldPose()
                                       .From(streamPose);
                    }
                    streamPose   = streamPose.Then(streamOffset);
                    shouldStream = true;
                }
            }
            else
            {
                _isHandTracked = false;
            }

            // Pose Stream data.
            shouldStream &= doPoseStream;
            shouldStream &= Application.isPlaying;
            shouldStream &= this.enabled && gameObject.activeInHierarchy;
            if (!shouldStream && _isStreamOpen)
            {
                OnClose();
                _isStreamOpen = false;
            }
            if (shouldStream && !_isStreamOpen)
            {
                OnOpen();
                _isStreamOpen = true;
            }
            if (shouldStream)
            {
                OnSend(streamPose);
            }
        }