예제 #1
0
        //Link 함수의 내용은 Bake 시에 진행해야한다.
        public void Bake(apBone bone)
        {
            _uniqueID    = bone._uniqueID;
            _meshGroupID = bone._meshGroupID;
            _defaultMatrix.SetMatrix(bone._defaultMatrix);


            _deltaPos   = Vector2.zero;
            _deltaAngle = 0.0f;
            _deltaScale = Vector2.one;

            _localMatrix.SetIdentity();

            _worldMatrix.SetIdentity();

            _color       = bone._color;
            _shapeWidth  = bone._shapeWidth;
            _shapeLength = bone._shapeLength;
            _shapeTaper  = bone._shapeTaper;

            _optionLocalMove = bone._optionLocalMove;
            _optionIK        = bone._optionIK;

            _isIKTail = bone._isIKTail;

            _IKTargetBoneID = bone._IKTargetBoneID;
            _IKTargetBone   = null;          //<<나중에 링크

            _IKNextChainedBoneID = bone._IKNextChainedBoneID;
            _IKNextChainedBone   = null;          //<<나중에 링크


            _IKHeaderBoneID = bone._IKHeaderBoneID;
            _IKHeaderBone   = null;          //<<나중에 링크


            _isIKAngleRange     = bone._isIKAngleRange;
            _IKAngleRange_Lower = bone._IKAngleRange_Lower;
            _IKAngleRange_Upper = bone._IKAngleRange_Upper;
            _IKAnglePreferred   = bone._IKAnglePreferred;


            _isIKCalculated       = false;
            _IKRequestAngleResult = 0.0f;



            _transformLocalMatrix.SetIdentity();
        }
예제 #2
0
        // Functions
        //---------------------------------------------------
        // Bone to File
        //---------------------------------------------------
        public void SetBone(int unitID, apBone bone, Dictionary <int, int> boneID2UnitIDs)
        {
            _unitID = unitID;

            _boneUniqueID = bone._uniqueID;
            _linkedBone   = bone;


            _name = bone._name;

            if (bone._parentBoneID < 0)
            {
                _parentUnitID = -1;
            }
            else
            {
                _parentUnitID = boneID2UnitIDs[bone._parentBoneID];
            }

            _level = bone._level;
            _depth = bone._depth;
            _childUnitID.Clear();
            if (bone._childBoneIDs != null)
            {
                for (int i = 0; i < bone._childBoneIDs.Count; i++)
                {
                    int childID = bone._childBoneIDs[i];
                    if (childID >= 0)
                    {
                        _childUnitID.Add(boneID2UnitIDs[childID]);
                    }
                }
            }

            _defaultMatrix.SetMatrix(bone._defaultMatrix);

            _color       = bone._color;
            _shapeWidth  = bone._shapeWidth;
            _shapeLength = bone._shapeLength;
            _shapeTaper  = bone._shapeTaper;

            _optionIK = bone._optionIK;

            _isIKTail = bone._isIKTail;

            _IKTargetBoneUnitID = -1;
            if (bone._IKTargetBoneID >= 0)
            {
                _IKTargetBoneUnitID = boneID2UnitIDs[bone._IKTargetBoneID];
            }

            _IKNextChainedBoneUnitID = -1;
            if (bone._IKNextChainedBoneID >= 0)
            {
                _IKNextChainedBoneUnitID = boneID2UnitIDs[bone._IKNextChainedBoneID];
            }
            _IKHeaderBoneUnitID = -1;
            if (bone._IKHeaderBoneID >= 0)
            {
                _IKHeaderBoneUnitID = boneID2UnitIDs[bone._IKHeaderBoneID];
            }

            _isIKAngleRange     = bone._isIKAngleRange;
            _IKAngleRange_Lower = bone._IKAngleRange_Lower;
            _IKAngleRange_Upper = bone._IKAngleRange_Upper;
            _IKAnglePreferred   = bone._IKAnglePreferred;
            _isSocketEnabled    = false;
        }
        //Link 함수의 내용은 Bake 시에 진행해야한다.
        /// <summary>
        /// [Please do not use it]
        /// </summary>
        /// <param name="bone"></param>
        public void Bake(apBone bone)
        {
            _name        = bone._name;
            _uniqueID    = bone._uniqueID;
            _meshGroupID = bone._meshGroupID;
            _defaultMatrix.SetMatrix(bone._defaultMatrix);


            _deltaPos   = Vector2.zero;
            _deltaAngle = 0.0f;
            _deltaScale = Vector2.one;

            _localMatrix.SetIdentity();

            _worldMatrix.SetIdentity();

            _worldMatrix_NonModified.SetIdentity();
            _vertWorld2BoneModWorldMatrix.SetIdentity();

            _color       = bone._color;
            _shapeWidth  = bone._shapeWidth;
            _shapeLength = bone._shapeLength;
            _shapeTaper  = bone._shapeTaper;

            _optionLocalMove = bone._optionLocalMove;
            _optionIK        = bone._optionIK;

            _isIKTail = bone._isIKTail;

            _IKTargetBoneID = bone._IKTargetBoneID;
            _IKTargetBone   = null;          //<<나중에 링크

            _IKNextChainedBoneID = bone._IKNextChainedBoneID;
            _IKNextChainedBone   = null;          //<<나중에 링크


            _IKHeaderBoneID = bone._IKHeaderBoneID;
            _IKHeaderBone   = null;          //<<나중에 링크


            _isIKAngleRange = bone._isIKAngleRange;
            //이게 기존 코드
            //_IKAngleRange_Lower = bone._IKAngleRange_Lower;
            //_IKAngleRange_Upper = bone._IKAngleRange_Upper;
            //_IKAnglePreferred = bone._IKAnglePreferred;

            //이게 변경된 IK 코드
            _IKAngleRange_Lower = bone._defaultMatrix._angleDeg + bone._IKAngleRange_Lower;
            _IKAngleRange_Upper = bone._defaultMatrix._angleDeg + bone._IKAngleRange_Upper;
            _IKAnglePreferred   = bone._defaultMatrix._angleDeg + bone._IKAnglePreferred;


            _isIKCalculated       = false;
            _IKRequestAngleResult = 0.0f;
            _IKRequestWeight      = 0.0f;

            _socketTransform = null;

            _transformLocalMatrix.SetIdentity();

            _childBones = null;

            _isIKChainInit = false;
        }
