Exemplo n.º 1
0
        void InitHand(HandModel hand)
        {
            hand.allTransforms = AvatarHelpers.GetAllTransforms(hand);
            hand.bones         = AvatarHelpers.GetHandBones(hand);

            AvatarHelpers.UpdateFingerLengths(hand, hand.proxyHand.scale);
        }
Exemplo n.º 2
0
        private void Start()
        {
            model.proxyHand.relatedHandlers.Add(this);


            slaveBones = AvatarHelpers.GetSlaveHandBones(model.proxyHand.slave);

            // Ignore palm-finger collisions
            for (int i = 0; i < slaveBones.Length; i++)
            {
                if (!slaveBones[i].colliderRef)
                {
                    continue;
                }

                Physics.IgnoreCollision((model.proxyHand.slave.wrist as SlaveBoneModel).colliderRef, slaveBones[i].colliderRef, true);
            }

            // Set default configuration if needed
            if (model.configuration == null)
            {
                model.configuration = core.model.defaultHandPhysicsConfiguration;
            }

            for (int i = 0; i < slaveBones.Length; i++)
            {
                if (!slaveBones[i].jointRef)
                {
                    continue;
                }

                // Get initial connected body local rotations
                if (slaveBones[i].jointRef.connectedBody != null)
                {
                    slaveBones[i].initialConnectedBodyLocalRotation = slaveBones[i].jointRef.connectedBody.transform.localRotation;
                }
                else
                {
                    slaveBones[i].initialConnectedBodyLocalRotation = slaveBones[i].jointRef.transform.rotation;
                }

                // Set initial joint configurations
                if (slaveBones[i] == model.proxyHand.slave.wrist)
                {
                    PhysHelpers.SetSlaveBoneConfiguration(slaveBones[i].jointRef, model.configuration.wrist);
                }
                else if (slaveBones[i].isSpecial)
                {
                    PhysHelpers.SetSlaveBoneConfiguration(slaveBones[i].jointRef, model.configuration.specials);
                }
                else
                {
                    PhysHelpers.SetSlaveBoneConfiguration(slaveBones[i].jointRef, model.configuration.fingers);
                }

                slaveBones[i].rigidbodyRef.maxDepenetrationVelocity = model.configuration.fingers.maxLinearVelocity;
                slaveBones[i].rigidbodyRef.maxAngularVelocity       = model.configuration.fingers.maxAngularVelocity;
            }
        }
Exemplo n.º 3
0
        private void Start()
        {
            model.proxyHand.relatedHandlers.Add(this);

            slaveBones = AvatarHelpers.GetSlaveHandBones(model.proxyHand.slave);

            // Set default configuration if needed
            if (model.asset == null)
            {
                model.asset = BasicHelpers.FindScriptableObject <HandPhysicsConfigurationAsset>(core.model.defaultConfAssets);
            }

            // Make configuration editable
            model.configuration = new HandPhysicsConfiguration(model.asset.configuration);

            for (int i = 0; i < slaveBones.Length; i++)
            {
                if (slaveBones[i].colliderRef)
                {
                    // Ignore palm-finger collisions
                    Physics.IgnoreCollision((model.proxyHand.slave.wrist as SlaveBoneModel).colliderRef, slaveBones[i].colliderRef, true);
                }

                if (slaveBones[i].jointRef)
                {
                    // Get initial connected body local rotations and conn anchors
                    if (slaveBones[i].jointRef.connectedBody != null)
                    {
                        slaveBones[i].initialConnectedBodyLocalRotation     = slaveBones[i].jointRef.connectedBody.transform.localRotation;
                        slaveBones[i].initialConnectedAnchor                = slaveBones[i].jointRef.connectedAnchor;
                        slaveBones[i].jointRef.autoConfigureConnectedAnchor = false;
                    }
                    else
                    {
                        slaveBones[i].initialConnectedBodyLocalRotation = slaveBones[i].jointRef.transform.rotation;
                    }

                    // Set initial joint configurations
                    if (slaveBones[i] == model.proxyHand.slave.wrist)
                    {
                        PhysHelpers.SetSlaveBoneConfiguration(slaveBones[i].jointRef, model.configuration.wrist);
                    }
                    else if (slaveBones[i].isSpecial)
                    {
                        PhysHelpers.SetSlaveBoneConfiguration(slaveBones[i].jointRef, model.configuration.specials);
                    }
                    else
                    {
                        PhysHelpers.SetSlaveBoneConfiguration(slaveBones[i].jointRef, model.configuration.fingers);
                    }

                    // Initial built-in velocity clamps
                    slaveBones[i].rigidbodyRef.maxDepenetrationVelocity = model.configuration.fingers.maxLinearVelocity;
                    slaveBones[i].rigidbodyRef.maxAngularVelocity       = model.configuration.fingers.maxAngularVelocity;
                }
            }
        }
