Esempio n. 1
0
        // double[] filecontent = new double[102400]; //很大的缓存区,用来存储待显示的帧数据
        public void Load(string bvh_file_name)
        {
            try
            {
                FileStream fs = new FileStream(bvh_file_name, FileMode.Open);
                StreamReader sr = new StreamReader(fs, Encoding.ASCII);

                char[] line = new char[4096];//
                string token;
                //string separater = " :,\t";

                List<Joint> joint_stack = new List<Joint>();
                Joint joint = null;
                Joint new_joint = new Joint();
                bool is_site = false;
                double x, y, z;
                int i, j;
                //Clear();// 第一次不用清理
                m_file_name = bvh_file_name;//这一段 是解析文件路径名的。最后计算出的是  text.bvh
                //const char *  mn_first = bvh_file_name;
                //const char *  mn_last = bvh_file_name + strlen( bvh_file_name );
                //if ( strrchr( bvh_file_name, '\\' ) != NULL )
                //    mn_first = strrchr( bvh_file_name, '\\' ) + 1;
                //else if ( strrchr( bvh_file_name, '/' ) != NULL )
                //    mn_first = strrchr( bvh_file_name, '/' ) + 1;
                //if ( strrchr( bvh_file_name, '.' ) != NULL )
                //    mn_last = strrchr( bvh_file_name, '.' );
                //if ( mn_last < mn_first )
                //    mn_last = bvh_file_name + strlen( bvh_file_name );
                //motion_name.assign( mn_first, mn_last );

                //file.open( bvh_file_name, ios::in );
                //byte[] filecontentEXXXX = new byte[102400]; //很大的缓存区,用来存储待显示的帧数据
                //srr.Read(filecontentEXXXX, 0, (int)file.Length);
                if (!fs.CanRead)
                {
                    return;
                }

                while (!sr.EndOfStream)
                {
                    token = sr.ReadLine();

                    Tokens f = new Tokens(token, new char[] { ' ' });

                    if (f.GetFirstNotEmptyString().Equals("{"))
                    {
                        joint_stack.Add(joint);
                        joint = new_joint;
                        continue;
                    }
                    if (f.GetFirstNotEmptyString().Equals("}"))
                    {
                        int lastindex = joint_stack.Count - 1;
                        joint = joint_stack[lastindex];
                        joint_stack.RemoveAt(lastindex);
                        is_site = false;
                        continue;
                    }

                    if ((f.GetFirstNotEmptyString().Equals("ROOT")) || (f.GetFirstNotEmptyString().Equals("JOINT")))
                    {
                        new_joint = new Joint();
                        new_joint.index = m_joints.Count;
                        new_joint.parent = joint;
                        new_joint.has_site = false;

                        new_joint.offset[0] = 0.0;
                        new_joint.offset[1] = 0.0;
                        new_joint.offset[2] = 0.0;

                        new_joint.site[0] = 0.0;
                        new_joint.site[1] = 0.0;
                        new_joint.site[2] = 0.0;

                        m_joints.Add(new_joint);
                        if (joint != null)
                            joint.children.Add(new_joint);

                        f.position++;
                        token = f.elements[f.position];

                        while (token.Equals(string.Empty))
                        {
                            f.position++;
                            token = f.elements[f.position];

                        }
                        if (token != string.Empty)
                        {
                            new_joint.name = token;
                        }
                        m_joint_index[new_joint.name] = new_joint;
                        continue;
                    }

                    if (f.GetFirstNotEmptyString().Equals("End"))
                    {
                        new_joint = joint;
                        is_site = true;
                        continue;
                    }

                    if (f.GetFirstNotEmptyString().Equals("OFFSET"))
                    {
                        f.position++;
                        token = f.elements[f.position++];

                        if (token != string.Empty)
                        {
                            x = double.Parse(token);
                        }
                        else
                        {
                            x = 0.0;
                        }
                        token = f.elements[f.position++];
                        if (token != string.Empty)
                        {
                            y = double.Parse(token);
                        }
                        else
                        {
                            y = 0.0;
                        }
                        token = f.elements[f.position];
                        if (token != string.Empty)
                        {
                            z = double.Parse(token);
                        }
                        else
                        {
                            z = 0.0;
                        }

                        if (is_site)
                        {
                            joint.has_site = true;
                            joint.site[0] = x;
                            joint.site[1] = y;
                            joint.site[2] = z;
                        }
                        else
                        {
                            joint.offset[0] = x;
                            joint.offset[1] = y;
                            joint.offset[2] = z;
                        }
                        continue;
                    }

                    if (f.GetFirstNotEmptyString().Equals("CHANNELS"))
                    {
                        f.position++;
                        token = f.elements[f.position++];

                        int joint_channels_size = int.Parse(token);

                        for (i = 0; i < joint_channels_size; i++)
                        {
                            Channel channel = new Channel();
                            channel.joint = joint;
                            channel.index = m_channels.Count;
                            m_channels.Add(channel);
                            joint.channelstmp.Add(channel);
                            token = f.elements[f.position++];
                            if (token.Equals("Xrotation"))
                                channel.type = ChannelEnum.X_ROTATION;
                            else if (token.Equals("Yrotation"))
                                channel.type = ChannelEnum.Y_ROTATION;
                            else if (token.Equals("Zrotation"))
                                channel.type = ChannelEnum.Z_ROTATION;
                            else if (token.Equals("Xposition"))
                                channel.type = ChannelEnum.X_POSITION;
                            else if (token.Equals("Yposition"))
                                channel.type = ChannelEnum.Y_POSITION;
                            else if (token.Equals("Zposition"))
                                channel.type = ChannelEnum.Z_POSITION;
                        }
                    }

                    if (f.GetFirstNotEmptyString().Equals("MOTION"))
                        break;

                }

                m_is_load_success = true;

                //获取帧数据
                //C# 读取每一帧的数据
                //token = sr.ReadLine();
                //Tokens ff = new Tokens(token, new char[] { ' ' });

                //if (ff.GetFirstNotEmptyString().Equals("Frames"))
                //{
                //    ff.position++;
                //    token = ff.elements[ff.position];
                //    m_num_frame = int.Parse(token);

                //    token = sr.ReadLine();
                //    Tokens fff = new Tokens(token, new char[] { ' ' });

                //    if (fff.GetFirstNotEmptyString().Equals("FrameTime"))
                //    {
                //        fff.position++;
                //        token = fff.elements[fff.position];
                //        m_interval = float.Parse(token);

                //        m_num_channel = m_channels.Count;
                //        //m_motion = new double[m_num_frame*];
                //        //filecontent
                //        m_m_motion = new double[m_num_channel * m_num_frame];

                //        for (i = 0; i < m_num_frame; i++)
                //        {
                //            //file.getline(line, BUFFER_LENGTH);
                //            //token = strtok(line, separater);

                //            //

                //            token = sr.ReadLine();
                //            Tokens fffff = new Tokens(token, new char[] { ' ', '\t', '|' });

                //            for (j = 0; j < m_num_channel; j++)
                //            {
                //                token = fffff.elements[fffff.position];
                //                while (token == string.Empty)
                //                {
                //                    fffff.position++;
                //                    token = fffff.elements[fffff.position];
                //                }

                //                m_m_motion[i * m_num_channel + j] = double.Parse(token);
                //                fffff.position++;
                //            }
                //        }

                //        sr.Close();
                //        fs.Close();
                //        m_is_load_success = true;
                //    }
                //}

            }
            catch (System.IO.FileNotFoundException ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show("逗比,没找到文件!");
                return;
            }
        }
