public void ProcessMotionBytes(byte[] motionBytes, Vector3 offset, bool startAnimation = true)
        {
            annotation       = null;
            legacyAnnotation = null;
            Stream ms = new MemoryStream(motionBytes);

            ms.Seek(0, SeekOrigin.Begin);
            var            bz2InputStream = new BZip2InputStream(ms);
            BsonReader     reader         = new BsonReader(bz2InputStream);
            JsonSerializer serializer     = new JsonSerializer();

            motion = serializer.Deserialize <CAnimationClip>(reader);
            motion.scaleTranslations(scaleFactor);
            motion.translateFrames(offset);
            frameTime     = motion.getFrameTime();
            animationTime = 0;
            frameIdx      = 0;
            speedFactor   = 1.0f;
            playAnimation = startAnimation;
            numFrames     = motion.GetNumFrames();
            maxAnimatTime = numFrames * frameTime;
            init          = true;
        }
        /// <summary>
        /// Process JSON string into CAnnotation or CLegacyAnnotation and visualize result.
        /// </summary>
        /// <param name="annotationSring"> JSON string </param>
        public void ProcessAnnotationString(string annotationSring)
        {
            if (!init)
            {
                return;
            }
            JsonSerializer serializer = new JsonSerializer();
            JsonReader     reader     = new JsonTextReader(new StringReader(annotationSring));
            bool           success    = false;

            try
            {
                Debug.Log("process legacy annotation format");
                legacyAnnotation = serializer.Deserialize <CLegacyAnnotation>(reader);


                frameLabels = new List <List <int> >();
                labels      = new List <string>();
                for (int j = 0; j < legacyAnnotation.sections.Count; j++)
                {
                    labels.Add("c" + j.ToString());
                }
                numFrames = motion.GetNumFrames();

                for (int i = 0; i < numFrames; i++)
                {
                    frameLabels.Add(new List <int>());
                    for (int j = 0; j < legacyAnnotation.sections.Count; j++)
                    {
                        if (legacyAnnotation.sections[j].start_idx < i && i < legacyAnnotation.sections[j].end_idx)
                        {
                            frameLabels[i].Add(j);//store index of label
                        }
                    }
                }
                success = true;
            }
            catch
            {
                Debug.Log("could not process legacy annotation format");
            }
            if (success)
            {
                return;
            }

            try
            {
                Debug.Log("process annotation format");
                annotation = serializer.Deserialize <CAnnotation>(reader);

                Debug.Log(annotation);
                numFrames   = motion.GetNumFrames();
                frameLabels = new List <List <int> >();
                labels      = new List <string>();
                foreach (var label in annotation.sections.Keys)
                {
                    labels.Add(label);
                }
                numFrames = motion.GetNumFrames();

                for (int i = 0; i < numFrames; i++)
                {
                    frameLabels.Add(new List <int>());
                    foreach (var label in labels)
                    {
                        for (int j = 0; j < annotation.sections[label].Count; j++)
                        {
                            if (annotation.sections[label][j].start_idx < i && i < annotation.sections[label][j].end_idx)
                            {
                                frameLabels[i].Add(j);//store index of label
                            }
                        }
                    }
                }
            }
            catch
            {
                Debug.Log("could not process annotation format");
            }
        }