示例#1
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);
        }
示例#2
0
        // Functions
        //-----------------------------------------------
        public static bool SaveAnimFile(apAnimClip animClip, string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return(false);
            }
            if (animClip == null ||
                animClip._targetMeshGroup == null)
            {
                return(false);
            }

            //데이터를 넣자

            int    animUniqueID = animClip._uniqueID;
            string animName     = animClip._name;

            int  FPS        = animClip.FPS;
            int  startFrame = animClip.StartFrame;
            int  endFrame   = animClip.EndFrame;
            bool isLoop     = animClip.IsLoop;

            List <apRetargetTimelineUnit> timelineUnits = new List <apRetargetTimelineUnit>();

            int         animTargetMeshGroupID = animClip._targetMeshGroup._uniqueID;
            apMeshGroup targetMeshGroup       = animClip._targetMeshGroup;
            string      meshGroupName         = animClip._targetMeshGroup._name;

            //1. Timeline을 설정하자
            int curTimelineUnitID = 0;

            for (int i = 0; i < animClip._timelines.Count; i++)
            {
                apRetargetTimelineUnit timelineUnit = new apRetargetTimelineUnit();
                timelineUnit.SetTimeline(curTimelineUnitID, animClip._timelines[i]);

                timelineUnits.Add(timelineUnit);
                curTimelineUnitID++;
            }


            //2. Transform/Bone 을 설정
            List <apRetargetSubUnit> transforms_All  = new List <apRetargetSubUnit>();
            List <apRetargetSubUnit> bones_All       = new List <apRetargetSubUnit>();
            List <apRetargetSubUnit> transforms_Root = new List <apRetargetSubUnit>();
            List <apRetargetSubUnit> bones_Root      = new List <apRetargetSubUnit>();

            MakeSubUnits(targetMeshGroup, transforms_All, transforms_Root, bones_All, bones_Root);

            //2-2. AnimEvent 설정
            List <apRetargetAnimEvent> animEvents = new List <apRetargetAnimEvent>();

            if (animClip._animEvents.Count > 0)
            {
                for (int i = 0; i < animClip._animEvents.Count; i++)
                {
                    apRetargetAnimEvent newEvent = new apRetargetAnimEvent();
                    newEvent.SetAnimationEvent(animClip._animEvents[i]);

                    animEvents.Add(newEvent);
                }
            }

            //3. Control Param 설정
            List <apRetargetControlParam> controlParams = new List <apRetargetControlParam>();
            int nControlParams       = targetMeshGroup._parentPortrait._controller._controlParams.Count;
            int curContolParamUnitID = 0;

            for (int i = 0; i < nControlParams; i++)
            {
                apControlParam         controlParam = targetMeshGroup._parentPortrait._controller._controlParams[i];
                apRetargetControlParam cpUnit       = new apRetargetControlParam();
                cpUnit.SetControlParam(curContolParamUnitID, controlParam);

                curContolParamUnitID++;

                controlParams.Add(cpUnit);
            }


            FileStream   fs = null;
            StreamWriter sw = null;

            try
            {
                fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
                sw = new StreamWriter(fs);

                sw.WriteLine("-----------------------------------------------------------------------------------");
                sw.WriteLine("Animation Clip");
                sw.WriteLine("-----------------------------------------------------------------------------------");
                sw.WriteLine(animUniqueID);
                sw.WriteLine(animName);
                sw.WriteLine(FPS);
                sw.WriteLine(startFrame);
                sw.WriteLine(endFrame);
                sw.WriteLine((isLoop ? "1" : "0"));
                sw.WriteLine(animTargetMeshGroupID);
                sw.WriteLine(meshGroupName);

                sw.WriteLine("-----------------------------------------------------------------------------------");
                sw.WriteLine("SubTransforms");
                sw.WriteLine(transforms_All.Count);
                sw.WriteLine("-----------------------------------------------------------------------------------");
                for (int i = 0; i < transforms_All.Count; i++)
                {
                    sw.WriteLine(transforms_All[i].GetEncodingData());
                }

                sw.WriteLine("-----------------------------------------------------------------------------------");
                sw.WriteLine("SubBones");
                sw.WriteLine(bones_All.Count);
                sw.WriteLine("-----------------------------------------------------------------------------------");
                for (int i = 0; i < bones_All.Count; i++)
                {
                    sw.WriteLine(bones_All[i].GetEncodingData());
                }

                sw.WriteLine("-----------------------------------------------------------------------------------");
                sw.WriteLine("Animation Timelines");
                sw.WriteLine(timelineUnits.Count);
                sw.WriteLine("-----------------------------------------------------------------------------------");
                for (int i = 0; i < timelineUnits.Count; i++)
                {
                    timelineUnits[i].EncodeToFile(sw);
                }

                sw.WriteLine("-----------------------------------------------------------------------------------");
                sw.WriteLine("Animation Events");
                sw.WriteLine(animEvents.Count);
                sw.WriteLine("-----------------------------------------------------------------------------------");
                if (animEvents.Count > 0)
                {
                    for (int i = 0; i < animEvents.Count; i++)
                    {
                        animEvents[i].EncodeToFile(sw);
                    }
                }

                sw.WriteLine("-----------------------------------------------------------------------------------");
                sw.WriteLine(" Controller Parameters ");
                sw.WriteLine(controlParams.Count);
                sw.WriteLine("-----------------------------------------------------------------------------------");
                if (controlParams.Count > 0)
                {
                    for (int i = 0; i < controlParams.Count; i++)
                    {
                        sw.WriteLine(controlParams[i].GetEncodingData());
                    }
                }

                sw.Flush();
                sw.Close();
                fs.Close();
                sw = null;
                fs = null;
            }
            catch (Exception ex)
            {
                Debug.LogError("SaveAnimFile Exception : " + ex);

                if (sw != null)
                {
                    sw.Close();
                    sw = null;
                }

                if (fs != null)
                {
                    fs.Close();
                    fs = null;
                }

                return(false);
            }

            return(true);
        }