Пример #1
0
        public static void BoneZAngleInspector(HumanoidTarget.TargetedBone bone, SerializedProperty minProperty, SerializedProperty maxProperty, float defaultMin, float defaultMax)
        {
            float min = minProperty.floatValue;
            float max = maxProperty.floatValue;

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("Limits Z", GUILayout.MinWidth(70));

            min = EditorGUILayout.FloatField(min, GUILayout.Width(65));
            GUI.SetNextControlName(bone.bone.transform.name + "Z1");
            EditorGUILayout.MinMaxSlider(ref min, ref max, -180, 180);
            GUI.SetNextControlName(bone.bone.transform.name + "Z2");
            max = EditorGUILayout.FloatField(max, GUILayout.Width(65));

            if (GUILayout.Button("R"))
            {
                min = defaultMin;
                max = defaultMax;
                GUI.FocusControl(bone.bone.transform.name + "Z1");
            }

            EditorGUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck())
            {
                minProperty.floatValue = min;
                maxProperty.floatValue = max;
                SceneView.RepaintAll();
            }
        }
Пример #2
0
        HumanoidTarget.TargetedBone[] ITarget.GetBones()
        {
            HumanoidTarget.TargetedBone[] bones = new HumanoidTarget.TargetedBone[] {
                thumb.proximal,
                thumb.intermediate,
                thumb.distal,

                index.proximal,
                index.intermediate,
                index.distal,

                middle.proximal,
                middle.intermediate,
                middle.distal,

                ring.proximal,
                ring.intermediate,
                ring.distal,

                little.proximal,
                little.intermediate,
                little.distal,
            };

            for (int i = 0; i < bones.Length; i++)
            {
                bones[i].name = boneNames[i];
            }

            return(bones);
        }
Пример #3
0
        public static void BoneZAngleInspector(HumanoidTarget.TargetedBone bone, float defaultMin, float defaultMax)
        {
            float oldMin = bone.bone.minAngles.z;
            float oldMax = bone.bone.maxAngles.z;

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("Z Limits", GUILayout.MinWidth(70));

            GUI.SetNextControlName(bone.bone.transform.name + "Z1");
            bone.bone.minAngles.z = EditorGUILayout.FloatField(bone.bone.minAngles.z, GUILayout.Width(65));

            EditorGUILayout.MinMaxSlider(ref bone.bone.minAngles.z, ref bone.bone.maxAngles.z, -180, 180);

            GUI.SetNextControlName(bone.bone.transform.name + "Z2");
            bone.bone.maxAngles.z = EditorGUILayout.FloatField(bone.bone.maxAngles.z, GUILayout.Width(65));

            if (GUILayout.Button("R"))
            {
                bone.bone.minAngles.z = defaultMin;
                bone.bone.maxAngles.z = defaultMax;
                GUI.FocusControl(bone.bone.transform.name + "Z1");
            }

            EditorGUILayout.EndHorizontal();

            if (bone.bone.maxAngles.y != oldMax || bone.bone.minAngles.y != oldMin)
            {
                SceneView.RepaintAll();
            }
        }
Пример #4
0
        public override void Update()
        {
#if UNITY_2017_2_OR_NEWER
            if (tracker == null || !tracker.enabled || !enabled || XRSettings.loadedDeviceName != "OpenVR")
#else
            if (tracker == null || !tracker.enabled || !enabled || VRSettings.loadedDeviceName != "OpenVR")
#endif
            { return; }

            HumanoidTarget.TargetedBone targetBone = handTarget.GetTargetBone(attachedBone);
            if (viveTracker == null)
            {
                UpdateTarget(targetBone.target, sensorTransform);
                return;
            }

            if (viveTracker.trackerId < 0)
            {
                viveTracker.trackerId = FindArmTracker(handTarget.isLeft);
            }

            viveTracker.UpdateComponent();
            if (viveTracker.status != Status.Tracking)
            {
                return;
            }

            UpdateTarget(targetBone.target, viveTracker);
        }