Exemplo n.º 4
0
        protected void Awake()
        {
            // Fingers

            if (fingers == null || fingers.Length == 0)
            {
                AvatarHelpers.HandModelInit(this);
            }

            // Bones

            bones = AvatarHelpers.GetHandBones(this);

            // Transforms (depends on .bones)

            allTransforms = AvatarHelpers.GetAllTransforms(this);
        }
        public async Task <byte[]> GenerateAvatar(string name, string formatExtension, Int32 squareSize, CancellationToken cancellationToken)
        {
            name = AvatarHelpers.CleanName(name);

            var backgroundColor = await _paletteProvider.GetColorForString(name, cancellationToken);

            var generator = _avatarGenerators.FirstOrDefault(p => p.Extension.Equals(formatExtension, StringComparison.OrdinalIgnoreCase));

            if (generator == null)
            {
                throw new InvalidOperationException("No generator found for extension " + formatExtension);
            }

            var buffer = await generator.GenerateAvatar(name, squareSize, Rgba32.ParseHex("fff"), backgroundColor, cancellationToken);

            return(buffer);
        }
Exemplo n.º 6
0
        protected void Awake()
        {
            // Fingers

            if (fingers == null || fingers.Length == 0)
            {
                List <FingerModel> fingerList = new List <FingerModel>();

                if (thumb)
                {
                    fingerList.Add(thumb);
                }
                if (index)
                {
                    fingerList.Add(index);
                }
                if (middle)
                {
                    fingerList.Add(middle);
                }
                if (ring)
                {
                    fingerList.Add(ring);
                }
                if (pinky)
                {
                    fingerList.Add(pinky);
                }

                fingers = fingerList.ToArray();
            }

            for (int i = 0; i < fingers.Length; i++)
            {
                fingers[i].hand = this;
            }

            // Bones

            bones = AvatarHelpers.GetHandBones(this);

            // Transforms (depends on .bones)

            allTransforms = AvatarHelpers.GetAllTransforms(this);
        }
Exemplo n.º 7
0
        void UpdateHand(HandModel hand)
        {
            bool wasPinching = false;
            bool wasGrasping = false;

            float tempValue;

            int tempIndex;

            for (int i = 0; i < hand.fingers.Length; i++)
            {
                // Strength
                tempIndex = hand.fingers[i].bones.Length - 2;
                hand.fingers[i].strengthLerp = AvatarHelpers.GetBoneRotLerp(hand.fingers[i].bones[tempIndex], conf.maxLocalRotZ, conf.minLocalRotZ);

                // Flex
                hand.fingers[i].flexLerp = AvatarHelpers.GetFingerFlexion(hand.fingers[i], conf.minFlexRelDistance, hand.proxyHand.scale);

                // Base rotation (Closed/Opened)
                tempIndex = hand.fingers[i].bones.Length - 3;
                hand.fingers[i].baseRotationLerp = AvatarHelpers.GetBoneRotLerp(hand.fingers[i].bones[tempIndex], conf.maxLocalRotZ, conf.minLocalRotZ);
                hand.fingers[i].isClosed         = hand.fingers[i].baseRotationLerp > conf.minLerpToClose;

                // Palm line
                hand.fingers[i].palmLineLerp = AvatarHelpers.GetPalmLineLerp(hand.fingers[i], conf.maxPalmRelDistance, conf.minPalmRelDistance, hand.proxyHand.scale);

                // Pinch
                tempValue = hand.fingers[i].pinchLerp;
                if (hand.fingers[i].flexLerp < conf.minFlexLerpToDisablePinch)
                {
                    hand.fingers[i].pinchLerp = AvatarHelpers.GetFingerPinch(hand.fingers[i], conf.maxPinchRelDistance, conf.minPinchRelDistance, hand.proxyHand.scale);
                }
                else
                {
                    hand.fingers[i].pinchLerp = 0.0f;
                }
                hand.fingers[i].pinchSpeed = (hand.fingers[i].pinchLerp - tempValue) / Time.deltaTime;

                if (hand.fingers[i] == hand.index)
                {
                    wasPinching = hand.fingers[i].isPinching;
                }
                hand.fingers[i].isPinching = hand.fingers[i].pinchLerp > conf.minLerpToPinch;
            }

            // Fist
            hand.fistLerp = AvatarHelpers.GetHandFist(hand);
            hand.isFist   = hand.fistLerp > conf.minLerpToFist;

            // Grasp
            tempValue       = hand.graspLerp;
            hand.graspLerp  = AvatarHelpers.GetHandGrasp(hand);
            hand.graspSpeed = (hand.graspLerp - tempValue) / Time.deltaTime;

            wasGrasping     = hand.isGrasping;
            hand.isGrasping = hand.graspLerp > conf.minLerpToGrasp;

            // Ray
            if (hand.ray)
            {
                hand.ray.forward = AvatarHelpers.GetHandRayDirection(hand);
                hand.ray.gameObject.SetActive(Vector3.Dot(hand.palmNormal.forward, hand.ray.forward) > 0.0f);
            }

            if (hand is MasterHandModel)
            {
                EmitEvents(hand as MasterHandModel, hand.proxyHand.handler, wasPinching, wasGrasping);
            }
        }
