예제 #1
0
        private static int MakeSubUnitsFromBonesRecursive(
            apBone targetBone,
            int startUnitID,
            List <apRetargetSubUnit> bones_All,
            List <apRetargetSubUnit> bones_Root,
            apRetargetSubUnit parentSubUnit
            )
        {
            apRetargetSubUnit newUnit = new apRetargetSubUnit();

            newUnit.SetSubData(startUnitID, null, null, targetBone, parentSubUnit);

            startUnitID++;
            bones_All.Add(newUnit);
            if (parentSubUnit == null)
            {
                bones_Root.Add(newUnit);
            }

            if (targetBone._childBones.Count > 0)
            {
                for (int i = 0; i < targetBone._childBones.Count; i++)
                {
                    startUnitID = MakeSubUnitsFromBonesRecursive(
                        targetBone._childBones[i],
                        startUnitID,
                        bones_All,
                        bones_Root,
                        newUnit
                        );
                }
            }

            return(startUnitID);
        }
예제 #2
0
        private static int MakeSubUnitsFromMeshGroupTransformRecursive(
            apMeshGroup rootMeshGroup,
            apTransform_MeshGroup meshGroupTransform,
            int startUnitID,
            List <apRetargetSubUnit> transforms_All,
            List <apRetargetSubUnit> transforms_Root,
            apRetargetSubUnit parentSubUnit
            )
        {
            //MeshGroup Transform을 추가한다.
            apRetargetSubUnit newGroupSubUnit = new apRetargetSubUnit();

            newGroupSubUnit.SetSubData(startUnitID, null, meshGroupTransform, null, parentSubUnit);

            transforms_All.Add(newGroupSubUnit);
            if (parentSubUnit == null)
            {
                transforms_Root.Add(newGroupSubUnit);
            }

            startUnitID++;

            if (meshGroupTransform._meshGroup != null && meshGroupTransform._meshGroup != rootMeshGroup)
            {
                if (meshGroupTransform._meshGroup._childMeshTransforms != null)
                {
                    for (int i = 0; i < meshGroupTransform._meshGroup._childMeshTransforms.Count; i++)
                    {
                        //MeshTransform을 추가한다.
                        apTransform_Mesh meshTransform = meshGroupTransform._meshGroup._childMeshTransforms[i];

                        apRetargetSubUnit newSubUnit = new apRetargetSubUnit();
                        newSubUnit.SetSubData(startUnitID, meshTransform, null, null, newGroupSubUnit);
                        startUnitID++;

                        transforms_All.Add(newSubUnit);
                    }
                }

                //하위에 다른 MeshGroup Transform이 있는 경우
                if (meshGroupTransform._meshGroup._childMeshGroupTransforms != null)
                {
                    //재귀 호출을 한다
                    for (int i = 0; i < meshGroupTransform._meshGroup._childMeshGroupTransforms.Count; i++)
                    {
                        apTransform_MeshGroup childMeshGroup = meshGroupTransform._meshGroup._childMeshGroupTransforms[i];

                        startUnitID = MakeSubUnitsFromMeshGroupTransformRecursive(
                            rootMeshGroup,
                            childMeshGroup,
                            startUnitID,
                            transforms_All,
                            transforms_Root,
                            newGroupSubUnit
                            );
                    }
                }
            }
            return(startUnitID);
        }
