// Drop Down 相關
    public void SelectDropDownList(int index)
    {
        LastSelectIndex = index;
        ShowSelectIndexPeople(index);

        BVHPeople people = reader.People[index].GetComponent <BVHPeople>();

        UnityChan.GetDefaultData(people.MotionStringList.ToArray());
        Menu.value = index;
    }
    private void ParseByMotionData(string [] data, int index)
    {
        BVHPeople tempPeople = People[index].GetComponent <BVHPeople>();

        for (int i = 0; i < data.Length; i++)
        {
            if (data[i].StartsWith("MOTION"))
            {
                continue;
            }
            else if (data[i].StartsWith("Frames:"))
            {
                continue;
            }
            else if (data[i].StartsWith("Frame Time:"))
            {
                data[i] = data[i].Replace("\t", " ");
                string[] info = data[i].Split(' ');
                info = ParseAllUselessItems(info);

                tempPeople.framePerSec = float.Parse(info[info.Length - 1]);
            }
            else
            {
                data[i] = data[i].Replace("\t", " ");
                string[] info = data[i].Split(' ');
                info = ParseAllUselessItems(info);

                // 怕有東西雷
                if (info.Length <= 1)
                {
                    break;
                }

                List <float> motionData = new List <float>();
                for (int j = 0; j < info.Length; j++)
                {
                    float listData = float.Parse(info[j]);
                    motionData.Add(listData);
                }
                tempPeople.MotionData.Add(motionData);
            }
        }
    }