예제 #4
0
        // File To Bone
        //---------------------------------------------------
        public bool DecodeData(string strSrc)
        {
            try
            {
                if (strSrc.Length < 3)
                {
                    return(false);
                }
                int nName = int.Parse(strSrc.Substring(0, 3));
                _name = strSrc.Substring(3, nName);

                strSrc = strSrc.Substring(3 + nName);

                //나머지는 델리미터를 이용한다.
                string[] strUnits = strSrc.Split(new string[] { "/" }, StringSplitOptions.None);
                int      iStr     = 0;
                _unitID = int.Parse(strUnits[iStr]);
                iStr++;

                _parentUnitID = int.Parse(strUnits[iStr]);
                iStr++;

                _level = int.Parse(strUnits[iStr]);
                iStr++;

                _depth = int.Parse(strUnits[iStr]);
                iStr++;

                _childUnitID.Clear();
                int nChild = int.Parse(strUnits[iStr]);
                iStr++;

                for (int i = 0; i < nChild; i++)
                {
                    _childUnitID.Add(int.Parse(strUnits[iStr]));
                    iStr++;
                }

                _defaultMatrix.SetIdentity();
                _defaultMatrix.SetTRS(
                    new Vector2(float.Parse(strUnits[iStr]), float.Parse(strUnits[iStr + 1])),
                    float.Parse(strUnits[iStr + 2]),
                    new Vector2(float.Parse(strUnits[iStr + 3]), float.Parse(strUnits[iStr + 4]))
                    );

                iStr += 5;

                _color.r = float.Parse(strUnits[iStr]);
                _color.g = float.Parse(strUnits[iStr + 1]);
                _color.b = float.Parse(strUnits[iStr + 2]);
                _color.a = float.Parse(strUnits[iStr + 3]);
                iStr    += 4;

                _shapeWidth  = int.Parse(strUnits[iStr]);
                _shapeLength = int.Parse(strUnits[iStr + 1]);
                _shapeTaper  = int.Parse(strUnits[iStr + 2]);
                iStr        += 3;

                _optionIK = (apBone.OPTION_IK) int.Parse(strUnits[iStr]);
                _isIKTail = (int.Parse(strUnits[iStr + 1]) == 1) ? true : false;
                iStr     += 2;

                _IKTargetBoneUnitID      = int.Parse(strUnits[iStr]);
                _IKNextChainedBoneUnitID = int.Parse(strUnits[iStr + 1]);
                _IKHeaderBoneUnitID      = int.Parse(strUnits[iStr + 2]);
                iStr += 3;

                _isIKAngleRange     = (int.Parse(strUnits[iStr]) == 1) ? true : false;
                _IKAngleRange_Lower = float.Parse(strUnits[iStr + 1]);
                _IKAngleRange_Upper = float.Parse(strUnits[iStr + 2]);
                _IKAnglePreferred   = float.Parse(strUnits[iStr + 3]);
                iStr += 4;

                _isSocketEnabled = (int.Parse(strUnits[iStr]) == 1) ? true : false;

                _isImportEnabled = true;
                _isIKEnabled     = true;
                _isShapeEnabled  = true;
            }
            catch (Exception ex)
            {
                Debug.LogError("Decode Exception : " + ex);
                return(false);
            }


            return(true);
        }