예제 #3
0
        public bool LoadAnimClip(string filePath)
        {
            FileStream   fs = null;
            StreamReader sr = null;

            Clear();

            try
            {
                fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                sr = new StreamReader(fs);

                sr.ReadLine();                //"---"
                sr.ReadLine();                //"Animation Clip"
                sr.ReadLine();                //"---"

                _animUniqueID          = int.Parse(sr.ReadLine());
                _animName              = sr.ReadLine();
                _FPS                   = int.Parse(sr.ReadLine());
                _startFrame            = int.Parse(sr.ReadLine());
                _endFrame              = int.Parse(sr.ReadLine());
                _isLoop                = int.Parse(sr.ReadLine()) == 1 ? true : false;
                _animTargetMeshGroupID = int.Parse(sr.ReadLine());
                _meshGroupName         = sr.ReadLine();

                sr.ReadLine();                //"---"
                sr.ReadLine();                //"SubTransforms"
                int nTransforms = int.Parse(sr.ReadLine());
                sr.ReadLine();                //"---"
                for (int i = 0; i < nTransforms; i++)
                {
                    apRetargetSubUnit transformUnit = new apRetargetSubUnit();
                    transformUnit.DecodeData(sr.ReadLine());
                    _transforms_Total.Add(transformUnit);                    //<<링크는 나중에
                }


                sr.ReadLine();                //"---"
                sr.ReadLine();                //"SubBones"
                int nBones = int.Parse(sr.ReadLine());
                sr.ReadLine();                //"---"
                for (int i = 0; i < nBones; i++)
                {
                    apRetargetSubUnit boneUnit = new apRetargetSubUnit();
                    boneUnit.DecodeData(sr.ReadLine());

                    _bones_Total.Add(boneUnit);
                }

                sr.ReadLine();                //"---"
                sr.ReadLine();                //"Animation Timelines"
                int nTimelines = int.Parse(sr.ReadLine());
                sr.ReadLine();                //"---"
                for (int i = 0; i < nTimelines; i++)
                {
                    apRetargetTimelineUnit timelineUnit = new apRetargetTimelineUnit();
                    bool parseResult = timelineUnit.DecodeData(sr);
                    if (!parseResult)
                    {
                        Debug.LogError("Parse Failed");
                    }

                    _timelineUnits.Add(timelineUnit);
                }


                sr.ReadLine();                //"---"
                sr.ReadLine();                //"Animation Event"
                int nEvnet = int.Parse(sr.ReadLine());
                sr.ReadLine();                //"---"
                for (int i = 0; i < nEvnet; i++)
                {
                    apRetargetAnimEvent animEvent = new apRetargetAnimEvent();
                    bool parseResult = animEvent.DecodeData(sr);
                    if (!parseResult)
                    {
                        Debug.LogError("Parse Failed");
                    }

                    _animEvents.Add(animEvent);
                }

                sr.ReadLine();                //"---"
                sr.ReadLine();                //"Controller Parameters"
                int nControllerParams = int.Parse(sr.ReadLine());
                sr.ReadLine();                //"---"
                for (int i = 0; i < nControllerParams; i++)
                {
                    apRetargetControlParam controlParam = new apRetargetControlParam();
                    bool parseResult = controlParam.DecodeData(sr.ReadLine());
                    if (!parseResult)
                    {
                        Debug.LogError("Parse Error");
                    }

                    _controlParams.Add(controlParam);
                }


                sr.Close();
                fs.Close();

                sr = null;
                fs = null;

                _isLoaded = true;
                _filePath = filePath;
            }
            catch (Exception ex)
            {
                Debug.LogError("LoadAnimClip Exception : " + ex);
                return(false);
            }
            return(true);
        }
