Exemplo n.º 1
0
        private static void _SetRotationKey(Transform joint)
        {
            var oldQ = joint.localRotation;

            joint.Rotate(new Vector3(1, 0, 0));
            Undo.RecordObject(joint, "baking");
            joint.localRotation = oldQ;
            HotFix.FixRotation(joint);
        }
Exemplo n.º 2
0
        /// <summary>
        /// mirror thisBone's data to corresponding
        /// </summary>
        public void ApplyMirror(Transform thisBone)
        {
            Transform thatBone = GetMirrorBone(thisBone);

            if (thatBone == null)
            {
                return;
            }

            Undo.RecordObject(thatBone, "Apply Mirror");

            Axis selfAxisValue       = _GetAxisValue(thisBone);
            Axis selfParentAxisValue = _GetAxisValueForParent(thisBone);

            //rot
            {
                Vector3    planeNormal = Vector3.right;
                Quaternion oldQ        = thisBone.localRotation;
                Quaternion newQ        = oldQ;
                if (selfAxisValue != selfParentAxisValue)
                {
                    planeNormal = _GetPlaneNormal(selfParentAxisValue);
                    newQ        = _ReflectQ(oldQ, selfAxisValue, planeNormal);
                }
                else
                {
                    switch (selfAxisValue)
                    {
                    case Axis.XY:
                    {
                        newQ.x = -newQ.x;
                        newQ.y = -newQ.y;
                    }
                    break;

                    case Axis.XZ:
                    {
                        newQ.x = -newQ.x;
                        newQ.z = -newQ.z;
                    }
                    break;

                    case Axis.YZ:
                    {
                        newQ.y = -newQ.y;
                        newQ.z = -newQ.z;
                    }
                    break;

                    default:
                        Dbg.LogErr("MirrorCtrl.ApplyMirror: unexpected parentAxisValue: {0}", selfAxisValue);
                        break;
                    }
                }
                thatBone.localRotation = newQ;
            }

            //pos
            {
                Vector3 oldP = thisBone.localPosition;
                Vector3 newP = oldP;
                switch (selfParentAxisValue)
                {
                case Axis.XZ:
                {
                    newP.y = -newP.y;
                }
                break;

                case Axis.XY:
                {
                    newP.z = -newP.z;
                }
                break;

                case Axis.YZ:
                {
                    newP.x = -newP.x;
                }
                break;

                default:
                    Dbg.LogErr("MirrorCtrl.ApplyMirror: unexpected mirror axis value (2nd): {0}", selfParentAxisValue);
                    break;
                }
                thatBone.localPosition = newP;
            }

            //scale
            {
                thatBone.localScale = thisBone.localScale;
            }

            HotFix.FixRotation(thatBone);
        }