public static void AddBezierKeyframes(byte[] interpolation, int type, VMDHSConverter.QuaternionKeyframe prev_keyframe, VMDHSConverter.QuaternionKeyframe cur_keyframe, int interpolationQuality, ref VMDHSConverter.QuaternionKeyframe[] keyframes, ref int index)
            {
                if (prev_keyframe == null || VMDHSConverter.IsLinear(interpolation, type))
                {
                    VMDHSConverter.QuaternionKeyframe[] array = keyframes;
                    int num = index;
                    index      = num + 1;
                    array[num] = cur_keyframe;
                    return;
                }
                Vector2 bezierHandle  = VMDHSConverter.GetBezierHandle(interpolation, type, 0);
                Vector2 bezierHandle2 = VMDHSConverter.GetBezierHandle(interpolation, type, 1);

                for (int i = 0; i < interpolationQuality; i++)
                {
                    float   t  = (float)(i + 1) / (float)interpolationQuality;
                    Vector2 t2 = VMDHSConverter.SampleBezier(bezierHandle, bezierHandle2, t);
                    VMDHSConverter.QuaternionKeyframe[] array2 = keyframes;
                    int num = index;
                    index       = num + 1;
                    array2[num] = VMDHSConverter.QuaternionKeyframe.Lerp(prev_keyframe, cur_keyframe, t2);
                }
            }
 public static VMDHSConverter.QuaternionKeyframe Lerp(VMDHSConverter.QuaternionKeyframe from, VMDHSConverter.QuaternionKeyframe to, Vector2 t)
 {
     return(new VMDHSConverter.QuaternionKeyframe(Mathf.Lerp(from.time, to.time, t.x), Quaternion.Slerp(from.value, to.value, t.y)));
 }
        private Dictionary <string, AnimationCurve> CollectCurve(VMDFormat format, string boneName, int interpolationQuality)
        {
            if (!format.motion_list.motion.ContainsKey(boneName))
            {
                return(null);
            }
            Dictionary <string, AnimationCurve> dictionary = new Dictionary <string, AnimationCurve>();
            List <VMDFormat.Motion>             list       = format.motion_list.motion[boneName];
            Vector3 zero = Vector3.zero;

            this.GetKeyframeCount(list, 0, interpolationQuality);
            this.GetKeyframeCount(list, 1, interpolationQuality);
            this.GetKeyframeCount(list, 2, interpolationQuality);
            List <VMDHSConverter.FloatKeyframe> list2 = new List <VMDHSConverter.FloatKeyframe>();
            List <VMDHSConverter.FloatKeyframe> list3 = new List <VMDHSConverter.FloatKeyframe>();
            List <VMDHSConverter.FloatKeyframe> list4 = new List <VMDHSConverter.FloatKeyframe>();

            VMDHSConverter.FloatKeyframe prev_keyframe  = null;
            VMDHSConverter.FloatKeyframe prev_keyframe2 = null;
            VMDHSConverter.FloatKeyframe prev_keyframe3 = null;
            int num  = 0;
            int num2 = 0;
            int num3 = 0;

            for (int i = 0; i < list.Count; i++)
            {
                float time = list[i].flame_no * 0.0333333351f;
                VMDHSConverter.FloatKeyframe floatKeyframe  = new VMDHSConverter.FloatKeyframe(time, list[i].location.x * this.scale.x + zero.x);
                VMDHSConverter.FloatKeyframe floatKeyframe2 = new VMDHSConverter.FloatKeyframe(time, list[i].location.y * this.scale.y + zero.y);
                VMDHSConverter.FloatKeyframe floatKeyframe3 = new VMDHSConverter.FloatKeyframe(time, list[i].location.z * this.scale.z + zero.z);
                VMDHSConverter.FloatKeyframe.AddBezierKeyframes(list[i].interpolation, 0, prev_keyframe, floatKeyframe, interpolationQuality, ref list2, ref num);
                VMDHSConverter.FloatKeyframe.AddBezierKeyframes(list[i].interpolation, 1, prev_keyframe2, floatKeyframe2, interpolationQuality, ref list3, ref num2);
                VMDHSConverter.FloatKeyframe.AddBezierKeyframes(list[i].interpolation, 2, prev_keyframe3, floatKeyframe3, interpolationQuality, ref list4, ref num3);
                prev_keyframe  = floatKeyframe;
                prev_keyframe2 = floatKeyframe2;
                prev_keyframe3 = floatKeyframe3;
            }
            if (list.Count != 0)
            {
                VMDHSConverter.FloatKeyframe[] custom_keys  = list2.ToArray();
                VMDHSConverter.FloatKeyframe[] custom_keys2 = list3.ToArray();
                VMDHSConverter.FloatKeyframe[] custom_keys3 = list4.ToArray();
                AnimationCurve value  = new AnimationCurve(this.ToKeyframesForLocation(custom_keys));
                AnimationCurve value2 = new AnimationCurve(this.ToKeyframesForLocation(custom_keys2));
                AnimationCurve value3 = new AnimationCurve(this.ToKeyframesForLocation(custom_keys3));
                dictionary.Add("localPosition.x", value);
                dictionary.Add("localPosition.y", value2);
                dictionary.Add("localPosition.z", value3);
            }
            VMDHSConverter.QuaternionKeyframe[] custom_keys4   = new VMDHSConverter.QuaternionKeyframe[this.GetKeyframeCount(list, 3, interpolationQuality)];
            VMDHSConverter.QuaternionKeyframe   prev_keyframe4 = null;
            int num4 = 0;

            for (int j = 0; j < list.Count; j++)
            {
                float      time2    = list[j].flame_no * 0.0333333351f;
                Quaternion rotation = list[j].rotation;
                VMDHSConverter.QuaternionKeyframe quaternionKeyframe = new VMDHSConverter.QuaternionKeyframe(time2, rotation);
                VMDHSConverter.QuaternionKeyframe.AddBezierKeyframes(list[j].interpolation, 3, prev_keyframe4, quaternionKeyframe, interpolationQuality, ref custom_keys4, ref num4);
                prev_keyframe4 = quaternionKeyframe;
            }
            Keyframe[] array  = null;
            Keyframe[] array2 = null;
            Keyframe[] array3 = null;
            this.ToKeyframesForRotation(custom_keys4, ref array, ref array2, ref array3, false);
            AnimationCurve value4 = new AnimationCurve(array);
            AnimationCurve value5 = new AnimationCurve(array2);
            AnimationCurve value6 = new AnimationCurve(array3);

            dictionary.Add("localEulerAngles.x", value4);
            dictionary.Add("localEulerAngles.y", value5);
            dictionary.Add("localEulerAngles.z", value6);
            return(dictionary);
        }
        public AnimationClip CreateCameraAnimationClip(VMDFormat format, GameObject camera_root, int interpolationQuality)
        {
            AnimationClip animationClip = new AnimationClip();

            if (VMDHSConverter.p_legacy != null)
            {
                VMDHSConverter.p_legacy.SetValue(animationClip, true, null);
            }
            BoneAdjustment boneAdjustment = this.boneAdjustment["camera"];

            if (camera_root.transform.Find("camera") == null)
            {
                new GameObject("camera").transform.parent = camera_root.transform;
            }
            if (camera_root.transform.Find("length") == null)
            {
                new GameObject("length").transform.parent = camera_root.transform;
            }
            if (camera_root.transform.Find("view_angle") == null)
            {
                new GameObject("view_angle").transform.parent = camera_root.transform;
            }
            if (camera_root.transform.Find("perspective") == null)
            {
                new GameObject("perspective").transform.parent = camera_root.transform;
            }
            List <VMDHSConverter.FloatKeyframe>       list  = new List <VMDHSConverter.FloatKeyframe>();
            List <VMDHSConverter.FloatKeyframe>       list2 = new List <VMDHSConverter.FloatKeyframe>();
            List <VMDHSConverter.FloatKeyframe>       list3 = new List <VMDHSConverter.FloatKeyframe>();
            List <VMDHSConverter.FloatLinearKeyframe> list4 = new List <VMDHSConverter.FloatLinearKeyframe>();
            List <VMDHSConverter.FloatLinearKeyframe> list5 = new List <VMDHSConverter.FloatLinearKeyframe>();
            List <Keyframe> list6 = new List <Keyframe>();

            VMDHSConverter.FloatKeyframe prev_keyframe  = null;
            VMDHSConverter.FloatKeyframe prev_keyframe2 = null;
            VMDHSConverter.FloatKeyframe prev_keyframe3 = null;
            int num  = 0;
            int num2 = 0;
            int num3 = 0;
            int num4 = 0;

            while ((long)num4 < (long)((ulong)format.camera_list.camera_count))
            {
                VMDFormat.CameraData cameraData = format.camera_list.camera[num4];
                float   num5     = 0.0333333351f * cameraData.flame_no;
                Vector3 location = cameraData.location;
                location.z = -location.z;
                location.x = -location.x;
                VMDHSConverter.FloatKeyframe       floatKeyframe  = new VMDHSConverter.FloatKeyframe(num5, location.x * this.scale.x);
                VMDHSConverter.FloatKeyframe       floatKeyframe2 = new VMDHSConverter.FloatKeyframe(num5, location.y * this.scale.y);
                VMDHSConverter.FloatKeyframe       floatKeyframe3 = new VMDHSConverter.FloatKeyframe(num5, location.z * this.scale.z);
                VMDHSConverter.FloatLinearKeyframe item           = new VMDHSConverter.FloatLinearKeyframe(num5, cameraData.length * this.scale.z);
                VMDHSConverter.FloatLinearKeyframe item2          = new VMDHSConverter.FloatLinearKeyframe(num5, cameraData.viewing_angle);
                VMDHSConverter.FloatKeyframe.AddBezierKeyframes(cameraData.interpolation, 0, prev_keyframe, floatKeyframe, interpolationQuality, ref list, ref num);
                VMDHSConverter.FloatKeyframe.AddBezierKeyframes(cameraData.interpolation, 1, prev_keyframe2, floatKeyframe2, interpolationQuality, ref list2, ref num2);
                VMDHSConverter.FloatKeyframe.AddBezierKeyframes(cameraData.interpolation, 2, prev_keyframe3, floatKeyframe3, interpolationQuality, ref list3, ref num3);
                list4.Add(item);
                list5.Add(item2);
                prev_keyframe  = floatKeyframe;
                prev_keyframe2 = floatKeyframe2;
                prev_keyframe3 = floatKeyframe3;
                Keyframe item3;
                item3 = new Keyframe(num5, (float)cameraData.perspective);
                list6.Add(item3);
                num4++;
            }
            if (format.camera_list.camera_count != 0u)
            {
                VMDHSConverter.FloatKeyframe[]       custom_keys  = list.ToArray();
                VMDHSConverter.FloatKeyframe[]       custom_keys2 = list2.ToArray();
                VMDHSConverter.FloatKeyframe[]       custom_keys3 = list3.ToArray();
                VMDHSConverter.FloatLinearKeyframe[] custom_keys4 = list4.ToArray();
                VMDHSConverter.FloatLinearKeyframe[] custom_keys5 = list5.ToArray();
                AnimationCurve animationCurve  = new AnimationCurve(this.ToKeyframesForLocation(custom_keys));
                AnimationCurve animationCurve2 = new AnimationCurve(this.ToKeyframesForLocation(custom_keys2));
                AnimationCurve animationCurve3 = new AnimationCurve(this.ToKeyframesForLocation(custom_keys3));
                AnimationCurve animationCurve4 = new AnimationCurve(this.ToKeyframesForLocation(custom_keys4));
                AnimationCurve animationCurve5 = new AnimationCurve(this.ToKeyframesForLocation(custom_keys5));
                Keyframe[]     array           = list6.ToArray();
                this.AddDummyKeyframe(ref array);
                AnimationCurve animationCurve6 = new AnimationCurve(array);
                animationClip.SetCurve("camera", typeof(Transform), "localPosition.x", animationCurve);
                animationClip.SetCurve("camera", typeof(Transform), "localPosition.y", animationCurve2);
                animationClip.SetCurve("camera", typeof(Transform), "localPosition.z", animationCurve3);
                animationClip.SetCurve("length", typeof(Transform), "localPosition.z", animationCurve4);
                animationClip.SetCurve("view_angle", typeof(Transform), "localPosition.z", animationCurve5);
                animationClip.SetCurve("perspective", typeof(Transform), "localPosition.z", animationCurve6);
            }
            List <VMDHSConverter.QuaternionKeyframe> list7 = new List <VMDHSConverter.QuaternionKeyframe>();
            Quaternion identity = Quaternion.identity;
            int        num6     = 0;

            while ((long)num6 < (long)((ulong)format.camera_list.camera_count))
            {
                VMDFormat.CameraData cameraData2 = format.camera_list.camera[num6];
                float   time   = 0.0333333351f * cameraData2.flame_no;
                Vector3 vector = cameraData2.rotation * 57.29578f;
                vector.y *= -1f;
                Quaternion quaternion = Quaternion.Euler(vector);
                quaternion = boneAdjustment.GetAdjustedRotation(quaternion);
                VMDHSConverter.QuaternionKeyframe item4 = new VMDHSConverter.QuaternionKeyframe(time, quaternion);
                list7.Add(item4);
                num6++;
            }
            Keyframe[] array2 = null;
            Keyframe[] array3 = null;
            Keyframe[] array4 = null;
            Dictionary <string, Keyframe[]> dictionary = this.ToKeyframesForRotation(list7.ToArray(), ref array2, ref array3, ref array4, false);
            AnimationCurve animationCurve7             = new AnimationCurve(dictionary["localRotation.x"]);
            AnimationCurve animationCurve8             = new AnimationCurve(dictionary["localRotation.y"]);
            AnimationCurve animationCurve9             = new AnimationCurve(dictionary["localRotation.z"]);
            AnimationCurve animationCurve10            = new AnimationCurve(dictionary["localRotation.w"]);

            animationClip.SetCurve("camera", typeof(Transform), "localRotation.x", animationCurve7);
            animationClip.SetCurve("camera", typeof(Transform), "localRotation.y", animationCurve8);
            animationClip.SetCurve("camera", typeof(Transform), "localRotation.z", animationCurve9);
            animationClip.SetCurve("camera", typeof(Transform), "localRotation.w", animationCurve10);
            return(animationClip);
        }
 private void CreateKeysForRotation(VMDFormat format, AnimationClip clip, string current_bone, string bone_path, int interpolationQuality)
 {
     try
     {
         if (this.boneNameMap.ContainsKey(current_bone))
         {
             string text = this.boneNameMap[current_bone];
             List <VMDFormat.Motion> list;
             if (!format.motion_list.motion.ContainsKey(text))
             {
                 Console.WriteLine("bone {0} not found in motionlist", text);
                 Console.WriteLine("Add dummy rotation frame (rot 0,0,0) for the bone {0}", text);
                 list = new List <VMDFormat.Motion>();
                 VMDFormat.Motion item = new VMDFormat.Motion(text, 0u, Vector3.zero, Quaternion.identity, new byte[64]);
                 list.Add(item);
             }
             else
             {
                 list = format.motion_list.motion[text];
             }
             Dictionary <string, AnimationCurve> dictionary = null;
             BoneAdjustment boneAdjustment = null;
             if (this.boneAdjustment.ContainsKey(current_bone))
             {
                 boneAdjustment = this.boneAdjustment[current_bone];
             }
             VMDHSConverter.QuaternionKeyframe[] custom_keys   = new VMDHSConverter.QuaternionKeyframe[this.GetKeyframeCount(list, 3, interpolationQuality)];
             VMDHSConverter.QuaternionKeyframe   prev_keyframe = null;
             int        num        = 0;
             Quaternion quaternion = Quaternion.identity;
             for (int i = 0; i < list.Count; i++)
             {
                 float      num2        = list[i].flame_no * 0.0333333351f;
                 Quaternion quaternion2 = list[i].rotation;
                 if (dictionary != null)
                 {
                     AnimationCurve animationCurve = null;
                     dictionary.TryGetValue("localEulerAngles.x", out animationCurve);
                     AnimationCurve animationCurve2 = null;
                     dictionary.TryGetValue("localEulerAngles.y", out animationCurve2);
                     AnimationCurve animationCurve3 = null;
                     dictionary.TryGetValue("localEulerAngles.z", out animationCurve3);
                     Quaternion quaternion3 = Quaternion.identity;
                     if (animationCurve != null && animationCurve2 != null && animationCurve3 != null)
                     {
                         quaternion3  = Quaternion.Euler(animationCurve.Evaluate(num2), animationCurve2.Evaluate(num2), animationCurve3.Evaluate(num2));
                         quaternion2 *= quaternion3;
                     }
                 }
                 if (boneAdjustment != null)
                 {
                     quaternion2 = boneAdjustment.GetAdjustedRotation(quaternion2);
                 }
                 if (i != 0)
                 {
                     quaternion2 = Quaternion.Slerp(quaternion, quaternion2, 0.99999f);
                 }
                 VMDHSConverter.QuaternionKeyframe quaternionKeyframe = new VMDHSConverter.QuaternionKeyframe(num2, quaternion2);
                 VMDHSConverter.QuaternionKeyframe.AddBezierKeyframes(list[i].interpolation, 3, prev_keyframe, quaternionKeyframe, interpolationQuality, ref custom_keys, ref num);
                 prev_keyframe = quaternionKeyframe;
                 quaternion    = quaternion2;
             }
             Keyframe[] array  = null;
             Keyframe[] array2 = null;
             Keyframe[] array3 = null;
             Dictionary <string, Keyframe[]> dictionary2 = this.ToKeyframesForRotation(custom_keys, ref array, ref array2, ref array3, false);
             new AnimationCurve(array);
             new AnimationCurve(array2);
             new AnimationCurve(array3);
             AnimationCurve animationCurve4 = new AnimationCurve(dictionary2["localRotation.x"]);
             AnimationCurve animationCurve5 = new AnimationCurve(dictionary2["localRotation.y"]);
             AnimationCurve animationCurve6 = new AnimationCurve(dictionary2["localRotation.z"]);
             AnimationCurve animationCurve7 = new AnimationCurve(dictionary2["localRotation.w"]);
             clip.SetCurve(bone_path, typeof(Transform), "localRotation.x", animationCurve4);
             clip.SetCurve(bone_path, typeof(Transform), "localRotation.y", animationCurve5);
             clip.SetCurve(bone_path, typeof(Transform), "localRotation.z", animationCurve6);
             clip.SetCurve(bone_path, typeof(Transform), "localRotation.w", animationCurve7);
             if (text == "センター")
             {
                 this.centerXCurve = animationCurve4;
                 this.centerYCurve = animationCurve5;
                 this.centerZCurve = animationCurve6;
                 this.centerWCurve = animationCurve7;
             }
         }
     }
     catch (KeyNotFoundException)
     {
     }
 }