private async void RemoveExecute()
        {
            Int64 startTicks = Log.VIEWMODEL("(BoneDetailViewModel) Enter", Common.LOG_APPNAME);

            var isReferenced =
                await _BoneDataService.IsReferencedByDogAsync(SelectedBone.Id);

            if (isReferenced)
            {
                //MessageDialogService.ShowInfoDialog(
                //    $"The Dog ({SelectedBone.Name})" +
                //    " can't be removed;  It is referenced by at least one Dog");

                var message = $"The Dog ({SelectedBone.Name})" +
                              " can't be removed;  It is referenced by at least one Dog";

                DialogService.Show("NotificationDialog", new DialogParameters($"message={message}"), r =>
                {
                });

                return;
            }

            SelectedBone.PropertyChanged -= Wrapper_PropertyChanged;
            _BoneDataService.Remove(SelectedBone.Model);
            Bones.Remove(SelectedBone);
            SelectedBone = null;
            HasChanges   = _BoneDataService.HasChanges();

            ((DelegateCommand)SaveCommand).RaiseCanExecuteChanged();

            Log.VIEWMODEL("(BoneDetailViewModel) Exit", Common.LOG_APPNAME, startTicks);
        }
示例#2
0
        public static BoneWrapper[] GetHumanBones(Dictionary <Transform, bool> actualBones)
        {
            string[]      humanBoneNames = HumanTrait.BoneName;
            BoneWrapper[] bones          = new BoneWrapper[humanBoneNames.Length];
            for (int i = 0; i < humanBoneNames.Length; i++)
            {
                Transform bone = null;

                var humanBoneName = humanBoneNames[i];
                bones[i] = new BoneWrapper(humanBoneName, bone);
            }
            return(bones);
        }
        void AddExecute()
        {
            Int64 startTicks = Log.VIEWMODEL("(BoneDetailViewModel) Enter", Common.LOG_APPNAME);

            var wrapper = new BoneWrapper(new Domain.Bone());

            wrapper.PropertyChanged += Wrapper_PropertyChanged;

            _BoneDataService.Add(wrapper.Model);
            Bones.Add(wrapper);

            wrapper.Name = "";  // Trigger the validation

            Log.VIEWMODEL("(BoneDetailViewModel) Exit", Common.LOG_APPNAME, startTicks);
        }
示例#4
0
        private static bool DrawBone(int shownBodyView, int i, Rect rect, BoneWrapper bone, bool hasHover)
        {
            if (BonePositions[shownBodyView, i] == Vector2.zero)
            {
                return(false);
            }
            Vector2 b = BonePositions[shownBodyView, i];

            b.y *= -1f;
            b.Scale(new Vector2(rect.width * 0.5f, rect.height * 0.5f));
            b = rect.center + b;
            const int num   = 19;
            Rect      rect2 = new Rect(b.x - num * 0.5f, b.y - num * 0.5f, num, num);

            //Returns true if this is being hovered
            return(bone.BoneDotGUI(rect2, rect2, new Rect(25, rect.y + 6, 150, 20), i, hasHover));
        }
示例#5
0
        // ReSharper disable once MemberCanBePrivate.Global
        public static BoneWrapper[] GetBoneArray(Animator animator)
        {
            string[] boneName = HumanTrait.BoneName;
            IEnumerable <HumanBodyBones> humanBodyBones = Enum.GetValues(typeof(HumanBodyBones)).Cast <HumanBodyBones>();

            BoneWrapper[] bones = new BoneWrapper[boneName.Length];
            int           i     = 0;

            foreach (HumanBodyBones humanBodyBone in humanBodyBones)
            {
                if (humanBodyBone == HumanBodyBones.LastBone)
                {
                    break;
                }
                bones[i] = new BoneWrapper(boneName[i], animator == null ? null : animator.GetBoneTransform(humanBodyBone));
                i++;
            }

            return(bones);
        }
        // private async void OpenDetailView(OpenDetailViewEventArgs args)
        // {
        // Int64 startTicks = Log.EVENT("(BoneDetailViewModel) Enter", Common.LOG_APPNAME);

        // await LoadAsync(args.Id);

        // Log.EVENT("(BoneDetailViewModel) Exit", Common.LOG_APPNAME, startTicks);
        // }

        #endregion

        #region Public Methods

        public override async Task LoadAsync(int id)
        {
            Int64 startTicks = Log.VIEWMODEL("(BoneDetailViewModel) Enter Id:({id})", Common.LOG_APPNAME);

            Id = id;

            foreach (var wrapper in Bones)
            {
                wrapper.PropertyChanged -= Wrapper_PropertyChanged;
            }

            Bones.Clear();

            var items = await _BoneDataService.AllAsync();

            foreach (var model in items)
            {
                var wrapper = new BoneWrapper(model);
                wrapper.PropertyChanged += Wrapper_PropertyChanged;
                Bones.Add(wrapper);
            }

            Log.VIEWMODEL("(BoneDetailViewModel) Exit", Common.LOG_APPNAME, startTicks);
        }
