Exemple #1
0
        /// <summary>
        /// MeshGroup 메뉴 + Modifier 중 Rigging Modifier에서만 제어할 수 있다.
        /// Rigging 테스트를 위해 임시 WorldMatrix를 만들어서 움직인다.
        /// Rigging Modifier 활성할때마다 변수가 초기화됨.
        /// 자식 MeshGroup의 Bone도 제어 가능하다 (!)
        /// Default와 달리 IK Lock이 걸려있으므로 IK 계산을 해야한다.
        /// </summary>
        /// <param name="curMouseGL"></param>
        /// <param name="curMousePosW"></param>
        /// <param name="deltaMoveW"></param>
        /// <param name="btnIndex"></param>
        /// <param name="isFirstMove"></param>
        public void Move__Modifier_Rigging(Vector2 curMouseGL, Vector2 curMousePosW, Vector2 deltaMoveW, int btnIndex, bool isFirstMove)
        {
            if (Editor.Select.MeshGroup == null ||
                Editor.Select.Bone == null ||
                Editor._boneGUIRenderMode != apEditor.BONE_RENDER_MODE.Render ||
                Editor.Select.Modifier == null ||                 //<<Modifier가 null이면 안된다.
                !Editor.Controller.IsMouseInGUI(curMouseGL) ||
                deltaMoveW.sqrMagnitude == 0.0f
                )
            {
                return;
            }

            apBone         bone                = Editor.Select.Bone;
            apMeshGroup    meshGroup           = Editor.Select.MeshGroup;
            apMeshGroup    boneParentMeshGroup = bone._meshGroup;        //Bone이 속한 MeshGroup. 다를 수 있다.
            apModifierBase modifier            = Editor.Select.Modifier; //선택한 Modifier

            if (modifier.ModifierType != apModifierBase.MODIFIER_TYPE.Rigging)
            {
                //리깅 Modifier가 아니라면 패스
                return;
            }
            if (!Editor.Select.IsRigEditTestPosing)
            {
                //TestPosing이 허용되지 않았다면 패스
                return;
            }

            _boneSelectPosW = curMousePosW;

            //Move로 제어 가능한 경우는
            //1. IK Tail일 때
            //2. Root Bone일때 (절대값)
            if (bone._isIKTail)
            {
                //Debug.Log("Request IK : " + _boneSelectPosW);
                float weight = 1.0f;
                if (deltaMoveW.sqrMagnitude < 5.0f)
                {
                    //weight = 0.2f;
                }
                //bool successIK = bone.RequestIK(_boneSelectPosW, weight, !isFirstSelectBone);
                bool successIK = bone.RequestIK(_boneSelectPosW, weight, true);

                if (!successIK)
                {
                    return;
                }
                apBone headBone = bone._IKHeaderBone;
                if (headBone != null)
                {
                    apBone curBone = bone;
                    //위로 올라가면서 IK 결과값을 Default에 적용하자
                    while (true)
                    {
                        float deltaAngle = curBone._IKRequestAngleResult;
                        //float nextAngle = curBone._defaultMatrix._angleDeg + deltaAngle;
                        float nextAngle = curBone._rigTestMatrix._angleDeg + deltaAngle;                        //Rig Test로 할 것

                        if (nextAngle < -180.0f)
                        {
                            nextAngle += 360.0f;
                        }
                        if (nextAngle > 180.0f)
                        {
                            nextAngle -= 360.0f;
                        }

                        //curBone._defaultMatrix.SetRotate(nextAngle);
                        curBone._rigTestMatrix.SetRotate(nextAngle);

                        curBone._isIKCalculated       = false;
                        curBone._IKRequestAngleResult = 0.0f;

                        if (curBone == headBone)
                        {
                            break;
                        }
                        if (curBone._parentBone == null)
                        {
                            break;
                        }
                        curBone = curBone._parentBone;
                    }

                    //마지막으론 World Matrix 갱신
                    headBone.MakeWorldMatrix(true);
                    headBone.GUIUpdate(true);
                }
            }
            else if (bone._parentBone == null)
            {
                apMatrix renderUnitMatrix = null;
                if (bone._renderUnit != null)
                {
                    //Render Unit의 World Matrix를 참조하여
                    //로컬 값을 Default로 적용하자
                    renderUnitMatrix = bone._renderUnit.WorldMatrixWrap;
                }

                apMatrix localMatrix    = bone._localMatrix;
                apMatrix newWorldMatrix = new apMatrix(bone._worldMatrix);
                newWorldMatrix.SetPos(newWorldMatrix._pos + deltaMoveW);

                if (renderUnitMatrix != null)
                {
                    newWorldMatrix.RInverse(renderUnitMatrix);
                }
                newWorldMatrix.Subtract(localMatrix);                //이건 Add로 연산된거라 Subtract해야한다.



                //bone._defaultMatrix.SetPos(newWorldMatrix._pos);
                bone._rigTestMatrix.SetPos(newWorldMatrix._pos - bone._defaultMatrix._pos);


                bone.MakeWorldMatrix(true);
                bone.GUIUpdate(true);
            }
        }
