Beispiel #1
0
    private static void SaveToCache(string cachePath, KeyframeData keyframeData)
    {
        var json = JsonSerializer.Serialize(keyframeData, _jsonOptions);

        Directory.CreateDirectory(Path.GetDirectoryName(cachePath) ?? throw new ArgumentException($"Provided path ({cachePath}) is not valid.", nameof(cachePath)));
        File.WriteAllText(cachePath, json);
    }
 public void OpenWindow(float time, KeyframeData key)
 {
     m_Instance.minSize = new Vector2(WINDOW_MIN_WIDTH, WINDOW_MIN_HIEGHT);
     m_KeyframeTime     = time;
     m_KeyframeData     = key;
     Repaint();
     this.Focus();
 }
    void FixedUpdate()
    {
        //显示boxCollider
        if (m_isBoxColliderHide)
        {
            if (m_self != null && !m_self.IsDead)
            {
                if (Time.time - m_boxColliderHideTime >= m_boxColliderHideDuration)
                {//显示
                    m_isBoxColliderHide = false;
                    if (m_self.CenterCollider != null)
                    {
                        m_self.CenterCollider.gameObject.layer = LayerMask.NameToLayer("Actor");
                    }
                }
            }
        }
        {
            foreach (Shader item in m_shaderList.Values)
            {
                if (item.m_index >= item.m_data.AnimCurveInfoList.Count)
                {//shader改变完毕,等待重新开始
                    continue;
                }

                float now = Time.time;
                if (now - item.m_starTime > item.m_data.m_interval || item.m_index == -1)
                {
                    item.m_starTime = now - item.m_data.m_interval;
                    ++item.m_index;

                    if (item.m_index >= item.m_data.AnimCurveInfoList.Count)
                    {//shader改变完毕,等待重新开始
                        continue;
                    }
                    Renderer[] renders = gameObject.GetComponentsInChildren <Renderer>();
                    foreach (Renderer r in renders)
                    {
                        KeyframeData info = item.m_data.AnimCurveInfoList[item.m_index % item.m_data.AnimCurveInfoList.Count];
                        foreach (var propItem in info.PropertyInfoList)
                        {
                            if (r.material.HasProperty(propItem.m_name))
                            {
                                if (propItem.m_color != Color.white)
                                {
                                    r.material.SetColor(propItem.m_name, propItem.m_color);
                                }
                                if (propItem.m_value != float.MinValue)
                                {
                                    r.material.SetFloat(propItem.m_name, propItem.m_value);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Beispiel #4
0
    /// <summary>
    /// Extracts the keyframes in ticks (scaled using the container timestamp scale) from the matroska container.
    /// </summary>
    /// <param name="filePath">The file path.</param>
    /// <returns>An instance of <see cref="KeyframeData"/>.</returns>
    public static KeyframeData GetKeyframeData(string filePath)
    {
        using var stream = File.OpenRead(filePath);
        using var reader = new EbmlReader(stream);

        var seekHead = reader.ReadSeekHead();
        // External lib does not support seeking backwards (yet)
        Info  info;
        ulong videoTrackNumber;

        if (seekHead.InfoPosition < seekHead.TracksPosition)
        {
            info             = reader.ReadInfo(seekHead.InfoPosition);
            videoTrackNumber = reader.FindFirstTrackNumberByType(seekHead.TracksPosition, MatroskaConstants.TrackTypeVideo);
        }
        else
        {
            videoTrackNumber = reader.FindFirstTrackNumberByType(seekHead.TracksPosition, MatroskaConstants.TrackTypeVideo);
            info             = reader.ReadInfo(seekHead.InfoPosition);
        }

        var keyframes = new List <long>();

        reader.ReadAt(seekHead.CuesPosition);
        reader.EnterContainer();

        while (reader.FindElement(MatroskaConstants.CuePoint))
        {
            reader.EnterContainer();
            ulong?trackNumber = null;
            // Mandatory element
            reader.FindElement(MatroskaConstants.CueTime);
            var cueTime = reader.ReadUInt();

            // Mandatory element
            reader.FindElement(MatroskaConstants.CueTrackPositions);
            reader.EnterContainer();
            if (reader.FindElement(MatroskaConstants.CuePointTrackNumber))
            {
                trackNumber = reader.ReadUInt();
            }

            reader.LeaveContainer();

            if (trackNumber == videoTrackNumber)
            {
                keyframes.Add(ScaleToTicks(cueTime, info.TimestampScale));
            }

            reader.LeaveContainer();
        }

        reader.LeaveContainer();

        var result = new KeyframeData(ScaleToTicks(info.Duration ?? 0, info.TimestampScale), keyframes);

        return(result);
    }
        static (float, KeyframeData) KeyframeConversion(UnityEngine.Keyframe inKey)
        {
            var key = new KeyframeData
            {
                InTangent  = inKey.inTangent,
                OutTangent = inKey.outTangent,
                Value      = inKey.value,
            };

            return(inKey.time, key);
        }
    private void OnClickFrame(ActionFrameData data)
    {
        ResetKeyFrameTex();
        m_KeyFrameDataDict = ActionHelper.ConvertKeyFrameData(m_FileData.FrameDatalist);
        KeyframeData framedata = m_KeyFrameDataDict[(float)data.Time];

        if (null != framedata)
        {
            framedata.isSelected = true;
        }
    }
Beispiel #7
0
    private void SetupNextDanceAnimation()
    {
        m_keyFrameIndex = 0;
        m_tardyCounter  = 0f;
        string path = Path.Combine(AnimationDirectory, KeyframeAnimations[m_listIndex]);
        string json = File.ReadAllText(path);

        m_ActiveData = JsonUtility.FromJson <KeyframeData>(json);
        CreateTargetsForKeyFrame(m_keyFrameIndex);

        countdownToPoint = freePointInterval;
    }
Beispiel #8
0
    // Use this for initialization
    void Start()
    {
        IsRecording         = false;
        m_jointObjects      = new Dictionary <JointType, GameObject>();
        m_keyframeData      = new KeyframeData();
        m_keyframeData.Name = "TestDance";
        var joints = this.GetComponentsInChildren <JointTracker>(false);

        foreach (JointTracker j in joints)
        {
            m_jointObjects[j.JointToUse] = j.gameObject;
        }
    }
Beispiel #9
0
    // Set up the joints that our key frame animation will use.
    void Awake()
    {
        m_keyframeData      = new KeyframeData();
        m_keyframeData.Name = (AnimationName != "") ? AnimationName : "TestAnimation";

        m_jointObjects = new Dictionary <JointType, GameObject>();
        var joints = this.GetComponentsInChildren <KeyframeJoint>(false);

        foreach (KeyframeJoint j in joints)
        {
            m_jointObjects[j.JointToUse] = j.gameObject;
        }
    }
Beispiel #10
0
 void StringToList(string temp)
 {
     if (string.IsNullOrEmpty(temp))
     {
         return;
     }
     string[] array = temp.Split(new char[1] {
         ';'
     });
     foreach (var item in array)
     {
         if (string.IsNullOrEmpty(item))
         {
             continue;
         }
         KeyframeData info = new KeyframeData(item);
         AnimCurveInfoList.Add(info);
     }
 }
Beispiel #11
0
    void Update()
    {
        if (!gameObject.activeSelf)
        {
            return;
        }
        AnimCurveData data = AnimCurveDataManager.Singleton.GetAnimCurveData("Anim/" + m_pathName + ".bytes");
        int           key  = (int)((data.AnimCurveInfoList.Count - 1) * Percent);

        if (key <= m_lastKey)
        {
            return;
        }
        if (key >= data.AnimCurveInfoList.Count)
        {
            Debug.LogWarning("曲线数据出错,当前key是:" + key.ToString() + ", name is " + m_pathName);
            return;
        }
        m_lastKey = key;
        foreach (var item in m_objList)
        {
            Renderer[] renders = item.GetComponents <Renderer>();
            foreach (Renderer r in renders)
            {
                KeyframeData info = data.AnimCurveInfoList[key];
                foreach (var propItem in info.PropertyInfoList)
                {
                    if (r.material.HasProperty(propItem.m_name))
                    {
                        if (propItem.m_color != Color.white)
                        {
                            r.material.SetColor(propItem.m_name, propItem.m_color);
                        }
                        if (propItem.m_value != float.MinValue)
                        {
                            r.material.SetFloat(propItem.m_name, propItem.m_value);
                        }
                    }
                }
            }
        }
    }
Beispiel #12
0
    public static Dictionary <float, KeyframeData> ConvertKeyFrameData(List <ActionFrameData> actionFrameData)
    {
        Dictionary <float, KeyframeData> result = new Dictionary <float, KeyframeData>();

        if (actionFrameData != null)
        {
            foreach (ActionFrameData value in actionFrameData)
            {
                if (!result.ContainsKey((float)value.Time))
                {
                    KeyframeData key = new KeyframeData();
                    key.framedatalist = new List <ActionFrameData>();
                    key.framedatalist.Add(value);
                    result.Add((float)value.Time, key);
                }
                else
                {
                    KeyframeData key = result[(float)value.Time];
                    key.framedatalist.Add(value);
                }
            }
        }
        return(result);
    }
Beispiel #13
0
    void UpdateCameraLight()
    {
        switch (m_cameraLightType)
        {
        case ENCameraLightType.enL2D:
        {
            AnimCurveData data = AnimCurveDataManager.Singleton.GetAnimCurveData("Anim/" + m_cameraLightL2D + ".bytes");
            float         now  = Time.time;
            if (now - m_cameraLightStartTime > data.m_interval || m_cameraLightIndex == -1)
            {
                m_cameraLightStartTime = now;
                ++m_cameraLightIndex;
                if (m_cameraLightIndex >= data.AnimCurveInfoList.Count)
                {
                    m_cameraLightType      = ENCameraLightType.enIng;
                    m_cameraLightStartTime = now;
                    m_cameraLightIndex     = -1;
                    return;
                }
                Renderer[] renders = m_darkerObj.GetComponentsInChildren <Renderer>();
                foreach (Renderer r in renders)
                {
                    KeyframeData info = data.AnimCurveInfoList[m_cameraLightIndex % data.AnimCurveInfoList.Count];
                    foreach (var propItem in info.PropertyInfoList)
                    {
                        if (r.material.HasProperty(propItem.m_name))
                        {
                            //if (propItem.m_color != Color.white)
                            //{
                            //    r.material.SetColor(propItem.m_name, propItem.m_color);
                            //}
                            if (propItem.m_value != float.MinValue)
                            {
                                r.material.SetFloat(propItem.m_name, propItem.m_value);
                            }
                        }
                    }
                }
            }
        }
        break;

        case ENCameraLightType.enIng:
            if (Time.time - m_cameraLightStartTime > m_cameraLightDuration)
            {
                m_cameraLightType      = ENCameraLightType.enD2L;
                m_cameraLightStartTime = Time.time;
                m_cameraLightIndex     = -1;
            }
            break;

        case ENCameraLightType.enD2L:
        {
            AnimCurveData data = AnimCurveDataManager.Singleton.GetAnimCurveData("Anim/" + m_cameraLightD2L + ".bytes");
            float         now  = Time.time;
            if (now - m_cameraLightStartTime > data.m_interval || m_cameraLightIndex == -1)
            {
                m_cameraLightStartTime = now;
                ++m_cameraLightIndex;
                if (m_cameraLightIndex >= data.AnimCurveInfoList.Count)
                {
                    m_cameraLightType = ENCameraLightType.enNone;
                    return;
                }
                Renderer[] renders = m_darkerObj.GetComponentsInChildren <Renderer>();
                foreach (Renderer r in renders)
                {
                    KeyframeData info = data.AnimCurveInfoList[m_cameraLightIndex % data.AnimCurveInfoList.Count];
                    foreach (var propItem in info.PropertyInfoList)
                    {
                        if (r.material.HasProperty(propItem.m_name))
                        {
                            //if (propItem.m_color != Color.white)
                            //{
                            //    r.material.SetColor(propItem.m_name, propItem.m_color);
                            //}
                            if (propItem.m_value != float.MinValue)
                            {
                                r.material.SetFloat(propItem.m_name, propItem.m_value);
                            }
                        }
                    }
                }
            }
        }
        break;

        default:
            break;
        }
    }
        public void ComputeSegments_InvalidDuration_ThrowsArgumentException()
        {
            var keyframeData = new KeyframeData(0, new[] { MsToTicks(10000) });

            Assert.Throws <ArgumentException>(() => DynamicHlsPlaylistGenerator.ComputeSegments(keyframeData, 6000));
        }
 public void ComputeSegments_Valid_Success(KeyframeData keyframeData, int desiredSegmentLengthMs, double[] segments)
 {
     Assert.Equal(segments, DynamicHlsPlaylistGenerator.ComputeSegments(keyframeData, desiredSegmentLengthMs));
 }
    private void GetData(float time, AnimationClipCurveData[] array, AnimCurveData data)
    {
        KeyframeData info = new KeyframeData();

        foreach (AnimationClipCurveData item in array)
        {
            float  value = item.curve.Evaluate(time);
            string name  = item.propertyName;
            name = name.Replace("material.", "");

            if (name.Contains(".r") || name.Contains(".g") ||
                name.Contains(".b") || name.Contains(".a"))
            {
                string key = name.Substring(0, name.Length - 2);

                KeyframeData.PropertyInfo propInfo = info.PropertyInfoList.Find(i => i.m_name == key);
                if (propInfo == null)
                {
                    Color c = Color.white;
                    if (name.Contains(".r"))
                    {
                        c.r = value;
                    }
                    else if (name.Contains(".g"))
                    {
                        c.g = value;
                    }
                    else if (name.Contains(".b"))
                    {
                        c.b = value;
                    }
                    else if (name.Contains(".a"))
                    {
                        c.a = value;
                    }

                    propInfo         = new KeyframeData.PropertyInfo(key);
                    propInfo.m_color = c;

                    info.PropertyInfoList.Add(propInfo);
                }
                else
                {
                    if (name.Contains(".r"))
                    {
                        propInfo.m_color.r = value;
                    }
                    else if (name.Contains(".g"))
                    {
                        propInfo.m_color.g = value;
                    }
                    else if (name.Contains(".b"))
                    {
                        propInfo.m_color.b = value;
                    }
                    else if (name.Contains(".a"))
                    {
                        propInfo.m_color.a = value;
                    }
                }
            }
            else
            {
                KeyframeData.PropertyInfo propInfo = info.PropertyInfoList.Find(i => i.m_name == name);
                if (propInfo == null)
                {
                    propInfo         = new KeyframeData.PropertyInfo(name);
                    propInfo.m_value = value;

                    info.PropertyInfoList.Add(propInfo);
                }
                else
                {
                    propInfo.m_value = value;
                }
            }
        }
        data.AnimCurveInfoList.Add(info);
    }
 public void OpenWindow(float time, KeyframeData key)
 {
     m_Instance.minSize = new Vector2(WINDOW_MIN_WIDTH, WINDOW_MIN_HIEGHT);
     m_KeyframeTime = time;
     m_KeyframeData = key;
     Repaint();
     this.Focus();
 }
    public static Dictionary<float, KeyframeData> ConvertKeyFrameData(List<ActionFrameData> actionFrameData)
    {
        Dictionary<float, KeyframeData> result = new Dictionary<float, KeyframeData>();

        if (actionFrameData != null)
        {
            foreach (ActionFrameData value in actionFrameData)
            {
                if (!result.ContainsKey((float)value.Time))
                {
                    KeyframeData key = new KeyframeData();
                    key.framedatalist = new List<ActionFrameData>();
                    key.framedatalist.Add(value);
                    result.Add((float)value.Time, key);
                }
                else
                {
                    KeyframeData key = result[(float)value.Time];
                    key.framedatalist.Add(value);
                }
            }
        }
        return result;
    }