Exemple #1
0
        public bool SetCameraAnimation(string path)
        {
            Dictionary <string, BoneAdjustment> dictionary = new Dictionary <string, BoneAdjustment>();

            dictionary.Add("camera", BoneAdjustment.Init("VMDCameraAnim", this.boneAdjustSpec, Vector3.zero, false));
            KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Debug, string.Format("bone adjustment init", path));
            if (!File.Exists(path))
            {
                KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Debug, string.Format("File not found. {0} ", path));
                return(false);
            }
            this.Stop();
            bool result;

            using (BinaryReader binaryReader = new BinaryReader(File.OpenRead(path)))
            {
                VMDFormat format = VMDLoader.Load(binaryReader, path, "VMDCameraAnim");
                KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Debug, string.Format("VMD file loaded {0}:", path));
                this._cameraVMDFilePath = path;
                AnimationClip animationClip = new VMDHSConverter(dictionary, this._scaleBase * this.modelScale).CreateCameraAnimationClip(format, base.gameObject, 4);
                KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Debug, string.Format("Converted as an animation clip", animationClip));
                KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Debug, string.Format("Set to animation ", this.cameraAnimation));
                animationClip.name = "VMDCameraAnim";
                this.cameraAnimation.AddClip(animationClip, "VMDCameraAnim");
                this.cameraAnimation.clip = animationClip;
                AnimationState animationState = this.cameraAnimation["VMDCameraAnim"];
                KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Debug, string.Format("Found animation info {0}", animationState));
                animationState.speed    = this._speed;
                animationState.wrapMode = (this._loop ? (WrapMode)2 : (WrapMode)1);
                result = true;
            }
            return(result);
        }
Exemple #2
0
        public static BoneAdjustment Init(string boneName, string axisSpec, Vector3 rotAdjustment, bool rotAxisAdjustment)
        {
            BoneAdjustment boneAdjustment = new BoneAdjustment();

            boneAdjustment.boneName = boneName;
            boneAdjustment.SetSpec(axisSpec);
            boneAdjustment.SetRotAdjustment(rotAdjustment);
            boneAdjustment.rotAxisAdjustment = rotAxisAdjustment;
            return(boneAdjustment);
        }
        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)
     {
     }
 }