Esempio n. 3
0
    public void UpdateMotionPos(GameObject people)
    {
        int       CurrentIndex = 0;
        BVHPeople bvhPeople    = people.GetComponent <BVHPeople>();

        GameObject[] joints = bvhPeople.Joints.ToArray();

        for (int i = 0; i < joints.Length; i++)
        {
            Transform TempBonesTran = SearchHumanBoneTransformByName(joints[i].name);
            if (TempBonesTran == null)
            {
                continue;
            }

            // 把 Motion 套上去
            Quaternion org = new Quaternion(MotionPos[CurrentIndex * 4],
                                            MotionPos[CurrentIndex * 4 + 1],
                                            MotionPos[CurrentIndex * 4 + 2],
                                            MotionPos[CurrentIndex * 4 + 3]);

            Joints[CurrentIndex++].transform.rotation = joints[i].transform.rotation * org;
        }

        // 位移
        Vector3 pos = joints[0].transform.localPosition;

        pos.x /= bvhPeople.InitMotionHeight;
        pos.y /= bvhPeople.InitMotionHeight;
        pos.z /= bvhPeople.InitMotionHeight;

        if (!IsSetOffsetY && pos != Vector3.zero)
        {
            OffsetY      = pos.y;
            IsSetOffsetY = true;
        }


        pos.y -= OffsetY;
        this.transform.localPosition = pos;
    }
    private void ParseByBodyData(string [] data, int index, string FilePath)
    {
        #region 創一個新的 People
        string     tempName   = "";
        GameObject tempPeople = new GameObject();
        BVHPeople  script     = tempPeople.AddComponent <BVHPeople>();

        string[] FilePathList = FilePath.Split('/');
        tempPeople.name = "People " + index + " " + FilePathList[FilePathList.Length - 1];
        #endregion
        #region Parse 出高度
        float TempHeight = 0;
        for (int i = 0; i < data.Length; i++)
        {
            if (data[i] == "HIERARCHY")
            {
                continue;
            }
            #region Root & Joint & End Site
            else if (data[i].Contains("ROOT") || data[i].Contains("JOINT"))
            {
                string[] name = data[i].Split(' ');
                name     = ParseAllUselessItems(name);
                tempName = name[1];
            }
            else if (data[i].Contains("End Site"))
            {
                continue;
            }
            #endregion
            #region 讀到 上括號 下括號
            else if (data[i].Contains("{"))
            {
                continue;
            }
            else if (data[i].Contains("}"))
            {
                continue;
            }
            #endregion
            #region 跟物體 Info 有關係
            else if (data[i].Contains("OFFSET"))
            {
                data[i] = data[i].Replace("\t", " ");
                string[] info = data[i].Split(' ');
                info = ParseAllUselessItems(info);

                #region Hip 以上是 Top,以 Hip 以下是 Buttom
                switch (tempName)
                {
                case "LeftHip":
                case "LeftKnee":
                case "LeftAnkle":
                    TempHeight -= float.Parse(info[2]);
                    break;

                case "Chest":
                case "LeftCollar":
                case "LeftShoulder":
                case "Neck":
                case "Head":
                    TempHeight += float.Parse(info[2]);
                    break;
                }
                #endregion
            }
            else if (data[i].Contains("CHANNELS"))
            {
                continue;
            }
            #endregion
        }
        #endregion
        #region Parse 資料
        GameObject tempJoint = null;
        Transform  p         = null;

        for (int i = 0; i < data.Length; i++)
        {
            if (data[i] == "HIERARCHY")
            {
                continue;
            }
            #region Root & Joint & End Site
            else if (data[i].Contains("ROOT") || data[i].Contains("JOINT"))
            {
                string[] name = data[i].Split(' ');
                name     = ParseAllUselessItems(name);
                tempName = name[1];

                tempJoint = new GameObject();//  GameObject.Instantiate(Joint);

                // 將資料丟進去
                script.Joints.Add(tempJoint);
            }
            else if (data[i].Contains("End Site"))
            {
                string[] info = tempJoint.transform.parent.name.Split(' ');

                tempName  = info[0] + " End";
                tempJoint = new GameObject();//GameObject.Instantiate(Joint);

                script.Joints.Add(tempJoint);
            }
            #endregion
            #region 讀到 上括號 下括號
            else if (data[i].Contains("{"))
            {
                if (p == null)
                {
                    p = tempPeople.transform;
                }
                else
                {
                    p = p.GetChild(p.childCount - 1);
                }
            }
            else if (data[i].Contains("}"))
            {
                p = p.parent;
            }
            #endregion
            #region 跟物體 Info 有關係
            else if (data[i].Contains("OFFSET"))
            {
                data[i] = data[i].Replace("\t", " ");
                string[] info = data[i].Split(' ');
                info = ParseAllUselessItems(info);

                tempJoint.transform.SetParent(p);
                tempJoint.name = tempName;

                float x = float.Parse(info[info.Length - 3]);
                float y = float.Parse(info[info.Length - 2]);
                float z = float.Parse(info[info.Length - 1]);

                tempJoint.transform.localPosition = new Vector3(x, y, z);

                if (tempJoint.transform.parent.name.Contains("People"))
                {
                    continue;
                }
                #region 加上 Line Render 把線畫出來
                LineRenderer line = tempJoint.AddComponent <LineRenderer>();
                line.positionCount = 2;
                line.useWorldSpace = true;

                if (IsUnityChan)
                {
                    line.startWidth = 0.01f;
                    line.endWidth   = 0.05f;
                }
                else
                {
                    line.startWidth = 0.1f;
                    line.endWidth   = 1;
                }

                script.Bones.Add(line);
                #endregion
                #region 先把連接的資料連起來
                ConnectInfo connectInfo = new ConnectInfo(tempJoint.name, tempJoint.transform.parent.name);
                script.BonesInfo.Add(connectInfo);
                #endregion
            }
            else if (data[i].Contains("CHANNELS"))
            {
                data[i] = data[i].Replace("\t", " ");

                string[] info = data[i].Split(' ');
                info = ParseAllUselessItems(info);

                // CHANNELS 3 XX XX XX
                int count = int.Parse(info[1]);
                for (int j = 0; j < count; j++)
                {
                    script.MotionStringList.Add(tempName + " " + info[j + 2]);
                }
            }
            #endregion
        }
        #endregion

        if (IsUnityChan)
        {
            tempPeople.transform.localPosition += new Vector3(0, 0.785f, 0);
            tempPeople.transform.localScale     = new Vector3(0.02f, 0.02f, 0.02f);
        }

        // 加到堆疊裡
        tempPeople.GetComponent <BVHPeople>().InitMotionHeight = TempHeight;

        tempPeople.transform.SetParent(PeopleGroup.transform);
        People.Add(tempPeople);
    }