Пример #1
0
        /// <summary>
        /// Set the Editor Pose
        /// </summary>
        private void EditorHandPose()
        {
            if (myTarget != null && myTarget.enabled)
            {
                MakeLeapHand(myTarget);

                if (myTarget.SetEditorPose)
                {
                    if (myTarget.GetLeapHand() == null)
                    {
                        myTarget.InitHand();
                        myTarget.BeginHand();
                        myTarget.UpdateHand();
                    }
                    else
                    {
                        myTarget.UpdateHand();
                    }
                }
                else
                {
                    myTarget.ResetHand();
                }
            }
        }
Пример #2
0
            /// <summary>
            /// Draw a button to allow the user to automatically bind the hand
            /// </summary>
            void DrawAutoBindButton()
            {
                if (GUILayout.Button(new GUIContent("Auto Bind", "Automatically try to search and bind the hand"), editorSkin.button, GUILayout.MaxWidth(EditorGUIUtility.currentViewWidth), GUILayout.MinHeight(spaceSize)))
                {
                    if (EditorUtility.DisplayDialog("Auto Bind",
                                                    "Are you sure you want to discard all your changes and run the Auto Bind process?", "Yes", "No"))
                    {
                        Undo.RegisterFullObjectHierarchyUndo(handBinder, "AutoBind");
                        Undo.undoRedoPerformed += AutoRigUndo;
                        HandBinderAutoBinder.AutoBind(handBinder);
                        handBinder.UpdateHand();
                    }
                }

                GUILayout.Label(message1, editorSkin.label);
                GUILayout.Label(dividerLine);
            }
        /// <summary>
        /// This function is used to search the HandBinder scipts children transforms to auto assign them for the user
        /// </summary>
        /// <param name="handBinder">The binder that the found transforms will get assigned too</param>
        public static void AutoRig(HandBinder handBinder)
        {
            handBinder.ResetHand();
            BoneDefinitions boneDefinitions = null;

            //Check to see if we have an autorigger Definitions scriptable object
            if (handBinder.CustomBoneDefinitions == null)
            {
                boneDefinitions = new BoneDefinitions();
            }
            else
            {
                boneDefinitions = handBinder.CustomBoneDefinitions.BoneDefinitions;
            }

            //Get all children of the hand
            var children = GetAllChildren(handBinder.transform);

            var thumbBones  = SelectBones(children, boneDefinitions.DefinitionThumb, true);
            var indexBones  = SelectBones(children, boneDefinitions.DefinitionIndex);
            var middleBones = SelectBones(children, boneDefinitions.DefinitionMiddle);
            var ringBones   = SelectBones(children, boneDefinitions.DefinitionRing);
            var pinkyBones  = SelectBones(children, boneDefinitions.DefinitionPinky);
            var wrist       = SelectBones(children, boneDefinitions.DefinitionWrist).FirstOrDefault();
            var Elbow       = SelectBones(children, boneDefinitions.DefinitionElbow).FirstOrDefault();

            handBinder.boundHand.fingers[0].boundBones = AssignUnityBone(thumbBones);
            handBinder.boundHand.fingers[1].boundBones = AssignUnityBone(indexBones);
            handBinder.boundHand.fingers[2].boundBones = AssignUnityBone(middleBones);
            handBinder.boundHand.fingers[3].boundBones = AssignUnityBone(ringBones);
            handBinder.boundHand.fingers[4].boundBones = AssignUnityBone(pinkyBones);
            handBinder.boundHand.wrist = AssignBoundBone(wrist);
            handBinder.boundHand.elbow = AssignBoundBone(Elbow);
            if (wrist != null && Elbow != null)
            {
                handBinder.elbowLength = (wrist.position - Elbow.position).magnitude;
            }

            EstimateWristRotationOffset(handBinder);

            handBinder.UpdateHand();
            handBinder.DebugModelTransforms = true;
            handBinder.SetEditorPose        = true;
        }
Пример #4
0
        /// <summary>
        /// This function is used to search the child Transforms of the HandBinder script to automatically try and assign them for the user
        /// </summary>
        /// <param name="handBinder">The HandBinder that the found Transform target will get assigned to</param>
        public static void AutoBind(HandBinder handBinder)
        {
            handBinder.ResetHand();
            BoneNameDefinitions boneDefinitions = new BoneNameDefinitions();

            //Get all children of the hand
            var children = new List <Transform>();

            children.Add(handBinder.transform);
            children.AddRange(GetAllChildren(handBinder.transform));

            var thumbBones  = SortBones(SelectBones(children, boneDefinitions.DefinitionThumb), false, true);
            var indexBones  = SortBones(SelectBones(children, boneDefinitions.DefinitionIndex), handBinder.UseMetaBones);
            var middleBones = SortBones(SelectBones(children, boneDefinitions.DefinitionMiddle), handBinder.UseMetaBones);
            var ringBones   = SortBones(SelectBones(children, boneDefinitions.DefinitionRing), handBinder.UseMetaBones);
            var pinkyBones  = SortBones(SelectBones(children, boneDefinitions.DefinitionPinky), handBinder.UseMetaBones);
            var wrist       = SelectBones(children, boneDefinitions.DefinitionWrist).FirstOrDefault();
            var elbow       = SelectBones(children, boneDefinitions.DefinitionElbow).FirstOrDefault();

            handBinder.BoundHand.fingers[0].boundBones = AssignTransformToBoundBone(thumbBones);
            handBinder.BoundHand.fingers[1].boundBones = AssignTransformToBoundBone(indexBones);
            handBinder.BoundHand.fingers[2].boundBones = AssignTransformToBoundBone(middleBones);
            handBinder.BoundHand.fingers[3].boundBones = AssignTransformToBoundBone(ringBones);
            handBinder.BoundHand.fingers[4].boundBones = AssignTransformToBoundBone(pinkyBones);
            handBinder.BoundHand.wrist = AssignBoundBone(wrist);
            handBinder.BoundHand.elbow = AssignBoundBone(elbow);

            if (wrist != null && elbow != null)
            {
                handBinder.ElbowLength = (wrist.position - elbow.position).magnitude;
            }

            EstimateWristRotationOffset(handBinder);
            CalculateElbowLength(handBinder);

            handBinder.GetLeapHand();
            handBinder.UpdateHand();
            handBinder.DebugModelTransforms = true;
            handBinder.SetEditorPose        = true;
        }