コード例 #1
0
        private MD3Animation ExtractAnimation(String line)
        {
            String[] values  = line.Split(' ', '\t', '/');
            String[] strings = new String[5];
            int      index   = 0;

            foreach (String s in values)
            {
                if (s.Length != 0 && index < 5)
                {
                    strings[index++] = s;
                }
            }

            MD3Animation ani = new MD3Animation();

            ani.StartFrame      = int.Parse(strings[0]);
            ani.Count           = int.Parse(strings[1]);
            ani.LoopingFrames   = int.Parse(strings[2]);
            ani.FramesPerSecond = int.Parse(strings[3]);
            ani.Name            = strings[4];
            return(ani);
        }
コード例 #2
0
        /// <summary>
        /// Loads the the info for animations from a file.
        /// </summary>
        /// <param name="stream">Stream to load animations from.</param>
        /// <returns>Returns two AnimationPlayer objects.</returns>
        private AnimationPlayer[] LoadAnimations(Stream stream)
        {
            StreamReader reader = new StreamReader(stream);

            IList lowerAnimations = new ArrayList();
            IList upperAnimations = new ArrayList();

            int legOffset   = 0;
            int torsoOffset = 0;

            // Fill animations
            while (reader.Peek() != -1)
            {
                string line = reader.ReadLine();
                if (line.Length != 0 && char.IsDigit(line[0]))
                {
                    MD3Animation ani = ExtractAnimation(line);
                    if (ani.Name.StartsWith("BOTH"))
                    {
                        lowerAnimations.Add(ani);
                        upperAnimations.Add(ani);
                    }
                    else if (ani.Name.StartsWith("TORSO"))
                    {
                        if (torsoOffset == 0)
                        {
                            torsoOffset = ani.StartFrame;
                        }
                        upperAnimations.Add(ani);
                    }
                    else if (ani.Name.StartsWith("LEGS"))
                    {
                        if (legOffset == 0)
                        {
                            legOffset = ani.StartFrame;
                        }
                        ani.StartFrame = ani.StartFrame - legOffset + torsoOffset;
                        lowerAnimations.Add(ani);
                    }
                    else
                    {
                        System.Diagnostics.Debug.Write("MD3 Config file - invalid name: " + ani.Name);
                    }
                }
            }
            reader.Close();

            // create AnimationPlayers
            AnimationClip[] lowerClips = new AnimationClip[lowerAnimations.Count];
            AnimationClip[] upperClips = new AnimationClip[upperAnimations.Count];

            for (int i = 0; i < lowerClips.Length; i++)
            {
                MD3Animation ani = (MD3Animation)lowerAnimations[i];
                lowerClips[i] = new AnimationClip(ani.Name, ani.StartFrame, ani.StartFrame + ani.Count - 1,
                                                  (float)ani.Count / ani.FramesPerSecond, ani.LoopingFrames != 0);
            }

            for (int i = 0; i < upperClips.Length; i++)
            {
                MD3Animation ani = (MD3Animation)upperAnimations[i];
                upperClips[i] = new AnimationClip(ani.Name, ani.StartFrame, ani.StartFrame + ani.Count - 1,
                                                  (float)ani.Count / ani.FramesPerSecond, ani.LoopingFrames != 0);
            }
            return(new AnimationPlayer[] { new AnimationPlayer(lowerClips), new AnimationPlayer(upperClips) });
        }