Пример #5
0
        private void UpdateFacePoint(FaceTarget faceTarget, HumanoidTarget.TargetedBone faceBone)
        {
            if (faceBone.bone.transform == null)
            {
                return;
            }

            HumanoidTarget.TargetedBone parentBone;
            Quaternion parentRotation;

            if (faceBone.target.transform.parent == faceTarget.jaw.target.transform && faceTarget.jaw.bone.transform != null)
            {
                parentBone     = faceTarget.jaw;
                parentRotation = faceTarget.jaw.bone.targetRotation;
            }
            else
            {
                parentBone     = faceTarget.headTarget.head;
                parentRotation = faceTarget.headTarget.head.bone.targetRotation;
            }

            Vector3 localPosition = parentBone.target.transform.InverseTransformPoint(faceBone.target.transform.position);

            faceBone.bone.transform.position = parentBone.bone.transform.position + parentBone.bone.targetRotation * localPosition;

            Quaternion localRotation = parentBone.bone.targetRotation * faceBone.target.transform.localRotation;

            faceBone.bone.transform.rotation = localRotation * faceBone.target.toBoneRotation;

            //Quaternion jawRotationOnParent = parentRotation * faceBone.target.transform.localRotation;
            //faceBone.bone.transform.rotation = jawRotationOnParent * faceBone.target.toBoneRotation;
        }
Пример #6
0
        private void UpdateEyeLid(HumanoidTarget.TargetedBone eyeLid)
        {
            if (eyeLid.bone.transform == null)
            {
                return;
            }

            //eyeLid.target.transform.LookAt(eyeTarget.face.focusPoint);
            eyeLid.bone.transform.rotation = eyeLid.target.transform.rotation * eyeLid.target.toBoneRotation;

            //Quaternion eyeLidRotationOnParent = faceTarget.headTarget.head.bone.targetRotation * jaw.target.transform.localRotation;
            //jaw.bone.transform.rotation = eyeLidRotationOnParent * jaw.target.toBoneRotation;
        }
Пример #7
0
        protected static Quaternion LimitAngle(HumanoidTarget.TargetedBone targetedBone, ref Quaternion lastLocalBoneRotation, Quaternion boneRotation)
        {
            if (targetedBone.parent == null || targetedBone.parent.bone.transform == null)
            {
                return(boneRotation);
            }

            Quaternion parentRotation = targetedBone.parent.bone.targetRotation;
            Quaternion localRotation  = Quaternion.Inverse(parentRotation) * boneRotation;

            float lastAngle = Quaternion.Angle(Quaternion.identity, lastLocalBoneRotation);
            float angle     = Quaternion.Angle(parentRotation, boneRotation);

            if (angle < lastAngle)
            {
                // Decreasing angle

                // No damping or limit

                lastLocalBoneRotation = localRotation;
                return(boneRotation);
            }
            else
            {
                // Increasing angle
                Quaternion deltaLocalRotation = Quaternion.Inverse(lastLocalBoneRotation) * localRotation;

                // Damping tension based limit
                float tension = targetedBone.GetTension();
                float f       = Mathf.Clamp01(1 - tension * tension);
                deltaLocalRotation    = Quaternion.Slerp(Quaternion.identity, deltaLocalRotation, f);
                lastLocalBoneRotation = lastLocalBoneRotation * deltaLocalRotation;

                // Hard limit
                lastLocalBoneRotation = Quaternion.RotateTowards(Quaternion.identity, lastLocalBoneRotation, targetedBone.bone.maxAngle);

                return(parentRotation * lastLocalBoneRotation);
            }
        }
Пример #8
0
 protected Vector3 LimitAngles(HumanoidTarget.TargetedBone bone, Vector3 angles)
 {
     angles = UnityAngles.Clamp(angles, bone.bone.minAngles, bone.bone.maxAngles);
     return(angles);
 }
Пример #9
0
 public TargetedPhalanges(TargetedFinger finger, HumanoidTarget.TargetedBone nextBone)
     : base(nextBone)
 {
     this.finger = finger;
 }