示例#7
0
        private static Vector3 GetBoneAlignmentDirection(BoneWrapper[] bones, Quaternion avatarOrientation, int boneIndex)
        {
            if (sBonePoses[boneIndex] == null)
            {
                return(Vector3.zero);
            }

            BoneWrapper bone = bones[boneIndex];
            Vector3     dir;

            // Get the child bone
            BonePoseData pose           = sBonePoses[boneIndex];
            int          childBoneIndex = -1;

            if (pose.childIndices != null)
            {
                foreach (int i in pose.childIndices)
                {
                    if (bones[i].bone != null)
                    {
                        childBoneIndex = i;
                        break;
                    }
                }
            }
            else
            {
                childBoneIndex = GetHumanBoneChild(bones, boneIndex);
            }

            // TODO@MECANIM Something si wrong with the indexes
            //if (boneIndex == (int)HumanBodyBones.LeftHand)
            //  Debug.Log ("Child bone for left hand: "+childBoneIndex);

            if (childBoneIndex >= 0 && bones[childBoneIndex] != null && bones[childBoneIndex].bone != null)
            {
                // Get direction from bone to child
                BoneWrapper childBone = bones[childBoneIndex];
                dir = childBone.bone.position - bone.bone.position;

                // TODO@MECANIM Something si wrong with the indexes
                //if (boneIndex == (int)HumanBodyBones.LeftHand)
                //  Debug.Log (" - "+childBone.humanBoneName + " - " +childBone.bone.name);
            }
            else
            {
                if (bone.bone.childCount != 1)
                {
                    return(Vector3.zero);
                }

                dir = Vector3.zero;
                // Get direction from bone to child
                foreach (Transform child in bone.bone)
                {
                    dir = child.position - bone.bone.position;
                    break;
                }
            }

            return(dir.normalized);
        }
示例#8
0
        public static void MakeBoneAlignmentValid(BoneWrapper[] bones, Quaternion avatarOrientation, int boneIndex)
        {
            if (boneIndex < 0 || boneIndex >= sBonePoses.Length || boneIndex >= bones.Length)
            {
                return;
            }

            BoneWrapper  bone = bones[boneIndex];
            BonePoseData pose = sBonePoses[boneIndex];

            if (bone.bone == null || pose == null)
            {
                return;
            }

            if (boneIndex == (int)HumanBodyBones.Hips)
            {
                float angleX = Vector3.Angle(avatarOrientation * Vector3.right, Vector3.right);
                float angleY = Vector3.Angle(avatarOrientation * Vector3.up, Vector3.up);
                float angleZ = Vector3.Angle(avatarOrientation * Vector3.forward, Vector3.forward);
                if (angleX > pose.maxAngle || angleY > pose.maxAngle || angleZ > pose.maxAngle)
                {
                    bone.bone.rotation = Quaternion.Inverse(avatarOrientation) * bone.bone.rotation;
                }
                return;
            }

            Vector3 dir = GetBoneAlignmentDirection(bones, avatarOrientation, boneIndex);

            if (dir == Vector3.zero)
            {
                return;
            }
            Quaternion space   = GetRotationSpace(bones, avatarOrientation, boneIndex);
            Vector3    goalDir = space * pose.direction;

            if (pose.planeNormal != Vector3.zero)
            {
                dir = Vector3.ProjectOnPlane(dir, space * pose.planeNormal);
            }

            // If the bone direction is not close enough to the target direction,
            // rotate it so it matches the target direction.
            float deltaAngle = Vector3.Angle(dir, goalDir);

            if (deltaAngle > pose.maxAngle * 0.99f)
            {
                Quaternion adjust = Quaternion.FromToRotation(dir, goalDir);

                // If this bone is hip or knee, remember global foor rotation and apply it after this adjustment
                Transform  footBone = null;
                Quaternion footRot  = Quaternion.identity;
                if (boneIndex == (int)HumanBodyBones.LeftUpperLeg || boneIndex == (int)HumanBodyBones.LeftLowerLeg)
                {
                    footBone = bones[(int)HumanBodyBones.LeftFoot].bone;
                }
                if (boneIndex == (int)HumanBodyBones.RightUpperLeg || boneIndex == (int)HumanBodyBones.RightLowerLeg)
                {
                    footBone = bones[(int)HumanBodyBones.RightFoot].bone;
                }
                if (footBone != null)
                {
                    footRot = footBone.rotation;
                }

                // Adjust only enough to fall within maxAngle
                float adjustAmount = Mathf.Clamp01(1.05f - (pose.maxAngle / deltaAngle));
                adjust = Quaternion.Slerp(Quaternion.identity, adjust, adjustAmount);

                bone.bone.rotation = adjust * bone.bone.rotation;

                // Revert foot rotation to what it was
                if (footBone != null)
                {
                    footBone.rotation = footRot;
                }
            }
        }