Exemplo n.º 8
0
 void InitHand(HandModel hand)
 {
     AvatarHelpers.UpdateFingerLengths(hand, hand.proxyHand.scale);
 }
Exemplo n.º 9
0
        void UpdateHand(HandModel hand, HandViewModel viewModel, CoreConfiguration conf)
        {
            bool wasGrasping = hand.isGrasping;

            float tempValue;

            int tempIndex;

            for (int f = 0; f < hand.fingers.Length; f++)
            {
                if (hand.fingers[f].bones.Length == 0)
                {
                    continue;
                }

                bool wasPinching = hand.fingers[f].isPinching;

                if (model.strength)
                {
                    // Strength
                    if (hand.fingers[f].bones.Length >= 3)
                    {
                        tempIndex = hand.fingers[f].bones.Length - 2;
                    }
                    else
                    {
                        tempIndex = hand.fingers[f].bones.Length - 1;
                    }

                    hand.fingers[f].strengthLerp = AvatarHelpers.GetBoneRotLerp(hand.fingers[f].bones[tempIndex].transformRef, conf.maxLocalRotZ, conf.minLocalRotZ);
                }

                if (model.flex)
                {
                    // Flex
                    hand.fingers[f].flexLerp = AvatarHelpers.GetFingerFlexion(hand.fingers[f], conf.minFlexRelDistance, hand.proxyHand.scale);
                }

                if (model.grasp)
                {
                    // Base rotation (Closed/Opened)
                    hand.fingers[f].baseRotationLerp = AvatarHelpers.GetBoneRotLerp(hand.fingers[f].fingerBase, conf.maxLocalRotZ, conf.minLocalRotZ);
                    hand.fingers[f].isClosed         = hand.fingers[f].baseRotationLerp > conf.minLerpToClose;
                }

                if (model.fist)
                {
                    // Palm line
                    hand.fingers[f].palmLineLerp = AvatarHelpers.GetPalmLineLerp(hand.fingers[f], conf.maxPalmRelDistance, conf.minPalmRelDistance, hand.proxyHand.scale);
                }

                if (model.pinch)
                {
                    // Pinch
                    tempValue = hand.fingers[f].pinchLerp;

                    if (hand.fingers[f].flexLerp < conf.minFlexLerpToDisablePinch)
                    {
                        hand.fingers[f].pinchLerp = AvatarHelpers.GetFingerPinch(hand.fingers[f], conf.maxPinchRelDistance, conf.minPinchRelDistance, hand.proxyHand.scale);
                    }
                    else
                    {
                        hand.fingers[f].pinchLerp = 0.0f;
                    }

                    // Pinch speed
                    hand.fingers[f].pinchSpeed = (hand.fingers[f].pinchLerp - tempValue) / Time.deltaTime;

                    // Is Pinching
                    hand.fingers[f].isPinching = hand.fingers[f].pinchLerp > conf.minLerpToPinch;

                    // Time counter
                    if (hand.fingers[f].isPinching)
                    {
                        hand.fingers[f].timePinching += Time.deltaTime;
                    }
                    else
                    {
                        hand.fingers[f].timePinching = 0.0f;
                    }

                    // Gesture intention
                    if (hand.fingers[f].isPinching)
                    {
                        hand.fingers[f].pinchIntentionTime = Mathf.Clamp(hand.fingers[f].timePinching, 0.0f, model.configuration.minTimeToIntention);
                    }
                    else
                    {
                        hand.fingers[f].pinchIntentionTime = Mathf.Clamp(hand.fingers[f].pinchIntentionTime - Time.deltaTime, 0.0f, model.configuration.minTimeToIntention);
                    }

                    hand.fingers[f].pinchIntentionLerp = Mathf.InverseLerp(0.0f, model.configuration.minTimeToIntention, hand.fingers[f].pinchIntentionTime);
                }

                // Events
                EmitFingerEvents(hand.fingers[f], viewModel.fingers[f], wasPinching);
            }

            if (model.fist)
            {
                // Fist
                hand.fistLerp = AvatarHelpers.GetHandFist(hand);
                hand.isFist   = hand.fistLerp > model.minLerpToFist;
            }

            if (model.grasp)
            {
                // Grasp
                tempValue       = hand.graspLerp;
                hand.graspLerp  = AvatarHelpers.GetHandGrasp(hand);
                hand.graspSpeed = (hand.graspLerp - tempValue) / Time.deltaTime;

                hand.isGrasping = hand.graspLerp > model.minLerpToGrasp;

                // Time grasping
                if (hand.isGrasping)
                {
                    hand.timeGrasping += Time.deltaTime;
                }
                else
                {
                    hand.timeGrasping = 0.0f;
                }

                // Gesture intention
                if (hand.isGrasping)
                {
                    hand.graspIntentionTime = Mathf.Clamp(hand.timeGrasping, 0.0f, model.configuration.minTimeToIntention);
                }
                else
                {
                    hand.graspIntentionTime = Mathf.Clamp(hand.graspIntentionTime - Time.deltaTime, 0.0f, model.configuration.minTimeToIntention);
                }

                hand.graspIntentionLerp = Mathf.InverseLerp(0.0f, model.configuration.minTimeToIntention, hand.graspIntentionTime);
            }

            if (model.rays)
            {
                // Ray
                if (hand.ray && hand.proxyHand && hand.proxyHand.shoulderTip)
                {
                    hand.ray.forward = AvatarHelpers.GetHandRayDirection(hand, hand.proxyHand.shoulderTip);
                    hand.ray.gameObject.SetActive(Vector3.Dot(hand.palmNormal.forward, hand.ray.forward) > 0.0f);
                }
            }

            // Events
            EmitHandEvents(hand, viewModel, wasGrasping);
        }
