예제 #1
0
        /// <summary>
        /// init data
        /// </summary>
        /// <param name="bvh">bone</param>
        /// <param name="content">content</param>
        public BVHNode(BVHNodeString bvh, BVHContent content, int ParentLevel)
        {
            #region Set fields value.
            this.Level = ++ParentLevel;
            this.Name  = StringProccesing.CleanUp(bvh.Name);
            this.Id    = content.Skeleton.BoneCount;
            #endregion

            content.Skeleton.BoneCount++;

            #region Calculate offset and channels.
            this.Offset = StringProccesing.StringToVector3(bvh.Offset.Replace("OFFSET", ""));

            this.Channels = StringToChannels(
                bvh.Channels.Remove(bvh.Channels.IndexOf("CHANNELS"),
                                    "CHANNELS".Length + 2));
            #endregion

            #region Add this bones channel to content channel collection.
            for (int i = 0; i < Channels.Length; i++)
            {
                Channels[i].pifl = content.Skeleton.BoneChannels.Count;
                content.Skeleton.BoneChannels.Add(Channels[i]);
            }
            #endregion

            #region Set EndsiteOffset if needed.
            if (bvh.EndSiteOffset != null)
            {
                EndSiteOffset = StringProccesing.StringToVector3(bvh.EndSiteOffset.Replace("OFFSET", ""));
            }
            #endregion

            #region Initialize children and add them from BVHNodeString.
            Children = new List <BVHNode>();

            for (int i = 0; i < bvh.Children.Count; i++)
            {
                Children.Add(new BVHNode(bvh.Children[i], content, Level));
            }
            #endregion

            #region If bone has children, set EndSiteOffset as Offset of first one.
            if (EndSiteOffset == null)
            {
                EndSiteOffset = Children[0].Offset;
            }
            #endregion
        }
예제 #2
0
        /// <summary>
        /// Load all data from bvh file.
        /// </summary>
        /// <param name="filecontent">bvh file content.</param>
        public BVHContentString(string filecontent, bool analizeRoot)
        {
            this.file = filecontent;

            if (analizeRoot)
            {
                int    start    = file.IndexOf("ROOT") + 5;
                string name     = file.Substring(start, file.IndexOf('{') - start);
                string brackets = file.Substring(file.IndexOf('{'),
                                                 StringProccesing.GetIndexOfClosing(file, file.IndexOf('{')) - file.IndexOf('{'));

                Root = new BVHNodeString(name, brackets);
            }

            string motion = file.Substring(file.IndexOf("MOTION"));

            int framesIndex    = motion.IndexOf("Frames");
            int frameTimeIndex = motion.IndexOf("Frame Time");

            FramesCount = motion.Substring(framesIndex + "Frames:".Length,
                                           frameTimeIndex - 1 - framesIndex - "Frames".Length);

            frameTimeIndex += "Frame Time: ".Length;

            int frameTimeEnd = frameTimeIndex;

            while (motion[frameTimeEnd] == '.' ||
                   char.IsNumber(motion[frameTimeEnd]))
            {
                frameTimeEnd++;
            }

            frameTimeEnd--;

            FrameTime = motion.Substring(frameTimeIndex,
                                         frameTimeEnd - frameTimeIndex);

            Frames = motion.Substring(
                frameTimeEnd + 1, motion.Length - frameTimeEnd - 1);
        }