Пример #1
0
        /// <summary>
        /// Assign the new transform to the serialized property
        /// </summary>
        /// <param name="boneProperty"></param>
        /// <param name="boundTransform"></param>
        private void AssignTransform(SerializedProperty boneProperty, Transform boundTransform)
        {
            //Setting a new bone has to be done when the hand is not an in editor pose, so doing this will reset the hand
            if (setEditorPose.boolValue == true)
            {
                myTarget.ResetHand();
                setEditorPose.boolValue = false;
            }

            var startTransform = boneProperty.FindPropertyRelative("startTransform");

            startTransform.FindPropertyRelative("position").vector3Value = boundTransform.localPosition;
            startTransform.FindPropertyRelative("rotation").vector3Value = boundTransform.localRotation.eulerAngles;
        }
        /// <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;
        }
Пример #3
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;
        }
Пример #4
0
 /// <summary>
 /// Undo the previous binding applied to the hand
 /// </summary>
 public void AutoRigUndo()
 {
     Close();
     handBinder.ResetHand(true);
     Undo.undoRedoPerformed -= AutoRigUndo;
 }