예제 #4
0
        private static void MakeSubUnits(apMeshGroup targetMeshGroup,
                                         List <apRetargetSubUnit> transforms_All,
                                         List <apRetargetSubUnit> transforms_Root,
                                         List <apRetargetSubUnit> bones_All,
                                         List <apRetargetSubUnit> bones_Root)
        {
            int unitID = 0;


            if (targetMeshGroup._childMeshTransforms != null)
            {
                for (int i = 0; i < targetMeshGroup._childMeshTransforms.Count; i++)
                {
                    apTransform_Mesh meshTransform = targetMeshGroup._childMeshTransforms[i];

                    apRetargetSubUnit newSubUnit = new apRetargetSubUnit();
                    newSubUnit.SetSubData(unitID, meshTransform, null, null, null);
                    unitID++;

                    transforms_All.Add(newSubUnit);
                    transforms_Root.Add(newSubUnit);
                }
            }


            if (targetMeshGroup._childMeshGroupTransforms != null)
            {
                for (int i = 0; i < targetMeshGroup._childMeshGroupTransforms.Count; i++)
                {
                    apTransform_MeshGroup meshGroupTransform = targetMeshGroup._childMeshGroupTransforms[i];

                    //재귀 호출로 ChildMeshGroup의 SubUnit을 만들어주자
                    unitID = MakeSubUnitsFromMeshGroupTransformRecursive(targetMeshGroup, meshGroupTransform,
                                                                         unitID,
                                                                         transforms_All, transforms_Root,
                                                                         null);
                }
            }

            //Sort를 다시 하자
            for (int i = 0; i < transforms_All.Count; i++)
            {
                apRetargetSubUnit subUnit = transforms_All[i];
                int sortIndex             = -1;
                if (subUnit._type == apRetargetSubUnit.TYPE.MeshTransform)
                {
                    sortIndex = targetMeshGroup._renderUnits_All.FindIndex(delegate(apRenderUnit a)
                    {
                        if (a._meshTransform == null)
                        {
                            return(false);
                        }
                        return(a._meshTransform._transformUniqueID == subUnit._uniqueID);
                    });
                }
                else if (subUnit._type == apRetargetSubUnit.TYPE.MeshGroupTransform)
                {
                    sortIndex = targetMeshGroup._renderUnits_All.FindIndex(delegate(apRenderUnit a)
                    {
                        if (a._meshGroupTransform == null)
                        {
                            return(false);
                        }
                        return(a._meshGroupTransform._transformUniqueID == subUnit._uniqueID);
                    });
                }
                subUnit._sortIndex = sortIndex;
            }
            transforms_All.Sort(delegate(apRetargetSubUnit a, apRetargetSubUnit b)
            {
                return(b._sortIndex - a._sortIndex);
            });



            //Bone도 넣자
            //<BONE_EDIT>
            //if(targetMeshGroup._boneList_Root.Count > 0)
            //{
            //	for (int i = 0; i < targetMeshGroup._boneList_Root.Count; i++)
            //	{
            //		unitID = MakeSubUnitsFromBonesRecursive(targetMeshGroup,
            //												targetMeshGroup._boneList_Root[i],
            //												unitID, bones_All, bones_Root, null);
            //	}
            //}

            //>> Bone Set으로 변경
            if (targetMeshGroup._boneListSets.Count > 0)
            {
                apMeshGroup.BoneListSet boneSet = null;
                for (int iSet = 0; iSet < targetMeshGroup._boneListSets.Count; iSet++)
                {
                    boneSet = targetMeshGroup._boneListSets[iSet];
                    for (int iRoot = 0; iRoot < boneSet._bones_Root.Count; iRoot++)
                    {
                        unitID = MakeSubUnitsFromBonesRecursive(
                            boneSet._bones_Root[iRoot],
                            unitID, bones_All, bones_Root, null);
                    }
                }
            }


            //Sort를 다시 하자
            for (int i = 0; i < bones_All.Count; i++)
            {
                apRetargetSubUnit subUnit = bones_All[i];
                //<BONE_EDIT>

                //subUnit._sortIndex = targetMeshGroup._boneList_All.FindIndex(delegate (apBone a)
                //{
                //	return a._uniqueID == subUnit._uniqueID;
                //});

                //>>Bone Set을 이용
                subUnit._sortIndex = -1;

                apMeshGroup.BoneListSet boneSet = null;
                int startIndex = 0;
                for (int iSet = 0; iSet < targetMeshGroup._boneListSets.Count; iSet++)
                {
                    boneSet = targetMeshGroup._boneListSets[iSet];

                    //현재의 Bone List에 있는지 확인
                    int resultIndex = boneSet._bones_All.FindIndex(delegate(apBone a)
                    {
                        return(a._uniqueID == subUnit._uniqueID);
                    });

                    if (resultIndex >= 0 && resultIndex < boneSet._bones_All.Count)
                    {
                        //찾았다.
                        subUnit._sortIndex = startIndex + resultIndex;
                        break;
                    }
                    else
                    {
                        //업다면 기본 인덱스 증가
                        startIndex += boneSet._bones_All.Count;
                    }
                }
            }
            bones_All.Sort(delegate(apRetargetSubUnit a, apRetargetSubUnit b)
            {
                return(a._sortIndex - b._sortIndex);
            });
        }
        // Functions
        //----------------------------------------------
        // TF/Bone -> File
        //----------------------------------------------
        public void SetSubData(int unitID,
                               apTransform_Mesh meshTransform,
                               apTransform_MeshGroup meshGroupTransform,
                               apBone bone,
                               apRetargetSubUnit parentRetargetUnit)
        {
            _unitID = unitID;

            _parentUnitID = -1;
            _childUnitIDs.Clear();

            _parentUnit = null;
            _childUnits.Clear();

            if (meshTransform != null)
            {
                _type     = TYPE.MeshTransform;
                _uniqueID = meshTransform._transformUniqueID;

                _name = meshTransform._nickName;

                _defaultMatrix.SetMatrix(meshTransform._matrix);
                _defaultColor = meshTransform._meshColor2X_Default;
                _isVisible    = meshTransform._isVisible_Default;
            }
            else if (meshGroupTransform != null)
            {
                _type     = TYPE.MeshGroupTransform;
                _uniqueID = meshGroupTransform._transformUniqueID;

                _name = meshGroupTransform._nickName;

                _defaultMatrix.SetMatrix(meshGroupTransform._matrix);
                _defaultColor = meshGroupTransform._meshColor2X_Default;
                _isVisible    = meshGroupTransform._isVisible_Default;
            }
            else if (bone != null)
            {
                _type     = TYPE.Bone;
                _uniqueID = bone._uniqueID;

                _name = bone._name;

                _defaultMatrix.SetMatrix(bone._defaultMatrix);
                _defaultColor = Color.white;
                _isVisible    = true;
            }
            else
            {
                Debug.LogError("Wrong Sub Unit");
                return;
            }

            if (parentRetargetUnit != null)
            {
                //Parent와 연결한다.

                _parentUnitID = parentRetargetUnit._unitID;
                _parentUnit   = parentRetargetUnit;

                parentRetargetUnit._childUnitIDs.Add(_unitID);
                parentRetargetUnit._childUnits.Add(this);
            }
        }