Exemple #2
0
        //------------------------------------------------------------------------------------------------------------
        // Bone - Move (Default / Rigging Test / Modifier / AnimClip Modifier)
        // Local Move / IK 처리 옵션에 따라 변경 값이 다르다
        // Local Move / IK는 "허용하는 경우" 서로 배타적으로 수정한다. (토글 버튼을 두자)
        // (1) Local Move : Parent에 상관없이 Local Position을 바꾼다. RootNode를 제외하고는 모두 Off.
        // (2) IK : 제어한 마우스 위치에 맞게 Parent들을 회전한다. 실제로 Local Postion이 바뀌진 않다.
        //          IK가 설정되어있다면 다중 IK 처리를 하며, 그렇지 않다면 바로 위의 Parent만 IK를 적용한다. (Root 제외)
        //------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// MeshGroup 메뉴에서 Bone의 Default 편집 중의 이동
        /// Edit Mode가 Select로 활성화되어있어야 한다.
        /// 선택한 Bone이 현재 선택한 MeshGroup에 속해있어야 한다.
        /// IK Lock 여부에 따라 값이 바뀐다.
        /// IK Lock이 걸려있을 때) Parent 본의 Default Rotate가 바뀐다. (해당 Bone의 World를 만들어주기 위해서)
        /// IK Lock이 걸려있지않을 때) 해당 Bone의 Default Pos가 바뀐다.
        /// </summary>
        /// <param name="curMouseGL"></param>
        /// <param name="curMousePosW"></param>
        /// <param name="deltaMoveW"></param>
        /// <param name="btnIndex"></param>
        /// <param name="isFirstMove"></param>
        public void Move__Bone_Default(Vector2 curMouseGL, Vector2 curMousePosW, Vector2 deltaMoveW, int btnIndex, bool isFirstMove)
        {
            if (Editor.Select.MeshGroup == null ||
                Editor.Select.Bone == null ||
                Editor._boneGUIRenderMode != apEditor.BONE_RENDER_MODE.Render ||
                Editor.Select.BoneEditMode != apSelection.BONE_EDIT_MODE.SelectAndTRS ||
                !Editor.Controller.IsMouseInGUI(curMouseGL)
                )
            {
                return;
            }

            if (deltaMoveW.sqrMagnitude == 0.0f && !isFirstMove)
            {
                return;
            }

            apBone      bone      = Editor.Select.Bone;
            apMeshGroup meshGroup = Editor.Select.MeshGroup;

            if (bone._meshGroup != meshGroup)
            {
                //직접 속하지 않고 자식 MeshGroup의 Transform인 경우 제어할 수 없다.
                return;
            }

            if (isFirstMove)
            {
                apEditorUtil.SetRecord_MeshGroup(apUndoGroupData.ACTION.MeshGroup_BoneDefaultEdit, Editor, bone._meshGroup, null, false, false);
            }

            //bool isFirstSelectBone = false;
            //TODO..
            if (_isBoneSelect_MovePosReset)
            {
                _boneSelectPosW            = bone._worldMatrix._pos;
                _isBoneSelect_MovePosReset = false;
                //isFirstSelectBone = true;
            }
            else
            {
                _boneSelectPosW += deltaMoveW;                //<<여기에 IK를 걸어주자
            }
            _boneSelectPosW = curMousePosW;

            //Move로 제어 가능한 경우는
            //1. IK Tail일 때
            //2. Root Bone일때 (절대값)
            if (bone._isIKTail)
            {
                //Debug.Log("Request IK : " + _boneSelectPosW);
                float weight = 1.0f;
                if (deltaMoveW.sqrMagnitude < 5.0f)
                {
                    //weight = 0.2f;
                }
                //bool successIK = bone.RequestIK(_boneSelectPosW, weight, !isFirstSelectBone);
                bool successIK = bone.RequestIK(_boneSelectPosW, weight, true);

                if (!successIK)
                {
                    return;
                }
                apBone headBone = bone._IKHeaderBone;
                if (headBone != null)
                {
                    apBone curBone = bone;
                    //위로 올라가면서 IK 결과값을 Default에 적용하자
                    while (true)
                    {
                        float deltaAngle = curBone._IKRequestAngleResult;
                        //if(Mathf.Abs(deltaAngle) > 30.0f)
                        //{
                        //	deltaAngle *= deltaAngle * 0.1f;
                        //}
                        float nextAngle = curBone._defaultMatrix._angleDeg + deltaAngle;

                        nextAngle = apUtil.AngleTo180(nextAngle);

                        curBone._defaultMatrix.SetRotate(nextAngle);

                        curBone._isIKCalculated       = false;
                        curBone._IKRequestAngleResult = 0.0f;

                        if (curBone == headBone)
                        {
                            break;
                        }
                        if (curBone._parentBone == null)
                        {
                            break;
                        }
                        curBone = curBone._parentBone;
                    }

                    //마지막으론 World Matrix 갱신
                    headBone.MakeWorldMatrix(true);
                    headBone.GUIUpdate(true);
                }
            }
            else if (bone._parentBone == null ||
                     (bone._parentBone._IKNextChainedBone != bone))
            {
                //수정 : Parent가 있지만 IK로 연결 안된 경우 / Parent가 없는 경우 2가지 모두 처리한다.

                apMatrix parentMatrix = null;
                if (bone._parentBone == null)
                {
                    if (bone._renderUnit != null)
                    {
                        //Render Unit의 World Matrix를 참조하여
                        //로컬 값을 Default로 적용하자
                        parentMatrix = bone._renderUnit.WorldMatrixWrap;
                    }
                }
                else
                {
                    parentMatrix = bone._parentBone._worldMatrix;
                }

                apMatrix localMatrix    = bone._localMatrix;
                apMatrix newWorldMatrix = new apMatrix(bone._worldMatrix);
                newWorldMatrix.SetPos(newWorldMatrix._pos + deltaMoveW);

                if (parentMatrix != null)
                {
                    newWorldMatrix.RInverse(parentMatrix);
                }
                newWorldMatrix.Subtract(localMatrix);                //이건 Add로 연산된거라 Subtract해야한다.

                bone._defaultMatrix.SetPos(newWorldMatrix._pos);


                bone.MakeWorldMatrix(true);
                bone.GUIUpdate(true);
            }
        }