Esempio n. 2
0
        public static void LoadRawFile(string raw_file_name)
        {
            //获取帧数据
            //C# 读取每一帧的数据
            FileStream fs = new FileStream(Application.StartupPath + "\\MotionFiles\\" + raw_file_name, FileMode.Open);
            StreamReader sr = new StreamReader(fs, Encoding.ASCII);

            string token = null;

            token = sr.ReadLine();
            Tokens ff = new Tokens(token, new char[] { ' ' });

            if (ff.GetFirstNotEmptyString().Equals("Frames"))
            {
                ff.position++;
                token = ff.elements[ff.position];
                m_num_frame = int.Parse(token);

                Global.frame_totalnum = m_num_frame;

                token = sr.ReadLine();
                Tokens fff = new Tokens(token, new char[] { ' ' });

                if (fff.GetFirstNotEmptyString().Equals("FrameTime"))
                {
                    //不要时间间隔这个值

                    //fff.position++;
                    //token = fff.elements[fff.position];
                    //m_interval = float.Parse(token);

                    m_num_channel = 66;//  m_channels.Count;  //ysj 暂定66了
                    m_m_motion = new double[m_num_channel * m_num_frame]; // m_num_frame这个值 需要从文件中读取出来,每次记录文件的时候,都需要在最后添加这样一个标记

                    for (int i = 0; i < m_num_frame; i++)
                    {
                        //file.getline(line, BUFFER_LENGTH);
                        //token = strtok(line, separater);

                        token = sr.ReadLine();
                        Tokens fffff = new Tokens(token, new char[] { ' ', '\t', '|' });

                        for (int j = 0; j < m_num_channel; j++)
                        {
                            token = fffff.elements[fffff.position];
                            while (token == string.Empty)
                            {
                                fffff.position++;
                                token = fffff.elements[fffff.position];
                            }

                            m_m_motion[i * m_num_channel + j] = double.Parse(token);
                            fffff.position++;
                        }
                    }

                    sr.Close();
                    fs.Close();
                    //m_is_load_success = true;
                }
            }
        }
Esempio n. 3
0
        public void LiveRenderFigure(string data, float scale)
        {
            //首先解析一帧数据
            if (data == null)
            {
                return;
            }
            string token = null;
            Tokens tmpff = new Tokens(data, new char[] { ' ', '\t', '|' });

            double[] tmpData = new double[66];
            for (int i = 0; i < 66; i++)
            {
                token = tmpff.elements[tmpff.position];
                while (token == string.Empty)
                {
                    tmpff.position++;
                    token = tmpff.elements[tmpff.position];
                }
                tmpData[i] = double.Parse(token);
                tmpff.position++;
            }

            RenderFigure(m_joints[0], tmpData, scale);
        }