public void PushNewUnitData(AnimUnitData unitData, float frameTime)
        {
            InitBuffers();
            this.unitData  = unitData;
            this.frameTime = frameTime;

            if (currentFrameCoroutine != null)
            {
                StopCoroutine(currentFrameCoroutine);
            }

            switch (Controller.Mode)
            {
            case PlayMode.Stream:
                if (AllowVerticalStablization)
                {
                    ComputeNewHeightDiff();                                // Vertical stablization
                }
                currentFrameCoroutine = StartCoroutine(FrameSteppingCoroutine());
                break;

            case PlayMode.FileJson:
                if (AllowVerticalStablization)
                {
                    ComputeNewHeightDiff();                                // Vertical stablization
                }
                currentFrameCoroutine = StartCoroutine(FrameInterpolatingCoroutine());
                break;

            case PlayMode.FileBvh:
                if (AllowVerticalStablization)
                {
                    ComputeNewHeightDiff();                                // Vertical stablization
                }
                currentFrameCoroutine = StartCoroutine(FrameInterpolatingCoroutine());
                break;

            case PlayMode.FileFbx:
                break;
            }
        }
Пример #2
0
        // Transit BVH data struct to AnimDataSet
        public static AnimDataSet HierarchyToDataSet(BvhHierarchy hierarchy)
        {
            if (hierarchy.nodes.Count != indexMap.Length)
            {
                Debug.Log("Invalid node number: input " + hierarchy.nodes.Count + " indexMap " + indexMap.Length);
                return(new AnimDataSet());
            }
            AnimDataSet dataSet = new AnimDataSet();

            dataSet.frameTime = hierarchy.frameTime;
            // Loop each frame
            foreach (List <float> numbers in hierarchy.frames)
            {
                if (numbers.Count != hierarchy.channelNodes.Count)
                {
                    Debug.Log("Invalid number of numbers");
                    return(new AnimDataSet());
                }
                AnimData     data     = new AnimData();
                AnimUnitData unitData = new AnimUnitData();
                unitData.ResetJointAngles();
                unitData.id   = 1;
                unitData.size = 1f;
                // Loop each node
                for (int i = 0; i < hierarchy.nodes.Count; i++)
                {
                    int opIndex = indexMap[i];
                    if (opIndex < 0)
                    {
                        continue;
                    }
                    Vector3 pos = new Vector3();
                    Vector3 rot = new Vector3();
                    // Loop each channel
                    foreach (KeyValuePair <int, string> ch in hierarchy.nodes[i].channels)
                    {
                        float value = numbers[ch.Key];
                        switch (ch.Value)
                        {
                        case "Xposition": pos.x = value; break;

                        case "Yposition": pos.y = value; break;

                        case "Zposition": pos.z = value; break;

                        case "Xrotation": rot.x = value; break;

                        case "Yrotation": rot.y = value; break;

                        case "Zrotation": rot.z = value; break;

                        default: break;
                        }
                    }
                    if (opIndex == 0)
                    {
                        if (pos != new Vector3())
                        {
                            unitData.totalPosition = pos;
                        }
                        if (rot != new Vector3())
                        {
                            unitData.jointAngles[opIndex] = AnimUnitData.AdamToUnityEuler(rot);
                        }
                    }
                    else
                    {
                        if (rot != new Vector3())
                        {
                            unitData.jointAngles[opIndex] = AnimUnitData.AdamToUnityEuler(rot);
                        }
                    }
                }
                //data.jointAngles[0] += Vector3.left * 180f;
                data.units.Add(unitData);
                dataSet.dataList.Add(data);
            }
            //Debug.Log(dataSet.dataLis);
            return(dataSet);
        }