Exemplo n.º 10
0
 void InitHand(HandModel hand)
 {
     AvatarHelpers.UpdateFingerLengths(hand, hand.extraScale);
 }
Exemplo n.º 11
0
        public void FingerStart(FingerModel finger)
        {
            finger.part = HumanBodyPart.Finger;

            // Find side
            if (finger.hand == finger.hand.body.leftHand)
            {
                finger.side = Side.Left;
            }
            else if (finger.hand == finger.hand.body.rightHand)
            {
                finger.side = Side.Right;
            }
            else
            {
                finger.side = Side.None;
            }

            // Find finger
            if (finger == finger.hand.thumb)
            {
                finger.finger = HumanFinger.Thumb;
            }
            else if (finger == finger.hand.index)
            {
                finger.finger = HumanFinger.Index;
            }
            else if (finger == finger.hand.middle)
            {
                finger.finger = HumanFinger.Middle;
            }
            else if (finger == finger.hand.ring)
            {
                finger.finger = HumanFinger.Ring;
            }
            else if (finger == finger.hand.pinky)
            {
                finger.finger = HumanFinger.Pinky;
            }
            else
            {
                finger.finger = HumanFinger.None;
            }

            // Clean null bones
            finger.bones.RemoveAll(b => b == null);

            // Find bones
            for (int b = 0; b < finger.bones.Count; b++)
            {
                finger.bones[b].humanBodyBone = AvatarHelpers.GetHumanFingerBone(finger.side, finger.finger, finger.bones.Count - 1 - b);
            }

            // Finger points
            if (!finger.knuckle)
            {
                finger.knuckle = finger.root.point;
            }

            if (!finger.tip)
            {
                List <BoneModel> distalCandidates = finger.bones.FindAll(b => b.children.Count == 0);
                if (distalCandidates.Count == 1 && distalCandidates[0].points.Count > 1)
                {
                    finger.tip = distalCandidates[0].points[1];
                }
                else
                {
                    Debug.LogWarning("Tip not found for finger " + finger.name);
                }
            }

            // Ordered bones
            AvatarHelpers.GetBonesFromRootToTip(finger, finger.bonesFromRootToTip);
        }