예제 #6
0
        private static void MakeSubUnits(apMeshGroup targetMeshGroup,
                                         List <apRetargetSubUnit> transforms_All,
                                         List <apRetargetSubUnit> transforms_Root,
                                         List <apRetargetSubUnit> bones_All,
                                         List <apRetargetSubUnit> bones_Root)
        {
            int unitID = 0;


            if (targetMeshGroup._childMeshTransforms != null)
            {
                for (int i = 0; i < targetMeshGroup._childMeshTransforms.Count; i++)
                {
                    apTransform_Mesh meshTransform = targetMeshGroup._childMeshTransforms[i];

                    apRetargetSubUnit newSubUnit = new apRetargetSubUnit();
                    newSubUnit.SetSubData(unitID, meshTransform, null, null, null);
                    unitID++;

                    transforms_All.Add(newSubUnit);
                    transforms_Root.Add(newSubUnit);
                }
            }


            if (targetMeshGroup._childMeshGroupTransforms != null)
            {
                for (int i = 0; i < targetMeshGroup._childMeshGroupTransforms.Count; i++)
                {
                    apTransform_MeshGroup meshGroupTransform = targetMeshGroup._childMeshGroupTransforms[i];

                    //재귀 호출로 ChildMeshGroup의 SubUnit을 만들어주자
                    unitID = MakeSubUnitsFromMeshGroupTransformRecursive(targetMeshGroup, meshGroupTransform,
                                                                         unitID,
                                                                         transforms_All, transforms_Root,
                                                                         null);
                }
            }

            //Sort를 다시 하자
            for (int i = 0; i < transforms_All.Count; i++)
            {
                apRetargetSubUnit subUnit = transforms_All[i];
                int sortIndex             = -1;
                if (subUnit._type == apRetargetSubUnit.TYPE.MeshTransform)
                {
                    sortIndex = targetMeshGroup._renderUnits_All.FindIndex(delegate(apRenderUnit a)
                    {
                        if (a._meshTransform == null)
                        {
                            return(false);
                        }
                        return(a._meshTransform._transformUniqueID == subUnit._uniqueID);
                    });
                }
                else if (subUnit._type == apRetargetSubUnit.TYPE.MeshGroupTransform)
                {
                    sortIndex = targetMeshGroup._renderUnits_All.FindIndex(delegate(apRenderUnit a)
                    {
                        if (a._meshGroupTransform == null)
                        {
                            return(false);
                        }
                        return(a._meshGroupTransform._transformUniqueID == subUnit._uniqueID);
                    });
                }
                subUnit._sortIndex = sortIndex;
            }
            transforms_All.Sort(delegate(apRetargetSubUnit a, apRetargetSubUnit b)
            {
                return(b._sortIndex - a._sortIndex);
            });



            //Bone도 넣자
            if (targetMeshGroup._boneList_Root.Count > 0)
            {
                for (int i = 0; i < targetMeshGroup._boneList_Root.Count; i++)
                {
                    unitID = MakeSubUnitsFromBonesRecursive(targetMeshGroup,
                                                            targetMeshGroup._boneList_Root[i],
                                                            unitID, bones_All, bones_Root, null);
                }
            }

            //Sort를 다시 하자
            for (int i = 0; i < bones_All.Count; i++)
            {
                apRetargetSubUnit subUnit = bones_All[i];
                subUnit._sortIndex = targetMeshGroup._boneList_All.FindIndex(delegate(apBone a)
                {
                    return(a._uniqueID == subUnit._uniqueID);
                });
            }
            bones_All.Sort(delegate(apRetargetSubUnit a, apRetargetSubUnit b)
            {
                return(a._sortIndex - b._sortIndex);
            });
        }