private void InitDataJson(string file)
        {
            string filePath = file;

            if (File.Exists(filePath))
            {
                string dataAsJson = File.ReadAllText(filePath);
                dataSet = AnimDataSet.FromJsonData(dataAsJson);
            }
            else
            {
                Debug.Log("File not exists: " + filePath);
            }
        }
        private void InitDataBvh(string file)
        {
            //string filePath = Path.Combine(Application.dataPath, file);
            string filePath = file;

            if (File.Exists(filePath))
            {
                string data = File.ReadAllText(filePath);
                dataSet = AnimDataSet.FromBvhData(data);
            }
            else
            {
                Debug.Log("File not exists");
            }
        }
        private void InitDataBvh(string file)
        {
            string filePath = file;

            if (File.Exists(filePath))
            {
                string data = File.ReadAllText(filePath);
                dataSet = AnimDataSet.FromBvhData(data);
            }
            else
            {
                Debug.Log("File not exists: " + filePath);
            }

            SceneController.instance.PushNewFrameData(dataSet.dataList[currentFrameNumber], frameTime);
        }
示例#4
0
        //public List<Vector3> default_skeleton;

        public static AnimDataSet FromJsonData(string text)
        {
            AnimDataSet dataSet = new AnimDataSet();

            try
            {
                dataSet = JsonUtility.FromJson <AnimDataSet>(text);
                foreach (AnimData data in dataSet.dataList)
                {
                    AnimData.Validate(data);
                }
                dataSet.isValid = true;
            }
            catch (Exception err)
            {
                Debug.Log(err);
            }
            return(dataSet);
        }
示例#5
0
        public static AnimDataSet FromJsonData(string text) // Json file mode
        {
            AnimDataSet dataSet = new AnimDataSet();

            try
            {
                dataSet = JsonUtility.FromJson <AnimDataSet>(text);
                foreach (AnimData data in dataSet.dataList)
                {
                    foreach (AnimUnitData unit in data.units)
                    {
                        unit.JsonInputToUnitySystem();
                    }
                }
            }
            catch (Exception err)
            {
                Debug.Log(err);
            }
            return(dataSet);
        }
示例#6
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);
        }