Beispiel #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);
        }
        private int GetKeyframeCount(List <VMDFormat.Motion> mlist, int type, int interpolationQuality)
        {
            int num = 0;

            for (int i = 0; i < mlist.Count; i++)
            {
                if (i > 0 && !VMDHSConverter.IsLinear(mlist[i].interpolation, type))
                {
                    num += interpolationQuality;
                }
                else
                {
                    num++;
                }
            }
            return(num);
        }
            public static void AddBezierKeyframes(byte[] interpolation, int type, VMDHSConverter.FloatKeyframe prev_keyframe, VMDHSConverter.FloatKeyframe cur_keyframe, int interpolationQuality, ref List <VMDHSConverter.FloatKeyframe> keyframes, ref int index)
            {
                if (prev_keyframe == null || VMDHSConverter.IsLinear(interpolation, type))
                {
                    keyframes.Add(cur_keyframe);
                    index = keyframes.Count <VMDHSConverter.FloatKeyframe>();
                    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);
                    keyframes.Add(VMDHSConverter.FloatKeyframe.Lerp(prev_keyframe, cur_keyframe, t2));
                    index = keyframes.Count <VMDHSConverter.FloatKeyframe>();
                }
            }
            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);
                }
            }